Skip to content

Instantly share code, notes, and snippets.

View tapmodo's full-sized avatar

Kelly Hallman tapmodo

  • Tapmodo Interactive LLC
  • California
View GitHub Profile
@tapmodo
tapmodo / 1-input-data.json
Last active August 18, 2020 00:50
Organize a flat array of objects into a better structure (~50% smaller)
[
{
"brand": {
"name": "Antonio's Pizzeria",
"slug": "1532df73-c60f-4cca-b03d-f535e031a7e1"
},
"location": {
"id": 1,
"name": "Downtown"
},
@tapmodo
tapmodo / 1-input-data.json
Created August 18, 2020 00:40
Organize a flat array of objects into a better structure (~50% smaller)
[
{
"brand": {
"name": "Antonio's Pizzeria",
"slug": "1532df73-c60f-4cca-b03d-f535e031a7e1"
},
"location": {
"id": 1,
"name": "Downtown"
},
function containsExactHalvesSubarray(v) {
const hash = {}
v = v.sort((a,b) => parseInt(a)-parseInt(b));
v.forEach(i => {
if (i < 0)
if (hash[i]) hash[i][0] = true
else hash[i/2] = [null,true]
else
if (hash[i/2]) hash[i/2][1] = true
@tapmodo
tapmodo / cartesian.js
Last active November 21, 2018 15:05
const collection = [
{ attributeValue: ["RED", "GOLD"] },
{ attributeValue: ["16G", "32G", "64G"] },
{ attributeValue: ["PLUS"] }
]
function cartesian(data) {
const f = (a,b) => [].concat(...a.map(d => b.map(e => [].concat(d, e))))
const recurse = (a, b, ...c) => (b? recurse(f(a, b), ...c): a)
return recurse(...data)

Keybase proof

I hereby claim:

  • I am tapmodo on github.
  • I am khallman (https://keybase.io/khallman) on keybase.
  • I have a public key ASCZaySVvMgIlUktbO90VOlMrP4SSIf6JeBk1Ya5K2bkxQo

To claim this, I am signing this object:

@tapmodo
tapmodo / foundation-2col-layout.scss
Created December 6, 2015 03:59
2 scrollable column layout, with header and footer, using Foundation 6
@import '../../bower_components/foundation-sites/scss/foundation';
@include foundation-everything;
.container {
@include grid-row(16) {
.sidebar { @include grid-column(5); }
.main-content { @include grid-column(11); }
}
}
var es = require('event-stream');
var fs = require('fs');
var ldif = require('ldif');
var Streamer = function(stream,options){
var chain = stream, self = this;
options = ldif._extend({},Streamer.defaults,options);
// Normalize pipeline array
if (!Array.isArray(options.pipeline))
@tapmodo
tapmodo / influx-collector.js
Last active October 29, 2015 02:50
This is a first stab at a batch uploader for InfluxDB. It seems to work. If you wanted to use this for any other queue batching operation, you could overload the write() and _send() methods...
var _ = require('lodash');
var debug = require('debug')('influx:batch');
var SeriesWriter = function(db,options){
this.db = db;
this.setOptions(options);
this.sending = false;
this.timer = null;
this.queue = [];
};
@tapmodo
tapmodo / map_and_filter.js
Created October 22, 2014 23:41
map and filter functions
// map function
function array_map(arr,fn) {
var rv = [];
for(var i=0, l=arr.length; i<l; i++)
rv.push(fn(arr[i]));
return rv;
};
@tapmodo
tapmodo / polyfills.js
Created October 22, 2014 23:24
Array.filter and Array.map Javascript Polyfills
// Array.map polyfill
if (Array.prototype.map === undefined) {
Array.prototype.map = function(fn) {
var rv = [];
for(var i=0, l=this.length; i<l; i++)
rv.push(fn(this[i]));
return rv;