Skip to content

Instantly share code, notes, and snippets.

@isaacl
isaacl / cq_stats.py
Created November 17, 2013 02:11
Commit queue stats
#!/usr/bin/python
# sudo apt-get install pip; sudo pip install requests request_cache
import argparse
import collections
from datetime import timedelta, datetime
import itertools
import json
import numpy
import operator
import re
@isaacl
isaacl / DisjointSets.py
Created November 20, 2013 11:52
Disjoint set data structure.
#!/usr/bin/python
"""
Simple implementation of disjoint set data structure using
path compression and union by rank.
Sequences of Find and Union run in O(a(x)) where a() is the
inverse of the Ackermann function. That means it's fast, for
python.
@isaacl
isaacl / mst.py
Last active January 4, 2016 05:29
mst for hierarchical trees
import collections
def counts(ls, d):
cnts = collections.defaultdict(int)
for l in ls:
while l:
cnts[l] += 1
l = d[l]
return cnts
def mst(ls, d):
import sys,os
sys.path.insert(0, os.environ.get('GOOGLE_APPENGINE_SDK_PATH'))
sys.path.insert(0, os.environ.get('GOOGLE_APPENGINE_NDB_PATH'))
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext import testbed
t = testbed.Testbed()
os.environ['APPLICATION_ID'] = 'foo'
t.activate()
t.init_datastore_v3_stub(use_sqlite=True, datastore_file='100GzipText.sqlite')
@isaacl
isaacl / log_rpcs.patch
Created February 27, 2014 06:14
rpc logging in dev_appserver
diff --git a/google/appengine/api/apiproxy_rpc.py b/google/appengine/api/apiproxy_rpc.py
index 7e73bfd..b39c490 100644
--- a/google/appengine/api/apiproxy_rpc.py
+++ b/google/appengine/api/apiproxy_rpc.py
@@ -112,6 +112,18 @@ class RPC(object):
assert self.__state is RPC.IDLE, ('RPC for %s.%s has already been started' %
(self.package, self.call))
assert self.callback is None or callable(self.callback)
+ call = self.callback
+ def c2(*args, **kwargs):
ilevy@paxon:/c/2/prom/ndbleak_cur$ ipython -ic 'from ndb_test import *; print fetch_entities(); print len(wd); len(ndb.tasklets._state.all_pending)'
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
^[[(22, 230000)
@isaacl
isaacl / ndb_urlfetch.py
Last active August 29, 2015 13:57
urlfetch mem test
import sys, os
sys.path.insert(0, os.environ.get('GOOGLE_APPENGINE_SDK_PATH'))
sys.path.insert(0, os.environ.get('GOOGLE_APPENGINE_NDB_PATH'))
sys.modules.pop('google', None)
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext import testbed
from google.appengine.api import urlfetch_errors
from google.appengine.runtime import apiproxy_errors
#from guppy import hpy
(($(compare image1.png image2.png -compose src -fuzz 2% -metric ae /dev/null 2>&1) | wc -c) > 4))
@isaacl
isaacl / script.js
Created October 17, 2014 07:25
Userscript: Stop websites from hijacking keyboard shortcuts.
// ==UserScript==
// @name Disable website keyboard hooks
// @description Stop websites from hijacking keyboard shortcuts.
// @author Isaac Levy
// @run-at document-start
// @include *
// @grant none
// @version 0.0.1
// @namespace https://isaacrlevy.com
// ==/UserScript==
@isaacl
isaacl / wh
Created November 16, 2014 00:55
A better version of 'which' which understands builtins and follows symlinks
#!/bin/bash -e
com="$1"
if [[ -z "$com" ]]; then
exit 1
fi
while true; do
case $(type -t "$com") in