Skip to content

Instantly share code, notes, and snippets.

@stephen-james
stephen-james / promise-patterns-loop.js
Created September 26, 2019 20:36
Promise Pattern: Loop helper function to sequentially loop through an array of promises
console.clear();
const loop = (arrayOfPromises, guard) => {
if (arrayOfPromises.length && (!guard || guard(arrayOfPromises[0]))) {
return arrayOfPromises.shift()().then(() => {
return loop(arrayOfPromises, guard);
})
}
return Promise.resolve();
@stephen-james
stephen-james / gist:19be16bb1cf39accecb1e5801167839f
Created October 31, 2018 13:57
Unwrapping Mobx Injected components
const unWrapMobxInjectedComponent = <T extends {}>(component: IWrappedComponent<T>): T => {
let last: any = component;
while (component.wrappedComponent) {
last = component.wrappedComponent;
}
return last as T;
}
@stephen-james
stephen-james / gist:7392dbb0f10b5081e74700c138602294
Created October 31, 2016 13:14
Find and Kill Process using Port
lsof -i tcp:{{port}}
// find PID from list
kill -9 {{PID}}
@stephen-james
stephen-james / material-helper.js
Created March 10, 2016 14:32
Mithril custom elements
// Primitive example of creating a helper library to describe elements
var m = require('mithril');
var materialElements = ['textfield'];
var mt = function(selector, options, children) {
if (selector === 'textfield') {
return m('div.mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label', [
m('input.mdl-textfield__input', {
id: options.id,
@stephen-james
stephen-james / material-helper.js
Created March 10, 2016 14:32
Mithril custom elements
// Primitive example of creating a helper library to describe elements
var m = require('mithril');
var materialElements = ['textfield'];
var mt = function(selector, options, children) {
if (selector === 'textfield') {
return m('div.mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label', [
m('input.mdl-textfield__input', {
id: options.id,
@stephen-james
stephen-james / gittruncatehistory.sh
Last active August 29, 2015 14:27 — forked from magnetikonline/gittruncatehistory.sh
Truncate Git history to a specific SHA1, dropping everything before it.
#!/bin/bash
# Lifted from: https://github.com/adrienthebo/git-tools/blob/master/git-truncate
# Note: seem to be finding the need to run this twice over to commit the truncate
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: $0 <drop before SHA1 commit> <branch>"
exit
fi
git filter-branch --parent-filter "sed -e 's/-p $1[0-9a-f]*//'" \
@stephen-james
stephen-james / karma.conf.js
Created May 19, 2015 22:42
karma.conf.js generated by gulp-starter and modified to reference proxyquireify
// Karma configuration
// Generated on Fri Jan 23 2015 17:22:58 GMT-0500 (EST)
var proxyquire = require('proxyquireify');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
@stephen-james
stephen-james / appHostNotifier.js
Created March 17, 2015 10:26
App host notifier, required by apps to handle development/debug notifications to and from the app host
angular
.module('ampAppHostNotifier', [])
.factory('appHostNotifier', [
'$rootScope',
'$window',
'$location',
function($rootScope, $window, $location) {
return {
init: function() {
@stephen-james
stephen-james / svg-cleaner.js
Created March 11, 2015 15:27
svg-cleaner.js
var fs = require('fs');
var path = require('path');
// validate args
if (process.argv.length < 3) {
console.log('usage:');
console.log('\tnode svg-cleaner.js <path>')
return;
}
find /Users/Stephen/.npm -type d -print0 | xargs -0 chown Stephen