Skip to content

Instantly share code, notes, and snippets.

View damianesteban's full-sized avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
@damianesteban
damianesteban / pop_sim
Created August 15, 2013 00:59
by Stephen Chappell
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
@damianesteban
damianesteban / mandelbrot_recursion.py
Created August 15, 2013 15:35
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
damianesteban / pySecureServer.py
Created August 15, 2013 22:30 — forked from ajself/pySecureServer.py
Secure python SimpleHTTPServer
# 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()
# 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
#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):
@damianesteban
damianesteban / class_attr.py
Created September 6, 2013 17:16
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
damianesteban / tembo_geo.py
Created September 7, 2013 15:08
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
damianesteban / oop_game1.py
Created October 8, 2013 05:39
Python OOP Text-Based Game - Weapon Class
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):
@damianesteban
damianesteban / oop_game2.py
Created October 8, 2013 05:40
More examples of OOP text-based game classes in Python
rom collections import defaultdict
_items = defaultdict(set)
_owner = {}
class CanHaveItems(object):
@property
def items(self):
return iter(_items[self])
def take(self, item):
# 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)