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 Vehicle(): | |
def is_movable(self): return True | |
class Car(Vehicle): | |
def __init__(self, color): self.color = color | |
def has_wheels(self): return True | |
class CrashedCar(Car): | |
# overloading the grandparent 'is_movable' method | |
def is_movable(self): return False |
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 |
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
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
#!/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
#!/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
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/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
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
def func1(f=nil) | |
print("In func1a\n") | |
return f | |
end | |
def func2(f=func1) | |
print("In func2a\n") | |
return f() | |
end |