Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / level0.rb
Created February 23, 2014 22:27
Stripe CTF 2014, Level 0
#!/usr/bin/env ruby
# Our test cases will always use the same dictionary file (with SHA1
# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
# will automatically download this dictionary for you if you don't
# have it already.
path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
entries = File.read(path).split("\n")
@jimjh
jimjh / level0.sh
Created February 23, 2014 22:32
level0-java
#!/bin/bash
exec java \
-server \
-Djava.awt.headless=true \
-Xms256M \
-XX:CompileThreshold=1400 \
-Xloggc:./memory.log -verbose:gc -XX:+PrintGCDetails \
-cp out \
jim.SpellCheck \
$@
@jimjh
jimjh / basic_example.py
Created January 4, 2015 05:57
Basic Python Logging
import logging
def do_work():
logging.debug("x")
if __name__ == '__main__':
# Register STDOUT as a log handler.
# There are other ways to register handlers, but this is the simplest way.
# See https://docs.python.org/2/library/logging.html#logging.basicConfig
@jimjh
jimjh / do-stuff.sh
Last active August 29, 2015 14:26
script template
#!/usr/bin/env bash
# Usage:
# Without trace, just run `./do-stuff.sh`
# With trace, use `BASH_XTRACEFD=3 ./do-stuff 3> trace.txt`
# Requires bash 4.+
set -o pipefail
set -o nounset
set -o errexit
if [[ ${BASH_XTRACEFD:+x} ]]; then
@jimjh
jimjh / truecrypt_fix.bash
Created October 14, 2012 14:24
brew doctor and truecrypt
#!/bin/bash
libs=( "/usr/local/lib/libmacfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i64.2.dylib" \
"/usr/local/lib/libmacfuse_i64.2.dylib" \
"/usr/local/lib/libosxfuse_i32.la" \
"/usr/local/lib/libosxfuse_i64.la" \
"/usr/local/lib/pkgconfig/osxfuse.pc" )
@jimjh
jimjh / padding.go
Created November 4, 2012 14:56
Padding with sprintf
package main
import "fmt"
func main() {
// make sure that printf pads digits with zeros so we can sort the strings
// without converting to them back to ints
fmt.Printf("%010d\n", 1)
@jimjh
jimjh / crash_recover.go
Created November 27, 2012 04:23
Experiments with pagecache-centric logging and recovery in Go.
package main
// crash_recover.go experiments with recovering from a file that suddenly
// crashed (files are written without sync or close.)
import (
"encoding/binary"
"fmt"
"math/rand"
"os"
@jimjh
jimjh / parallel_rw.go
Created November 27, 2012 03:43
Experiments with parallel read/write in Go without file.Sync or file.Close
package main
// parallel_rw.go experiments with parallel read/write from a file without
// syncing (aka flushing) or closing.
import (
"encoding/binary"
"fmt"
// "math/rand"
"os"
@jimjh
jimjh / flushing_test.go
Created November 27, 2012 05:06
Benchmarks with 10% syncs versus no syncs.
package flushing
import (
"encoding/binary"
"fmt"
"math/rand"
"os"
"testing"
)
@jimjh
jimjh / pool.py
Created October 29, 2015 23:42
sharing state
def x():
# using a function as a convenient global object
print 'hello!'
x.favorite_band = 'Maroon 5'
def went_to_music_festival(s):
print 'favorite band was ' + x.favorite_band