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/python | |
# reference => http://www.puffinwarellc.com/index.php/news-and-articles/articles/33.html | |
from numpy import zeros | |
from scipy.linalg import svd | |
from math import log # needed for TFIDF | |
from numpy import asarray, sum | |
titles = ["The Neatest Little Guide to Stock Market Investing", |
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/python | |
# reference => http://glowingpython.blogspot.com/2011/10/perceptron.html | |
from pylab import rand,plot,show,norm | |
def generateData(n): | |
""" | |
generates a 2D linearly separable dataset with n samples, where the third element is the label | |
""" |
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/python | |
# http://en.wikipedia.org/wiki/Viterbi_algorithm | |
''' | |
Consider two friends, Alice and Bob, who live far apart from each other and who talk together daily over the telephone about what they did that day. Bob is only interested in three activities: walking in the park, shopping, and cleaning his apartment. The choice of what to do is determined exclusively by the weather on a given day. Alice has no definite information about the weather where Bob lives, but she knows general trends. Based on what Bob tells her he did each day, Alice tries to guess what the weather must have been like. | |
Alice believes that the weather operates as a discrete Markov chain. There are two states, "Rainy" and "Sunny", but she cannot observe them directly, that is, they are hidden from her. On each day, there is a certain chance that Bob will perform one of the following activities, depending on the weather: "walk", "shop", or "clean". Since Bob tells Alice about his activities, those are the observations. The entire |
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
f = open('filename.txt', 'r') | |
from BeautifulSoup import BeautifulSoup | |
soup = BeautifulSoup(f) | |
for tag in soup.findAll('a', href=True): | |
print tag['href'] |
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 | |
urls = re.findall(r'href=[\'"]?([^\'" >]+)', s) | |
print ', '.join(urls) |
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/python | |
# -*- coding: utf-8 -*- | |
import httplib2, json | |
__links__ = (r'http://developer.klout.com/iodocs') | |
KLOUT_API_KEY = '' # required! | |
''' |
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 pycurl, urllib, json, sys, httplib2 | |
''' | |
curl -d 'track=google' https://stream.twitter.com/1/statuses/filter.json -uusername:password | |
http://dev.twitter.com/pages/streaming_api_methods | |
https://gist.github.com/1046726 | |
http://www.angryobjects.com/2011/10/15/http-with-python-pycurl-by-example/ | |
''' |
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 | |
# encoding: utf-8 | |
__links__ = r'https://gist.github.com/916362' | |
import smtplib | |
from datetime import datetime | |
import email.utils | |
from email.mime.text import MIMEText |
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
# dropping a database via pymongo | |
from pymongo import Connection | |
c = Connection() | |
c.drop_database('mydatabase') | |
# drop a collection via pymongo | |
from pymongo import Connection | |
c = Connection() | |
c['mydatabase'].drop_collection('mycollection') |
OlderNewer