Skip to content

Instantly share code, notes, and snippets.

View joshbode's full-sized avatar
💽

Josh Bode joshbode

💽
  • Melbourne, Victoria, Australia
View GitHub Profile
@joshbode
joshbode / gist:6423988
Last active December 22, 2015 05:28
XeLaTeX Example
\documentclass{article}
% font setup
\usepackage{ifxetex}
\ifxetex
\usepackage[log-declarations=false]{xparse}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Arial Unicode MS}
\else
\usepackage[utf8]{inputenc}
@joshbode
joshbode / gist:6822121
Created October 4, 2013 07:15
Mixo-Fixo: Typo and casual reverse-engineering tolerant inefficient string-token encoding method. Features: - changing a single character in the input changes many characters in the output - valid token-space is very sparse
"""
Mixo-Fixo: Typo and casual reverse-eingineering tolerant, inefficient string-token encoding method.
"""
def chunks(l, n):
""" Yield successive n-sized chunks from l."""
for i in xrange(0, len(l), n):
yield l[i:i+n]
@joshbode
joshbode / Info.plist
Created October 4, 2013 08:51
Custom USB Device ID for RAVEn USB Smart Meter Device. FTDI plist (/System/Library/Extensions/FTDIUSBSerialDriver.kext/Contents/Info.plist)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- SNIP -->
<key>IOKitPersonalities</key>
<dict>
<!-- SNIP -->
<key>RFA-Z106-RA-PC RAVEn</key>
<dict>
@joshbode
joshbode / gist:9543330
Last active August 29, 2015 13:57
String template class with Oracle/SAS-style substitution rules.
from string import Template
class OracleTemplate(string.Template):
"""Substitution variables, ala Oracle SQL*Plus"""
pattern = r"""
&(?:
(?P<escaped>&) |
(?P<braced>[_a-z0-9]+)\. |
(?P<named>[_a-z0-9]+) |
#!/usr/bin/env python
import signal
class InterruptableRegion(object):
def __init__(self, sig=signal.SIGINT):
self.sigs = list(sig) if isinstance(sig, (list, tuple)) else [sig]
@joshbode
joshbode / ffi_test.c
Created April 5, 2014 13:24
Test FFI on Python
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ffi_test.h"
const char greeting_format[] = "%s, %s, you old %s, you!";
/* get species name */
@joshbode
joshbode / nullable.r
Last active August 29, 2015 14:01
Nullable Reference Class fields in R
#' Create a nullable class field for a reference class.
#'
#' @param name name of class.
#' @examples \dontrun{
#' Foo = setRefClass('Foo', fields=c(a=nullable('list'), b='character'))
#' x = Foo$new(a=list(1,2,3), y="Non-NULL 'a'")
#' y = Foo$new(a=NULL, y="NULL 'a'")
#' }
nullable = function(name) {
union_name = paste(name, 'NULL', sep='_')
@joshbode
joshbode / keg
Last active August 29, 2015 14:01
Get access to keg-only commands from homebrew
#!/usr/bin/env python
import sys
import os
import os.path
import json
import signal
import subprocess
# process arguments
@joshbode
joshbode / gist:243a4ae33281cf4e8409
Last active August 29, 2015 14:01
R Reference Classes - Simple Class Factory
A = setRefClass("A",
methods=list(
hello=identity,
process=function(x) {-x}
)
)
B = setRefClass("B",
contains='A',
methods=list(
process=function(x) {
@joshbode
joshbode / unlock.py
Last active August 29, 2015 14:02
Super-Optimistic Disk Image Password-Guesser: ./unlock.py foo.dmg 6
#!/usr/bin/env python
import sys, time, string, logging, itertools, subprocess, multiprocessing
hdiutil_opts = [
'-quiet', '-readonly', '-stdinpass', '-nomount', '-noverify', '-noautofsck', '-noidme', '-noautoopen'
]
def mount(image, queue):
"""Worker to attempt to mount the image. Return if successful or poisoned."""