Skip to content

Instantly share code, notes, and snippets.

@twolfson
twolfson / concerns-keyed_model.rb
Created June 12, 2018 02:34
Rails acts-as-keyed updated/simplified
# Largely based on `acts-as-keyed` but with less magic (namely make `to_param` consistent, don't overwrite `find`)
# https://github.com/jhubert/acts-as-keyed
# http://vaidehijoshi.github.io/blog/2015/10/13/stop-worrying-and-start-being-concerned-activesupport-concerns/
module KeyedModel
extend ActiveSupport::Concern
KEY_CREATION_RETRIES = 100
KEY_LENGTH = 8
included do
@twolfson
twolfson / main.sh
Created April 14, 2018 19:33
Unnest folders into 1 flat folder of symlinks
#!/usr/bin/env bash
# Do you have a bunch of nested folders of images that you want to scroll through easily?
# Well this script is for you, it will take nested folders and symlink their files so they're easily scrollable
# It retains the full path so files which should be next to each other still are :+1:
# Exit under sane conditions
set -euo pipefail
# Allow spaces in path names
# https://stackoverflow.com/a/7039579
@twolfson
twolfson / main.sh
Created April 13, 2018 23:34
Increment README version script
#!/usr/bin/env bash
# Exit on first error, unset variable, or pipe failure
set -euo pipefail
# Define our constants
README_FILEPATH="README.md"
# Resolve our version being deployed
# **1.0.0** -> 1.0.0
version="$(grep -E "\*\*\d+\.\d+\.\d+\*\*" "${README_FILEPATH}" | sed "s/\*//g")"
@twolfson
twolfson / main.rb
Last active March 16, 2018 18:42
Pipe child process stdout and stderr to main process in Ruby
Open3.popen3("./tmp.sh") do |stdin, stdout, stderr, wait_thr|
# Stream output
# DEV: We'd like to stream both `stderr` and `stdout` but it was getting troublesome
# with `.alive?` and `gets()` blocking each other
while line = stdout.gets()
$stdout.puts(line)
end
# Finish any last stderr or stdout
stdout_remainder = stdout.read()
@twolfson
twolfson / main.sh
Last active October 22, 2021 05:32
Increment CFBundleVersion script, generally reusable for incrementing version in bash
#!/usr/bin/env bash
# Exit on first error, unset variable, or pipe failure
set -euo pipefail
# Define our constants
PLIST_FILEPATH="path/to/plist.plist"
# Resolve our version being deployed
# https://gist.github.com/sekati/3172554
# DEV: `plutil` doesn't support extraction easily (could use `-o -` but it's wrapped in XML/binary/JSON)
@twolfson
twolfson / IconDisabled.png
Created December 16, 2017 11:52
Proof of concept to demonstrate how `tabs.sendMessage` refuses to send in Firefox's responive design mode
IconDisabled.png
@twolfson
twolfson / IconDisabled.png
Last active December 16, 2017 11:53
Proof of concept to demonstrate how `runtime.onMessage` is missing tab in Firefox's responive design mode
IconDisabled.png
@twolfson
twolfson / README.md
Last active November 17, 2017 07:42
Xcode customizations

It's my first time setting up Xcode but I want to keep track of my preferences (probably move it to a dotfile if it becomes serious). Here's our notes:

  • Navigation
    • Navigation: Uses Focused Editor
  • Fonts & Colors
    • Theme: Default
  • Text Editing
    • Editing
      • Page guide at column: 120
  • Source Control
@twolfson
twolfson / README.md
Last active November 14, 2017 08:41
Replace Gratipay content with support me page

I've been adding Gratipay to my README's for a long time. As a result of Gratipay shutting down, I need to update all of my README content. Here's my strategy:

Script

@twolfson
twolfson / README.md
Last active November 10, 2017 00:24
RAILS_ENV overloading with `bin/rake` and `config/boot.rb`

We are using dotenv with Rails and Spring but running into timing issues where Dotenv loads/assumes we're in development before RSpec can override RAILS_ENV

To prevent this from happening consistently, we've added a patch in bin/rake and config/boot.rb

We verified our patch works with puts in spec/rails_helper.rb:

puts("RAILS_ENV", ENV["RAILS_ENV"])
puts("S3_REGION", ENV["S3_REGION"])
ENV["RAILS_ENV"] ||= "test"