Skip to content

Instantly share code, notes, and snippets.

View FireyFly's full-sized avatar

FireFly FireyFly

View GitHub Profile
@FireyFly
FireyFly / shallow-vs-deep.md
Last active December 11, 2015 18:48
Shallow vs. deep copy (illustrations)

Shallow vs. deep copy

var arr1 = [ {foo:1, bar:2},
             {foo:3, bar:4},
             {foo:5} ]

\

@FireyFly
FireyFly / ternary.js
Created December 4, 2012 16:00
nested ternary formatting
function foo(bar) {
return bar === baz? 'hello'
: bar === quux? 'hey'
: /*otherwise*/ 'hi'
}
@FireyFly
FireyFly / main.c
Created November 19, 2012 22:31
Experimenting with XOR-linked lists
#include <stdio.h>
#include "xorlist.h"
int main(void) {
struct Node *list = NULL;
for (int i=1; i<=15; i++) {
push(i, &list);
}
@FireyFly
FireyFly / a
Created August 16, 2012 22:25 — forked from gkatsev/gist:3374141
JS: The Hip Parts.
Chapters =
[ Comma-First is Comma Right
, !function Expressions!
, <!--Comments with Style-->
, Blow it Out Your Semi-Colon ]
@FireyFly
FireyFly / example.lua
Created August 15, 2012 22:16
Lua super-light fancy delegative prototypal inheritance
local Base = require('library').Base
local Person = Base {
-- missing properties: name
speak = function (self)
return "Hello, I am " .. self.name
end
}
local Programmer = Person {
@FireyFly
FireyFly / gist:3359544
Created August 15, 2012 12:05
SpiderMonkey globals
js> function inspect(obj) {var res = []; for (var k in obj) res.push([k, typeof (o = obj[k]) == 'boolean' ? o : typeof o].join(":")); return "{ " + res.join(", ") + " }"}
js> print(Object.getOwnPropertyNames(this).map(function(n) {return [n, inspect(Object.getOwnPropertyDescriptor(this, n))].join(Array(24-n.length).join(" "))}).join("\n"))
Function { value:function, writable:true, enumerable:false, configurable:true }
Object { value:function, writable:true, enumerable:false, configurable:true }
eval { value:function, writable:true, enumerable:false, configurable:true }
PerfMeasurement { value:function, writable:true, enumerable:false, configurable:true }
version { value:function, writable:true, enumerable:false, configurable:true }
revertVersion { value:function, writable:true, enumerable:false, configurable:true }
options { value:function, writable:true, enumerable:false, configurable:true }
load {
@FireyFly
FireyFly / library.js
Created August 2, 2012 22:49
Append extra arguments to a function
function a(a1, callback) {
// ...does stuff
callback("a", "b", "c")
}
@FireyFly
FireyFly / am-i-being-dumb.js
Created July 24, 2012 17:15 — forked from cowboy/am-i-being-dumb.js
JavaScript: split on :, handling escaped \:
// Split colon-separated parts, unescaping (but not splitting on) any \:
function split(str) {
return str.match(/(?:\\:|[^:])+/g).map(function(part) {
return part.replace(/\\:/g, ':')
});
}
// Eg.
@FireyFly
FireyFly / gist:3137013
Created July 18, 2012 15:41 — forked from ailabs-software/gist:3136976
Is this ECMAScript okay?
var __objectInheritanceCalculated = [];
while((function()
{
/* There is a object class that has not been processed */
var __t = 0;
for (var m in objectclasses) { __t++; }
if (__t <= __objectInheritanceCalculated.length) return false;
return true;
})())
{
//-- Definition
Function.prototype.compose = function (/* ...args */) {
var args = Array.prototype.slice.call(arguments)
, funs = [ this ].concat(args)
return function (/* ... */) {
return funs.reduceRight(function (args, f) {
return [ f.apply(null, args) ]
}, arguments)[0]
}