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
#!/usr/bin/python | |
# | |
# (originally entered at https://gist.github.com/1035399) | |
# | |
# License: GPLv3 | |
# | |
# To download the AFINN word list do: | |
# wget http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/6010/zip/imm6010.zip | |
# unzip imm6010.zip | |
# |
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 func1(f=nil) | |
print("In func1a\n") | |
return f | |
end | |
def func2(f=func1) | |
print("In func2a\n") | |
return f() | |
end |
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 func1(f1=None): | |
print("In func1a") | |
return f1 | |
def func2(f2=func1): | |
print("In func2a") | |
return f2() | |
def func1(f1=func2): | |
print("In func1b") |
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
#!/usr/bin/python | |
# http://rainbowdash.net/notice/2764341 | |
text = "@zeldatra I'm surprised you got my hair spot on though, " + \ | |
"considering how I exaggerate it so much. " + \ | |
"Thanks! Although I dunno why?" | |
import os.path | |
import re |
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 blessings, re, readline, rlcompleter | |
readline.parse_and_bind("tab: complete") # For tab completion | |
_term = blessings.Terminal() # For coloring text output | |
while True: | |
expr = raw_input(">>> ") | |
try: | |
_ = eval(expr) | |
print(re.sub('5', _term.bold_red_on_green('5'), str(_), |
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
#!/usr/bin/env python | |
""" | |
mydocopter. | |
Usage: mydocopter [options] <filename> | |
Options: | |
-v --verbose Log messages | |
-o OUTPUT --output=OUTPUT Output file | |
-a <a> Initial coefficient for second order term [default: 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
#!/usr/bin/python2.7 | |
# -*- coding: UTF8 -*- | |
""" | |
Copyright: Eesti Vabariigi Valimiskomisjon | |
(Estonian National Electoral Committee), www.vvk.ee | |
Written in 2004-2013 by Cybernetica AS, www.cyber.ee | |
This work is licensed under the Creative Commons | |
Attribution-NonCommercial-NoDerivs 3.0 Unported License. |
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 peak_to_peak(iterable): | |
""" | |
From an input iterable find the present maximum range. Only yield when the range gets larger | |
""" | |
it = iter(iterable) | |
first_value = it.next() | |
the_min = first_value | |
the_max = first_value | |
while True: | |
value = it.next() |
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 is a modified version of the timing code by | |
Patrick Altman "Try / Except Performance in Python: A Simple Test" | |
http://paltman.com/2008/01/18/try-except-performance-in-python-a-simple-test/ | |
""" | |
import time | |
def time_me(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
xs = [ float(i)/64.0 for i in range(-150, 41) ] | |
ys = [ float(i)/16.0 for i in range(-25,26) ] | |
for y in ys: | |
s = '' | |
for x in xs: | |
z = 0j; i = 0 | |
while i < 10: | |
z = z**2 + x+y*1j | |
if abs(z) > 2: | |
break # Get out of inner loop |