Skip to content

Instantly share code, notes, and snippets.

View KylePDavis's full-sized avatar

Kyle P Davis KylePDavis

View GitHub Profile
@KylePDavis
KylePDavis / get_rnd_img_gm.sh
Created February 17, 2020 22:46
Get Random Images
#!/bin/bash
# command line args
ID="$1";
OUT="$2";
# defaults
[ "$ID" ] || ID="$RANDOM"
[ "$OUT" ] || OUT="rnd_img_$(printf %08d "$ID").jpg"
@KylePDavis
KylePDavis / convert_to_gif.sh
Last active July 31, 2019 20:52
Convert a movie to a reasonably high quality GIF
#!/bin/bash
################################################################################
#
# USAGE:
# ./convert_to_gif.sh MOVIE_FILE [MOVIE_FILE_2]
#
# ARGS:
# MOVIE_FILE - the name of the movie file
#
# ENV VAR SETTINGS:
@KylePDavis
KylePDavis / ln-pkg.sh
Last active June 9, 2020 18:04
A simple way to symlink local npm packages into your node_modules for testing
#!/bin/bash -e
################################################################################
# Links a local Node.js package directory into the current node_modules/ folder.
# This is simpler and more isolated than `npm link` so it's better for quick one-off testing.
#
# USAGE:
# ~/bin/ln-pkg.sh LOCAL_PKG_DIR [LOCAL_PKG_DIR_2]
#
################################################################################
[ -d "node_modules" ] || { echo "missing node_modules/"; exit 1; }
@KylePDavis
KylePDavis / backup.sh
Created March 19, 2015 15:08
Self-contained auto-updating rsync-based backup script from a lifetime ago used to cross-sync data to local backup servers and then remote backup servers
#!/bin/sh
# Description:
# Automated backup script designed to support multiple backup servers.
#
# ChangeLog:
# 20130822 kdavis - Updated to use fully qualified hostname
# 20120125 kdavis - Minor updates for mysqldump over ssh so it can use the same security model as rsync, setting env vars from command line, and logging
# 20080610 kdavis - Added missing rsync error code handling to one of the backup methods that uses rsync internally
# 20080123 kdavis - Added more debugging; and...
# 20080119 kdavis - Added lock files/PID checks to ensure only one instance
@KylePDavis
KylePDavis / etc_launchd.conf
Created August 25, 2014 14:10
Mac OS X Power User ProTip: Increase OS Limits
# Increased file and proc limits for Mac OS X based on http://superuser.com/a/514049
limit maxfiles 8192 20480
limit maxproc 1000 2000
@KylePDavis
KylePDavis / karma_test.js
Last active August 29, 2015 14:02
Self-hosted Karma Test Case Template
// Karma one-liner to make these tests self-hosted (needs karma.conf.js support for TEST_FILE env var)
if(typeof require!=='undefined' && require.main===module) global.describe=function(){}, process.env.TEST_FILE=__filename, require("karma").server.start({configFile:__dirname+'/../karma.conf.js'});
describe('app.module.thing', function(){
// module deps
beforeEach(module('app.module'));
// vars injected
var $rootScope;
@KylePDavis
KylePDavis / get_url_stats.sh
Created March 26, 2014 03:30
A simple script to get the given URL with cURL and output stats.
#!/bin/bash
# A simple script to get the given URL with cURL and output stats.
#
# USAGE:
# get_url_stats.sh <URL>
#
###############################################################################
out() { echo "`date +%Y%m%dT%H%M%SZ`: $*"; }
err() { out "$*" 1>&2; }
@KylePDavis
KylePDavis / sh_template_template.sh
Created February 13, 2014 02:56
A template for shell-based templates. Good for generalizing config files and the like.
#!/bin/bash
# Template bash script using given script file as source for variable values
if [ -f "$1" ]; then source "$1" || echo "#! ERROR: Unable to read variables from script: $1!" 1>&2 && exit 1; fi
(awk '/TMPL$/,/^TMPL/{print}' "$0" | grep -Eio '(^|[^\])\${?[A-Z][A-Z0-9_]*}?' | cut -c3- | tr -d '{}' | sort -u) | grep -v -w -F "$(env | cut -f1 -d= | sort)" | sed 's/^/ERROR: need tmpl var: /' | grep . && exit 123 || true
###############################################################################
cat<<TMPL
# Config generated on $(date)
HOST=$SOME_HOST
FILES="$(ls -1 | paste -sd,)"
TMPL
@KylePDavis
KylePDavis / mocha_test.js
Last active October 12, 2015 19:18
Self-hosted Mocha Test Case Template
"use strict";
// Mocha one-liner to make these tests self-hosted
if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
// requires
var assert = require("assert"),
MyClass = require("../../lib/MyClass");
@KylePDavis
KylePDavis / js_object_copy_slice.js
Created November 12, 2012 15:20
Experimenting with the idea of copying Object slices and creating composite Objects via slices
var util = require("util");
var o = {
p1: {
c1:[{l1:"a"}, {l2:"b"}],
c2:{l3:3, l4:4}
},
p2: {foo:"bar"}
};
process.stdout.write("// Original object:\n");