Skip to content

Instantly share code, notes, and snippets.

View gbishop's full-sized avatar

Gary Bishop gbishop

View GitHub Profile
'''A data server with use with dojo'''
import tornado.httpserver
import tornado.ioloop
import tornado.web
import os
import json
import re
import random
import string
@gbishop
gbishop / debug.js
Created April 7, 2010 00:01
Hook dojo.require to insert line-number tracing calls into blocks. Call DbG() from the console to access the resulting trace object.
// A hack to insert simple line number tracing into javascript code included with dojo.require
// Add a URL parameter trace to invoke line-by-line printing on the console or
// trace=silent to collect the messages in an array, you can retrieve them with DbG()
DbG =
(function () {
// get the url parameters
var parms = dojo.queryToObject(window.location.search.substring(1));
var flag = parms.trace;
if (typeof(flag) == 'undefined') {
// bail if not requested
@gbishop
gbishop / unclocal
Created April 7, 2010 20:38
nginx sites-avaiable file for ubuntu
# Configuration for local development for the unc open web.
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www;
/* this is an attempt to use the new then and when functions in Dojo 1.5 to handle a chain of async
actions. The scenario is open 2 databases, get a record from the 2nd db, write a record to the 1st that uses data from that record. save it. This is 4 async steps.
*/
// dfetch is a hack to get a database fetch method wrapped up as a deferred. We could add a
// method to the db class to make this a bit prettier
function dfetch(db, query) {
var def = new dojo.Deferred();
db.fetch({
query: query,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Try Json Refs</title>
<style type="text/css">
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/resources/dojo.css";
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/Grid.css";
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/claroGrid.css";
#!/usr/bin/python
'''Yet another Montage experiment for desktop wallpaper
This version works with a variant on the "Pseudo-Poisson" dart throwing algorithms
that were popular in stochastic ray-tracing years ago. It throws darts at a rectangular
region ensuring that no darts are closer together than a minimum distance. It allows the
minimum distance to scale down so you can have some big pictues and some smaller pictures.
The help text was intended to be self explanatory...
# monkey patch the python json module to handle undefined
import json
json.decoder._CONSTANTS['undefined'] = None
json.scanner.pattern('(-?Infinity|NaN|true|false|null|undefined)')(json.decoder.JSONConstant)
json.decoder.JSONScanner = json.decoder.Scanner(json.decoder.ANYTHING)
if __name__ == '__main__':
print json.loads('{ "foo": 1, "bar": undefined }')
@gbishop
gbishop / hitcher.js
Created November 2, 2010 14:37
A hack at customized callback behavior in dojo
dojo.provide('uow.hitcher');
/*
uow.hitcher: provide additional control over callbacks
usage:
my = uow.hitcher({ callPeriod: 500 }); // note this didn't hitch, it created a hitcher named my.
your = uow.hitcher(); // this one is independent of the first
@gbishop
gbishop / diffObjects.py
Created December 26, 2010 13:22
Visually compare python objects with diff
from difflib import Differ
from pprint import pformat
def diff(o1, o2):
po1 = pformat(o1).splitlines()
po2 = pformat(o2).splitlines()
d = Differ()
r = [ line for line in d.compare(po1, po2) if line[0] in '+-' ]
return '\n'.join(r)
@gbishop
gbishop / muteRadio
Created January 6, 2011 19:17
Mute Rhythmbox at the top of the hour so I don't hear the news break
#!/usr/bin/python
'''I run this with crontab using the line:
1 8-17 * * 1-5 /home/gb/bin/muteRadio
'''
import sys
import os
import time
import dbus