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 |
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
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
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 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
# 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
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
from collections import Sequence, Mapping | |
from sys import getsizeof | |
def traverse(obj): | |
if isinstance(obj, basestring): | |
yield obj | |
elif isinstance(obj, Sequence): | |
yield obj | |
for o in obj: | |
for inner_o in traverse(o): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
An Athenian Stranger Clinias of Crete Megillus of Lacedaemon | |
Athenian To whom do you ascribe the authorship of your legal arrangements, Strangers? To a god or to some man? Clinias To a god, Stranger, most rightfully to a god. We Cretans call Zeus our lawgiver; while in Lacedaemon , where our friend here has his home, I believe they claim Apollo as theirs. Is not that so, Megillus? Megillus Yes. Athenian Do you then, like Homer, Cp. Hom. Od. 19.178 . say that | |
Minos used to go every ninth year to hold converse with his father Zeus, and that he was guided by his divine oracles in laying down the laws for your cities? Clinias So our people say. And they say also that his brother Rhadamanthys,—no doubt you have heard the name,—was exceedingly just. And certainly we Cretans | |
would maintain that he won this title owing to his righteous administration of justice in those days. Athenian Yes, his renown is indeed glorious and well befitting a son of Zeus. And, since you and our friend Megillus were bo |
OlderNewer