Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
tonyonodi / gist:77b26854e458cb6caef4
Created May 1, 2015 22:41
Non-awful array comparison
// compares contents but nor order... which may or may not be what you want
var arr1 = [1,2,3],
arr2 = [1,2,3];
arr1.every(function(item) {
return arr2.indexOf(item) >= 0;
})
cmd + shift + p
Search "Package Control"
// Prototypeless objects in JS
var map = Object.create(null); // null has no protype or properties
"toString" in map;
// false
@tonyonodi
tonyonodi / gist:a459b13c3657cb59cf82
Created December 17, 2014 02:50
Keep things out of global scope
/* source: http://toddmotto.com/avoiding-anonymous-javascript-functions */
(function (window, document, undefined) {
// la la la
})(window, document);
@tonyonodi
tonyonodi / gist:04dcc3a12adf8105d322
Last active August 29, 2015 14:10
Javascript quine
// source code for a quine (excluding this comment).
console.log(function(string, delimiter) {return string.slice(0, -27) + delimiter + string + delimiter + string.slice(-27)}("console.log(function(string, delimiter) {return string.slice(0, -27) + delimiter + string + delimiter + string.slice(-27)}(, String.fromCharCode(34)))", String.fromCharCode(34)))
@tonyonodi
tonyonodi / gist:4b2db10170419dc5f18f
Last active August 29, 2015 14:04
Lisp like javascript
var range = function(a, b) {
var array,
direction;
array = new Array();
direction = ( b - a ) / Math.abs( b - a );
var i;
for ( i = a; i <= b; i += direction )
array.push( i );