Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# Pre-commit hook for git which removes trailing whitespace, converts tabs to spaces, and enforces a max line length.
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@ltfschoen
ltfschoen / bulletproof-git-workflow.md
Last active January 18, 2017 23:34 — forked from db/bulletproof-git-workflow.md
bulletproof git workflow

Bulletproof Git Workflow

start working

git checkout master
git pull
git checkout -b feature/my-work
# edit your files
@ltfschoen
ltfschoen / python_list_iterator_comparison.py
Created February 14, 2017 08:36
Python List Iterator Comparison Demo
# copy, paste, and execute this code in a python repl with python v2.7.12 or greater installed
import sys; assert sys.version_info >= (2,7,12)
# reimplement default repr function to return a module, name, and memory address of given object
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self))
)
@ltfschoen
ltfschoen / test_debug_levels_in_python.py
Created February 22, 2017 03:39
test_debug_levels_in_python
# Note: Some Python interpreters may prevent setting the severity level to certain levels below a threshold
import logging
logger = logging.getLogger('sudoku logger')
logger
def run_logger_calls():
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
@ltfschoen
ltfschoen / test_assertions_in_python.py
Created February 22, 2017 03:41
test_assertions_in_python.py
values = {}
assert type(values) is not object, "values is not an None: %r" % values
assert type(values) is bool, "values is not a Boolean: %r" % values
@ltfschoen
ltfschoen / main_function_that_takes_debug_level_from_cli_in_python.py
Created February 22, 2017 03:45
main_function_that_takes_debug_level_from_cli_in_python.py
#!/usr/bin/env python
import sys
import logging
import logging.config # import associated logging.conf. Refer to https://docs.python.org/3/howto/logging.html
import solution # import a file called say solution.py
def get_log_level(log_args):
valid_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR'] # numeric levels 10, 20, 30, 40
proposed_level = log_args[0].split("=", 1)[1].upper()
@ltfschoen
ltfschoen / lexical_sum.js
Created March 20, 2017 03:19
Lexically nested functions within enclosing function
// Lexically nested function definitions defined within enclosing function
function Sum(arg0) {
function Inner1(arg1) {
function Inner2(arg2) {
return arg0 + arg1 + arg2;
}
return Inner2;
}
return Inner1;
}
@ltfschoen
ltfschoen / merge_sort.js
Created March 27, 2017 09:08
Merge Sort
let mergeSort = (arr) => {
if (arr.length < 2) {
console.log("Merging len 1: ", arr);
return arr;
}
console.log("Merging len > 1: ", arr)
let mid = parseInt(arr.length / 2),
l = arr.slice(0, mid),
@ltfschoen
ltfschoen / find_min_sorted_array_rotated.js
Last active March 27, 2017 11:43
Find Min Value of Rotated Sorted Array
/**
* Given a sorted array as input (ascending order only
* and without duplicates) that may be rotated
* and return the minimum value.
*/
let getMin = (x, y) => { return x <= y ? x : y; }
let getMid = (l, h) => { return parseInt((l + h)/2, 10); }
/**
@ltfschoen
ltfschoen / gist:c4b4cb56cb6d547992d7ff181982141d
Created April 30, 2017 06:24
# Apollo-bot snippet of Python code showing how Bot server may reply to user with text message
def reply(user_id, msg):
resp = requests.post("https://graph.facebook.com/v2.6/me/messages",
params={"access_token": fb_AT},
data=json.dumps({
"recipient": {"id": user_id},
"message": {"text": msg}
}),
headers={'Content-type': 'application/json'})