Skip to content

Instantly share code, notes, and snippets.

@0x5742
0x5742 / hg-connect.sh
Created July 19, 2015 12:00
mercurial: connecting two related repositories
# This is how to fix things if you somehow manage to end up with two
# repositories for the same project, where the last changeset in the
# old repo should be the parent of the first changeset in the new one.
# I needed to do this for Schism Tracker at one point. No idea how I
# mangled it, but here's what I did.
# (A tip of the hat owed to #mercurial on Freenode for helping me.)
# FOREWARNING: this will alter all the changeset IDs in the new repo!
newid=$(hg -R newrepo log -r0 --template '{node}')
@0x5742
0x5742 / airclick.py
Created July 8, 2015 17:43
quick-and-dirty interface for the Griffin AirClick RF remote
#!/usr/bin/env python
import struct, os, subprocess
"""
030200?? - buttons that are currently down
01 play/pause
02 increase volume
04 decrease volume
08 next
@0x5742
0x5742 / twitter-show-usernames.css
Created July 2, 2015 17:12
(User stylesheet) Twitter: show @usernames instead of display names
@namespace url(http://www.w3.org/1999/xhtml);
/* (CC-BY) Storlek - https://twitter.com/SwedishForSize
Drop this into Stylish or similar. */
@-moz-document domain("twitter.com") {
.context .pretty-link,
.social-context .pretty-link,
.stream-item-activity-line-notification .pretty-link {
@0x5742
0x5742 / wget.sh
Created June 28, 2015 22:24
a wget-ish thing with bash sockets
#!/bin/bash
die() {
echo "usage: $0 [http://]somehost[:port][/blah/blah]" >&2
echo " or $0 somehost [port] /blah/blah" >&2
exit 1
}
case "$#" in
1)
@0x5742
0x5742 / lex.py
Created June 16, 2015 19:18
lightweight regex lexer
import re
tokenizer = re.compile(r"""
(?P<string> " (?: [^\\"] | \\. )* " ) |
(?P<number> 0[Xx][0-9A-Fa-f]+ | [0-9]+ ) |
(?P<comment> \# .*? (?= \n | $ ) ) |
(?P<ident> [A-Za-z_] [A-Za-z0-9_]* ) |
(?P<paren> [()] ) |
(?P<brace> [{}] ) |
(?P<bracket> [][] ) |
@0x5742
0x5742 / shellcode.py
Created June 16, 2015 19:16
run shellcode using python ctypes
m = b'black magic'
x = b'\x31\xc0\x40\xc3' # payload: xor eax, eax; inc eax; ret (x86)
from ctypes import *
p = string_at(id(m), 64).index(m)
CDLL(None)._FuncPtr(id(x) + p)()
@0x5742
0x5742 / rename.c
Created June 13, 2015 22:13
a cheap substitute for util-linux rename
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int n, diff, fromlen, tolen, leftlen;
const char *name, *from, *to, *pos;
char *buf;
@0x5742
0x5742 / namedparams.c
Created June 10, 2015 21:53
Named parameters in C
/* This is a way to make a function with named parameters in standard C99.
Most typical programmer errors (parameter typo, etc.) produce at least
somewhat reasonable compiler messages.
Unlike some other methods of doing this, this supports default parameters
which can be defined to any value, and does not require any cumbersome
syntax such as casts or struct accessors when calling the function.
Originally posted on 4chan /prog/.
@0x5742
0x5742 / osswave.py
Last active August 29, 2015 14:22
Drop-in replacement for ossaudiodev that writes its output to a .wav file.
#!/usr/bin/python
import wave
FILENAME = 'tmp.wav'
AFMT_S16_NE = 16
AFMT_S16_LE = 16
AFMT_U8 = 8
@0x5742
0x5742 / noise.py
Created June 10, 2015 21:03
make some noise
#!/usr/bin/python
# (works on both 2.x and 3.x)
import math
import struct
import sys
import ossaudiodev as oss
SAMPLE_RATE = 48000