Skip to content

Instantly share code, notes, and snippets.

View homostellaris's full-sized avatar
🤤
Fun

Daniel Metcalfe homostellaris

🤤
Fun
View GitHub Profile
@homostellaris
homostellaris / gist:b3732c18a3631a0a6d3181f74d6bf4cb
Created December 28, 2021 16:27
See what is taking up system data space on macOS
cd ~/Library
du -h | sort -nr | less
@homostellaris
homostellaris / promise-execution-order.js
Last active February 26, 2024 07:31
Promise execution order
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
})
@homostellaris
homostellaris / count-chrome-bookmarks.js
Last active February 26, 2024 07:06
Count Chrome bookmarks
chrome.bookmarks.getTree(tree => {
let bookmarksCount = 0;
function countBookmarks(children) {
for (child of children) {
if (child.children) {
countBookmarks(child.children)
} else if (child.url) {
bookmarksCount += 1
} else {
@homostellaris
homostellaris / habitat.sh
Last active April 28, 2020 13:31
habitat.sh
#!/bin/sh
# 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.
DOT_ENV_FILE_PATH=${OPTARG:-./.env}
# Shift option parameters away so that $1 becomes the command to run rather than '-f'.
shift $((OPTIND-1))
@homostellaris
homostellaris / git-merge-behaviour.sh
Last active November 9, 2017 18:23
Git merge behaviour
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>
@homostellaris
homostellaris / Grandpa Bear and the Mysterious Null Roar.md
Last active January 27, 2016 17:15
An investigation into the meaning of 'this' and class load order.

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.";