Skip to content

Instantly share code, notes, and snippets.

View searls's full-sized avatar
💚

Justin Searls searls

💚
View GitHub Profile
@searls
searls / sorbet_override.rb
Created June 17, 2023 13:20
Sorbet's documentation doesn't give particularly elucidative examples of using the runtime check callbacks available to override Sorbet's default behavior, so here's an example of how I'm doing it in Mocktail.
# Override Sorbet's runtime checks inside a given block's execution to allow
# testing of, among other things, Mocktail's own runtime type checks.
# See doc: https://sorbet.org/docs/tconfiguration
#
# Note that the messages being raised are the same as those constructed in
# sorbet-runtime (0.5.10847)
#
# Example usage:
# def test_not_a_class
# e = SorbetOverride.disable_call_validation_checks do
# typed: true
# This script prints:
#
# <-- Stubbing based on kwarg comparison with a TYPED method
# Should be tim: "jan greeting"
# Should be jan: "jan greeting"
# Should be nil: "jan greeting"
# <-- Stubbing based on kwarg comparison with an UNTYPED method
@searls
searls / english.txt
Last active May 11, 2023 08:35
Ruby Kaigi 2023 - Matz Keynote Transcription. Includes Matsuda-san intro and sponsor presentations. Transcribed and Translated by OpenAI Whisper https://replicate.com/openai/whisper )
Welcome to Matsumoto. I mean, physically or virtually. We're so happy to have you here. I think I'm seeing a thousand people in front of me here in this venue. I think it's been a while. It's been a while. It's been like four years since we had this number of people in the Kaigi venue. Four years. I'd like to say thank you for gathering again, coming back to RubyKaigi. I feel like the Kaigi is back. Because of you. Because of you, in the venue. Because you are back. But actually, since there have been four years of blank period of Kaigi, I said you're back, but actually we should be having newcomers to the Kaigi. So, please let me know. Please tell me, who are the first-timers of RubyKaigi? I mean, raise your hand if you are coming to RubyKaigi for the first time. Thank you. Thank you for coming. We really welcome your attendance. So, one thing I'd like to tell you, I have to tell you is... Um... Not that. The COC thing, the Code of Conduct, the core of the conduct is be nice to each other. So, let us be nice
@searls
searls / chat_gpt_streaming_example.rb
Created April 18, 2023 22:33
net/http's `read_body` is all you need to read streaming responses from the ChatGPT API. No need for a gem dependency
require_relative "../config/environment"
uri = URI("https://api.openai.com/v1/chat/completions")
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Authorization"] = "Bearer #{ENV["OPEN_AI_API_KEY"]}"
req.body = JSON.dump({
model: "gpt-4",
max_tokens: 80,
messages: [{role: "user", content: "What's the best way to learn Ruby?"}],
@searls
searls / react-was-a-mistake.md
Last active April 11, 2023 21:04
I asked Bing Chat, "Write a blog post in the style of Justin Searls about why React was a mistake."

React was a mistake

I know what you’re thinking: “Not another React rant!” But hear me out. I’m not here to bash React for its performance, its ecosystem, or its popularity. I’m here to argue that React was a mistake because it fundamentally changed the way we think about web development, and not for the better.

React introduced a new paradigm for building web applications: components. Components are reusable pieces of UI that can have their own state, logic, and rendering. Components can be composed together to form complex interfaces, and React takes care of updating the DOM when the component state changes.

Sounds great, right? Well, not so fast. There are some serious drawbacks to this approach that are often overlooked or ignored by React enthusiasts.

First of all, components are not a natural fit for the web. The web is based on documents, not applications. Documents are structured by HTML elements, styled by CSS rules, and enhanced by JavaScript behaviors. HTML, CSS, and JavaScript are designed t

@searls
searls / keybindings.json
Last active April 28, 2023 16:47
VS Code 1.77 added the `runCommands` command, which is basically a macro that you can define right in your keybindings file by chaining multiple commands together. In this case I bound individual test runs, file-scoped tests, and full Rake tasks to command-R + modifiers. (The `m` CLI is the m gem, which allows running minitests by file and line)…
[
{
"command": "runCommands",
"key": "cmd-r",
"args": {
"commands": [
"workbench.action.files.save",
"workbench.action.terminal.focus",
{
"command": "workbench.action.terminal.sendSequence",
@searls
searls / cops_to_csv.rb
Created March 28, 2023 14:34
Ruby file to convert a Rubocop YAML file (rubocop-rails in this case) to a CSV for the purpose of evaluating the rules
# Purpose: Generate a CSV file from the rubocop-rails config file
#
# Usage: ruby driver.rb [csv_file_name] # defaults to rubocop-rails.csv
require "yaml"
require "csv"
def doc_url(cop_name)
squished = cop_name.downcase.delete("/")
"https://docs.rubocop.org/rubocop-rails/cops_rails.html##{squished}"
@searls
searls / tailwind.config.js
Created March 21, 2023 23:40
A sample Tailwind configuration file, heavily inspired by @PixelJanitor
function spacing () {
const scale = Array(201)
.fill(null)
.map((_, i) => [i * 0.5, `${i * 0.5 * 8}px`])
const values = Object.fromEntries(scale)
values.px = '1px'
values.xs = '2px'
values.sm = '4px'
return values
}
@searls
searls / standard_on_rails.diff
Created February 19, 2023 19:30
This is the only diff remaining when I ran a brand new rails app through `standardrb --fix` for the first time.
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 87ec21e..9f34f1b 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -53,7 +53,6 @@ Rails.application.configure do
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
-
# Raises error for missing translations.
@searls
searls / rails_bisect_step
Created February 1, 2023 20:34
Used in conjunction with [this script](https://gist.github.com/searls/5c6b77213dbc7202ca39f4e70d975eee) to make it easier to git bisect rails apps whose database changes during the affected sha range
#!/usr/bin/env bash
# Usage:
#
# First, be sure you're running `git bisect start --no-checkout`, so you can
# checkout the bisect head yourself and do some pre-flight stuff like rewind
# migrations
#
# $ git bisect good
# Bisecting: 22 revisions left to test after this (roughly 5 steps)