Skip to content

Instantly share code, notes, and snippets.

Josh Cheek JoshCheek

Block or report user

Report or block JoshCheek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
JoshCheek / dot_is_for_minitest.rb
Created Sep 25, 2019
Experiment that adds `.is` (like the old RSpec `.should`) to Minitest
View dot_is_for_minitest.rb
require 'minitest/autorun'
module DotIs
# Track the current test so that we can run assertions in its context
def self.current_test=(test)
Thread.current[:dot_is_current_test] = test
def self.current_test
Thread.current.fetch :dot_is_current_test
JoshCheek / metaprogrammed_active_record_clone.rb
Created Sep 24, 2019
Metaprogrammed ActiveRecord "clone" (just a fun morning experiment)
View metaprogrammed_active_record_clone.rb
class Query
def initialize(table, db)
@db, @table, @cols, @rest = db, table.downcase, '*', ''
def method_missing(clause, *args)
clause == :select \
? @cols = args.join(', ') \
: @rest << ' ' << [clause, *args].join(' ')
JoshCheek / lambda-calc.js
Created Sep 23, 2019
lambda calc translation
View lambda-calc.js
($true => $false => $if => y => succ => zero => toJs =>
(one => two => three => add => nil => cons =>
(multiply => map => reduce =>
console.log(reduce(arr => n => [...arr, toJs(n)])(
// Translation of this program into lambda calculus
// const arr = [1,2,3]
// const timesTwoPlusIndex = (el, index) => (el*2) + index
JoshCheek / gettext_erb_html.rb
Last active Sep 22, 2019
Just playing. Gives `gettext` its own HTML tags.
View gettext_erb_html.rb
# Just playing (based on
require 'nokogiri'
require 'erb'
require 'gettext'
class ErbHtml
include GetText # I have no dea how to use this gem :shrug:
# Based on their example:
JoshCheek /
Created Sep 13, 2019
Example of making a Rails inspired minimalist web framework for Rack
# ru means "rackup"
class Object
private def erb(text)
class MyRails
attr_accessor :routes
JoshCheek / recentness.rb
Created Aug 16, 2019
List db tables by the recentness of their `created_at` column.
View recentness.rb
# example: ruby recentness.rb myapp_development | column -t
dbname = ARGV.fetch(0)
require 'pg'
puts "schema\ttable\tlast-insert"
PG.connect(dbname: dbname).exec(<<~SQL).each { |row| puts row.values.join "\t" }
create function pg_temp.recentness(table_schema text, table_name text, out last_insert timestamp)
as $fn$ begin
execute format('select max(created_at) from %I.%I', table_schema, table_name)
into last_insert;
end $fn$ language plpgsql;
JoshCheek / gist:7cc84715dc7ab6deef40adf9982bf755
Created Aug 12, 2019
Using a refinement to scope a monkey patch
View gist:7cc84715dc7ab6deef40adf9982bf755
# code we don't own
class User
def initialize(first_name, last_name)
@first_name, @last_name = first_name, last_name
def full_name
@first_name + " " + @last_name
JoshCheek /
Last active Aug 1, 2019
Thoughts on creating an acceptance/feature test suite for a website with a React frontend and a few services on the backend

Make fewer tests that are larger, because the tests are going to be extremely expensive and fragile. Make assertions that are very permissive, eg assert that you see a success message, but not what the message says. Because there's a million ways for these tests to fail. Someone changes some wording in a message and tests fail. Someone changes the DOM structure and the tests fail. Someone changes a classname and the tests fail. Some async operation takes longer than expected or resolves in some unexpected order, and the tests fail. But in all those situations, the thing you are testing is still correct, it's just that the way the test checks it is fragile, and the thing you are testing is volatile. So you want the tests to only assert the most important things, and the art of it is figuring out how permissive you want to be. Eg you want to be assertive enough that they don't accidentally pass when they actually should fail, but still permissive enough that they can tolerate irrelevant volatility.

For tooling

JoshCheek / map_ar_enum_to_pg_enum.rb
Created Jul 31, 2019
ActiveRecord enum / PostgreSQL enum
View map_ar_enum_to_pg_enum.rb
# require 'pg'; PG.connect(dbname: 'postgres').exec('create database josh_testing') # <-- uncomment to create the db (only needs to run once)
# ===== Setup ActiveRecord =====
require 'active_record'
require 'logger'
ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'josh_testing'
ActiveRecord::Base.logger = $stdout
ActiveSupport::LogSubscriber.colorize_logging = false
# ===== Migration =====
JoshCheek / google-apps-translate.js
Last active Jul 19, 2019
Google Apps script to translate selections back and forth between English and Spanish
View google-apps-translate.js
* @OnlyCurrentDoc Limits the script to only accessing the current sheet.
function onOpen() {
.addItem('Translate selection to Spanish', 'translateSelectionToSpanish')
.addItem('Translate selection to English', 'translateSelectionToEnglish')
You can’t perform that action at this time.