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 multiprocessing | |
import Queue, threading | |
import sys, time | |
class CoroutineProcess(multiprocessing.Process): | |
""" Will run a coroutine in its own process, using the | |
multiprocessing library. The coroutine thread runs as | |
a daemon, and is closed automatically when it is no longer | |
needed. Because it exposes send and close methods, a CoroutineProcess | |
wrapped coroutine can be dropped in for a regular coroutine.""" |
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
var abbrev_to_name = {'AK': 'Alaska', 'AL' : 'Alabama', 'AR' : 'Arkansas', 'AZ' : 'Arizona', 'CA' : 'California', 'CO' : 'Colorado', 'CT' : 'Connecticut', 'DE' : 'Delaware', 'DC' : 'District of Columbia', 'FL' : 'Florida', 'GA' : 'Georgia', 'HI' : 'Hawaii', 'IA' : 'Iowa', 'ID' : 'Idaho', 'IL' : 'Illinois', 'IN' : 'Indiana', 'KS' : 'Kansas', 'KY' : 'Kentucky', 'LA' : 'Louisiana', 'MA' : 'Massachusetts', 'MD' : 'Maryland', 'ME' : 'Maine', 'MI' : 'Michigan', 'MN' : 'Minnesota', 'MS' : 'Mississippi', 'MO' : 'Missouri', 'MT' : 'Montana', 'NC' : 'North Carolina', 'ND' : 'North Dakota', 'NE' : 'Nebraska', 'NH' : 'New Hampshire', 'NJ' : 'New Jersey', 'NM' : 'New Mexico', 'NV' : 'Nevada', 'NY' : 'New York', 'OH' : 'Ohio', 'OK' : 'Oklahoma', 'OR' : 'Oregon', 'PA' : 'Pennsylvania', 'RI' : 'Rhode Island', 'SC' : 'South Carolina', 'SD' : 'South Dakota', 'TN' : 'Tennessee', 'TX' : 'Texas', 'UT' : 'Utah', 'VA' : 'Virginia', 'VT' : 'Vermont', 'WA' : 'Washington', 'WI' : 'Wisconsin', 'WV' : 'West Virginia', 'WY' : 'Wyoming'}; |
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
spiral_side = 1001 | |
num_corners = spiral_side/2 | |
total = 1 | |
corners = (1, 1, 1, 1) | |
additions = (2, 4, 6, 8) | |
for i in xrange(num_corners): | |
corners = map(sum, zip(corners, additions)) | |
additions = map(lambda x: x+8, additions) |
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 | |
test_str = "hello world|" | |
test_times = 1000 | |
def test_str_add(): | |
result = "" | |
for i in xrange(test_times-1): | |
result += test_str | |
return result |
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 recursive_fib(n, cache={}): | |
if n <= 1: | |
return 1 | |
cache[n] = cache.get(n) or n * recursive_fib(n - 1, cache) | |
return cache[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
// Rename: | |
// .locu-mobile-menu => .mobile-mixin | |
// .locu-web-menu => .web-mixin | |
// Then, use the mixins like so | |
@media screen and (max-width: 480px) { | |
.mobile-mixin; | |
} | |
// Keep this if you want the mobile preview to show your small-screen style |
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 gmail(recipients, subject, message, sender_username, sender_password): | |
import smtplib | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(username, password) | |
if not (isinstance(recipients, list) or isinstance(recipients, tuple)): | |
recipients = [recipients] |
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
number = int(raw_input('Enter a number between 20 and 0: ')) | |
# Only one of the following statements will print. If a condition | |
# (like "number < 20") is matched, then only that part of the block | |
# will run. That's what elif does. Else, if. | |
if number < 20: | |
print '%d is less than 20' % number | |
elif number < 10: | |
print '%d is less than 10' % number | |
elif number < 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
alias g="git" | |
alias ga="git add" | |
alias gb="git branch" | |
alias gba="git branch -a" | |
alias gbd="git branch -d" | |
alias gbdr="git push origin --delete" | |
alias gc="git commit" | |
alias gca="git commit -a" | |
alias gch="git checkout" | |
alias gl="git log --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --date=relative" |
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 mock | |
def mock_object(data=None): | |
result = mock.MagicMock() | |
for key, value in data.iteritems(): | |
if isinstance(value, dict): | |
result.configure_mock(**{ | |
key: mock_object(value), | |
}) | |
else: | |
result.configure_mock(**{ |
OlderNewer