Skip to content

Instantly share code, notes, and snippets.

View Jeff-Russ's full-sized avatar

Jeffrey Russ Jeff-Russ

View GitHub Profile
@Jeff-Russ
Jeff-Russ / Ruby: chained vs nested methods
Last active May 7, 2016 21:05
Ruby: chained vs nested methods
Ruby: chained vs nested methods
@Jeff-Russ
Jeff-Russ / callbackhell.html
Created May 15, 2016 05:57
Callback Cell II: The Return of Spaghetti Code
<!DOCTYPE html><html><head><script type="text/javascript">
var i = 0;
function print(message){ console.log(i+' '+message) }
function main(callback){
print('main')
i++;
if(i < 6) window.setTimeout( no_arg, 100);
else callback('I was passed to callback.');
@Jeff-Russ
Jeff-Russ / node-new
Created May 20, 2016 07:20
`rails new <appname>` for Node.js apps
#!/bin/sh
SD=$(dirname "${BASH_SOURCE[0]}")
function echo_blue { echo "\033[34m$1\033[0m"; }
function echo_green { echo "\033[32m$1\033[0m"; }
function echo_red { echo "\033[31m$1\033[0m"; }
function echo_magenta { echo "\033[35m$1\033[0m"; }
####################### PARAMETER CHECKS ######################################
@Jeff-Russ
Jeff-Russ / treeclone.sh
Last active May 20, 2016 18:40
This shell script will copy all file and directories recursively but not overwrite anything unless specified
#!/bin/sh
# treeclone - pretty much just a wrapper around cp but only for cloning the
# CONTENTS of a directory (via /. ) recursively (-a) and non-destructive (-n)
# by default. Useful for preventing disaster from forgetting -n
if [ "$#" -eq 1 ]; then TO=$CALLER
elif [ "$#" -lt 4 ]; then TO=$2
else
echo "incorrect number of args: treeclone takes at 1 - 3 args"
echo "This will copy all file and directories recursively but not overwrite anything:"
@Jeff-Russ
Jeff-Russ / faux-nest-bash3.sh
Last active May 21, 2016 03:59
faking nested arrays and hashes in bash3
#!/bin/sh
# faux nesting for bash 3 using indexes or keys.
# See explanation below
function nested {
# find array referred to by arg 1
local container=${1}[@]
local container=(${!container})
# if arg 2 an integer, use normally:
if [[ $2 =~ ^-?[0-9]+$ ]]; then
@Jeff-Russ
Jeff-Russ / node-appgen
Last active May 22, 2016 06:38
`rails new <appname>` + project cloning for Node.js apps
#!/bin/sh
# node-appgen
SD=$(dirname "${BASH_SOURCE[0]}")
CALLER_PATH=$(pwd)
COPY_SRC="$SD/node-appgen-default"
INSTALLER="$SD/node-appgen-default/node-appgen-installs"
EMAIL=$(git config user.email || "")
AUTHOR=$(git config user.name || id -F || id -un || whoami)
@Jeff-Russ
Jeff-Russ / _ Demo: Sass:log.md
Last active May 26, 2016 19:34
Debug you complex Sass right to the browser!

Demo: Sass:log

Debug you complex Sass right to the browser!

@Jeff-Russ
Jeff-Russ / _ Shell Command: addpath .md
Last active May 26, 2016 19:37
Temporarily add a bunch of scripts to PATH to make directly executable

Shell Command: addpath

Temporarily add that a path to your $PATH and make contents executable as if built in commands.

Study: .bashrc vs .bash_profile

On most *nix:

  • ~/.bash_profile
    • executed when type un/pw to login via console
    • executed when type un/pw to login via ssh
    • not executed when you type /bin/bash to start a new bash instance
    • not executed when open a new terminal instance unless mac os

Study: Execute Shell Commands from Node.js