Skip to content

Instantly share code, notes, and snippets.

@davidszotten
davidszotten / external.js
Created May 12, 2011 09:17
draft coding standards
(function() {
})();
@davidszotten
davidszotten / gist:1091866
Created July 19, 2011 09:51
fabric bash completion
# only load the commands when launching shell.
# if you make frequent edits to your fab file, consider moving this inside _fab()
_fab_commands=$(~/path/to/virtualenv/bin/fab --fabfile=~/path/to/fabfile/fabfile.py --shortlist)
_fab()
{
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "${_fab_commands}" -- ${cur}) )
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@davidszotten
davidszotten / verify_pull_requests.sh
Created November 1, 2012 10:26
Verify that a list of pull requests have been merged into a given branch
#!/bin/bash
progname=$(basename $0)
if [ "$1" = "--setup" ]
then
origin=$(git config --get remote.origin.url)
git remote add pulls $origin
git config remote.pulls.fetch "+refs/pull/*/head:refs/remotes/pulls/pr/*"
elif [ -z "$(git config --get remote.pulls.url)" ]
@davidszotten
davidszotten / iterxml.py
Created August 22, 2013 21:40
socket server for parsing streaming xml
""" socket server for parsing streaming xml
based on
http://stackoverflow.com/a/2270249/105043 and
http://eventlet.net/doc/examples.html#echo-server
usage:
$ python iterxml.py &
# push two documents to make sure we can start over
$ cat sample.xml sample.xml |nc localhost 6000
@davidszotten
davidszotten / webadmin_hack.js
Last active August 29, 2015 13:55
neo4j webadmin bookmarklet
// js to add shortcut to go directly to node view from graph browser
// use: got to graph view, and run bookmarklet. once enabled,
// hold down cmd and click a node to go to its edit view
javascript: (function(){
require('webadmin').modules.browser.view.visualizedView.viz.sys.renderer.bind("node:click", function(node, ev) {
var data = node.data;
if (typeof data.neoNode === "undefined") {
return;
}
@davidszotten
davidszotten / argspec_benchmarks.py
Last active August 29, 2015 14:00
Benchmarking argspec strategies
from __future__ import print_function # want same code for py2/py3
import inspect
import sys
has_signature = (sys.version_info[:2] >= (3, 3))
BAD_ARGS, GOOD_ARGS = (1, 2)
@davidszotten
davidszotten / gist:334e56e5125476090983
Created July 4, 2014 16:19
sqlalchemy `and` gotcha
# `and` doesn't work unfortunately.
# python doesn't allow overriding `and` behaviour
>>> print Booking.id == 1 and Booking.id == 2
bookings.id = :id_1
>>> print and_(Booking.id == 1, Booking.id == 2)
bookings.id = :id_1 AND bookings.id = :id_2
@davidszotten
davidszotten / redis_pubsub.c
Created August 7, 2014 16:32
redis c pubsub
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis.h>
int main(int argc, char **argv) {
unsigned int j;
redisContext *conn;
redisReply *reply;
Welcome to the profile statistics browser.
collection27.prof% sort cu
collection27.prof% stats 100
Thu Oct 9 14:08:04 2014 collection27.prof
10266541 function calls (9856337 primitive calls) in 10.750 seconds
Ordered by: cumulative time
List reduced from 12086 to 100 due to restriction <100>