Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
@damianesteban
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():
return
@damianesteban
damianesteban / mandelbrot_recursion.py
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…
View mandelbrot_recursion.py
# 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 Aug 15, 2013 — forked from ajself/pySecureServer.py
Secure python SimpleHTTPServer
View pySecureServer.py
# 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()
View one-liners.py
# 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
View hello.py
#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 Sep 6, 2013
Simple program that demonstrates when writing to a class attribute in Python.
View class_attr.py
# 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 Sep 7, 2013
choreo code using the Tembo Python SDK. Simple geo loc.
View tembo_geo.py
# 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 Oct 8, 2013
Python OOP Text-Based Game - Weapon Class
View oop_game1.py
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 Oct 8, 2013
More examples of OOP text-based game classes in Python
View oop_game2.py
rom collections import defaultdict
_items = defaultdict(set)
_owner = {}
class CanHaveItems(object):
@property
def items(self):
return iter(_items[self])
def take(self, item):
View oop_game3,py.py
# 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)