Skip to content

Instantly share code, notes, and snippets.

View shift's full-sized avatar

Vincent Palmer shift

View GitHub Profile
@jbott
jbott / install.sh
Last active August 22, 2023 19:09 — forked from mx00s/install.sh
NixOS install script based on @grahamc's "Erase Your Darlings" blog post
#!/usr/bin/env bash
#
# NixOS install script synthesized from:
#
# - Erase Your Darlings (https://grahamc.com/blog/erase-your-darlings)
# - ZFS Datasets for NixOS (https://grahamc.com/blog/nixos-on-zfs)
# - NixOS Manual (https://nixos.org/nixos/manual/)
# - Original gist by @nuxeh (https://gist.github.com/nuxeh/35fb0eca2af4b305052ca11fe2521159)
#
@sylr
sylr / postgres-9.5-sharding.sh
Last active June 11, 2019 21:23
Postgresql 9.5 sharding example
echo master shard_{0,1,2,3} | xargs -n1 /usr/local/bin/dropdb -p 6432 -h /tmp -U postgres
echo master shard_{0,1,2,3} | xargs -n1 /usr/local/bin/createdb -p 6432 -h /tmp -U postgres
for a in {0..3}; do
echo "
CREATE TABLE users (id serial PRIMARY KEY, username TEXT NOT NULL);
ALTER SEQUENCE users_id_seq INCREMENT BY 4 RESTART WITH $a;
" | /usr/local/bin/psql -p 6432 -h /tmp -U postgres -d shard_$a;
done
@lost-theory
lost-theory / netstat-2015.md
Last active September 10, 2018 11:25
netstat on all machines -> python -> graphviz -> png
$ knife ssh -m "...every host in the network..." "sudo netstat -nutap" -a hostname > meganetstat.txt
$ python
>>> from collections import Counter as C
>>> HS = "...every host in the network...".split()
>>> ip = lambda s: s.split(":")[0]
>>> xs = [map(ip, [x[0], x[4], x[5]]) for x in [x.strip().split() for x in open("meganetstat.txt").readlines() if "tcp" in x] if len(x)>=6]
>>> ipmap = [(h, C([x[1] for x in xs if x[0] == h])) for h in HS]
>>> ipmapx = dict([(sorted([(x,y) for (x,y) in ip[1].items() if x.startswith("10.")], key=lambda t: -t[1])[0][0], ip[0]) for ip in ipmap])
>>> sorted(C(map(ipmapx.get, [x[2] for x in xs if x[2].startswith("10.")])).items(), key=lambda t: t[1])