Skip to content

Instantly share code, notes, and snippets.

View omaraboumrad's full-sized avatar

Omar Abou Mrad omaraboumrad

View GitHub Profile
@omaraboumrad
omaraboumrad / fiddle.html
Last active December 25, 2015 23:39
sprite management w/ test
<div id="qunit"></div>
<div id="qunit-fixture"></div>
@omaraboumrad
omaraboumrad / fiddle.js
Last active December 23, 2016 05:23
sprite management w/ sample
window.onload = init;
function init(){
// -- Sprite Management Api -- //
var rectangular_intersection = function(r1, r2){
var t1 = [r1[0], r1[0] + r1[2], r1[1], r1[1] + r1[3]];
var t2 = [r2[0], r2[0] + r2[2], r2[1], r2[1] + r2[3]];
return !(t2[0] > t1[1] ||
t2[1] < t1[0] ||
t2[2] > t1[3] ||
@omaraboumrad
omaraboumrad / fiddle.css
Last active December 25, 2015 23:29
space shooter
p{
font-family: verdana;
font-size: 12px;
}
@omaraboumrad
omaraboumrad / fiddle.html
Created October 19, 2013 15:34
space glider
<audio autoplay loop>
<source src="https://dl.dropboxusercontent.com/u/18982788/starwars.mp3" />
</audio>
@omaraboumrad
omaraboumrad / fiddle.js
Created October 19, 2013 15:24
Parallax scrolling
window.onload = init;
function init(){
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.width = 400;
canvas.height = 400;
var ctx = canvas.getContext('2d');
@omaraboumrad
omaraboumrad / fiddle.js
Last active May 30, 2018 13:45
character jumping
window.onload = init;
function init(){
var ImageLoader = function(args, callback){
// Usage: new ImageLoader({
// 'img1':'/url/to/img1',
// 'img2':'/url/to/img2',}, cb);
// Returns: {'img1': [Image], 'img2': [Image]}
@omaraboumrad
omaraboumrad / singledispatch.py
Last active December 23, 2015 08:19
Poor man's singledispatch
# Define
def singledispatch(func):
through_map = {}
def register(through):
def _on(what):
through_map[through] = what
return what
return _on
def dispatch(what):
@omaraboumrad
omaraboumrad / sprite_sheet.py
Last active December 22, 2015 11:09
Dealing with a spritesheet of 16 images in a 4x4 matrix
import sys
import pygame
class Character(pygame.sprite.Sprite):
def __init__(self, *group):
super(Character, self).__init__(*group)
self.sheet = pygame.image.load('char.png')
self.at = 0
self.elapsed = 0
self.rect = pygame.rect.Rect(50, 100, 50, 50)
@omaraboumrad
omaraboumrad / bootstrap.py
Created September 3, 2013 22:44
sily little vagrant bootstrapper
#! /usr/bin/python
import os
def cmd(txt):
print '>>> {} <<<'.format(txt)
return os.system(txt) >> 8
def test(what):
return cmd(what) == 0
@omaraboumrad
omaraboumrad / node.py
Last active December 22, 2015 04:18
simple bidirectional tree
class NodeList(list):
def __init__(self, root, items):
self.root = root
super(NodeList, self).__init__(items)
def append(self, item):
item._parent = self.root
super(NodeList, self).append(item)
class Node(object):