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 getElementsByClassName = function(className) { | |
var element = arguments[1] || document.body, | |
results = [], | |
has_class_name = [].indexOf.call(element.classList, className) !== -1, | |
children_results = [].map.call(element.children, function(element) { | |
return getElementsByClassName(className,element)[0]; | |
}).filter(Boolean); | |
if (has_class_name) { | |
results.push(element); |
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
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script> |
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 addf(x) { | |
return function(y) { | |
return x + y; | |
} | |
} | |
addf(3)(4) | |
------------------------- |
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 applyf(binary) { | |
return function(x) { | |
return function(y) { | |
return binary(x, y); | |
}; | |
}; | |
} | |
addf = applyf(add); | |
addf(3)(4) //=> 7 |
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 parse_git_branch { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
echo "git:("${ref#refs/heads/}$(num_git_commits_ahead)")" | |
} | |
function num_git_commits_ahead { | |
num=$(git status 2> /dev/null \ | |
| grep "Your branch is ahead of" \ | |
| awk '{split($0,a," "); print a[9];}' 2> /dev/null) || return | |
if [[ "$num" != "" ]]; then |
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
Array.prototype.last = function(n) { | |
if (n === undefined) { | |
return this[this.length-1]; | |
} | |
var answers = []; | |
for(var i = this.length-1; i>this.length-n-1;i-=1){ | |
answers.unshift(this[i]); | |
} | |
return answers; | |
} |
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
String.prototype.reverse = function() { | |
return this.split("").reverse().join("") | |
} |
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
<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script> | |
<script>window.jQuery || document.write('<script type="text/javascript" src="scripts/jquery-ui-1.8.24.js"><\/script'')</script> |
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
// Super-optimised version of FizzBuzz | |
var array = []; | |
array[3] = array[6] = array[9] = array[12] = "Fizz<br>"; | |
array[5] = array[10] = "Buzz<br>"; | |
array[0] = "FizzBuzz<br>"; | |
var str = ""; | |
for( var i=1; i<=100; ++i) { | |
str += array[ i%15 ] || i + "<br>"; | |
} |
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
Append an array to another array | |
var a = [4,5,6]; | |
var b = [7,8,9]; | |
[].push.apply(a, b); | |
uneval(a); // is: [4, 5, 6, 7, 8, 9] |
OlderNewer