Skip to content

Instantly share code, notes, and snippets.

@munro
munro / functional.js
Created January 6, 2012 21:16
Phredbob Inheritance
function algorithm(v) {
if (v === 0) {
return 'a';
} else if (v === 1) {
return 'b';
} else if (v === 2) {
return 'c';
}
}
@munro
munro / auto_restart_node.js
Created January 11, 2012 18:43
Auto Restart Node
// Auto restart server on file changes
(function () {
var fs = require('fs'),
original = require.extensions['.js'];
function exitOnChange(filename) {
fs.watchFile(filename, function (curr, prev) {
if (curr.mtime !== prev.mtime) {
process.exit();
}
@munro
munro / php_macros.php
Created January 13, 2012 20:56
PHP Macros
<?php
// TODO: bind macroed function to original function's scope
function getFunctionCode($rfn) {
return implode(array_slice(
preg_split('/\r?\n/', file_get_contents($rfn->getFileName())),
$rfn->getStartLine() - 1,
$rfn->getEndLine() - $rfn->getStartLine() + 1
));
}
@munro
munro / class_dsl.php
Created January 16, 2012 20:19
PHP Class DSL
<?php
$MyClass = $createClass(function () {
inherit($BaseClass);
mixin($OtherClass);
$this->my_var = 123;
decorate($someFunction);
$this->__construct = function ($self) {
$MyClass->$parent->__construct->call($self);
@munro
munro / inception.js
Created February 3, 2012 00:16
Apply Inception
var λ = (λ = function λ() {
console.log('called λ', this, arguments);
return λ;
}).apply.apply.apply(λ.apply, [λ, [undefined, [1, 2, 3]]]);
@munro
munro / base_views.php
Created February 21, 2012 20:08
PHP Class-Based Views
<?php
class Http404 extends Exception {
}
class Builder {
private $callback, $args, $kwargs;
public function __construct($callback, $args = array(), $kwargs = array()) {
$this->callback = $callback;
$this->args = $args;
$this->kwargs = $kwargs;
@munro
munro / tailCall.js
Created February 22, 2012 23:21
Tail Call Optimization
// http://paulbutler.org/archives/tail-recursion-in-python/
function tailCall(fn) {
return function () {
fn = fn.apply(this, arguments);
while (typeof fn === 'function') {
fn = fn();
}
return fn;
};
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f "$HOME/.localrc" ]; then
. $HOME/.localrc
fi
@munro
munro / guess_what.js
Created March 15, 2012 18:13
Why to use semicolons
function guessWhat() {
return function (surprise) {
console.log('guess what?', surprise)
}
}
guessWhat()
(function () {
return "I'm an argument!"
@munro
munro / README.md
Created March 22, 2012 05:43
Hello World — 0x0539.org

This is my first Blog!

Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar. Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar. Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar.

Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar. Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar. Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar Foobar.

See inception.js

  • Item A
  • Item B