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
/* | |
* NchanSubscriber | |
* usage: var sub = new NchanSubscriber(url, opt); | |
* | |
* opt = { | |
* subscriber: 'longpoll', 'eventsource', or 'websocket', | |
* //or an array of the above indicating subscriber type preference | |
* reconnect: undefined or 'session' or 'persist' | |
* //if the HTML5 sessionStore or localStore should be used to resume | |
* //connections interrupted by a page load |
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 blobToDataURI (blob, res) { | |
var reader = new FileReader(); | |
reader.readAsDataURL(blob); | |
reader.onloadend = function() { | |
res(reader.result) | |
} | |
} |
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 base64ToFile (dataURI) { | |
let byteString, | |
mimestring | |
if(dataURI.split(',')[0].indexOf('base64') !== -1 ) { | |
byteString = atob(dataURI.split(',')[1]) | |
} else { | |
byteString = decodeURI(dataURI.split(',')[1]) | |
} |
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
resize(){ | |
for f in *.jpg; do | |
mogrify $f -resize "275x275" -gravity center -background white -extent 275x275 $f | |
done | |
} |
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
alias wh="identify -format '%w %h' $1" | |
scale(){ | |
for f in *.jpg; do | |
isWH="$(wh $f)" | |
getWH=(`echo $isWH | tr ' ' ' '`) | |
if [ ${getWH[1]} -ge 1000 ]; then | |
mogrify -geometry x1000 $f | |
fi | |
done |
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
# apt-get install libvips libvips-dev | |
for f in *.tif; do | |
echo "Converting $f"; vips copy "$f" "$(basename "$f" .tif).jpg"; | |
done |
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
const waterfall = async function (input, ...funcs) { | |
const list = [] | |
for(let f of funcs) | |
if(!list.length) | |
list.push(await f(input)) | |
else | |
list.push(await f(list.shift()) | |
return list.pop() |
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
const upper = async function (n) { | |
const list = [] | |
for(let i of new Array(n+1).join('.').split('').map((a,b) => b+1)){ | |
list.push(await new Promise(res => { | |
if (list.length) | |
res(list.toString().split(',').pop()*2) | |
else | |
res(n) | |
})) |
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
const twoPower = (x) => { | |
return new Promise((resolve,reject) => { | |
resolve(Math.pow(x, 2)) | |
}) | |
} | |
const threePower = (x) => { | |
return new Promise((resolve,reject) => { | |
resolve(Math.pow(x, 3)) | |
}) |
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
var money = function money(num) { | |
var _ = num.split('').reverse(), | |
n = []; | |
for (var i = 0; i < Math.ceil(_.length / 3); i++) { | |
n = n.concat(_.slice(i * 3, i * 3 + 3), ","); | |
} | |
n.pop(); |