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 dateutil.parser | |
d1 = '2008-09-03T20:56:35.450686Z' | |
d2 = dateutil.parser.parse(d1) | |
d3 = d2.astimezone(dateutil.tz.tzutc()) | |
s = 'Fri, 09 Dec 2011 13:50:20 +0000' | |
import dateutil.parser | |
d = dateutil.parser.parse(s) | |
>>> d |
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 pymongo import Connection | |
import datetime | |
import time | |
#connect to mongodb | |
connection = Connection(‘newitfarmer.com’, 27017) |
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
# http://stackoverflow.com/questions/748324/python-convert-those-tinyurl-bit-ly-tinyurl-ow-ly-to-full-urls | |
############# | |
# urllib2 | |
import urllib2 | |
fp = urllib2.urlopen('http://bit.ly/rgCbf') | |
fp.geturl() | |
# ==> 'http://webdesignledger.com/freebies/the-best-social-media-icons-all-in-one-place' |
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
given a text file containing stopwords, return a python list of its contents. | |
this list is optimized for twitter/social media and filters out stuff | |
like RT, nowplaying, lastfm, 4sq etc. | |
def get_stopwords(file='stopwords.txt'): | |
words = open(file,'r') | |
stopwords = [word.strip() for word in words] | |
return set(stopwords) |
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
""" | |
tiny script to convert a pandas data frame into a JSON object | |
""" | |
import ujson as json | |
import pandas | |
import numpy as np | |
df = pandas.DataFrame({ | |
"time" : [1,2,3,4,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
# a messy hack written by Edd Dumbill. http://twitter.com/edd | |
# You may need to rerun this script if you hit a Twitter Error because you | |
# use up API rate limiting. That's why we pickle the results, so we can resume | |
# where we left off. | |
# get the twitter module using 'easy_install twitter' | |
from twitter.api import Twitter, TwitterError | |
from twitter.oauth import OAuth |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 as np, numpy.linalg as linalg | |
def fast_svd(M, k): | |
p = k+5 | |
Y = np.dot(M, np.random.normal(size=(M.shape[1],p))) | |
Q,r = linalg.qr(Y) | |
B = np.dot(Q.T,M) | |
Uhat, s, v = linalg.svd(B, full_matrices=False) | |
U = np.dot(Q, Uhat) | |
return U.T[:k].T, s[:k], v[:k] |