Skip to content

Instantly share code, notes, and snippets.

View deecewan's full-sized avatar

David Buchan-Swanson deecewan

View GitHub Profile
@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 / 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 / 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 = {}
(() => {
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'))
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));
}
@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
let myVar = 1;
function deleteIfBad() {
if (myVar > 1) {
deleteProductionDatabase();
}
}
function doSomething() {
myVar = 3;
if (someCondition) {
myVar = 4;
}
}
@deecewan
deecewan / errors.sh
Created February 1, 2018 06:44
Flow errors from redux-persist
Error: node_modules/redux-persist/es/persistStore.js.flow:67
67: persistor.purge = () => {
^^^^^ property `purge`. Property not found in
67: persistor.purge = () => {
^^^^^^^^^ object type
Error: node_modules/redux-persist/es/persistStore.js.flow:78
78: persistor.flush = () => {
^^^^^ property `flush`. Property not found in
78: persistor.flush = () => {
@deecewan
deecewan / with_amazon_keys.zsh
Created March 27, 2018 01:42
Select amazon api keys to run a command with from your ~/.aws/credentials file.
function with_amazon_keys() {
local chosen_profile=$1
if [ $# -gt 0 ]; then
shift;
fi;
local AWS_CREDENTIAL_LOCATION="$HOME/.aws/credentials"
local old_ifs="$IFS"
local IFS=$'\n'
local aws_credentials=("${(@f)$(cat $AWS_CREDENTIAL_LOCATION)}")