Skip to content

Instantly share code, notes, and snippets.

@johntrimble
johntrimble / gist:1954826
Created March 2, 2012 01:48
Wrapping functions in Java sucks.
public <A,B> Function<Function<A,B>, Function<A,B>> requiresTx() {
return new Function<Function<A,B>, Function<A,B>>() {
@Override
public Function<A,B> apply(final Function<A,B> f) {
return new Function<A,B>() {
public B apply(final A a) {
return txService.required(new Callable<B>() {
public B call() throws Exception {
return f.apply(a);
};
@johntrimble
johntrimble / generate-ubuntu-ami-mapping.py
Created June 21, 2012 00:13
Python script for generating a mapping of regions to the latest AMI for a given Ubuntu distribution and instance type for use in CloudFormation template.
#!/usr/bin/env python
import urllib2
import json
import itertools
import sys
import argparse
def groupby(data, key):
kf = lambda x: x[key]
result = itertools.groupby(sorted(data,None,kf), kf)
@johntrimble
johntrimble / useful-git-commands.md
Last active January 3, 2016 03:49
These are useful Git commands I keep forgetting.

Listing branches by most recent commit:

git for-each-ref --sort=-committerdate refs/heads/

Listing branches not yet merged:

git branch --no-merged <BRANCH_NAME>
@johntrimble
johntrimble / install-sixaxis.sh
Last active August 9, 2018 14:21
PS3 DualShock 3 controller on the Raspberry Pi
#!/bin/sh
#############################################################################
# This script installs the sixad driver for the Sixaxis PS3 Controller on a
# fresh install of the official Raspbian image (2014-01-07) for the Raspberry
# Pi.
#
# Setup:
# Attach a compatible Bluetooth adapter to the Pi. You can find a list of
# compatible adapters at <http://elinux.org/RPi_USB_Bluetooth_adapters>. I
# use the Sabrent BT-USBT and it works fine.
@johntrimble
johntrimble / RESULTS.md
Last active August 29, 2015 13:56
ClojureScript Collections Performance

Using V8, I got the following results when compiling performance.cljs with advanced mode:

[data array-data], (js/sumXsAndYsJs data), 1000 runs, 41 msecs
[data array-data], (sumsXsAndYsWithDotimesOnArrayNativeFieldAccessAndMutableLocals data), 1000 runs, 114 msecs
[data array-data-records], (sumsXsAndYsWithDotimesOnArrayNativeFieldAccessAndMutableLocals data), 1000 runs, 124 msecs
[data vec-data-records], (sumsXsAndYsWithDotimesNativeFieldAccessAndMutableLocals data), 1000 runs, 362 msecs
[data vec-data-records], (sumXsAndYsWithLoopAndNativeFieldAccess data), 1000 runs, 1115 msecs
[data vec-data-records], (sumXsAndYsWithLoop data), 1000 runs, 2065 msecs
[data vec-data-array-map], (sumXsAndYsWithLoop data), 1000 runs, 2530 msecs