This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* source: http://toddmotto.com/avoiding-anonymous-javascript-functions */ | |
(function (window, document, undefined) { | |
// la la la | |
})(window, document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototypeless objects in JS | |
var map = Object.create(null); // null has no protype or properties | |
"toString" in map; | |
// false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd + shift + p | |
Search "Package Control" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Obviously you can't parse XML with regex but if you just need to grab some values from a feed quickly... | |
(?<=tag>).*(?=<\/tag) | |
should do the trick. Falls over if anything is nested etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(n) { | |
return (function(fact_iter) { | |
return fact_iter(fact_iter, 1, 1) | |
})(function(f_i, product, counter) { | |
return counter > n ? | |
product : | |
f_i(f_i, counter * product, counter + 1) | |
}) | |
})(5) // returns 5! or 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// doesn't work for some reason | |
lambda {|n| | |
lambda {|fact_iter| | |
fact_iter(fact_iter, 1, 1) | |
}.call(lambda {|f_i, product, counter| | |
if counter > n | |
product | |
else | |
f_i(f_i, counter * product, counter + 1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Turn a horrible string into a slug | |
" My string -is 1234!!5 here".trim() | |
.toLowerCase() | |
.replace(/[\s\-]+/g, "-") | |
.replace(/[^\w\-]+/g, ""); |
OlderNewer