Skip to content

Instantly share code, notes, and snippets.

@akellehe
akellehe / edge.py
Created June 15, 2015 18:57
A basic edge in a tree.
class Edge(object):
def __init__(self, parent, child, created_at):
self.parent = parent
self.child = child
self.created_at = created_at
self.generation = 0
@akellehe
akellehe / online.py
Created June 15, 2015 18:58
Two methods for computing graph statistics online. Tree name and edge are the only inputs.
conn = StrictRedis()
def online_size(sender, tree_name=None, edge=None):
conn.incr('{0}.size'.format(tree_name))
def online_depth(sender, tree_name=None, edge=None):
with conn.lock('{0}.depth'.format(tree_name)):
current_depth = conn.get('{0}.depth'.format(tree_name)) or 0
if int(current_depth) < edge.generation:
conn.set('{0}.depth'.format(tree_name), edge.generation)
@akellehe
akellehe / should_add.py
Created June 15, 2015 18:59
Criteria for adding an edge to a tree.
def should_add(self, edge):
return all([
self.would_be_leaf(edge),
self.is_earliest_parent(edge)])
var downstream = function(buzz_id, root_id, limit) {
if (root_id == null){
return db.user_edge_v2.find({
"buzzid": buzz_id
}).count()
}
var limit = typeof limit != 'undefined' ? 1000 : limit;
var seen = {root_id: true};
var nodeq = [root_id];
var downstream_count = 0;
5 procs started on release0.13.3 @ 13:45
@akellehe
akellehe / parse_article_links.py
Created November 30, 2015 01:21
Parse article links out of wikipedia string
import mwlib.parser.nodes
import mwlib.uparser
import codecs
with codecs.open('us.dat', 'rb', encoding='utf-8') as fp:
text = fp.read()
article = mwlib.uparser.parseString(title='us', raw=text)
nodes = article.find(mwlib.parser.nodes.ArticleLink)
for n in nodes:

Keybase proof

I hereby claim:

  • I am akellehe on github.
  • I am eggrollinabox (https://keybase.io/eggrollinabox) on keybase.
  • I have a public key whose fingerprint is C60E 4730 5FAF 8873 EB5D 7B8D 1ECC C4D0 7D83 2E78

To claim this, I am signing this object:

@akellehe
akellehe / 0_reuse_code.js
Created July 29, 2016 20:36
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
def mod(X, Y):
return X - Y * (X / Y)
* Why does a split dict get resized multiple times when there are only one reference (instance of a class) and once when there are many reference
* When does it go from a combined dict back to a split dict?
BUILD INTERFACE TO ASK ANONYMOUS QUESTIONS