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
board_size = 8 | |
def get_free_states(queens): | |
""" | |
Get free board states for a set of queens | |
""" | |
free_states = [[True]*board_size for i in range(0,board_size)] | |
for queen in queens: | |
for i in range(0,board_size): | |
for signs in [(1,1),(-1,-1),(1,-1),(-1,1),(1,0),(-1,0),(0,1),(0,-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 defaultdict | |
import abc | |
class MapReducer(object): | |
__metaclass__ = abc.ABCMeta | |
@abc.abstractmethod | |
def map(self,items): | |
return [] |
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 wnck | |
import gtk | |
import time | |
if __name__ == '__main__': | |
screen = wnck.screen_get_default() | |
screen.force_update() | |
while True: | |
while gtk.events_pending(): | |
gtk.main_iteration() |
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
def jsonp(): | |
def decorator(f): | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
if not 'callback' in request.args: | |
abort(404) | |
response = f(*args, **kwargs) | |
if isinstance(response,str): |
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
create table natural_numbers (n int); | |
insert into natural_numbers values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128), (129), (130), (131), (132), (133), (134), (135), (136), (137), (138), (139), (140), (141), (142), (143), (144), (145), (146), (147), (148), (149), (150), (151), (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 scipy.stats import binom | |
def workload(n_subscribers,n_capacity,p_call): | |
""" | |
Calculates the estimated workload (in percent) of a system to which n_subscribers connect at any given time with probability *p_call* and that can process *n_capacity* clients in parallel. | |
Arguments: | |
n_subscribers : The number of subscribers that might use the system at the given time. | |
n_capacity : The maximum number of subscribers that the system can process in parallel. |
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 redis | |
import time | |
class LockTimeout(BaseException): | |
pass | |
class Lock(object): | |
""" | |
Implements a distributed lock using Redis. |
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 requests | |
import json | |
import datetime | |
import time | |
import sys | |
import math | |
ACCESS_TOKEN = '[put your API key here]' | |
usage = """Retrieves a list of all Github users using the Github API. |
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 | |
def get_random_color(pastel_factor = 0.5): | |
return [(x+pastel_factor)/(1.0+pastel_factor) for x in [random.uniform(0,1.0) for i in [1,2,3]]] | |
def color_distance(c1,c2): | |
return sum([abs(x[0]-x[1]) for x in zip(c1,c2)]) | |
def generate_new_color(existing_colors,pastel_factor = 0.5): | |
max_distance = None |
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
code_hierarchy_data = [ | |
"", | |
[ | |
416598, | |
11581 | |
], | |
{ | |
"docs": [ | |
"docs", | |
[ |
NewerOlder