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
################# | |
def sanitiseNames(dummyObject): | |
################# | |
if type(dummyObject)==dict: | |
for k,v in dummyObject.items(): | |
if re.search('\$',k,re.U): | |
# Replace | |
dummyObject[k.replace('$','')]=v | |
del dummyObject[k] |
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 requests | |
ids=['qJS3xnD7Mus','LrNSOnQIVbI','p3tUqRBiMVo'] | |
for id in ids: | |
commentsLink='https://gdata.youtube.com/feeds/api/videos/'+id+'/comments?v=2'+'&alt=json&max-results=50 | |
commentsRaw=requests.get(commentsLink) | |
print commentsRaw.ststus_code | |
# 404 means not found, 200 means success |
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 | |
def entropy(vals): | |
sum=0.0 | |
norm=0.0 | |
for v in vals:norm+=v | |
vals=[v/norm for v in vals] | |
for v in vals:sum+=(v*np.log(v)) | |
return -1.0*sum | |
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
for a,b in df.groupby('topics'): | |
b.resample('D',how='count')['content'].plot(label=a,legend=True,figsize=(20,10),logy=False) |
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 flask import Flask,render_template,jsonify,make_response,request,current_app,url_for | |
import pymysql | |
app=Flask('yt_db') | |
api=Api(app) | |
########################## | |
@app.route("/hello") | |
def hello(): | |
return 'Hello world' |
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
for v in $(say -v ? | awk '{print $1}'); do echo $v; say -v $v 'CHeck out my voice' ;done |
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
def check_args(*types): | |
def real_decorator(func): | |
def wrapper(*args, **kwargs): | |
for val, typ in zip(args, types): | |
assert isinstance(val, typ), "Value {} is not of expected type {}".format(val, typ) | |
return func(*args, **kwargs) | |
return wrapper | |
return real_decorator | |
def do_long_computation(name): |
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 glob | |
import shapefile | |
from matplotlib.path import Path | |
class HitDetector(): | |
''' | |
Class to test if an arbitrary (lat,long) point | |
is within the boundary of a country outline | |
and which region it belongs in. Uses shapefiles | |
from gadm.org |
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 twitter | |
import csv | |
import json | |
""" | |
NOTE: You must have python-twitter installed on the machine running this script; | |
You can install it by running this on the command line: | |
sudo pip install python-twitter |
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 mpl_toolkits.basemap import Basemap | |
m = Basemap(projection='merc',lon_0=0,lat_0=0,resolution='l',area_thresh=30000,llcrnrlon=-120,llcrnrlat=-60,urcrnrlon=170,urcrnrlat=70) | |
m.drawcountries(linewidth=0.25,color='white') | |
m.drawlsmask(lakes=False) | |
for coord in random.sample(coords,10000): | |
# We select 10k checkins at random as too many checkins | |
m.plot(coord[1],coord[0],marker='o',color='r',markersize=1,latlon=True,alpha=0.1) | |
plt.savefig('map.png',dpi=200) |
OlderNewer