This file contains hidden or 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
(F=(L,d)=>{(C=d.createElement("canvas")).width=C.height=L;X=C.getContext("2d");for(i=L*L;i--;)X.fillStyle=`rgb(${n=`(F=${F})(16,document)`.charCodeAt(i)||32},${n},${n})`,X.fillRect(i%L,0|(i/L),1,1);d.body.appendChild(C)})(16,document) | |
// After running this code you should be able to grab the pixel values as a Uint8ClampedArray | |
// from the canvas context 'X' and use that to verify like so: | |
var charCodes = Array.from(X.getImageData(0,0,16,16).data).filter((_,i)=>i%4===0) | |
String.fromCharCode.apply(null, charCodes) |
This file contains hidden or 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
(y=x=>`(y=${y})()`)() | |
// if you want to alert it: | |
(y=x=>alert(`(y=${y})()`))() |
This file contains hidden or 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
// I'm not proud of this but JS has forced my hand | |
function pause(time) { | |
if (typeof time !== "number") { | |
throw("time should be a number in milliseconds"); | |
} | |
var endTime; | |
endTime = (new Date()).getTime() + time; | |
while(1) { | |
var newTime = (new Date()).getTime(); |
This file contains hidden or 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
El Capitan breaks gem install as per http://stackoverflow.com/questions/30812777/cannot-install-cocoa-pods-after-uninstalling-results-in-error/30851030#30851030 | |
Use: | |
sudo gem install -n /usr/local/bin gem-name | |
instead. |
This file contains hidden or 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, ""); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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" |