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 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 / 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)
@kousu
kousu / mkcert
Created February 21, 2016 06:52
openssl sucks
#!/bin/sh
#
# generates a self-signed CA and certificates signed by that CA.
# If you install the CA into your certificate stores (in Firefox: Prefs->Advanced->Certs->Import, in Gnome: open the .crt in and whose .crt,.key pair can be used
# worked out with http://www.akadia.com/services/ssh_test_certificate.html and trial and error
# (as usual, with OpenSSL)
# Usage:
# ./mkcert # and follow the prompts, to make a CA
# ./mkcert my.domain.name
#!/bin/sh
# this wraps an arbitrary program in dmenu
# usage: dmenu_do "<dmenu arguments>" -- "<command>"
# dmenu will run with no options, and if the user gives input, <command> will be run with input as trailing arguments
# #
# Example: dmenu_do "-p \"Web Search:\"" -- "sr duckduckgo -j"
# becomes sr duckduckgo -j `dmenu -p "Web Search:"`, except it only runs if dmenu succeeds
#
# This is not a perfect wrapper:
# ideally the API would be: dmenu_do [dmenu args] -- command [args]