Skip to content

Instantly share code, notes, and snippets.


Justin Searls searls

View GitHub Profile
searls / do-this.js
Created May 24, 2020
How to play web audio that won't interrupt background system-wide audio playback in iOS
View do-this.js
let audioContext
export function play (url) {
const AudioContext = window.AudioContext || window.webkitAudioContext
if (!audioContext) audioContext = new AudioContext()
const request = new window.XMLHttpRequest()'GET', url, true)
request.responseType = 'arraybuffer'
request.addEventListener('load', function (e) {
const source = audioContext.createBufferSource()
source.buffer = audioContext.createBuffer(request.response, false)
View sets_csrf_token.rb
module StaticRails
class SetsCsrfToken
def call(req, res)
value: masked_authenticity_token(req.session),
path: "/",
expires: + 24 * 60 * 60)
searls / reset_fixtures
Created Mar 3, 2020
Manually your Rails test fixtures whenever you want
View reset_fixtures
#!/usr/bin/env ruby
ENV["RAILS_ENV"] = "test"
require_relative "../config/environment"
View save_revalidly.rb
class SaveRevalidly
Result =, :errors, keyword_init: true)
def call(model)
if true, errors: model.errors.messages)
original_errors = model.errors.messages.dup
if model.invalid? && model.errors.keys.present?
subsequently_succeeded =
View unject
diskutil eject /dev/disk3
SafeEjectGPU Eject

Given this program foo.rb:

require "optparse"

options = {delimiter: " "} { |op|
  op.on("-d", "--delimiter [DELIM]", "String separating columns")

Here's a neat trick.

I treat my git clones as disposable between computers, but keep my project-specific dotfiles (usually containing environment variables, individual configurations, and so on) synced across devices in iCloud. Then, this script is just a matter of adding symlinks for each of the dotfiles I've saved for each of my projects to each of their clones.

So if my dotfiles are saved like this:

$ tree -a ~/icloud-drive/dotfiles/project-dotfiles/
├── searls
searls /
Created Jun 15, 2019
A script I wrote to preview a build directory (in my case Hugo's `public` folder, but adjust to taste).
# 1. Navigate to the built folder & start a server in it
cd public
python -m SimpleHTTPServer "$port" &
# 2. Trap any killing of this process so that we kill the backgrounded server

I was asked to share a few memories of Jim Weirich as someone prepared for a conference talk about him, so I figured I'd share what came to mind here:

  1. My cofounder Todd Kaufman would often refer to Jim as the "Santa Claus of the Ruby community". He was a big, jolly guy and he always brought joy to every room he was in. If people take away one thing to know about Jim, it's that even when he had 30 years of experience on someone, he always treated them with tremendous deference and respect. He always approached my ideas and questions as if they were urgent and fascinating, even if he'd encountered them dozens of times before. It's a trait I strive to imitate whenever I meet people at a user group or a conference, because it made such an impact on me when someone that I looked up to treated me like my experiences mattered to them.

  2. I would sometimes drive 2 hours from Columbus to Cincinnati just to hang out at Jim's office. No matter what client work he had to do, he was never too busy for me. I remember


WaniKani sent me this interview since I'd reached the program's max level. I figured I'd save my answers here for posterity.

Q: Why did you study Japanese?

I took German language in high school, but both its similarities to English and the near English fluency in every German person I've ever met conspired to discourage me from really taking it seriously.

I did, however, learn that the act of studying another language was a deeply perspective-altering activity. When you see how a language and a culture are inextricably linked, it triggers in me an introspection of my own ideology—what do I take for granted that's encoded into the English words I say or how I use them?

Ultimately, this led me to want to learn the most challenging language I could find, with a secondary priority for cultures that my own experience would relate to the least. Of Japanese, Chinese, and Russian, the emphasis on subtlety and harmony in Japanese culture put it over the top. Once I started studying,

You can’t perform that action at this time.