Skip to content

Instantly share code, notes, and snippets.

function FindProxyForURL(url, host)
{
if (dnsDomainIs(host, ".pandora.com"))
return "PROXY 199.189.84.217:3128"
if (dnsDomainIs(host, ".spotify.com"))
return "PROXY 54.246.92.203:80"
return "DIRECT"
}
from __future__ import division
from bs4 import BeautifulSoup as bs
import requests
import re
import time
from pymongo import MongoClient
from time import mktime
from datetime import datetime
import plotly.plotly as py
import plotly.graph_objs as go
@thinrhino
thinrhino / send_email.py
Created May 2, 2014 10:34
Send mails using Mandrill API
from mandrill import Mandrill
import base64
mail_client = Mandrill('<api_key>')
frm_email = 'email@email.com'
frm_name = 'Given Name'
# Sending image as attachment
img_attachment = base64.b64encode(open('~/sample_image.jpg', 'rb').read())
@thinrhino
thinrhino / tf-idf.py
Created May 5, 2014 13:09
Calculate tf-idf
# ref: http://www.tfidf.com/
# Example:
# Consider a document containing 100 words wherein the word cat appears 3 times.
# The term frequency (i.e., tf) for cat is then (3 / 100) = 0.03. Now, assume we
# have 10 million documents and the word cat appears in one thousand of these.
# Then, the inverse document frequency (i.e., idf) is calculated as log(10,000,000 / 1,000) = 4.
# Thus, the Tf-idf weight is the product of these quantities: 0.03 * 4 = 0.12.
#
# Hence:
# 1. Calculate term frequency