Skip to content

Instantly share code, notes, and snippets.

View frostney's full-sized avatar
🐢

Johannes Stein frostney

🐢
View GitHub Profile
@frostney
frostney / gist:ca41937e0eb86fb4a833
Created December 1, 2014 23:07
Requiring global properties like CommonJS modules
(function() {
var modules = {};
var require = function(name) {
var globals = Object.keys(window);
if (Object.keys(modules).length !== globals.length) {
globals.forEach(function(item) {
if (!Object.hasOwnProperty.call(modules, item)) {
modules[item] = window[item];
@frostney
frostney / gist:644da01f725b8c72f3a2
Created August 21, 2014 08:55
Normalizing a path
var normalize = function(path, delimiter) {
if (delimiter == null) {
delimiter = '/';
}
var pathArr = path.split(delimiter);
var newPath = [];
for (var i = 0, j = pathArr.length; i < j; i++) {
(function(item) {
@frostney
frostney / gist:b179a80bfea5d19f50e7
Created May 7, 2014 21:56
Prototyping GameObjects with fluent APIs and tagged behaviors in a group
class GameObject
constructor: ->
@x = 0
@y = 0
@behaviors = {}
andObject = @
@move = (x, y) =>
@x += x
@frostney
frostney / gist:10783806
Last active August 29, 2015 13:59
Prototyping GameObject-/Behavior-Relationship
class Behavior
constructor: (descriptor) ->
mixedice [@, @::], new EventMap()
@type = 'Behavior'
@name = "#{@type}-#{Date.now()}"
@children = {}
@parent = null
@frostney
frostney / gist:9197604
Created February 24, 2014 21:31
Observable class draft, not complete what I want yet, just a little experiment
class Observable
constructor: (data) ->
@changes = []
Object.defineProperty @, 'data',
get: -> data
set: (value) ->
data = value
i() for i in @changes
value
@frostney
frostney / tilemap.js
Created February 8, 2014 15:04
Simple TileMap
define('tilemap', function() {
var TileMap = (function() {
var TileMap = function(width, height) {
if (width == null) {
width = {
min: 0,
max: 4
};
@frostney
frostney / gist:8497678
Created January 18, 2014 22:28
Node.js CommonJS style require for the browser
require = (name) ->
if Object.hasOwnProperty.call require.cache, name
moduleExp = require.cache[name].module.exports
exportObj = require.cache[name].exports
else
moduleObj = {}
exportObj = {}
require.modules[name].apply(this, [require, moduleObj, exportObj]);
require.cache[name] or= {}
@frostney
frostney / gist:8363027
Created January 10, 2014 21:31
EventMap in C#
public class EventMap
{
public delegate void SenderEvent(object sender);
public delegate void Event();
protected Dictionary<String, ArrayList> events;
public object Sender { get; set; }
@frostney
frostney / gist:8141002
Created December 27, 2013 01:03
TextureManager proof-of-concept with Q written in CoffeeScript
class TextureManager
constructor: ->
@textures = {}
load: (texture, callback) ->
texture = [texture] unless Array.isArray texture
textures = @textures
promises = for t in texture
(cb) ->
@frostney
frostney / gist:8140201
Last active January 1, 2016 11:49
Simple texture loader in JavaScript using HTML5 canvas elements
texturize = (url, callback) ->
image = new Image()
image.src = url
image.onload = ->
canvas = document.createElement 'canvas'
context = canvas.getContext '2d'
canvas.width = image.width
canvas.height = image.height