Skip to content

Instantly share code, notes, and snippets.

@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>
@davidszotten
davidszotten / gist:02c101f0bc268a8d7741
Created November 16, 2014 18:15
coverage test run output
py27 runtests: commands[3] | /home/david/cov_src/.tox/py27/bin/python setup.py --quiet build_ext --inplace
py27 runtests: commands[4] | /home/david/cov_src/.tox/py27/bin/python igor.py test_with_tracer c
=== CPython 2.7.2+ with C tracer (.tox/py27/bin/python) ===
....................................................................................................................................................................................................................................................................................................................................................................E..........................................................................................
======================================================================
ERROR: test_subprocess_with_pth_files (tests.test_process.ProcessStartupTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/david/cov_src/tests/test_process.py", line
@davidszotten
davidszotten / monitor.py
Last active August 29, 2015 14:12
uwsgi dumper
#!/usr/bin/env python
import datetime
import os
import socket
import subprocess
import sys
ERROR = ' HTTP/1.1" 499'
$ cat covtest.py
import requests
requests.get('http://www.google.com')
$ coverage run -L covtest.py ; coverage report
Name Stmts Miss Cover
--------------------------------
covtest.py 2 0 100%
@davidszotten
davidszotten / conftest.py
Created May 14, 2015 10:50
pytest fixture lineage
def get_lineage(request):
name = request.fixturename
node = str(request.node)
try:
return [name] + get_lineage(request._parent_request)
except AttributeError:
return [node]
print ' <- '.join(get_lineage(request))
@davidszotten
davidszotten / README.txt
Created June 11, 2015 14:45
Nameko rpc step-through
add `import pdb; pdb.set_trace()` to `RpcConsumer.handle_message` and `ReplyListener.handle_message`