Skip to content

Instantly share code, notes, and snippets.

View jonspeicher's full-sized avatar

Jon Speicher jonspeicher

View GitHub Profile
@jonspeicher
jonspeicher / resample.py
Created October 28, 2010 05:53
Read Cartesian points from a CSV and resample at a regular interval with linear interpolation.
#!/usr/bin/env python
import bisect, sys
def point(entry):
return tuple([float(value) for value in entry.split(',')])[0:2]
def normalize(value, max_value):
return value * (1.0 / max_value)
@jonspeicher
jonspeicher / trigraph.c
Created August 19, 2010 06:02
Enjoy some late-night obfuscation.
??=include <stdio.h> /??/
*int (func_p)(); *??/
/ int y = 0xDE;
??=define p(i) ??/
printf("%x\n", i); // ??\
??=define p(i) func_p (*bar)(i)??/
??=define p(i) prinf("\n%y\n", bar);
??=define l(y, func_p) (y << (func_p * 8))
int main(int a, char* v??(??)) ??<
int i = ??-(l(0x21, 3) ??! l(0x52, 2) ??! l(0x41, 1) ??! 0x10); p(i); ??>
@jonspeicher
jonspeicher / gist:375361
Created April 22, 2010 15:17
Recursively perform multiline regex substitution in files matching a spec.
#!/usr/bin/env python
import re, os
SEARCH_PATTERN = '^(\s*)\/>\s*<Platform\s*Name=\"WexEVM \(ARMV4I\)\"\s*\/>\s*$'
REPLACE_PATTERN = r'\1/>'
pattern = re.compile(SEARCH_PATTERN, re.MULTILINE)
for (dirpath, dirnames, filenames) in os.walk('.'):
@jonspeicher
jonspeicher / gist:285486
Created January 24, 2010 22:30
Add colored status to your bash prompt while in a Mercurial repo.
# Define a few colors for later use. The escaped brackets tell bash that they
# are non-printable and keep word-wrapping sane.
TXT_RED='\['`tput setaf 1`'\]'
TXT_GREEN='\['`tput setaf 2`'\]'
TXT_RESET='\['`tput sgr0`'\]'
# Build a prompt decorator if we're in a hg repo. The branch name is included
# in green if the branch is default, red otherwise. A symbol appears if the
# working directory is not clean. This uses Steve Losh's excellent hg-prompt
@jonspeicher
jonspeicher / gist:279815
Created January 18, 2010 05:56
Add colored status to your bash prompt while in a git repo.
# Define a few colors for later use. The escaped brackets tell bash that they
# are non-printable and keep word-wrapping sane.
TXT_RED='\['`tput setaf 1`'\]'
TXT_GREEN='\['`tput setaf 2`'\]'
TXT_RESET='\['`tput sgr0`'\]'
# Build a prompt decorator if we're in a git repo. The branch name is included
# in green if the branch is master, red otherwise. An asterisk appears if the
# working directory is not clean.