cURL Cheatsheet

Nice things you can do with cURL # Resolve a hostname with a given ip curl http://iix.se --resolve iix.se:80:206.189.18.126 # Run many queries in a loop (either for looping or load testing) curl 'http://localhost:8080/oauth/login?[1-10]' -d '{ "username": "[email protected]", "password": "secret" }' -vvv -H "Content-Type: application/json" # Light load testing an endpoint (Z=parallell, -s/-o removes output, -w sets new output) curl -Z -so /dev/null -w "%{time_total} %{http_code}\n" 'https://acme.system.com/api/endpoint?[1-20]'

May 25, 2020  |  🏷️Curl

A Hugo homepage workflow

Hugo is a framework for building static webpages. It pairs well with creating a git repository and creating a push-webhook which rebuilds the homepage every time you change it. This post is just documenting how to do just that for an existing hugo repository. Create a static repo with nginx pointing to it Clone a hugo repo and put it in /srv/hugo.iix.se Pop over to the folder and run hugo to generate a static page chown -R nginx:nginx /srv/hugo.iix.se Create a nginx vhost with location / { root /srv/hugo.iix.se/public } systemctl nginx reload Check that the page works Create an endpoint for updating This can be be done in a number of ways, but an easy way is creating a fastcgi endpoint in nginx, since we got that running already. ...

Iptables Cheatsheet

Various stuff I forget how I do it. View iptables # View iptables sudo iptables -nvL Add/Remove/Replace # Add a rule iptables -A INPUT -p tcp --dport 80 -j ACCEPT # Append to end of chain iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT # Insert at position 1 in chain # Delete a rule iptables -D INPUT 5 # 5 is index 5 in the INPUT-chain # Replace a rule iptables -R INPUT 1 -p tcp -s 192.168.0.0/24 --dport 80 -j ACCEPT # Replace rule at index 1 Persisting Generally, tables are saved in ...

Optimizing MySQL Queries et. Indexes

Things I have learned from troubleshooting mySQL queries Links Index och prestanda i MySQL Join types (from explain) MySQL Profiling Commands # Run query without cache SELECT SQL_NO_CACHE * from users where name like 'Ol%'; # Profiling SET SESSION profiling = 1; SHOW PROFILES; SHOW PROFILE FOR QUERY 3; SHOW STATUS LIKE 'Last_Query_Cost'; How to index/optimize Optimize OR Example: SELECT * FROM users where customerNumber='qwe' OR birthDate='2020-01-01'; You need an index for each OR, which will create a merge index on modern innoDB. If you are missing an index for one OR you will have to do a full table scan. Basically, one condition can ruin the query. If you create a joined index on (customerNumber, birthDate) or (birthDate, customerNumber) they will have not effect. To use a joined index you have to do two solo queries and UNION them. ...

May 24, 2020  | 

Guitar pedals - What to buy

Pedals I wont buy Hungry Robot - Wardenclyffe Chase Bliss & Cooper - Generation Loss Pedals I might buy Behringer TO800 Vintage Tube Overdrive - 270 SEK Extra stuff 0.15m Patch Angled Jack - 25 SEK

March 18, 2020  | 

Remove subfolder from all git history

# Remove DIRECTORY_NAME from all commits, then remove the refs to the old commits # (repeat these two commands for as many directories that you want to remove) git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY_NAME/' --prune-empty --tag-name-filter cat -- --all git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d # Ensure all old refs are fully removed rm -Rf .git/logs .git/refs/original # Perform a garbage collection to remove commits with no refs git gc --prune=all --aggressive

February 27, 2020  |  🏷️Git

Dexed patches I like

Cartridge collections: Dexed_cart_1.0.zip Patches !Instruments > Misc > 2003.SYX > Brass&REV7: Punchy brass with slight echo !Instruments > Misc > DECKARD.SYX > SYNTHI 1-5: Versatile dark lead bass

February 19, 2020  |  🏷️Music

Heroes of Might and Magic VI does not start (black screen)

What I expected After installing Heroes of Might and Magic VI and then starting it through Steam, the game should enter the main menu. What I got The game screen is only black and never enters the main menu. How I solved it Go to My Documents > Heroes of Might and Magic VI. Open ProfileData with your favorite text editor Replace <gfx_Fullscreen2>Fullscreen</gfx_Fullscreen2> with <gfx_Fullscreen2>Windowed</gfx_Fullscreen2> Start game. Game will be in windowed mode, but it’s better than nothing ...

Kubernetes + GCloud + Kind Cheatsheet

Kubernetes + GCloud + Kind Cheatsheet Links Official Kubernetes Cheatsheet Kubectl Bash autocomplete source <(kubectl completion bash) Context - easy way of changing namespaces Contexts are saved to $HOME/.kube/config, so you can edit that file manually if you mess up. # One-time-only - create context kubectl config set-context iix --namespace=iix --user=kubernetes-admin --cluster=kubernetes # Later - use context kubectl config use-context iix Listing # List all images in the active namespace kubectl -n dev get pods -o jsonpath="{.items[*].spec.containers[*].image}" |tr -s '[[:space:]]' '\n' Modify existing daemonset kubectl get ds fluentd-gcp-v2.0 --namespace kube-system -o yaml > fluentd-gcp-ds.yaml # Replace stuff in fluentd-gcp-ds.yaml kubectl replace -f fluentd-gcp-ds.yaml Modify existing configmap Updating ConfigMap in the apiserver is more complicated than updating DaemonSet. It’s better to consider ConfigMap to be immutable. Then, in order to update the configuration, you should create ConfigMap with a new name and then change DaemonSet to point to it. ...

Using black or white text depending on background color

One problem which I encounter time and time again when creating a webpage or applications is matching text color with a changing background color. When creating a GUI you usually create a lot of white boxes with a black text on it, just to get sizes and stuff matching. Then later a designer or customer decides on a theme which affects how that box looks. Most of the time the background and text colors are hand-selected so they match well enough, but from time to time you have to create a box which can change background color on demand, and then you have to have the text color matching to make the box readable. I have done too many slightly different solutions to this problem, so I thought I would write something down here. Since most of the time, text colors are off-white and off-black, the formula should be tweakable to match any given hue. ...

May 11, 2019  |