Skip to content

Instantly share code, notes, and snippets.

View FireyFly's full-sized avatar

FireFly FireyFly

View GitHub Profile
@FireyFly
FireyFly / test2.coffee
Created June 22, 2011 21:30
Playing around with ES Harmony Proxies
Proxy ?= require "node-proxy"
desc =
getPropertyDescriptor: (name) ->
value: (Proxy.createFunction desc,
(rest...) ->
(arg1, args...) ->
restIdx = 0
if typeof arg1[name] == 'function'
arg1[name].apply arg1, rest.map (arg) ->
initGL = (canvas) ->
gl = canvas.getContext 'experimental-webgl'
gl.viewportWidth = canvas.width
gl.viewportHeight = canvas.height
if not gl
throw new Error "Could not initialise WebGL :("
gl
initGL = (canvas) ->
gl = canvas.getContext 'experimental-webgl'
gl.viewportWidth = canvas.width
gl.viewportHeight = canvas.height
if not gl
throw new Error "Could not initialise WebGL :("
gl
@FireyFly
FireyFly / bleh.json
Last active September 26, 2015 09:38
{ "x_type": "Number",
"x": 42,
"y_type": "[String]",
"y": [ "hello", "world" ] }
@FireyFly
FireyFly / gist:1122730
Created August 3, 2011 14:11 — forked from anonymous/gist:1120803
CoffeeScript Sample
vinyls = [
record:
name: "The best"
year: 2005
,
record:
name: "OK, The Best For Real"
year: 2010
]
var Talkable = {
talk: function(){
return this.name + ': ' + this.speech()
}
}
var Animal = Object |> {
trait Talkable,
name: 'Animal',
@FireyFly
FireyFly / bounce.as
Created November 27, 2011 00:55
NIC programs
// Program that moves around a 0xff word a 2D array with a
// width of 16 and a height of 8 occupying the memory pos-
// itions 0x80 - 0xff (inclusive), bouncing off edges.
//
// Author : Jonas Hoglund
// Date : 2011-11-21
//
// Constants
loadc re 0x00
// Foo is a simple type with a unique ID for each instance.
var idCounter = 0
function Foo() {
this.id = (++idCounter) // assign a unique ID to this instance
}
Foo.prototype.getID = function() {return this.id}
// We make sure that it's working as intended by creating two instances.
var foo = new Foo()
, foo2 = new Foo()
@FireyFly
FireyFly / gist:1975677
Created March 5, 2012 00:42 — forked from koistya/gist:1975645
Named parameters application of a function
/**
* Applies a set of named arguments to a `func`.
*
* Example: var f = function(x, y, z) { return x * (y - z); };
* namedApply(f, {x: 1, y: 2, z: 3});
*
* @param func {Function} A function to invoke.
* @param args {Object} A collection of named arguments.
* @return {Function} A new function with partially applied named arguments.
*/
@FireyFly
FireyFly / gist:2000920
Created March 8, 2012 13:08
Object inheritance
var Base = {}
Object.defineProperty(Base, 'extend', {
enumerable: false,
value: function(obj) {
var descs = {}
Object.getOwnPropertyNames(obj).forEach(function(key) {
descs[key] = Object.getOwnPropertyDescriptor(obj, key)
})
return Object.create(this, descs)