Skip to content

Instantly share code, notes, and snippets.

View samuraijane's full-sized avatar

Matthew Day samuraijane

View GitHub Profile
const shoppingList = ['apples', 'biscuits', 'cabbage', 'dip'];
const isCode200 = () => Math.random() >= 0.5;
function getShoppingList() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (isCode200()) {
resolve(shoppingList);
} else {
reject('There was a problem with the server, please try again.');
// callback functions can help us deal with asynchronous code but it can also get messy if we have multiple sequential callbacks (not shown here)
var shoppingList = ['apples', 'biscuits', 'cabbage'];
function addItem(item, callback) {
setTimeout(() => {
shoppingList.push(item);
console.log("Item added to shopping list");
callback();
}, 200);
// 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);
}
### 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/
#!/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
#!/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.
In order to run TypeScript code in a shell from the command line, you need NPM's `ts-node` package.
`npm install -g @ts-node@10.4.0`
`npm install -g @typescript@4.4.4`
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`
#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
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'
# --------------------------------------------------------------
# IMPORT ALIAS COMMANDS
# --------------------------------------------------------------
. ~/.alias
# --------------------------------------------------------------
# NODE VERSION MANAGER
# --------------------------------------------------------------
export NVM_DIR="$HOME/.nvm"