Skip to content

Instantly share code, notes, and snippets.

View vgoklani's full-sized avatar

Vishal Goklani vgoklani

View GitHub Profile
@vgoklani
vgoklani / datetime_parse.py
Created January 4, 2012 16:15
Parse date in Python
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
from pymongo import Connection
import datetime
import time
#connect to mongodb
connection = Connection(‘newitfarmer.com’, 27017)
@vgoklani
vgoklani / expand_url.py
Created February 13, 2012 00:08
Expand shortened URLs in Python
# 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'
@vgoklani
vgoklani / gist:1817700
Created February 13, 2012 15:44 — forked from neilkod/gist:1319966
my stopwords code, optimized for social media
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)
@vgoklani
vgoklani / df2json.py
Created March 1, 2012 15:23 — forked from mikedewar/df2json.py
A little script to convert a pandas data frame to a JSON object. Is there a better way?
"""
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],
@vgoklani
vgoklani / friends.py
Created April 1, 2012 22:25 — forked from ewilderj/friends.py
Make a graph of your social network from those you follow
# 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
@vgoklani
vgoklani / GPTutorial.ipynb
Created April 10, 2012 20:00 — forked from fonnesbeck/GPTutorial.ipynb
An iPython notebook containing a short PyMC tutorial on Gaussian Processes. Requires PyMC and iPython (>=0.12) to be installed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vgoklani
vgoklani / GPTutorial.ipynb
Created April 11, 2012 11:11 — forked from fonnesbeck/GPTutorial.ipynb
An iPython notebook containing a short PyMC tutorial on Gaussian Processes. Requires PyMC and iPython (>=0.12) to be installed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vgoklani
vgoklani / learning_curves.png
Created April 24, 2012 17:25 — forked from ogrisel/learning_curves.png
Learning Curves for under/overfitting evaluation
learning_curves.png
@vgoklani
vgoklani / fast_svd.py
Created April 26, 2012 03:08 — forked from alextp/fast_svd.py
Gunnar Martinsson's fast svd
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]