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
# Try to use the C implementation first, falling back to python | |
try: | |
from xml.etree import cElementTree as ElementTree | |
except ImportError, e: | |
from xml.etree import ElementTree | |
########## | |
def find(*args, **kwargs): | |
"""Find a book in the collection specified""" |
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
# Use reader() to create a an object for reading data from a CSV file. The reader can be used as an iterator | |
# to process the rows of the file in order. For example: | |
import csv | |
import sys | |
f = open(sys.argv[1], 'rt') | |
try: | |
reader = csv.reader(f) | |
for row in reader: |
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 attrs_verbose(self): | |
model = self.__class__ | |
# using this form: Record._meta.get_field('created_by').verbose_name | |
items = [] | |
for k, v in self.__dict__.items(): | |
try: | |
x = model._meta.get_field(k).verbose_name | |
except: | |
x = k | |
items += [(x, v)] |
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
# FIRST: | |
from django import template | |
from poms.pomsapp import models | |
register = template.Library() | |
# for People template | |
@register.inclusion_tag('admin/snippets/personfactoid_info.html') |
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 | |
myString = "This is my tweet check it out http://tinyurl.com/blah" | |
print re.search("(?P<url>https?://[^\s]+)", myString).group("url") |
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
>>> lst1 = [1,2,3,4,5,6,7,8,9,0,11,12,13] | |
>>> lst2 = [5,6,7,12,45,67,89,99] | |
>>> [i for i in lst1+lst2 if i not in lst1 or i not in lst2] | |
[1, 2, 3, 4, 8, 9, 0, 11, 13, 45, 67, 89, 99] | |
>>> |
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
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.ithinksw.com/"]]; |
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
CGFloat DegreesToRadians(CGFloat degrees) | |
{ | |
return degrees * M_PI / 180; | |
}; | |
CGFloat RadiansToDegrees(CGFloat radians) | |
{ | |
return radians * 180 / M_PI; | |
}; |
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
return ";".join(["%s=%s" % (k, v) for k, v in params.items()]) | |
# or | |
x = range(100) | |
print ";".join(["%s"%(f) for f in x]) |
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
for i, j, q in [1, 2, 3], [4, 5, 6], [7, 8, 9]: | |
print 'i =', i | |
print 'j = ', j | |
print 'q =', q |