Skip to content

Instantly share code, notes, and snippets.


Daniel Metcalfe moderatemisbehaviour

View GitHub Profile
View promise-execution-order.js
const hi = Promise.resolve('hi')
console.log(1, hi) // 1 Promise { 'hi' }
const hiAgain = hi.then(hi => {
console.log(4, hi) // hi
return hi
hiAgain.then(hi => { // No point in this additional `then` call
console.log(5, hi) // hi
return hi
View count-chrome-bookmarks.js
chrome.bookmarks.getTree(tree => {
let bookmarksCount = 0;
function countBookmarks(children) {
for (child of children) {
if (child.children) {
} else if (child.url) {
bookmarksCount += 1
} else {
# Loads environment variables from a dot env (.env) file before calling the specified command.
# Parse -f and assign it to $OPTARG. Also assigns 'f' to $opt but that is not needed.
getopts f: opt
# If a path has been provided for the dot env file use that otherwise look in the working directory.
# Shift option parameters away so that $1 becomes the command to run rather than '-f'.
shift $((OPTIND-1))
git init merge_test
# Initialized empty Git repository in /vagrant/merge_test/.git/
cd merge_test
echo "First commit." > a_file
git commit -am "First commit."
git log
# commit eb4173dbd9589057e4fa0df089de781b33db9f5c (HEAD -> master)
# Author: vagrant <vagrant@localhost.localdomain>
moderatemisbehaviour / Grandpa Bear and the Mysterious Null
Last active Jan 27, 2016
An investigation into the meaning of 'this' and class load order.
View Grandpa Bear and the Mysterious Null

Meet The Bears. Bears implement the Bear interface and extend AbstractBear. They can all roar and in fact they do roar every time they are constructed.

public interface Bear
    public void roar();

public abstract class AbstractBear implements Bear
    public String howIRawr = "ROAR.";