Skip to content

Instantly share code, notes, and snippets.

@dsc
dsc / README.md
Created June 22, 2012 05:16
Performance of JS Hash Implementations
@dsc
dsc / modelhaiku.py
Created June 22, 2012 20:31
modelhaiku.py
from sqlalchemy import *
class Haiku(Model):
id = Column(Integer, primary_key=True)
ctime = Column(DateTime, default=func.now())
line1 = Column(Text())
line2 = Column(Text())
line3 = Column(Text())
query = (Session.query(Haiku)
@dsc
dsc / jconsole-proxy.sh
Created August 7, 2012 01:15
jconsole via ssh proxy
#!/bin/bash
#/ jc -- jconsole via ssh proxy
#/
#/ Usage: jc [options] HOST JMX_PORT [PROXY_PORT=JMX_PORT] [JMX_HOST=HOST]
#/
#/ Starts a SOCKS proxy via ssh to connect to a
#/ JVM running on a remote and protected machine.
#/
#/ Arguments:
#!/bin/bash
for repo in $(cat repos.txt); do
repodir=$(perl -pe 's!/!-!g;' -e 's/^analytics-//' <<< "$repo")
echo git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir
if git clone --mirror ssh://gerrit.wikimedia.org/$repo.git $repodir; then
echo
else
break
fi
done
@dsc
dsc / events.coffee
Created September 17, 2012 19:28
events.co
# Technically, this is Coco, not CoffeeScript, but close enough.
{ toString:objToString } = Object::
isArray = Array.isArray or (o) -> objToString.call(o) is '[object Array]'
slice = [].slice
class exports.EventEmitter
@dsc
dsc / fix_block_indentation.py
Created September 19, 2012 19:35
Fix Block Indentation TextMate Command
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# TextMate command to correct block indentation for languages with
# semantic whitespace (like Python or CoffeeScript).
#
# Command settings:
# input: Selected Text or Document
# output: Replace Selected Text
# activation: cmd+shift+R
@dsc
dsc / chart.css
Created September 21, 2012 04:10
d3.js: A Sine Graph
svg {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
@dsc
dsc / img.py
Created October 8, 2012 21:42
Base class for Python CLI scripts, with example using PIL to display image dimensions on the shell.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Prints image dimensions.
"""
__author__ = 'David Schoonover <[email protected]>'
import sys, re, argparse
from subprocess import Popen, PIPE, STDOUT, check_output
from path import path
from bunch import *
@dsc
dsc / gist:3855240
Created October 8, 2012 21:52
Python argparse Cheatsheet
Arg Name or Optional Flags:
positional : str = "foo"
options : str = "-f", "--foo"
Standard:
action : str = [store], append, store_true, store_false, store_const, append_const, version
default : * = [None]
type : callable = [str], argparse.FileType(mode='wb', bufsize=0)
Exotic:
@dsc
dsc / teegram.js
Created October 12, 2012 21:03
Listens for UDP packets, sending the stream to stdout and also teeing it to another port on the local machine.
#!/usr/bin/env node
// Listens for UDP packets, sending the stream to stdout and
// also teeing it to another port on the local machine.
//
// Usage: teegram.js LISTEN_PORT TEE_PORT
var dgram = require('dgram');