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 | |
from pyleus.storm import SimpleBolt | |
class CountWordsBolt(SimpleBolt): | |
def initialize(self): | |
self.words = defaultdict(int) |
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 EmailVerification < ActiveRecord::Base | |
belongs_to :user | |
before_validation :default_values | |
UUID_GEN = UUID::Client.new '/tmp/uuid.sock' | |
validates :user_id, :presence => true | |
def verify! | |
self.verified = true |
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 LRUCache(max_size): | |
"""A simple dict-based LRU cache | |
The cached function must: | |
- Have no kwargs | |
- Have only hashable args | |
- If the decorated function is passed an unhashable arg, a TypeError | |
will be raised | |
- Be idempotent (be without side effects) | |
- Otherwise the cache could become invalid |
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 sys | |
def perms(s): | |
num_perms = 2**len(s) | |
for perm in xrange(num_perms): | |
yield ''.join( | |
c.swapcase() if (1 << i & perm) else c | |
for i, c in enumerate(s) | |
) |
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 string | |
import sys | |
def perms(s): | |
letter_map = [c in string.letters for c in s] | |
num_letters = sum(letter_map) | |
num_perms = 2**num_letters | |
for perm in xrange(num_perms): | |
letter_perms = [ |
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 TrieNode(object): | |
ident = None | |
children = None | |
def __init__(self): | |
self.children = {} | |
def insert(self, prefix, key=None): | |
if prefix: |
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 bottle import Bottl | |
import livesuggest | |
class MyApp(Bottle): | |
@get('/suggest/<prefix>') | |
def suggest(self, prefix): | |
self.request.content_type = 'application/json' | |
return livesuggest.prefix(prefix) |
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 re | |
import webob | |
import webob.exc | |
HTTP_METHODS = ('GET', 'POST', 'PUT') | |
class Apper(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
import re | |
import webob | |
import webob.exc | |
class Servlet(object): | |
name = 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
CC=g++ | |
CPPFLAGS=-O2 -Wall -Wextra -Werror -std=c++11 | |
PROJ=homework2 | |
BIN=$(PROJ) | |
SRCS=main.cpp vector3d.cpp | |
OBJS=$(subst .cpp,.o,$(SRCS)) | |
$(BIN): $(OBJS) | |
$(CC) -o $@ $^ |
OlderNewer