Skip to content

Instantly share code, notes, and snippets.

@CrypticSwarm
CrypticSwarm / broken.js
Created August 8, 2012 02:45
Showcases a subtle problem that can occur due to getters.
var optimist = require('optimist')
optimist.demand('color')
optimist.demand('size')
optimist.argv
// Flow is a construct that can chain together functions.
// Flow denotes regular function composition.
var chain1 =
Flow <- f1
<- f2
<- f3
chain1(123) // same as f3(f2(f1(123)))
// Can also chain together multiple things that go to one.
@CrypticSwarm
CrypticSwarm / handlerMaker.js
Created September 28, 2011 05:16
Harmony Proxies experiment.
//From http://wiki.ecmascript.org/doku.php?id=harmony:proxies
function handlerMaker(obj) {
return {
getOwnPropertyDescriptor: function(name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
// a trapping proxy's properties must always be configurable
if (desc !== undefined) { desc.configurable = true; }
return desc;
},
getPropertyDescriptor: function(name) {
(def items [:rock :paper :scissors])
(defn winner [m1 m2]
(mod (- m1 m2 1) 3))
(defn player-string [name symbol]
(str name (nth items symbol) " wins!"))
(defn player-wins [m1 m2]
(str (nth items m1) " vs. " (nth items m2) " !! "
Function.prototype.ac = (function(){
return ac;
function ac(len, bind, args){
var func = this
, args = args || [];
return function internal(){
args = args.concat(Array.prototype.slice.call(arguments));
len -= arguments.length;
if (len > 0) return internal;
else func.apply(bind, args);
var fs = require('fs');
var path = require('path');
var sys = require('sys')
, limit = 50
, count = 0;
function copytree(src, dst) {
if(!path.existsSync(src)) {
throw new Error(src + ' does not exists. Nothing to be copied');
}
(function(){
this.Class = function(params){
if (params instanceof Function) params = {initialize: params};
var newClass = function(){
this.Object.reset(this);
if (newClass._prototyping) return this;
this._current = $empty;
var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
require('./getter').grabInto(['./docs'], GLOBAL);
var path = './';
exports.generateDocs = function(out, files, format){
files = (files instanceof Array ? files : [files]);
var output = require(format).output;
files.forEach(function(file) {
out('OUTPUTING ' + file + ' starting\n\n');
require(path + file);
getDoced().forEach(function(item) {
output(out, item);
/*
Script: Keyboard.js
KeyboardEvents used to intercept events on a class for keyboard and format modifiers in a specific order so as to make
alt+shift+c the same as shift+alt+c.
License:
MIT-style license.
Authors:
Perrin Westrich
APE.Move = new Class({
Implements: [Options],
Extends: APE.UserClient,
options: {
container: document.body,
userEvents: [{cmd: 'send', raw: 'data'}, {cmd: 'setPos', raw: 'positions'}]
},