This file contains hidden or 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 simplejson, urllib # To get posts from Twitter | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import cm # Colormap | |
import scipy.stats # For kernel density estimation | |
# Get geo-tagged posts from Twitter | |
url = 'http://search.twitter.com/search?q=geotag&format=json&rpp=100' | |
resp = simplejson.load(urllib.urlopen(url)) | |
coords = np.asarray([ t['geo']['coordinates'][::-1] |
This file contains hidden or 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
# Modified Step1 Cone1.py from VTK examples by W. Schroeder (2006) Visualization... | |
import vtk, time | |
cone = vtk.vtkConeSource() # Cone graphical object | |
coneMapper = vtk.vtkPolyDataMapper() # 'Mapper' | |
coneMapper.SetInputConnection(cone.GetOutputPort()) | |
coneActor = vtk.vtkActor() # 'Actor' | |
coneActor.SetMapper(coneMapper) | |
ren1= vtk.vtkRenderer() # 'Renderer' |
This file contains hidden or 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 matplotlib.finance import quotes_historical_yahoo | |
from matplotlib.dates import num2date | |
from matplotlib.pyplot import * | |
from datetime import date | |
quotes = quotes_historical_yahoo('NVO', date(2011, 1, 1), date.today()) | |
dates = [ num2date(row[0]) for row in quotes ] | |
closeprice = [ row[1] for row in quotes ] | |
plot(dates, closeprice) | |
show() |
This file contains hidden or 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 pylab import * | |
from urllib2 import urlopen | |
from simplejson import load | |
from re import findall | |
url = 'http://neuro.imm.dtu.dk/w/api.php?' + \ | |
'action=query&list=blocks&' + \ | |
'bkprop=id|user|by|timestamp|expiry|reason|range|flags&' + \ | |
'bklimit=500&format=json' | |
data = load(urlopen(url)) |
This file contains hidden or 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 htmllib, formatter, urllib, urlparse | |
k = 1 | |
urls = {} | |
todownload = set(['http://www.dtu.dk']) | |
while todownload: | |
url0 = todownload.pop() | |
urls[url0] = set() | |
try: | |
p = htmllib.HTMLParser(formatter.NullFormatter()) |
This file contains hidden or 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 Tkinter import * | |
def hello(): | |
"""Callback function for button press.""" | |
print "Hello World" | |
# Main root window | |
root = Tk() | |
# A button with a callback function |
This file contains hidden or 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 Tkinter import * | |
root = Tk() | |
canvas = Canvas(root, width=400, height=200) | |
canvas.pack() | |
canvas.create_oval(10, 10, 110, 60, fill="grey") | |
canvas.create_text(60, 35, text="Oval") | |
canvas.create_rectangle(10, 100, 110, 150, outline="blue") | |
canvas.create_text(60, 125, text="Rectangle") | |
canvas.create_line(60, 60, 60, 100, width=3) |
This file contains hidden or 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://docs.cherrypy.org/stable/concepts/basics.html | |
import cherrypy | |
class HelloWorld: | |
def index(self): | |
return "Hello world!" | |
index.exposed = True | |
cherrypy.quickstart(HelloWorld()) |
This file contains hidden or 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
######### | |
# Tornado | |
wget https://raw.github.com/facebook/tornado/master/demos/helloworld/helloworld.py | |
python helloworld.py | |
# 100 concurrent | |
ab -c 100 -n 1000 -k localhost.localdomain:8888/ | grep "Time taken for tests:" | |
# Time taken for tests: 0.709 seconds | |
# 5 concurrent |
This file contains hidden or 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 shelve | |
import multiprocessing | |
import os | |
filename = "tmp.shelve" | |
N = 4 | |
end = 10000 | |
def insert((offset, jump, end, filename)): |