Skip to content

Instantly share code, notes, and snippets.

View sbstp's full-sized avatar

Simon Bernier St-Pierre sbstp

View GitHub Profile
@sbstp
sbstp / money_splitter.coffee
Last active August 29, 2015 13:55
Determines who should give how much to who, accounting for each person's input
displayNum = (num) ->
return '' + Math.round(num * 100) / 100
class Person
constructor: (@name, @input) ->
@balance = 0
give: (other, amount) ->
@balance -= amount
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;
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;
// 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);
function Const(hue) {
if (!(this instanceof Const)) {
var obj = Object.create(Const.prototype);
Const.apply(obj, arguments);
return obj;
}
this.hue = hue;
}
function instanceof2(obj, ctor) {
var proto = obj.__proto__;
while (proto !== null) {
if (proto === ctor.prototype) {
return true;
}
proto = proto.__proto__;
}
return false;
}
@sbstp
sbstp / bind.js
Last active August 29, 2015 13:57
function bind(fn, context) {
return function () {
return fn.apply(context, arguments);
}
}
function hey() {
console.log(this, arguments);
return 'moist';
}
function split(string) {
var curr
, lastQuoteIndex = 0
, lastSpaceIndex = 0
, parts = []
, isInQuotes = false;
for (var i = 0; i < string.length; i++) {
curr = string[i];
var re = /([^\s"']+)|"([^"]*)"/g;
var match;
var parts = [];
while (match = re.exec(text)) {
parts.push(match[1] || match[2]);
}
console.log(parts);
#!/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