Skip to content

Instantly share code, notes, and snippets.

View deecewan's full-sized avatar

David Buchan-Swanson deecewan

View GitHub Profile
@deecewan
deecewan / launch.sh
Last active October 17, 2017 03:43
set up the raspberry pi
LOCAL_IP=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
t() {
tmux send-keys -t $1 "$2" 'C-m'
}
tmux new-session -d
tmux split-window -v -p 100
tmux split-window -v -p 100
tmux split-window -v -p 100
import fs from 'fs';
class FSError extends Error {}
const readFile = (...args) =>
new Promise((resolve, reject) => {
fs.readFile(...args, (err, data) => {
if (err) {
return reject(new FSError(err));
}
(() => {
const myPromise = new Promise((res) => setTimeout(res, 10));
myPromise
.then(() => { throw new Error('shit\'s fucked'); })
.then(() => console.log('won\'t ever run'))
.catch(err => console.log('how is shit?', err))
.then(() => console.log('will run'))
.then(() => { throw new Error('some other error'); })
.then(() => console.log('won\'t run'))
@deecewan
deecewan / move.js
Created September 11, 2017 14:31
move all folders from root-level folder into repo-dependent folders, like Go's package manager
const fs = require('fs-extra');
const path = require('path');
function isRepo(folder) {
const contents = fs.readdirSync(folder);
return contents.includes('.git');
}
function parseConfig(config) {
const output = {}
@deecewan
deecewan / ar_5_enum.rb
Last active June 12, 2017 04:25
Rails enum
# File activerecord/lib/active_record/enum.rb, line 146
# https://github.com/rails/rails/blob/919a876a04d991bb5a984314ca985168cfbbbef5/activerecord/lib/active_record/enum.rb#L146
# rails 5 backport so we can get the _prefix and _suffix features
if Rails::VERSION::MAJOR < 5
module ActiveRecord
module Enum
def enum(definitions)
klass = self
enum_prefix = definitions.delete(:_prefix)
@deecewan
deecewan / ignore-whitespace.js
Created June 5, 2017 00:02
Add a checkbox to the Github Compare screen to ignore white space. Add this to tampermonkey
// ==UserScript==
// @name Github Whitespace
// @namespace http://deecewan.com/
// @version 0.1
// @description Add a checkbox to the Github Compare screen to ignore white space.
// @author David Buchan-Swanson
// @match https://github.com/*/*/compare/*
// @grant none
// ==/UserScript==
@deecewan
deecewan / Makefile
Created June 3, 2017 05:15
Makefile for a pandoc project converting markdown to latex
SHELL=zsh
.PHONY: all copy clean
all: copy out/main.tex
clean:
rm -r out/*
copy:
zsh -c 'setopt extendedglob; cp -r src/^(template.tex|*.md) out/'
@deecewan
deecewan / .zshrc
Created March 14, 2017 08:32
Store all your brew formula and reload in case of emergency
# ...
brw() {
brew $@
brew list --versions | perl -pe 's/([\w-(@\d\.\d)]+).*/$1/' > $CONFIG/brew_installed.txt
}
restore_from_brew() {
cat $CONFIG/brew_installed.txt | xargs brew install
}
@deecewan
deecewan / .babelrc
Created March 13, 2017 23:24
The files it takes for me to start a new JS lib
{
"presets": [["env", {
"targets": {
"node": 6.9
}
}], "stage-0"],
"plugins": [
"babel-plugin-syntax-trailing-function-commas",
"babel-plugin-transform-class-properties",
"babel-plugin-transform-flow-strip-types",
@deecewan
deecewan / testbg.js
Created March 12, 2017 01:57
Simple script to test Google Cloud Functions background functions
#!/usr/bin/env node
const join = require('path').join;
const read = require('fs').readFileSync;
const args = process.argv.slice(2);
const fnName = args[0];
const payload = args[1];
const fileBuffer = read(join(__dirname, 'payloads', `${payload}.json`));