Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Not truely a visitor pattern as no accept() methods are being implemented; in this case
* there's just no need to complicate things
*/
interface VisitorPattern
{
static public function visit(&$element);
}
@chandlerprall
chandlerprall / threaded_download.py
Created June 9, 2011 17:41
Small Python multi-threaded file downloader
import urllib2
import threading
from Queue import Queue
import sys, os, re
class ThreadedDownload(object):
REGEX = {
'hostname_strip':re.compile('.*\..*?/', re.I)
}
@chandlerprall
chandlerprall / treefix.py
Created June 9, 2011 17:47
Rebuilds an MPTT-style tree structure in a database table.
# Uses PySQLPool (http://code.google.com/p/pysqlpool/) for the database connection.
from PySQLPool.PySQLConnection import PySQLConnection
from PySQLPool.PySQLQuery import PySQLQuery
import urllib2
import threading
import sys
dbconn = PySQLConnection(host='localhost',user='user',password='password',port=3306,db='schema',charset='utf8')
query = PySQLQuery(dbconn, commitOnEnd=True)
@chandlerprall
chandlerprall / shrodinger.py
Created June 10, 2011 15:35
Python solver for bridge/zombie puzzle
import copy
class State(object):
solutions = []
def __init__(self):
self.zombied = []
self.bridged = []
self.flashlight = 'zombied'
self.weight = 0
@chandlerprall
chandlerprall / ThreeBSP.js
Created December 16, 2011 05:22
Port of Evan Wallace's csg.js to Three.js
THREE.Vector3.prototype.lerp = function ( a, t ) {
return this.clone().addSelf( a.clone().subSelf( this ).multiplyScalar( t ) );
};
THREE.Vertex.prototype.interpolate = function( other, t ) {
var v = new THREE.Vertex( this.position.lerp( other.position, t ) );
v.normal = this.normal.clone();
return v;
};
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="csg.js"></script>
<script type="text/javascript" src="http://chandler.prallfamily.com/threebuilds/builds/r46/ThreeDebug.js"></script>
<script type="text/javascript" src="ThreeBSP.js"></script>
@chandlerprall
chandlerprall / ThreeCSG.js
Created January 10, 2012 18:37
csg.js wrapper for three.js
/*
THREE.CSG
@author Chandler Prall <chandler.prall@gmail.com> http://chandler.prallfamily.com
Wrapper for Evan Wallace's CSG library (https://github.com/evanw/csg.js/)
Provides CSG capabilities for Three.js models.
Provided under the MIT License
*/
@chandlerprall
chandlerprall / tower.js
Created February 25, 2012 17:05
tower source code
'use strict';
var collisionsound1 = new buzz.sound( "assets/sounds/collision1", {
formats: [ 'wav' ]
});
collisionsound1.load();
var collisionsound2 = new buzz.sound( "assets/sounds/collision2", {
formats: [ 'wav' ]
});
@chandlerprall
chandlerprall / gist:3382986
Created August 17, 2012 21:46
meh - its old code, lots to improve. Haven't touched it in months
TerraFrame.TerrainShader = function ( shader_config ) {
var i, vertexShader, fragmentShader;
shader_config = TerraFrame.utils.merge(
{
uniforms: [],
textures: [],
pieces: [],
pervertex_textures: []
terrain_shader = new TerraFrame.TerrainShader({
uniforms: [
{ name: 'sunlight_dir', type: 'v3', value: new THREE.Vector3( -.5, .8, .7 ) }
],
textures: [
{ name: 'grass', asset: 'terrain.grass', repeat: new THREE.Vector2( 2, 2 ) },
{ name: 'rock', asset: 'terrain.rock', repeat: new THREE.Vector2( 3, 3 ) },
{ name: 'sand', asset: 'terrain.sand', repeat: new THREE.Vector2( 2, 2 ) }
],
pieces: [