Skip to content

Instantly share code, notes, and snippets.

View jmacqueen's full-sized avatar

Jonathan MacQueen jmacqueen

  • Bitsight
  • United States
View GitHub Profile
@jmacqueen
jmacqueen / PromiseRetry.js
Created April 11, 2017 13:16
Promise with retry
function tryWithRefresh(funcs, catchFunc){
const outerPromises = funcs.map( fn => typeof fn === 'function' ? fn() : fn )
return Promise.all(outerPromises)
.catch( (err) => {
if (err.status !== 401) { console.log(err); return; }
authService.refreshToken()
.then( () => {
console.log('refresh success')
const innerPromises = funcs.map( fn => typeof fn === 'function' ? fn() : fn )
Promise.all(innerPromises)
@jmacqueen
jmacqueen / application.js
Created October 6, 2016 16:06
Create an Ember application instance that can be imported into any file. Useful for container lookups in files outside of the usual hierarchy.
// app/instance-initializers/application.js
import appInst from 'appName/utils/application'
export function initialize( appInstance ) {
appInst.instance = appInstance
}
export default {
name: 'application',
initialize
};
@jmacqueen
jmacqueen / docker-compose.yml
Created September 22, 2016 01:56
Basic docker-compose.yml for playing with Kafka
zookeeper:
image: wurstmeister/zookeeper:3.4.6
ports:
- "2181:2181"
kafka:
image: ches/kafka:0.9.0.1
ports:
- "9092:9092"
links:
- zookeeper
@jmacqueen
jmacqueen / dyncount
Last active September 15, 2016 12:10
Helper bash script for AWS command line DockerDB scan counts
#!/bin/bash
case $1 in
help)
echo 'usage: dyncount <table> <column> <"="|"<>"|"<"|"<="|">"|">="> <type> <value>';
echo 'example: ./dyncount user firstName "=" S Gary';
echo '';
echo 'usage: dyncount <table> <column> <attribute_exists|attribute_not_exists>';
echo 'example: ./dyncount user firstName attribute_exists';
echo '';
@jmacqueen
jmacqueen / docker-ps.coffee
Created September 12, 2016 13:34
Ubersicht widget to display information about currently running Docker images
command: '/usr/local/bin/docker ps --format "{{.ID}}\t{{.Image}}\t{{.Command}}\t{{.Ports}}\t{{.Names}}"'
refreshFrequency: 5000
render: (output) -> """
<table>
<thead>
<tr>
<th>Container Id</th>
<th>Image</th>
@jmacqueen
jmacqueen / main.js
Created February 23, 2016 20:37
Functional approach to subdividing list of option strings into optgroups based on greedy matching the beginning of the strings
/* jshint esversion: 6 */
// Two strings enter...one string leaves
const longerString = (a,b) => {
if (a.length > b.length) { return a; }
return b;
};
// The longest possible match from the beginnning of the strings is returned
const stringHeadMatch = function(a,b) {
@jmacqueen
jmacqueen / enable-flexbox.coffee
Created December 7, 2015 15:38
Uebersicht widget to enable flexbox
alignItems : 'stretch' # default: 'stretch'
alignContent : 'stretch' # default: 'stretch'
flexDirection : 'row' # default: 'row'
flexWrap : 'wrap' # default: 'nowrap'
justifyContent : 'flex-start' # default: 'flex'-start'
refreshFrequency: false
command: "echo"
// jQuery-free form values
// Should work in IE9+
var frm = document.querySelector('form'); // Must return containing form
var valueHash = Object.keys(frm.elements).slice(frm.elements.length + 1).reduce(function(a,key){
var elm = frm.elements[key];
if(elm.type !== "checkbox" || elm.type == "checkbox" && elm.checked !== false) {
a[key] = elm.value;
}
@jmacqueen
jmacqueen / README.md
Last active December 30, 2015 00:59
D3.js: Zoomable Treemap!

Click on a grey box to zoom deeper into the tree. Click on the orange box at the top to back out a level.

Adapted from the man himself. I believe in standing on the shoulders of giants.

@jmacqueen
jmacqueen / README.md
Created November 12, 2013 23:42
D3.js: Collision Detection

Adding some collision detection makes the graph cleaner at a wider variety of settings. But notice that the conflict between collision detection, gravity pulling nodes together and links attempting to limit distance can create some unusual behavior at extreme values. The loners need a little space to escape :-)

There's some light refactoring going on here. The random node generation code now uses d3.range to generate an array of numbers and then map on top of that to create the node objects themselves. A similar approach is used for the links, too.

The collision detection code was lifted from here with minor tweaks to account for my node scaling.

If you want to interact with these D3.js gists without downloading them yourself, replace https://gist.github.com with http://bl.ocks.org to use Mike Bostock's excellent website for running D3.js gists.