Skip to content

Instantly share code, notes, and snippets.

View indatawetrust's full-sized avatar
🏠
Working from home

indatawetrust

🏠
Working from home
View GitHub Profile
/*
* 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
@indatawetrust
indatawetrust / blobtodatauri.js
Created January 2, 2017 21:31
Blob to Data URI
function blobToDataURI (blob, res) {
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
res(reader.result)
}
}
@indatawetrust
indatawetrust / base64toFile.js
Last active December 30, 2016 14:21
base64 to File object
function base64ToFile (dataURI) {
let byteString,
mimestring
if(dataURI.split(',')[0].indexOf('base64') !== -1 ) {
byteString = atob(dataURI.split(',')[1])
} else {
byteString = decodeURI(dataURI.split(',')[1])
}
@indatawetrust
indatawetrust / resize.sh
Created December 7, 2016 11:42
resize and white background
resize(){
for f in *.jpg; do
mogrify $f -resize "275x275" -gravity center -background white -extent 275x275 $f
done
}
@indatawetrust
indatawetrust / scale.sh
Created December 6, 2016 11:58
scales large images
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
@indatawetrust
indatawetrust / convert.sh
Created December 6, 2016 10:24
libvips | convert tif to jpg
# apt-get install libvips libvips-dev
for f in *.tif; do
echo "Converting $f"; vips copy "$f" "$(basename "$f" .tif).jpg";
done
@indatawetrust
indatawetrust / waterfall.js
Last active January 15, 2019 16:25
async await waterfall sample
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()
@indatawetrust
indatawetrust / upper.js
Created October 3, 2016 19:16
async await
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)
}))
@indatawetrust
indatawetrust / multiple.await.js
Created October 2, 2016 09:59
awaiting multiple values
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))
})
@indatawetrust
indatawetrust / money.js
Created September 30, 2016 11:58
money format
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();