Skip to content

Instantly share code, notes, and snippets.

@telamon
Last active December 31, 2015 20:58
Show Gist options
  • Save telamon/8043344 to your computer and use it in GitHub Desktop.
Save telamon/8043344 to your computer and use it in GitHub Desktop.
Simple lightweight `minderd` frontend/output parser written for/in node/js
#!/usr/bin/env node
var spawn = require('child_process').spawn,
util = require('util'),
child;
var bin= './minerd.exe',
args = {
algo: 'scrypt',
threads: 8,
user: 'LXKwG9oYazZPUc6ozF5t3zyf6xBxbEbTXP',
pass: 'x',
url: 'http://buf.snicter.com:9327',
scantime: 15
};
var args= Object.keys(args).map(function(i){ return '--'+i+" "+args[i]}).join(' ').split(' ');
var cores=[],log=[];
child = spawn(bin,args);
var updateSpeed = function(){
var speed = cores.reduce(function(c,i){
return c+i.speed;
},0);
speed = Math.round(speed*100)/100.0;
util.print("\u001b[2J\u001b[0;0H");
util.print("Speed: \t"+speed+" \tkhash/s\n");
log.splice(0,log.length - 15);
log.forEach(function(line){
util.print(line);
});
};
child.stdout.on('data',function(data){
log.push("out: "+data.toString());
});
child.stderr.on('data',function(data){
var line = data.toString();
var m = line.match(/thread (\d+): (\d+) hashes, (\d+(:?\.\d+)?) khash\/s/);
if(m){
cores[parseInt(m[1])]={nhashes:parseInt(m[2]),speed: parseFloat(m[3])};
}else{
log.push('Err: ' + line);
}
updateSpeed();
});
child.on('close',function(code){
console.log(bin,'Exited with code:',code);
updateSpeed();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment