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
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
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
end
def full_name
@first_name + " " + @last_name
end
end
@JoshCheek
JoshCheek / feature_testing.md
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
View feature_testing.md

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
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 = Logger.new $stdout
ActiveSupport::LogSubscriber.colorize_logging = false
# ===== Migration =====
@JoshCheek
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() {
DocumentApp.getUi()
.createMenu('Translate')
.addItem('Translate selection to Spanish', 'translateSelectionToSpanish')
.addItem('Translate selection to English', 'translateSelectionToEnglish')
.addToUi();
@JoshCheek
JoshCheek / ruby_and_js_vs_lua.sh
Last active Jul 13, 2019
Ruby vs JS vs Lua (all nonlinear, but JS has best perf)
View ruby_and_js_vs_lua.sh
# Code from this tweet: https://twitter.com/josh_cheek/status/1150035017319497728
$ node -e '
const n = 10000
const str = "x=" + "x".repeat(n)
const regex = /.*.*=.*/
const label = `n=${n}`
console.time(label)
const match = str.match(regex)
console.timeEnd(label)
View budding-of-the-brood.js
// "Budding of the Brood" by Josh Cheek (@josh_cheek on the twitter)
// Paste it into here: https://hydra-editor.glitch.me
// Or you can watch me run it here: https://vimeo.com/346283798
// And some explanatino of how it works here: https://vimeo.com/346242814
// Great explanation of the math here: https://www.youtube.com/watch?v=r6sGWTCMz2k
document.getElementsByClassName('console')[0].style.display = 'none'
function getPoint(time, getX) {
time = (time*5) % points.length
const [x1, y1] = points[Math.floor(time)]
@JoshCheek
JoshCheek / hydra.js
Last active Jun 22, 2019
Attempting to draw a hydra with hydra
View hydra.js
solid().constructor.prototype.sin = function (radius, frequency, offset=0) {
return this.scrollX(radius).rotate(offset,frequency)
}
// need to figure out how to convert these to epicycles
// 94.75,70.19999694824219 87.60526275634766,68.36907196044922 81.8226547241211,69.729736328125 79.25341796875,76.64624786376953 76.66010284423828,83.35103607177734 69.29661560058594,83.73706817626953 62.081077575683594,85.23097229003906 57.438026428222656,80.36616516113281 53.0716667175293,74.41837310791016 47.33558654785156,73.1541748046875 40.800262451171875,76.56771850585938 34.873775482177734,80.94866180419922 36.75628662109375,87.4500503540039 39.90579605102539,94.12261199951172 38.09734344482422,100.01497650146484 33.584781646728516,105.8336181640625 28.309032440185547,108.61717224121094 21.038862228393555,107.36031341552734 14.398143768310547,107.5927505493164 12.04347038269043,114.56926727294922 10.539800643920898,121.79061889648438 13.436785697937012,126.81439208984375 20.323444366455078,129.46315002441406 25.62
@JoshCheek
JoshCheek / scrape_sigs
Last active Jun 16, 2019
My hydra signature scraping script
View scrape_sigs
#!/usr/bin/env bash
node -e 'console.log(JSON.stringify(require("./src/composable-glsl-functions.js")))' \
| ruby -r json -e '
puts JSON.parse($stdin.read, symbolize_names: true)
.map { |name, defn| {**defn, name: name} }
.group_by { |defn| defn[:type] }
.sort
.each { |cat, defns| defns.sort_by! { |defn| defn[:name] } }
.map { |category, defns|
defns.zip([category]).map.with_index { |(defn,category),i|
View duo_lingo_clone.rb
#!/usr/bin/env ruby
require 'readline'
# copied from https://www.vistawide.com/spanish/top_100_spanish_words.htm
list = <<~WORDS
el / la (def. art.) the
de (prep.) of, from
que (conj.) that, which
y (conj.) and
a (prep.) to, at
You can’t perform that action at this time.