Skip to content

Instantly share code, notes, and snippets.


Damian Esteban damianesteban

View GitHub Profile
damianesteban / pop_sim
Created Aug 15, 2013
by Stephen Chappell
View pop_sim
def main():
while True:
creatures = get_creatures()
years = get_years()
summary = get_summary()
target = get_target()
simulate(creatures, years, summary, target)
if get_exit():
damianesteban /
Created Aug 15, 2013
Recursive Mandelbrot Generation (Python recipe) This program recursively generates a Mandelbrot set using Python and PyGame. The size of the window must be a power of two or you will get rendering errors in the final image. It was written as an exercise in recursion, primarily to further my own understanding of that. Created by Bill Pickett on S…
# 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
damianesteban /
Created Aug 15, 2013 — forked from ajself/
Secure python SimpleHTTPServer
# 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)
# Python Help
python -h
# Calendar
python -m calendar
python -m calendar -h
python -m calendar 1999
# Zip and Gzip Tools
python -m zipfile -l
#sudo apt-get install python-tornado
#there is an altertive as python3-tornado
#file below code into
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
damianesteban /
Created Sep 6, 2013
Simple program that demonstrates when writing to a class attribute in Python.
# 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
damianesteban /
Created Sep 7, 2013
choreo code using the Tembo Python SDK. Simple geo loc.
# 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")
damianesteban /
Created Oct 8, 2013
Python OOP Text-Based Game - Weapon Class
class Weapon(object):
def __init__(self, name): = name
self.parent = None
def destroy(self):
if self.parent:
def WeaponRef():
def getWeapon(self):
damianesteban /
Created Oct 8, 2013
More examples of OOP text-based game classes in Python
rom collections import defaultdict
_items = defaultdict(set)
_owner = {}
class CanHaveItems(object):
def items(self):
return iter(_items[self])
def take(self, item):
View oop_game3,
# 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):