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 time | |
import hmac | |
import struct | |
import base64 | |
import hashlib | |
def code(secret): | |
key = base64.b32decode(secret) | |
message = struct.pack(">Q", int(time.time()) / 30) | |
h = hmac.new(key, message, hashlib.sha1).digest() |
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
class Graph: | |
def __init__(self): | |
self.nodes = set() | |
self.edges = defaultdict(list) | |
self.distances = {} | |
def add_node(self, value): | |
self.nodes.add(value) | |
def add_edge(self, from_node, to_node, distance): |
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 primes(n): | |
yield 2 | |
primes=[2] | |
x = 1 | |
i = 3 | |
while(x<n): | |
isprime=True | |
for p in primes: | |
if i%p==0: isprime = False | |
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
#https://news.ycombinator.com/item?id=4694663 | |
from PIL import Image | |
import scipy | |
import scipy.cluster | |
from pprint import pprint | |
image = Image.open('logo.png') | |
NUM_CLUSTERS = 5 |
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
BASE_ALPH = tuple("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") | |
BASE_DICT = dict((c, v) for v, c in enumerate(BASE_ALPH)) | |
BASE_LEN = len(BASE_ALPH) | |
def base_decode(string): | |
num = 0 | |
for char in string: | |
num = num * BASE_LEN + BASE_DICT[char] | |
return num |
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 memoize(function): | |
cache = {} | |
def wrap(*args): | |
if not args in cache: | |
print '{0} not in {1}'.format(args, cache) | |
cache[args] = function(*args) | |
return cache[args] | |
return wrap | |
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
# -*- coding: utf-8 -*- | |
# | |
# A simple memory cache library | |
# Author: Craig Russell <[email protected]> | |
# | |
import time | |
class Cache(object): |
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
/* | |
This code is public domain. | |
The MurmurHash3 algorithm was created by Austin Appleby and put into the public domain. See http://code.google.com/p/smhasher/ | |
This C# variant was authored by | |
Elliott B. Edwards and was placed into the public domain as a gist | |
Status...Working on verification (Test Suite) | |
Set up to run as a LinqPad (linqpad.net) script (thus the ".Dump()" call) | |
*/ |
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
#!/usr/bin/python | |
zeroTo19 = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", | |
"ten", "eleven", "twelve", "thirteen", "fourteeen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] | |
tens = [ "", "", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" ] | |
denoms = [ (1000000000000, "trillion"), (1000000000, "billion"), (1000000, "million"), (1000, "thousand"), (100, "hundred") ] | |
def num2words(n): | |
if n<20: | |
return zeroTo19[n] |
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
# The Nginx configuration based on https://coderwall.com/p/rlguog | |
http { | |
ssl_certificate server.crt; | |
ssl_certificate_key server.key; | |
ssl_session_timeout 15m; | |
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_session_cache shared:SSL:10m; |
OlderNewer