Skip to content

Instantly share code, notes, and snippets.

View wknapik's full-sized avatar

Wojciech Knapik wknapik

View GitHub Profile
@wknapik
wknapik / README
Last active January 28, 2019 14:54
Lenovo Thinkpad P50, dock with external monitor, udev + xrandr auto switching
This switches between the laptop monitor ($intern) when undocked and a two monitor setup when docked ($extern right of $intern).
ENV{ID_VENDOR_ID}, ENV{ID_MODEL_ID}, x_user and intern need to be set.
Based on the Arch wiki, StackExchange and Google.
@wknapik
wknapik / cmd
Last active September 2, 2017 15:44
Set transmission (not transmission-gtk) as default torrent handler
# General.
xdg-mime default transmission.desktop x-scheme-handler/magnet
xdg-mime default transmission.desktop application/x-bittorrent
# GNOME.
gconftool-2 -t string -s /desktop/gnome/url-handlers/magnet/command "/usr/bin/transmission-remote -a '%s'"
gconftool-2 -t bool -s /desktop/gnome/url-handlers/magnet/needs_terminal false
gconftool-2 -t bool -s /desktop/gnome/url-handlers/magnet/enabled true
# https://wiki.archlinux.org/index.php/default_applications
@wknapik
wknapik / drawioxml2html.sh
Last active December 29, 2017 13:56
draw.io xml to html
#!/usr/bin/env bash
# USAGE: drawioxml2html.sh diagram.xml >diagram.html
# html encoding from https://stackoverflow.com/questions/12873682/#answer-12873723
diag="$(sed 's,.*<\(diagram [^>]*\)>\(.*\)<\(/diagram\)>.*,\1FOO\2BAR\3,g' <"$1"|\
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'|\
sed 's/&/\\&/g; s/FOO/\&gt;/; s/BAR/\&lt;/')"
@wknapik
wknapik / main.yml
Created November 3, 2017 12:04
Set up a tunnel to tiller to use with the ansible helm module
- set_fact:
tun_pid_file: ...
- name: set up a tunnel to tiller
shell: |
tiller_pod="$(kubectl get pod -l app=helm,name=tiller --namespace kube-system -o name|cut -d/ -f2)"
nohup kubectl port-forward "$tiller_pod" 44134:44134 --namespace kube-system </dev/null >/dev/null 2>&1 &
echo "$!" >{{ tun_pid_file|quote }}
creates: "{{ tun_pid_file }}"
@wknapik
wknapik / index.elm
Created May 13, 2018 17:32
List.sortBy produces different order between Chromium/Chrome and Firefox
module Main exposing (..)
import Html exposing (div, text)
import List
import Tuple
main =
Html.beginnerProgram { model = [], view = view, update = (\_ -> \x -> x) }
@wknapik
wknapik / foo.yml
Last active March 20, 2019 12:09
Delete aws secretsmanager secrets by name prefix (ansible, bash)
- set_fact:
prefix: foo/bar
- name: delete aws secretsmanager secrets by name prefix
shell: |
set -eo pipefail
shopt -s inherit_errexit 2>/dev/null || true
declare -a opt page_secrets secrets
while [[ "$next_token" != null ]]; do
read -ra opt <<<"${next_token:+--next-token "$next_token"}"
@wknapik
wknapik / example.md
Last active July 10, 2018 11:43
GitHub markdown collapsible/expandable sections

GitHub markdown collapsible/expandable sections

foo
bar
@wknapik
wknapik / README
Created October 25, 2018 19:38
Protect a process and its descendants from the oom killer
./oom-protector.sh <executable> <options>
@wknapik
wknapik / README
Last active April 23, 2020 06:13
Wait for kubernetes deployments to complete
Wait for kubernetes deployments to complete.
Two variants - s1.sh and s2.sh.
Usage:
./sX.sh
./sX.sh some-namespace
Both variants make just one pass through the list of deployments, so if another
deployment is started while the script is running, the result may not be
correct.
@wknapik
wknapik / README
Last active April 6, 2019 12:42
Generate a mapping of AWS regions and availability zones for use in cloudformation
Generate a mapping of AWS regions and availability zones for use in cloudformation