This file contains hidden or 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 System.Environment | |
fib_gen = 0 : 1 : [a + b | (a, b) <- zip fib_gen (tail fib_gen)] | |
main = do | |
args <- getArgs | |
let first_arg = if null args then "1" else head args | |
let fa = read first_arg :: Int | |
print $ last $ take fa fib_gen |
This file contains hidden or 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 check(A, B, C, index): | |
totals = [0 for _ in xrange(index)] | |
for i in xrange(index - 1, -1, -1): | |
totals[i] += B[i] | |
if C[i] != -1: | |
totals[C[i]] += totals[i] | |
return all([totals[i] <= A[i] for i in xrange(index)]) |
This file contains hidden or 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
# BaseTestClient is flask.testing.FlaskClient | |
class TestClient(BaseTestClient): | |
""" | |
Test Client. | |
""" | |
def __exit__(self, exc_type, exc_value, tb): | |
self.preserve_context = False | |
top = _request_ctx_stack.top |
This file contains hidden or 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
[ 0.637461] Write protecting the kernel text: 4232k | |
[ 0.637500] Write protecting the kernel read-only data: 1272k | |
[ 0.647427] random: systemd-tmpfile urandom read with 0 bits of entropy available | |
[ 0.650489] systemd-udevd[47]: starting version 212 | |
[ 0.653627] i8042: PNP: PS/2 Controller [PNP0303:PS2K] at 0x60,0x64 irq 1 | |
[ 0.653634] i8042: PNP: PS/2 appears to have AUX port disabled, if this is incorrect please boot with i8042.nopnp | |
[ 0.654699] i8042: Warning: Keylock active | |
[ 0.654847] serio: i8042 KBD port at 0x60,0x64 irq 1 | |
[ 0.660105] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input0 | |
[ 0.679289] sdhci: Secure Digital Host Controller Interface driver |
This file contains hidden or 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 sys | |
import os | |
from os.path import join | |
from mock import Mock, patch | |
from twisted.internet import defer | |
src_path = os.path.realpath(join(os.path.dirname(__file__), "../src/")) | |
current_path = os.path.realpath(os.path.dirname(__file__)) | |
sys.path.insert(0, current_path) | |
sys.path.insert(0, src_path) |
This file contains hidden or 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 unittest import TestCase | |
from mock import patch | |
class IDontNeedTheRest(Exception): | |
pass | |
DEBUG = False |
This file contains hidden or 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
class Measure(object): | |
def __init__(self): | |
self.__elapsed = None | |
def __enter__(self): | |
self.__start = time() | |
def __exit__(self, *args): | |
self.__elapsed = time() - self.__start |
This file contains hidden or 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 functools import wraps | |
from json import dumps | |
from datetime import datetime | |
def timeout_cache(max_timeout): | |
def timeout_cache_inner(fn): | |
fn._cache = {} | |
fn._timeout = max_timeout | |
@wraps(fn) |
This file contains hidden or 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
class MetaClass(type): | |
counter = 1 | |
def __new__(meta, name, bases, dct): | |
""" Gets called when we read in the class definition for which this is the metaclass of""" | |
print "MetaClass.__new__(%s, %s, %s, %s)" % (meta, name, bases, dct) | |
dct['class_num'] = meta.counter | |
meta.counter += 1 | |
return super(MetaClass, meta).__new__(meta, name, bases, dct) |
This file contains hidden or 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
your_list | |
unique_d = {} | |
for i, el in enumerate(your_list): | |
unique_d.setdefault(el, i) | |
preserved_order_unique = map(lambda x: x[0], sorted([(key, val) for key, val in unique_d.iteritems()], lambda y: y[1])) |