Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 numpy import max, min | |
def mean_diff(a): | |
""" | |
Parameters | |
---------- | |
a : array_like | |
""" | |
return float((max(a) - min(a)) / (len(a) - 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
import gdata.youtube.service | |
from time import sleep | |
class YtsClassic(object): | |
""" | |
http://finnaarupnielsen.wordpress.com/2009/09/21/getting-comments-from-youtube-via-pythons-gda/ | |
""" | |
def __init__(self): | |
self.yts = gdata.youtube.service.YouTubeService() |
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
# This example is close to the example provide by the emokit module. | |
from emokit import emotiv | |
import gevent | |
headset = emotiv.Emotiv() | |
gevent.spawn(headset.setup) | |
gevent.sleep(1.5) | |
try: |
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
class MyClass: | |
my_static_variable = "Static" # not self. | |
def __init__(self): | |
self.my_instance_variable = "Instance" | |
def change_static(self): | |
MyClass.my_static_variable = "Changed" # not self. | |
def change_instance(self): | |
self.my_instance_variable = "Also changed" | |
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
def accuracy(truth, predicted): | |
if len(truth) != len(predicted): | |
raise Exception("Wrong sizes ...") | |
total = len(truth) | |
if total == 0: | |
return 0 | |
hits = len(filter(lambda (x, y): x == y, zip(truth, predicted))) | |
return float(hits)/total | |
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 __future__ import division | |
from itertools import * | |
from pylab import * | |
from nltk.corpus import brown | |
from string import lower | |
from collections import Counter | |
# The data: token counts from the Brown corpus | |
tokens_with_count = Counter(imap(lower, brown.words())) |
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") |
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
import gdata.youtube.service | |
yts = gdata.youtube.service.YouTubeService() | |
urlpattern = "http://gdata.youtube.com/feeds/api/videos/" + \ | |
"9ar0TF7J5f0/comments?start-index=%d&max-results=25" | |
index = 1 | |
url = urlpattern % index | |
comments = [] | |
while True: | |
ytfeed = yts.GetYouTubeVideoCommentFeed(uri=url) | |
comments.extend([comment.content.text for comment in ytfeed.entry]) |