Skip to content

Instantly share code, notes, and snippets.

samthor /
Created May 30, 2012
Handler-compatible AsyncHandler which runs tasks on some other thread
package foo;
import android.os.Handler;
import android.os.HandlerThread;
* Subclass of {@link Handler} that does things on some background thread.
* @author Sam Thorogood (
samthor / broadcast.go
Created Jan 28, 2013
CastGroup, something that lets listeners subscribe to broadcast events. Built for the garage door; will be used to support hanging GETs on some event.
View broadcast.go
package main
import (
func main() {
c := NewCastGroup()
samthor /
Last active Jul 28, 2018
Shell interface to Closure compiler (in Python)
#!/usr/bin/env python
import json
import sys
try: # Py3
from urllib.parse import urlencode
from urllib.request import urlopen
from urllib.request import Request
except ImportError: # Py2
samthor /
Last active Aug 29, 2015
tool for merging git upstream
git status 1>/dev/null || exit 1
git fetch upstream
if [ "$?" != "0" ]; then
echo >&2
echo "fatal: no upstream remote configured" >&2
ORIGIN=$(git remote -v | grep ^origin | cut -f2 | cut -f1 -d' ' | head -n 1)
samthor / nano.c
Created Apr 12, 2015
nanosecond mtime to console
View nano.c
// nano.c: writes nanosecond mtime of first arg to console
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#define SEC_TO_NANO 1000000000
samthor /
Created Apr 13, 2015
library to run subprocesses in bash
# Library which causes a bash script to block until killed, shutting down its
# child processes when complete.
function _death {
echo "killing all subprocesses" 1>&2
pkill -P $$
exit 0 # still need to quit
trap _death SIGINT SIGTERM
samthor /
Last active Aug 29, 2015
renders svg or other images to mobile device sizes
#!/usr/bin/env python
import os
import sys
1: ['mdpi/', ''],
1.5: ['hdpi/'],
2: ['xxdpi/', '@2x'],
View validate-test.html
<!DOCTYPE html>
<link href=",300italic,400,400italic" rel="stylesheet" type="text/css" />
<style type="text/css">
.formrow {
min-height: 32px;
line-height: 40px;
samthor /
Created Jun 15, 2015
python counter helper
#!/usr/bin/env python3
import collections
class counterdict(collections.defaultdict):
def __init__(self):
collections.defaultdict.__init__(self, counterdict)
def __sub__(self, value):
"""Upgrade this counter to a number.
samthor / gulpfile.js
Created Jul 21, 2016
Minimal gulpfile for building JS
View gulpfile.js
* Copyright 2016 Google Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* Unless required by applicable law or agreed to in writing, software