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 main(): | |
while True: | |
creatures = get_creatures() | |
years = get_years() | |
summary = get_summary() | |
target = get_target() | |
simulate(creatures, years, summary, target) | |
if get_exit(): | |
return |
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
# Recursively draw the Mandelbrot set | |
# Dependencies: Python 2.7.5, PyGame 1.9.1 | |
import pygame | |
from pygame.locals import QUIT | |
from sys import exit | |
# size must be a power of 2 or you will get rounding errors in the image | |
# E.g. 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ... | |
size = 512 |
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
# http://www.piware.de/2011/01/creating-an-https-server-in-python/ | |
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes | |
import BaseHTTPServer, SimpleHTTPServer | |
import ssl | |
httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler) | |
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='path/to/localhost.pem', server_side=True) | |
httpd.serve_forever() |
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
# Python Help | |
python -h | |
# Calendar | |
python -m calendar | |
python -m calendar -h | |
python -m calendar 1999 | |
# Zip and Gzip Tools | |
python -m zipfile -l pcblib.zip |
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
#sudo apt-get install python-tornado | |
#there is an altertive as python3-tornado | |
#file below code into hello.py | |
import tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): |
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
# on line 11, we write to a CLASS attribute as opposed to an OBJECT attribute. | |
class Foo: | |
x = 42 | |
foo_1 = Foo() | |
foo_2 = Foo() | |
print(foo_1.a) # 42 | |
foo_1.a = 99 |
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
# Instantiate the Choreo, using a previously instantiated TembooSession object, eg: | |
# session = TembooSession('estebanrules', 'APP_KEY_NAME', 'APP_KEY_VALUE') | |
geocodeByAddressChoreo = GeocodeByAddress(session) | |
# Get an InputSet object for the choreo | |
geocodeByAddressInputs = geocodeByAddressChoreo.new_input_set() | |
# Set inputs | |
geocodeByAddressInputs.set_Address("323 East 21st Street New York, NY 10010") |
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
class Weapon(object): | |
def __init__(self, name): | |
self.name = name | |
self.parent = None | |
def destroy(self): | |
if self.parent: | |
self.parent.weaponDestroyed() | |
def WeaponRef(): | |
def getWeapon(self): |
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
rom collections import defaultdict | |
_items = defaultdict(set) | |
_owner = {} | |
class CanHaveItems(object): | |
@property | |
def items(self): | |
return iter(_items[self]) | |
def take(self, item): |
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
# One option would be to use a signal system | |
# Firstly, we have a reusable class that lets you define a signal | |
class Signal(object): | |
def __init__(self): | |
self._handlers = [] | |
def connect(self, handler): | |
self._handlers.append(handler) |