Skip to content

Instantly share code, notes, and snippets.

View Schoonology's full-sized avatar
🦄

Michael Schoonmaker Schoonology

🦄
View GitHub Profile
@Schoonology
Schoonology / new-computer.sh
Created August 3, 2018 01:13
Setup scripts
#!/bin/bash
set -evuo pipefail
IFS=$'\n\t'
DIR=$(dirname "${BASH_SOURCE[0]}")
run_if_closed() {
if ! [ -n "$(pgrep "${2:-$1}")" ]
then
echo "Opening $1..."
@Schoonology
Schoonology / README.md
Last active May 13, 2016 00:58
TestDouble + Ava Controller Test

I'm using AVA for the test runner, and testdouble for mocking. Glueing them together to test an Express route handler was completely straightforward, and worked the first time. Here's the gist of that.

Why a "controller test"?

My spec/E2E tests involve spinning up a Docker container, but—for the time being—if the application fails on start-up, the spec script (powered by Scripty, #onbrand) fails silently, which is annoying. To quickly solve my problem, I isolated the only controller I changed into a unit test. Normally, this isn't a great idea, as it's duplicating work and it can make it harder to change implementation details.

@Schoonology
Schoonology / spread-call.js
Created November 16, 2015 16:18
Spread-call
var arr = [1, 2, 3];
function foo(a, b, c){
console.log("this", this);
console.log("a", a);
console.log("b", b);
console.log("c", c);
}
foo(...arr); // Regular fn call
@Schoonology
Schoonology / Vagrantfile
Last active August 29, 2015 14:01
Mongo-only Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provision :shell, :path => "bootstrap.sh"
[8080, 6379, 27017, 5984].each do |port|
config.vm.network :forwarded_port, guest: port, host: port
@Schoonology
Schoonology / cluster.send.js
Last active December 17, 2015 23:39
An example of process.send vs worker.send.
var cluster = require('cluster')
if (cluster.isMaster) {
console.log('Master started.')
// If we're a master process, we can listen on the 'fork' event to get Worker instances.
// We'll use it to communicate with that process.
cluster.on('fork', function (worker) {
// Now that we have a worker, we can listen on 'message' events that worker has sent.
// These messages are sent via process.send, below, and are received only by the master.