This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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]) |