Skip to content

Instantly share code, notes, and snippets.

View walkable-tree.js
// flatten a tree of arbitrary depth and complexity
class WalkableTree {
constructor(data) { = data
*[Symbol.iterator]() {
for (let value of {
if (Array.isArray(value)) {
sam-artuso / test.js
Created Feb 14, 2017
How to unit test a promise deliberately designed to side-effect?
View test.js
// demo.js
function f() {
return Promise.resolve(true)
function g() {
module.exports = { f, g }
sam-artuso /
Last active Feb 11, 2017
How I stopped myself typing npm instead of yarn

Yarn is the new fancy NPM client by Facebook. Compared to the good ol' npm command line client, Yarn is faster and provides by default what you can achieve with npm shrinkwrap. It's even got fancier output. Emojis apart, its output is more succinct than npm's, which spits out a lot of things I don't really want to know about.

After switching to Yarn I found out how much I rely on muscular memory when typing on my keyboard. I found myself typing by mistake npm install when I should've typed yarn add When this happens, the yarn.lock file stops reflecting what is installed in the node_modules/ directory.

My solution to this problem was to alias npm like below. This alias will check if yarn.lock exists, stop me and even tell me off.

npm='test -e yarn.lock && >&2 echo "yarn.lock found in current directory. Use yarn instead." || npm'
sam-artuso /
Last active Feb 10, 2021
Setting up Babel and nodemon

Setting up Babel and nodemon

Inital set-up

Set up project:

mkdir project
cd project
npm init -y
foo='Follow the white rabbit.'
# sleep 3
sudo echo > /dev/tty1
for (( i=0; i<${#foo}; i++)); do
sudo echo -n "${foo:$i:1}" > /dev/tty1; sleep .1
sudo echo > /dev/tty1