Skip to content

Instantly share code, notes, and snippets.

View kousu's full-sized avatar

Nick Guenther kousu

  • Asymmetric Research
  • Canada
View GitHub Profile
def humanized_diff(L, delta):
"""
Convert the given (sorted!!) tabular diff to a string,
marked up with +s and -s, similar to regular diff(1)'s "-u" mode.
"""
D, A = delta
U, D = drop(L, D), [L[i] for i in D]
def prefix(v, S):
@kousu
kousu / lol.sh
Created July 12, 2014 01:02
nonblocking pipes with Popen
#!/bin/bash -e
i=0
while true; do
echo "yadda yadda ||$i||"
sleep 3;
i=$(($i+1))
done
#while true; do #HILARIOUS:
@kousu
kousu / f.sql
Created July 21, 2014 22:14
hacking postgres
-- 1) run postgres
-- 2) load this into it (if postgres wasn't compiled with python support, bad things will happen)
CREATE LANGUAGE plpython2u;
DROP FUNCTION IF EXISTS b();
CREATE FUNCTION b() RETURNS void AS $$
print "HATCH HATCH HATCH"
print plpy
@kousu
kousu / README
Created November 30, 2014 00:21
LG-P769: partial NAND dumps
This is a dump of the ASCII found in the bootloaders (plural!) on a T-Mobile branded LG-P769.
This phone is mostly just an Texas Instruments OMAP4430, which is a reasonably liberal system board.
The board has a microscopic 1st stage bootloader in ROM
x-loader is the tiny 2nd stage bootloader
u-boot is the standard ARM bootloader, which is a 3rd stage loader for this system, instead of being a 2nd stage like on most phones.
Each partition was dumped by
```
adb shell "su -c 'dd if=/dev/block/mmcblk0p$i of=/sdcard/mmcblk0p$i.img'"
adb shell pull /sdcard/mmcblk0p$i.img
@kousu
kousu / README
Last active May 13, 2016 10:40
Cs350 OS161 Install scripts
If you're on Archlinux you shouuuuld just be able to drop these two files in a dir by themselves, chmod +x them, and run "install.sh".
If you're on a different Unix you can probably adapt this without too much effort to your system, especially the part about .
If you're not in Winter 2015 you probably need to tweak update.sh.
Sorry for the poor documentation and poor testing! And also the almost complete lack of error handling!
Hopefully this helps someone else in the future! this represents 13 hours of my life!
Tip: make your empty dir a git repo so that then you can just do
```
git clean -df && git clean -xfd
@kousu
kousu / README
Last active August 29, 2015 14:14
partition plain text files by section marker for literate programming the way it should be done
...possibly python wins this one.
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http:#www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
@kousu
kousu / rdpvpn.sh
Created May 27, 2015 22:30
automagic VPNing into Windows machines, via ssh
#!/bin/sh
# automagic VPNing into Windows machines, via ssh
# this assumes the machine you're VPNing into also runs an ssh server, which admittedly is an unusual configuration (it could be stretched to not do this)
# we knock on the RDP port; if it doesn't respond, assume we're outside of the firewall, and construct a tunnel
#XXX -g workarea *does not work* with i3. Much sadness.
HOST=${HOST:=XXXXXXXXXXXXXXXXXXX}
PORT=${PORT:=3389}
@kousu
kousu / mpd.conf
Last active June 20, 2016 22:50
Local MPD.conf
# mpd config file
### XXX this has been manually hacked up to
# mpd (undocumentedly) checks $XDG_CONFIG_DIR/mpd/mpd.conf before ~/.mpdconf, before /etc/mpd.conf
# since it does that... why not the rest of the system eh?
# but this script doesn't understand environment vars of course, though it *will* expand ~/ to $HOME
# for some reason linux has decided that $XDG_RUNTIME_DIR should be on /run (/run/user/1000) which is annoying
# Files and directories #######################################################
@kousu
kousu / ircd
Created February 21, 2016 02:22
# #!/bin/sh
# unrealircd is designed to be VERY GOOD at staying alive
# which means it's very hard to kill
# ctrl-c'ing it doesn't kill it, but sometimes it restarts it
# instead, we background it and translate ctrl-c to a stronger signal, which it will listen to
#
CONF=$(mktemp ircd.conf.XXXXX)
LOG=$(mktemp ircd.log.XXXXXX)