Skip to content

Instantly share code, notes, and snippets.

View myndzi's full-sized avatar

Kris Reeves myndzi

  • Sigma Bold
  • Olympia, WA
View GitHub Profile
function dumpMemory(port) {
return getMemSize(port)
.then(function (size) {
var result = new Buffer(size);
return copyChunkLoop(result, 0, size)
});
}
@myndzi
myndzi / .js
Last active June 23, 2016 16:38
var Transform = require('stream').Transform;
var util = require('util');
function AggregateStream(reducer) {
Transform.call(this, { readableObjectMode: true });
if (typeof reducer !== 'function') {
throw new Error('Must supply a reducer');
}
this.aggregated = void 0;
this.reducer = reducer;
@myndzi
myndzi / .js
Last active June 30, 2016 20:41
function getDockerStuff() {
return new Promise((resolve, reject) => {
let data = '';
foo.create(name, template, config, function onComplete(exitCode, errors) {
if (exitCode !== null) {
reject(errors);
} else {
resolve(data);
}
'use strict';
var extend = require('xtend'),
Pool = require('./pool'),
RateLimiter = require('./ratelimiter');
module.exports = InputQueue;
function InputQueue(opts) {
opts = opts || { };
@myndzi
myndzi / .js
Last active August 1, 2016 00:54
function delay(ms) {
// error checking wouldn't hurt
return new Promise(resolve => setTimeout(resolve, delay));
}
function retryWithDelay(fn, delay, retries) {
if (retries <= 0) {
return Promise.reject(new Error('out of retries'));
}
return fn().catch(err => {
// typed catch or checking the kind of error here would be a good thing
myndzi@seckzi:~/test$ node foo
pg pool: function (options) {
var config = { Client: Client };
for (var key in options) {
config[key] = options[key];
}
Pool.call(this, config);
}
myndzi@seckzi:~/test$ npm ls
[email protected] /home/myndzi/test
@myndzi
myndzi / .js
Last active August 10, 2016 02:59
var EventEmitter = require('events').EventEmitter,
inherits = require('util').inherits;
var ID = 0;
function Fetcher(url) {
EventEmitter.call(this);
this.id = ID++;
this.url = url;
}
@myndzi
myndzi / .js
Last active November 3, 2016 06:06
var split = require('binary-split-streams2'),
fs = require('fs');
function requestStream(url) {
return Kefir.stream(emitter => {
let req = bhttp.get(url, { stream: true })
.pipe(split()); // default is \n -- no regex support, use a different module if you need variable line terminators
req.on('data', chunk => emitter.emit(chunk));
req.on('error', err => {
emitter.error(err); emitter.end();
foo bar
1 2
3 4
5 6
7 8
@myndzi
myndzi / .js
Created December 11, 2016 22:34
var qb = knex.select('songs.id', 'songs.name AS song', 'artists.name AS artist', 'songs.path', 'albums.name AS album')
.from('songs')
.join('genreAssociation', 'songs.id', 'genreAssociation.id_songs')
.join('artists', 'songs.id_artists', 'artists.id')
.join('albums', 'songs.id_albums', 'albums.id')
.where('genreAssociation.id', req.params.id)
if (req.session.playedSongs && req.session.playedSongs.length != 0 && req.session.playedSongs != []) {
qb.whereNotIn('songs.id', req.session.playedSongs);
}