Skip to content

Instantly share code, notes, and snippets.

View majgis's full-sized avatar

Michael Jackson majgis

View GitHub Profile
@majgis
majgis / .zshrc
Last active May 31, 2018 05:56
docker run helper function
# Execute docker run with --rm --network shared
# The shared network will be created if it dosn't already exist
dr () {
docker network inspect shared > /dev/null 2>&1
if [ $? -ne 0 ]
then
docker network create shared > /dev/null 2>&1
fi
local DOCKER_CMD="docker run --rm --network shared $@"
echo
@majgis
majgis / .zshrc
Last active May 16, 2022 10:38
automatically call nvm use if .nvmrc is present
# Taken from here:
# https://github.com/creationix/nvm#zsh
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
// var depPairs = [
// "KittenService: ",
// "Leetmeme: Cyberportal",
// "Cyberportal: Ice",
// "CamelCaser: KittenService",
// "Fraudstream: Leetmeme",
// "Ice: "
// ];
//
// Turn that into: `'KittenService, Ice, Cyberportal, Leetmeme, CamelCaser, Fraudstream'`
const storedTemplate = (a,b,c) => `a:${a}, b:${b}, c:${c}`
storedTemplate(1,2,3)
@majgis
majgis / run.js
Last active August 29, 2015 14:12
Browserify - expose
var fs = require( 'fs' );
var b = require( 'browserify' )();
var outputFile = fs.createWriteStream( './output.js' );
b.add( './index.js' );
b.require( './test.js', {expose: 't'} );
b.bundle().pipe( outputFile );
@majgis
majgis / gulpfile.js
Created November 23, 2014 08:36
find protractor selenium jar
var gulp = require('gulp');
var lib = require('./lib');
var protractor = require("gulp-protractor").protractor;
var jarPath = lib.getProtractorSeleniumJarPath();
gulp.task('default', function(){
gulp.src(["./spec/*.js"])
.pipe(protractor({
configFile: "protractor.config.js",
@majgis
majgis / gist:9680084
Last active August 29, 2015 13:57
Rough Node.js Hierarchical Queue
var http = require('http');
function RequestQueue() {
this._maxRequests = 3;
this._pendingCount = 0;
this._queue = [];
this.count = 0;
this._uriInQueue = {};
}
@majgis
majgis / gist:9558866
Created March 14, 2014 23:04
npm shrinkwrap
#-- Start pm-ops-utils dev --#
# Remove local modules and npm cache
alias npmPurge="
rm -rf node_modules
npm cache clean
"
# Ugly, but it is a fail-safe way of generating npm-shrinkwrap.json
alias updateShrinkwrap="
@majgis
majgis / collection.py
Last active December 17, 2015 01:38
A defaultnamedtuple which creates a namedtuple with default values when none are given.
""" Additional collections to augment Python's collections module.
"""
from collections import namedtuple
def defaultnamedtuple(
typename,
field_names,
verbose=False,
rename=False,
@majgis
majgis / interview.py
Last active December 16, 2015 19:28
Answer to an interview question.
""" Interview question
Write a method that takes a string, and returns the string in reverse.
For instance, if passed abc123 it should return 321cba
"""
class StringUtil(object):
""" Utility for strings