Skip to content

Instantly share code, notes, and snippets.

View frostney's full-sized avatar
🐢

Johannes Stein frostney

🐢
View GitHub Profile
@frostney
frostney / gist:8062502
Created December 20, 2013 22:14
Annoying your coworkers with masking JavaScript functions to look like Objective-C calls
// Yeah, what is null? Let's make it nil
var nil = null;
var objc_call = function(magic) {
if (magic === nil) {
return nil;
}
var args = Array.prototype.slice.call(arguments, 1);
@frostney
frostney / gist:7627609
Created November 24, 2013 14:04
Game engine experiment in CoffeeScript
###
This a small 1h experiment on creating a game environment which should look similar to a templating engine or QML.
This is just a mockup and may be developed into a game engine in the near future.
###
# Create a new game instance (It would be cool if you wouldn't need an instance and could just write "Game")
new Game ->
# Create a scene within the game
@scene ->
@frostney
frostney / gist:6997374
Created October 15, 2013 19:34
Example of mixing EventMap into a new constructor object with prototypes and direct objects being bound seperately
(function() {
'use strict';
var exportObject, hasModule, isObject,
__hasProp = {}.hasOwnProperty;
(function() {
var _ref;
return (_ref = Array.isArray) != null ? _ref : Array.isArray = function(a) {
return a.push === Array.prototype.push && (a.length != null);
@frostney
frostney / gist:6245988
Created August 15, 2013 23:40
Simple object traversion by dot notation
traverseObject = (o, key) ->
keyArray = if key.indexOf('.') > 0 then key.split('.') else [key]
for k in keyArray
return unless Object.hasOwnProperty.call o, k
o = o[k]
o
@frostney
frostney / gist:6245794
Last active December 21, 2015 03:58
Reusable mixins
do (root = @) ->
root.mixinList = {}
root.mixin = (target, name, params...) ->
root.mixin(target, n, params) for n in name if Array.isArray name
if typeof mixinList[name] is 'function'
mixinList[name].apply(target, params)
else
target[key] = value for key, value of mixinList[name] when not Object.hasOwnProperty.call target, key
@frostney
frostney / gist:6240668
Created August 15, 2013 13:05
Basic shim for getting performance.now() when now function is prefixed. (Prefixes everywhere :) )
var performance = window.performance;
performance.now = performance.now || (function() {
var vendors = ['ms', 'moz', 'webkit', 'o'];
var functionName = '';
for (var i = 0, j = vendors.length; i < j; i++) {
functionName = vendors[i] + 'Now';
if (performance[functionName]) {
return performance[functionName];
@frostney
frostney / gist:6091445
Last active December 20, 2015 07:09
Trying to find a better alternative to setTimeout(fn, 0)
var nextTick = function(fn) {
var id = window.requestAnimationFrame(function() {
fn && fn();
window.cancelAnimationFrame(id);
});
};
@frostney
frostney / gist:6042112
Created July 19, 2013 20:30
EventMap in HaXe
package ;
/**
* ...
* @author Johannes Stein
*/
class EventMap
{
private var map: Map<String, Array<Dynamic -> Void>>;
@frostney
frostney / amara.coffee
Last active December 18, 2015 15:58
Asynchronous module loader in about 50 lines of CoffeeScript. It's not a script loader though, all modules have to be in one file
do (root = if exports? then exports else @) ->
defined = []
modules = {}
evaluateModules = (ids, callback, after) ->
ids = [ids] if typeof deps is 'string'
depList = []
depLength = ids.length
@frostney
frostney / gist:5784526
Last active December 18, 2015 12:39
Safe and fast alternative for deleting items from arrays and objects
deleteItem = (obj, item) ->
if Array.isArray obj
i for i, num in obj when num isnt item
else
newObject = {}
newObject[key] = obj[key] for key of obj when key isnt item
newObject