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 cProfile | |
import contextlib | |
import os | |
@contextlib.contextmanager | |
def profile(filename='~/python.profile', *args, **kwargs): | |
profile = cProfile.Profile(*args, **kwargs) | |
profile.enable() |
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/env bash | |
if [[ $# -eq 0 ]]; then | |
git status | |
else | |
git $@ | |
fi |
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
int sum3(int x, int y, int z) { | |
int word1, word2; | |
word1 = (x ^ y) ^ z; | |
word2 = (x & y) | (x & z) | (y & z); | |
word2 <<= 1; | |
return word1 + word2; | |
} |
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 unittest | |
from mock import call, patch | |
class PatcherTestCase(unittest.TestCase): | |
def setUp(self): | |
self.patcher = patch('some_module.some_object') | |
self.mock_object = self.patcher.start() |
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 code import InteractiveConsole | |
import os | |
import sys | |
completer_locals = locals() | |
HISTFILE = os.path.expanduser("%s/.pyhistory" % os.environ["HOME"]) | |
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
# Again, these are contrived examples, but they do a slightly better job of | |
# illustrating the use of recursion in functional languages when no concept of | |
# program state is available. | |
# Notice that the if statement in the functional example 1 includes an else | |
# statement. This makes it more like a mathematical expression (because it | |
# causes the function to always return a certain value). Functional example 2 | |
# uses a syntax available in python that truly is an expression built with if | |
# and else statements. |
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/env python | |
import itertools | |
import sys | |
from collections import defaultdict | |
from pyparsing import CharsNotIn, Group, Optional, Word, ZeroOrMore, alphanums | |
word = Word(alphanums) | |
space = CharsNotIn(alphanums) | |
doc = ZeroOrMore(Group(word + Optional(space))) |
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 | |
import time | |
from datetime import datetime, timedelta | |
START_TIME = datetime(2013, 3, 23, 0, 0, 0, 0) | |
TRIP_TIME = timedelta(minutes=8.7 * 60) | |
END_TIME = START_TIME + TRIP_TIME | |
BAR_WIDTH = 100 |
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
""" | |
Utilities for dynamically updating links in rich text fields. | |
We had a project in which many models had rich text fields. These rich text | |
fields contained links to model instance detail pages. Since these links were | |
being entered by hand, we needed a way to update them in the event that the | |
instance for the detail page they were pointing to changed. | |
The routines in this file allow links in rich text content to be automatically | |
updated with a python html parsing library called `BeautifulSoup`. |
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
local base_cmd="grep --exclude-dir=CACHE --exclude-dir=ckeditor --binary-files=without-match --colour -Enr" | |
if [[ $# -eq 1 ]]; then | |
eval "$base_cmd $1 *" | |
elif [[ $# -gt 1 ]]; then | |
eval "$base_cmd $@" | |
else | |
echo "usage: se SEARCH_STRING [FILE_PATTERN]" | |
fi |