Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / Main.java
Created January 15, 2014 17:53
polymorphism
public class Main {
// which method does it invoke?
public static void main(String[] args) {
Object o = "this is a string";
asLong(o);
}
public static void asLong(String s) {
System.out.println("string");
@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 / jq-select-by-length.sh-session
Created June 18, 2014 16:24
jq - select objects based on lengths of arrays
# objects with at least one widget and at least one user
$ cat part-r-00000 | jq 'select((.widgets | length) > 0 and (.users | length) > 0)'
@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 / 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
@jimjh
jimjh / _vault
Last active November 2, 2015 21:58
zsh autocompletion for vault's subcommands
#compdef vault
# See https://vaultproject.io/
# Drop this file in ~/.oh-my-zsh/completions/_vault
subcommands=$(vault --help 2|& grep -E '^\s{4}' | awk '{printf $1; $1=""; print "\\:\x27"$0"\x27"}')
_arguments "1:subcommand:((${subcommands}))"
_message 'vault [-version] [-help] <command> [args]'
@jimjh
jimjh / child.sh
Created November 13, 2015 23:42
Using $@ vs $*
#!/bin/bash
# child.sh
# Prints all args.
while (( "$#" )); do
echo "arg: $1"
shift
done
@jimjh
jimjh / libgit2-fpm.sh
Last active December 29, 2015 19:41
libgit2-fpm.sh
#!/bin/bash
# cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr --build .
# make
# make install DESTDIR=~/tmpinstalldir
fpm -f \
-s dir \
-t deb \
-n libgit2 \
-v 0.23.4ppa1 \
-C ~/tmpinstalldir \