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
displayNum = (num) -> | |
return '' + Math.round(num * 100) / 100 | |
class Person | |
constructor: (@name, @input) -> | |
@balance = 0 | |
give: (other, amount) -> | |
@balance -= amount |
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
function extend(parent, child) { | |
var proto = {}; | |
for (fnName in parent.prototype) { | |
proto[fnName] = parent.prototype[fnName]; | |
} | |
for (fnName in child.prototype) { | |
proto[fnName] = child.prototype[fnName]; | |
} | |
child.super = parent; | |
child.prototype = proto; |
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 util = require('util'); | |
function extend(parent, child) { | |
// TODO copy old functions of the child prototype | |
var proto; | |
if (false/*Object.create*/) { | |
proto = Object.create(parent.prototype); | |
} else { | |
function f() {} | |
f.prototype = parent.prototype; |
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
// allow object inheritance | |
Object.extends = function (ctor, superCtor) { | |
// collect objects already on the prototype to "save" them | |
var descriptors = {}; | |
// copy properties from old prototype | |
Object.getOwnPropertyNames(ctor.prototype).forEach(function (propertyName) { | |
descriptors[propertyName] = Object.getOwnPropertyDescriptor(ctor.prototype, propertyName); | |
}, this); |
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
function Const(hue) { | |
if (!(this instanceof Const)) { | |
var obj = Object.create(Const.prototype); | |
Const.apply(obj, arguments); | |
return obj; | |
} | |
this.hue = hue; | |
} |
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
function instanceof2(obj, ctor) { | |
var proto = obj.__proto__; | |
while (proto !== null) { | |
if (proto === ctor.prototype) { | |
return true; | |
} | |
proto = proto.__proto__; | |
} | |
return false; | |
} |
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
function bind(fn, context) { | |
return function () { | |
return fn.apply(context, arguments); | |
} | |
} | |
function hey() { | |
console.log(this, arguments); | |
return 'moist'; | |
} |
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
function split(string) { | |
var curr | |
, lastQuoteIndex = 0 | |
, lastSpaceIndex = 0 | |
, parts = [] | |
, isInQuotes = false; | |
for (var i = 0; i < string.length; i++) { | |
curr = string[i]; | |
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 re = /([^\s"']+)|"([^"]*)"/g; | |
var match; | |
var parts = []; | |
while (match = re.exec(text)) { | |
parts.push(match[1] || match[2]); | |
} | |
console.log(parts); |
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
#!/bin/bash | |
# Requires pygments (the python library) | |
# Installation: | |
# pip install pygments | |
# Download the script and make it executable. | |
# Usage: | |
# code <filename> | |
pygmentize -f terminal $1 | less -R |
OlderNewer