This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "x_type": "Number", | |
"x": 42, | |
"y_type": "[String]", | |
"y": [ "hello", "world" ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vinyls = [ | |
record: | |
name: "The best" | |
year: 2005 | |
, | |
record: | |
name: "OK, The Best For Real" | |
year: 2010 | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Talkable = { | |
talk: function(){ | |
return this.name + ': ' + this.speech() | |
} | |
} | |
var Animal = Object |> { | |
trait Talkable, | |
name: 'Animal', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer