Skip to content

Instantly share code, notes, and snippets.

View samuraijane's full-sized avatar

Matthew Day samuraijane

View GitHub Profile
@samuraijane
samuraijane / hash_from_two_arrays.rb
Created April 17, 2015 17:15
Sometimes you need to create a new hash that blends two arrays, where the content in first array become the keys and the content in the second array become the values in the new hash. You can also assign that same value to each key if necessary.
# OPTION 1
# array_a is an array that holds what will become the keys in the new hash.
# array_b is an array that holds what will become the values in the new hash.
# Create a new empty hash.
my_hash = {}
# Send array_a and array_b into the new hash.
array_a.each_with_index { |key, value| my_hash[key] = array_b[value] }
# This works well for arrays that have the same amount of content so that things
# line up. I haven't researched what happens with one array has more content
# than the other.
@samuraijane
samuraijane / key-value-array.php
Created April 23, 2015 21:03
Key/value pairs in PHP are common so when you need to iterate through an array and return only the value, this is how you do it.
<?php
$array = array(
"Events",
"Webinars",
"Cloud",
"Collaboration",
"Innovation",
"Tips"
)
# --------------------------------------------------------------
# IMPORT ALIAS COMMANDS
# --------------------------------------------------------------
. ~/.alias
# --------------------------------------------------------------
# NODE VERSION MANAGER
# --------------------------------------------------------------
export NVM_DIR="$HOME/.nvm"
alias gs='git status -sb'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias gl='git log'
alias gp='git push origin master'
alias gpush='git push origin'
alias gdrop='git stash drop stash@{0}'
alias rebase='git pull --rebase'
#let Terminal know that you are using bash shell (the line that begins with '#!' is known as the interpreter line)
#!/bin/sh
#set the version number for this
#version 0.0.3 (8 July 2016)
#create a variable to hold the name of the new repository
#the '$1' denotes the first argument passed to this shell
#for example, entering 'xxr repo-name' in Terminal stores the first argument, or 'repo-name', in the variable 'repo'
repo=$1
In order to run TypeScript code in a shell from the command line, you need NPM's `ts-node` package.
`npm install -g @[email protected]`
`npm install -g @[email protected]`
If you see a warning or an error that TypeScript has an unmet peer dependency for `@type/node`, then install it directly.
`npm install -g @types/node`
Initiate a TypeScript Node Shell
`ts-node`
#!/bin/bash
PARENT_DIR=$1
if [[ -z $PARENT_DIR ]]; then
echo "Name of the parent directory"
read PARENT_DIR
fi
CURRENT_DIR=$(pwd)
[[ -d $PARENT_DIR ]] && echo $PARENT_DIR already exists. Process terminated.
#!/bin/bash
PARENT_DIR=$1
DOC_TITLE=$2
if (( $# < 2)); then
echo "- - - - -\nERROR: One or more missing arguments\nExecute this command as \"xxf <parentDirectoryName> <titleForHTMLDoc>\"\n- - - - -"
1>&2
exit 1 # if in ~/.bashrc, use return here instead of exit
fi
### CLI ###
1. `mkdir parent`
2. `cd parent`
3. `touch blah.txt`
4. `mkdir child`
5. `ls -al` --> .DS_Store is not present
### Finder ###
6. drag blah.txt from parent/ to parent/child/
7. drag blah.txt from parent/child/ to parent/
// without a callback, asynchronous code has unexpected results
var shoppingList = ['apples', 'biscuits', 'cabbage'];
function addItem(item) {
setTimeout(() => {
shoppingList.push(item);
console.log("Item added to shopping list");
}, 200);
}