Skip to content

Instantly share code, notes, and snippets.

@MorganBorman
MorganBorman / main.py
Created December 9, 2012 04:33
A short example of how to use vertex array objects in PyOpenGL
import OpenGL.GL as GL
import OpenGL.GL.shaders
import ctypes
import pygame
import numpy
vertex_shader = """
#version 330
in vec4 position;
@MorganBorman
MorganBorman / myeventsystem.py
Created October 18, 2012 22:28
simple event system
event_handlers = {}
def registerEventHandler(event_name, handler):
if not event_name in event_handlers.keys():
event_handlers[event_name] = []
event_handlers[event_name].append(handler)
class eventHandler(object):
'''Decorator which registers a function as an event handler.'''
def __init__(self, name):
@MorganBorman
MorganBorman / timesmerp.py
Created October 12, 2012 23:18
a function to time the smooth interpolation function
import time
import random
from noise_function import smerp
start_time = time.time()
for x in xrange(1000*1000):
smerp(random.uniform(0, 1), random.uniform(0, 0.5), random.uniform(0.51, 1))
@MorganBorman
MorganBorman / count.py
Created October 12, 2012 05:06
Counting using a generator which returns the digits of an arbitrary number system
def count(digitgen):
"Takes an iterator which yields the digits of a number system and counts using it."
def subcount(digitgen, places):
if places == 1:
for d in digitgen():
yield d
else:
for d in digitgen():
for ld in subcount(digitgen, places - 1):
@MorganBorman
MorganBorman / SignalObject.py
Created July 21, 2012 01:40
A very lightweight signaling library
"""
An extremely simple synchonous signal/slot handler system.
"""
class Signal(object):
def __init__(self):
self.slots = []
def connect(self, slot):
if not slot in self.slots:
@MorganBorman
MorganBorman / gist:2050629
Created March 16, 2012 15:47
Improved stats schema

user_sums_stats

user_id: Int

mode: Int

day: date

full_games: Int