Skip to content

Instantly share code, notes, and snippets.

@swdunlop
swdunlop / array2d.go
Created January 8, 2011 09:03
2d array of variable size
package main
import "fmt"
func main() {
m, n := 3, 3
a := make( [][]int, m )
for i, _ := range a {
a[i] = make( []int, n )
}
@swdunlop
swdunlop / mp3collect.go
Created January 31, 2011 23:29
a simple utility to hardlink mp3 files to a hash of their non-ID3 contents
package main
import "io"
import "os"
import "fmt"
import "encoding/hex"
import "crypto/sha256"
import "path"
import "strings"
@swdunlop
swdunlop / get-url-methods.py
Created April 13, 2011 02:28
A five line AndBug script that lists the methods associated with java.net.URL in an Android process (via adb forward).
from andbug.process import Process
p = Process()
p.connect(9012)
for m in p.classes(cn).methods(name='Ljava/net/URL;'):
print m.name, m.jni
@swdunlop
swdunlop / wall.coffee
Created June 22, 2011 19:25
A Coffeescript Message Wall With Long Poll Properties in Node.JS and Express
# our application server
app = require('express').createServer()
app.msgs = [] # a history of posted messages
app.defers = [] # a list of deferred responses
# / redirects to /q
app.get '/', (req, res) =>
res.redirect('/q')
# /q[/<xxx>] query messages from the wall; may block for a protracted period
@swdunlop
swdunlop / navi.coffee
Created July 4, 2011 00:17
Sample of some CoffeeScript from AndBug's Navi utility
layout_local = (k, v) ->
$('<div class="local">k = v</div>').text("#{k} = #{v}")
layout_frame = (f) ->
div = $('<div class="frame"></div>')
div.append($('<h3></h3>').text("Frame: " + f[0]))
div.addClass('native') if f[2]
div.append(layout_local l[0], l[1]) for l in f[2..]
div.hide()
return div
@swdunlop
swdunlop / xant
Created November 4, 2011 19:26
Runs Apache's ANT, suppressing all errors except compile output. For use with XCode 4
#!/usr/bin/env python
import sys
import re
import subprocess
RULES = [
#'[javac] foo.java:6: cannot find symbol'
[r'^ *\[javac\] ([^:]+:[^:]):(.*)$', '{0}: {1}'],
]
@swdunlop
swdunlop / scandump.go
Created December 4, 2012 18:44
Dumps Go text/scanner tokens to stdout as JSON
package main
import (
"encoding/json"
"os"
"text/scanner"
)
type Token struct {
Position scanner.Position `json:"pos"`
@swdunlop
swdunlop / PKGBUILD
Created May 28, 2013 17:15
Updated PKGBUILD for jq-git
# Maintainer: Alex Chamberlain <[email protected]>
name=jq
pkgname=$name-git
pkgver=1.1
pkgrel=3
epoch=
pkgdesc="Command-line JSON processor"
arch=('i686' 'x86_64')
url="http://stedolan.github.com/jq/"
license=('custom')
@swdunlop
swdunlop / Makefile
Last active March 28, 2017 19:29
Enabling SSH (and static password) at boot in a Finnix ISO for remote boot
FINNIX_VERSION ?= 108
FINNIX_URL ?= http://www.finnix.org/releases/$(FINNIX_VERSION)/finnix-$(FINNIX_VERSION).iso
FINNIX_ISO = src/finnix-$(FINNIX_VERSION).iso
SSH_ISO ?= finnix-$(FINNIX_VERSION)-ssh.iso
SSH_PASSWORD ?= applypasswordhereplease
BOOT_KERNEL ?= boot/x86/linux
BOOT_INITRD ?= boot/x86/initrd.xz
BOOT_VGA ?= normal
@swdunlop
swdunlop / plyml.go
Last active October 21, 2021 00:23
PLYML is a simple utility to convert OSX plists to/from YAML to make them easier to hack on
/* plyml converts Apple plists into YAML, and vice-versa. This is used to make it easier to hack on TextMate and Sublime Text themes. It depends on Apple's "plutil" utility, meaning it is only useful on OSX. */
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"launchpad.net/goyaml"
"os"
"os/exec"