Skip to content

Instantly share code, notes, and snippets.


Brandon Keepers bkeepers

View GitHub Profile
bkeepers / application.js
Created Mar 3, 2010
Get timezone offset from the browser and use it for timezones in Rails
View application.js
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
bkeepers / .gitconfig
Created Feb 19, 2013
Git aliases to make new commits that fixup or are squashed into previous commits
View .gitconfig
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autosquash $REV^' -
squash = !sh -c 'REV=$(git rev-parse $1) && git commit --squash $@ && git rebase -i --autosquash $REV^' -
bkeepers /
Last active Jan 17, 2022
Fail Rails system tests if there are any JavaScript errors

We're on the cusp of 2022 and most software is now written in JavaScript, but it is still virtually impossible to fail integration tests on a JavaScript error and get a useful stack trace from the browser.

This gist includes my description of the problem and sample code from my attempts to solve it.

What I want:

  • Integration test should fail (preferabbly immediately) on any uncaught JavaScript error (window.onerror, unhandledrejection, etc)
  • The stack trace should use source maps and be close to what browsers show in DevTools

The tools I'm currently using:

bkeepers / .profile
Created Jun 19, 2009
Split bash profile into multiple files
View .profile
# My ~/.profile file was getting too messy and unmaintainable, so I
# split everything out into separate files and sourced them
for file in ~/.profile.d/*
source $file
bkeepers /
Last active Jun 25, 2021
Keep two HTML5 video elements in sync.
videos = document.getElementsByTagName('video')
new VideoSync(videos[0], videos[1])
bkeepers / iframe_location_controller.js
Last active Mar 12, 2021
Stimulus controller to save location of same-origin iframe in hash of parent window and restore on reload.
View iframe_location_controller.js
import { Controller } from 'stimulus'
// Stimulus controller to save location of same-origin iframe in hash of parent
// window and restore on reload.
// <iframe src="…"
// data-controller="iframe-location"
// data-action="load->iframe-location#save">
// </frame>
View data.csv
age length price
36 29 12500
41 38 34900
45 13 1250
11 26 22400
19 48 265000
33 38 89900
5 42 399000
39 28 3200
39 27 14750
bkeepers / .env
Last active Nov 2, 2020
Probot plugin that ensures every commit message has the word "bananas"
View .env
# The ID of your GitHub App
# Uncomment this to get verbose logging
# LOG_LEVEL=trace # or `info` to show less
# Go to set this to the URL that you are redirected to.
bkeepers / application.rb
Created May 13, 2020
Add methods to `rails console`
View application.rb
module SailboatGuide
class Application < Rails::Application
console do
require 'console_helpers'
TOPLEVEL_BINDING.eval('self').extend ConsoleHelpers