Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View captainbrosset's full-sized avatar
👋

Patrick Brosset captainbrosset

👋
View GitHub Profile
@captainbrosset
captainbrosset / collision.js
Created June 4, 2013 21:32
Pixel-perfect javascript 2D collision detection
/*
2d pixel-perfect collision detection
Requires that each object has a rectangular bounding box (simple x/y/w/h, no rotation)
and a bit mask (i.e. an array of lines and columns containing 0s for empty pixels and 1s for solid pixels).
On each frame of the animation, take all pairs of objects and
1. compare the bounding boxes
2. for those that collide, check for overlayed bits by creating a new mask that is the AND of the 2 sub-masks and check for 1s
@liamcain
liamcain / autofilename.py
Created January 13, 2012 19:35
Autocomplete Filenames in Sublime Text 2
import sublime, sublime_plugin, os, re
class FileNameComplete(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
completions = []
sel = view.sel()[0].a
if "string" in view.syntax_name(sel):
pass
@devdave
devdave / visitor.py
Created January 13, 2012 16:30
Truncated base visitor class
class Visitor(object):
CHILD_ATTRS = ['value', 'thenPart', 'elsePart', 'expression', 'body','exception', 'initializer', 'tryBlock', 'condition','update', 'iterator', 'object', 'setup', 'discriminant', 'finallyBlock', 'tryBlock', 'varDecl', 'target']
def __init__(self, filepath):
self.filepath = filepath
#List of functions by line # and set of names
self.functions = defaultdict(set)
with open(filepath) as myFile:
self.source = myFile.read()