Skip to content

Instantly share code, notes, and snippets.

@constvoidblog
constvoidblog / exec_realtime_io.js
Last active July 1, 2018 22:27
Ingest spawn output in realtime, processing stdout/stderr as the spawned command emits output.
exec_realtime_io(cmd,log_cb,param_array,process_stdout_cb,process_stderr_cb,close_cb) {
var stdout='';
var stderr='';
log_cb(`running ${cmd} ${param_array}`);
var c = spawn(cmd,param_array);
c.stdout.on('data',(data)=> { stdout+=data; process_stdout_cb(data); });
c.stderr.on('data',(data)=> { stderr+=data; process_stderr_cb(data); });
c.on('close',(code)=>{ close_cb(code, stdout, stderr);});
}
@constvoidblog
constvoidblog / ls_nas.sh
Last active June 29, 2018 18:37
lftp bookmark wrapper for listing files on a nas
#!/bin/bash
#suppose we have a NAS bookmarked as music w/audio stored in "artist/album" format:
# ls_nas.sh music #list all artists
# ls_nas.sh music L #list all arists starting w/L
# ls_nas.sh music L*/ #list all albums of artists starting w/L
if [[ "$#" < 1 ]]; then
echo "ls_nas.sh <bookmark> [glob]"
echo " "
@constvoidblog
constvoidblog / sample_func.js
Last active October 29, 2017 23:51
A sample function
const fs = require(‘fs’);
function foo (a, b, f) {
new Promise((resolve,reject)=>
let c=a*b;
fs.writeFile(f,`${a} * ${b} = ${c}`, (err) => { if (err) { console.log(`issue writing data to ${f}: ${err}`); reject (err); }
resolve(c);
});
});
}
@constvoidblog
constvoidblog / package.json
Last active October 29, 2017 22:46
initial package.json
{
"name": "abjscdef",
"version": "0.2.0",
"description": "A better javascript cd encoder - flac",
"main": "abjscdef.js",
"scripts": {
//...per github..
},
"author": "const void*",
"license": "MIT",