Skip to content

Instantly share code, notes, and snippets.

View robcowie's full-sized avatar

Rob Cowie robcowie

  • Recycleye
  • Leeds/London, United Kingdom
View GitHub Profile
@robcowie
robcowie / Prettyprint JSON alias.sh
Created April 8, 2010 12:39
Commandline alias to prettyprint json
alias ppjson='python -c "import simplejson, sys; print simplejson.dumps(simplejson.loads(sys.stdin.read()), indent=4)" | pygmentize -f console -l js'
@robcowie
robcowie / woof.py
Created April 20, 2010 18:14
woof.py One-time file server
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# woof -- an ad-hoc single file webserver
# Copyright (C) 2004-2009 Simon Budig <simon@budig.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
// Usage
// $.dataSpy()
// $(document).bind('data.change', function(){console.log('data changed')} )
// $(document).bind('data.unchange', function(){console.log('data unchanged')} )
(function($) {
function hash(data, n) {
var norm = Math.pow(2, -32);
@robcowie
robcowie / WildcardDict.py
Created April 28, 2010 18:17
Dict that supports wildcards in sequence keys
# -*- coding: utf-8 -*-
import timeit
class Wildcard(object):
""""""
@classmethod
def any(cls, *args, **kargs):
cmp_func = lambda other: True
return Wildcard(cmp_func, *args, **kargs)
@robcowie
robcowie / mongo_mapreduce_by_week.js
Created May 4, 2010 15:18
mongodb map-reduce to group by week
m = function() {
var getWeek = function(d) {
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */
dowOffset = 1;
var newYear = new Date(d.getFullYear(),0,1);
var day = newYear.getDay() - dowOffset;
day = (day >= 0 ? day : day + 7);
var daynum = Math.floor((d.getTime() - newYear.getTime() - (d.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
var weeknum;
if (day < 4) {
@robcowie
robcowie / usa_sic_codes.sql
Created July 16, 2010 19:04
US SIC Codes, sql table definition and data
CREATE TABLE `sic_code` (
`code` varchar(32) NOT NULL DEFAULT '',
`label` varchar(256) DEFAULT NULL,
`parent_code` varchar(32) DEFAULT NULL,
`level` int(11) DEFAULT NULL
) DEFAULT CHARSET=utf8;
INSERT INTO `sic_code` (`code`,`label`,`parent_code`,`level`)
VALUES
('D','MANUFACTURING',NULL,0),
"""See http://techspot.zzzeek.org/?p=31"""
from sqlalchemy.interfaces import ConnectionProxy
import time
import logging
logging.basicConfig()
logger = logging.getLogger("myapp.sqltime")
logger.setLevel(logging.DEBUG)
(⦿)(⦿)
Default Renault radio unlock code: 1705
@robcowie
robcowie / eventriloquist.py
Created January 20, 2011 17:16
Supervisor --> AMQP event listener
# -*- coding: utf-8 -*-
"""
Run as a supervisor event listener process. See http://supervisord.org/events.html for more info.
An example eventlistener config block looks like:
[eventlistener:myeventhandler]
command=python /path/to/eventriloquist.py
events=EVENT