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 datetime import datetime, date | |
from sqlalchemy.orm.query import Query | |
def render_query(statement, bind=None): | |
""" | |
Generate an SQL expression string with bound parameters rendered inline | |
for the given SQLAlchemy statement. | |
WARNING: This method of escaping is insecure, incomplete, and for debugging | |
purposes only. Executing SQL statements with inline-rendered user values is |
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 numpy | |
# Imagine these come from a db cursor or something | |
coordinates = [(1,2,3), (4,5,6), (7,8,9)] | |
def my_gen(some_tuple): | |
for x, y, z in some_tuple: | |
yield x, y, z | |
a = numpy.fromiter(my_gen(coordinates), dtype=[('x', 'l'), ('y', 'l'), ('z', 'l')]) | |
""" |
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/perl | |
use strict; | |
use warnings; | |
use HTTP::Response; | |
my $response = HTTP::Response->new( | |
200, 'OK', [ 'Content-Type' => 'multipart/form-data' ] | |
); |
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 objc | |
import AddressBook as ab | |
import pprint as pp | |
def pythonize(objc_obj): | |
if isinstance(objc_obj, objc.pyobjc_unicode): | |
return unicode(objc_obj) | |
elif isinstance(objc_obj, ab.NSDate): | |
return objc_obj.description() |
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
#See: http://daringfireball.net/2010/07/improved_regex_for_matching_urls | |
import re, urllib | |
GRUBER_URLINTEXT_PAT = re.compile(ur'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))') | |
for line in urllib.urlopen("http://daringfireball.net/misc/2010/07/url-matching-regex-test-data.text"): | |
print [ mgroups[0] for mgroups in GRUBER_URLINTEXT_PAT.findall(line) ] | |
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 random | |
class Markov: | |
def __init__(self, file, size): | |
self.size = size | |
self.starts = [] | |
self.cache = {} | |
self.file_to_words(file) | |
self.parse_words() |
NewerOlder