Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am anthonyserious on github.
  • I am anthonyserious (https://keybase.io/anthonyserious) on keybase.
  • I have a public key ASASuIUilOzQ08H0pyuegMhuOSjvIiGRVSbRYr2MncGRXgo

To claim this, I am signing this object:

@anthonyserious
anthonyserious / stagger.js
Created October 12, 2016 19:15
Wrap functions to stagger (vs. lodash _.throttle, which drops throttled messages)
"use strict";
module.exports = function stagger(fn, ms) {
let queue = [];
let running = false;
let flush = () => {
if (queue.length === 0) {
running = false;
return;
@anthonyserious
anthonyserious / reduceq.js
Last active August 29, 2015 14:12
Q promise array reduce example based on http://stackoverflow.com/a/17764496/3753772
var Q = require("q");
var arr = [1,2,3,4];
arr.reduce(function(prev, item) {
return prev.then(function(p) {
console.log(item);
return Q.delay(0);
});
}, Q.resolve(1));
@anthonyserious
anthonyserious / stripfields.js
Last active August 29, 2015 14:12
Strip fields from object that are not in schema object
// Recursively strip out fields in objects and subobjects
function stripFields(schema, obj) {
var newObj = {};
var schemaType = schema.constructor.name;
var objType = obj.constructor.name;
// If types match and this property is not an Object, return the value
if (schemaType !== "Object") {
if(schemaType === objType) {
@anthonyserious
anthonyserious / mbeanToObj
Last active August 29, 2015 14:06
Converts standard JMX MBean names to JavaScript objects, where MBean names are of the form 'domain:key1=value1,key2=value2,...'
function mbeanToObject (mbean) {
var obj = {};
var a = mbean.split(":");
obj.domain = a[0];
obj.properties = [];
a[1].split(",").forEach(function(propPair) {
var pair = propPair.split("=");
obj.properties[pair[0]] = pair[1];
});
return obj;