This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import timeit | |
from random import choice, randint | |
from string import ascii_letters | |
# random_keys = [''.join([choice(ascii_letters) for i in range(randint(4,30))]) for i in range(10000)] | |
def add2dict(random_keys): | |
s = {} | |
for key in random_keys: | |
s[key] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Citation Simulator that tries to replicate academic citation | |
# patterns. Using pypy is recommended. MIT License. | |
import collections | |
import random | |
import argparse | |
class Article(object): | |
def __init__(self, journal, year): | |
self.journal = journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import math | |
import collections | |
# This gist tests my derivation of browsing similarity. | |
# The browsing similarity determines the probability of moving | |
# from a node of type one to another node of type one in a | |
# fully-connected weighted bipartite network, given that the | |
# weights are interpreted as transition probabilities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
setup = ''' | |
import numpy as np | |
def apply_indexed_fast(array, func_indices, func_table): | |
func_argsort = func_indices.argsort() | |
func_ranges = list(np.searchsorted(func_indices[func_argsort], range(len(func_table)))) | |
func_ranges.append(None) | |
out = np.zeros_like(array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
import itertools | |
# This creates a binomial tree in O(n) time, but using O(n) extra space. | |
# It's also possible to create an in-place binomial tree in O(n log n) | |
# time using O(1) extra space. | |
# Each tree here is represented by one leaf and zero or more subtrees | |
# stored in a list. The leaf is at tree[0]; each following item in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copyright Scott Enderle 2014 -- CC BY-SA 3.0 | |
# http://creativecommons.org/licenses/by-sa/3.0/ | |
# https://gist.github.com/senderle/47bf0b2b13112cf5851b | |
import sys | |
def parse_args(names_types_defaults): | |
''' | |
Takes a list of options and parses sys.argv: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Scott Enderle | |
# Originally posted at http://stackoverflow.com/a/6575693/577088 | |
from itertools import chain | |
from collections import defaultdict | |
class Graph(object): | |
def __init__(self, edges, vertices=()): | |
edges = list(list(x) for x in edges) | |
self.edges = edges |
NewerOlder