Skip to content

Instantly share code, notes, and snippets.

View angus-c's full-sized avatar

angus croll angus-c

View GitHub Profile
@angus-c
angus-c / I_can_haz_10.lol
Created April 28, 2011 18:32
I can haz 10?
HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
UP VAR!!1
VISIBLE VAR
IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE
@angus-c
angus-c / variables.js
Created May 21, 2011 16:51
variable decalration
//one statement - all on one line - good for short, similar purpose vars
var foo = [], bar = [], buzz = [];
//multiple var statements - good for large number or disperate purpose vars
var a = 12;
var collate = false;
var foo = [1,2,3,4];
var circle = {radius: 2, color: blue};
//one statement on multiple lines, no indent
@angus-c
angus-c / mixins.js
Created May 25, 2011 01:38
a fresh approach to mixins
//generic circle functions
var asCircle = function() {
this.area = function() {
return Math.PI * this.radius * this.radius;
}
this.grow = function() {
this.radius++;
}
this.shrink = function() {
this.radius--;
@angus-c
angus-c / jqueryBug.js
Created June 1, 2011 03:15
adding event handler to the <html> element in IE<9 will crash jquery 1.5.2
/*
* probably not good practice to attach event handlers to the <html> element but...
*/
//IE < 9 throws operation not supported error just on property existence check (not function invocation)
typeof $('html')[0]; //"unknown"
$('html')[0].removeAttribute //throws operation not supported error
/************************************************/
@angus-c
angus-c / gist:1081818
Created July 14, 2011 02:08 — forked from max-mapper/gist:1007605
BS ≈ BreakfastScript
Conditionals
( false :)
console.log "if"
:( true )
console.log "else if"
:()
console.log "else"
@angus-c
angus-c / wackyRandomizer.js
Created July 20, 2011 06:12
Wacky Randomizer
/*
Iterates every Math function in random order, with random arguments,
then randomly adds or subtracts each result and rounds the grand total.
Typical output:
+ tan(9)
+ sqrt(0)
- sin(0)
+ random()
@angus-c
angus-c / firstClass.dart
Created October 10, 2011 18:30
first class functions in dart
main() {
print((function(x) => x + 1)(multiply(6, 6)));
}
var multiply = function(a, b) {return a * b;};
@angus-c
angus-c / nodeListMixin.js
Created October 12, 2011 19:06
array-like NodeList via mixins
var NodeList = function() {};
var nodeListExtras = {x: 23};
mixin(NodeList.prototype, Array.prototype, nodeListExtras);
function mixin(obj /*, mixins*/) {
var mixins = [].slice.call(arguments, 1);
for (var i=0; i<mixins.length; i++) {
var thisMixin = mixins[i];
var props = Object.getOwnPropertyNames(thisMixin);
for (var j=0; j<props.length; j++) {
@angus-c
angus-c / gist:1334100
Created November 2, 2011 16:28 — forked from abozhilov/gist:1333507
Arguments default value (allow empty args)
function func(a, f) {
return function (args) {
args = args || {};
args.__proto__ = a;
f.call(this, args);
};
};
var f = func({foo : 10, bar : 20}, function (args) {
@angus-c
angus-c / fatArrow.js
Created March 31, 2012 17:24
es6 fat arrow syntax blocks call/apply context setting
function mixin(obj, fn) {
fn.call(obj);
}
//this gets bound dynamically
var withCircleUtils = function() {
this.area = function() {return this.radius * this.radius * Math.PI};
this.diameter = function() {return this.radius + this.radius};
}