Skip to content

Instantly share code, notes, and snippets.

View joekrump's full-sized avatar
🌱

Joe Krump joekrump

🌱
View GitHub Profile
@joekrump
joekrump / mock.ts
Created July 31, 2024 16:13
Playwright mock slow network request
const urlPattern = "**/some_endpoint";
const delayMS = 1000
await page.route(urlPattern, async (route) => {
const resolve = (route: Route) => route.continue();
const res = new Promise(() => resolve);
setTimeout(async () => {
await resolve(route);
}, delayMS);
@joekrump
joekrump / spec_helper.rb
Created June 6, 2024 22:36
RSpec enable cache conditional on meta data
# allow cache to be used in a test that uses the :with_cache metadata
config.around do |example|
if example.metadata[:with_cache]
Rails.cache = ActiveSupport::Cache.lookup_store(:memory_store)
Rails.cache.clear
end
example.run
end
@joekrump
joekrump / command.sh
Last active March 8, 2024 17:31
Quick resolve multiple files with conflicts when you know if you want "ours" or "theirs" for the resolution
# Helpful for when running git rebase -i and selecting multiple files to fixup or drop
# select ours for each conflict
git status | grep both | awk '{print $3}' | xargs git checkout --ours
# select theirs for each conflict
git status | grep both | awk '{print $3}' | xargs git checkout --theirs
# run with && git add . && git rebase --continue to add and move on
git status | grep both | awk '{print $3}' | xargs git checkout --ours && git add . && git rebase --continue
@joekrump
joekrump / Procfile
Created July 25, 2023 14:53
Procfile setup for Rails & Vite app
redis: redis-server # optional. Comment out if you are not using redis
web: bin/rails server -p 3000
worker: bundle exec sidekiq # optional. Comment out if you are not using sidekiq for background jobs
vite: bundle exec bin/vite dev
@joekrump
joekrump / devise_setup.sh
Created July 13, 2023 00:17
Setup devise
#!/usr/bin/env bash
bundle add devise && rails g devise:install && rails g devise user
@joekrump
joekrump / example_system_spec.rb
Last active June 27, 2023 15:27
Config for RSpec + capybara with playwright
describe 'test something', driver: :playwright do
let(:user) { create(:user) }
before do
login_as user
end
it 'goes to a page and checks to see that it contains some content when not authorized' do
page.goto(restricted_path)
@joekrump
joekrump / timer.html
Last active April 28, 2022 16:27
Timer button - Plain JavaScript and HTML
<!DOCTYPE html>
<html>
<head>
<title>Timer</title>
<style>
:root {
--text-color: black;
@joekrump
joekrump / colors.js
Created February 2, 2022 05:31
Color helpers
/**
* @param {string} hexString
* @returns {{ r: number; g: number; b: number; }}
*/
function getRGBFromHex(hexString) {
hexString = hexString.substring(1);
let aRgbHex = hexString.match(/.{1,2}/g);
return {
r: parseInt(aRgbHex[0], 16),
g: parseInt(aRgbHex[1], 16),
@joekrump
joekrump / get_file_paths.sh
Last active August 26, 2021 14:21
Get the paths to files that have webpack compile errors
# Combined commands (See below for descriptions about what each one is doing):
yarn run build | awk '$0~/ERROR in/' | sed -e 's/ERROR in //' -e 's/:[0-9]:[0-9]//' -e 's/:[0-9][0-9]:[0-9]//' -e 's/:[0-9][0-9]:[0-9][0-9]//' > file_paths.txt
# yarn run build > build_output.txt # Direct stdout to a file. yarn run build runs `webpack`
# awk '$0~/ERROR in/' build_output.txt > files_with_errors.txt # Get the lines that start with the string "ERROR in" and print them to the file, files_with_errors.txt
# sed -e 's/ERROR in //' -e 's/:[0-9]:[0-9]//' -e 's/:[0-9][0-9]:[0-9]//' -e 's/:[0-9][0-9]:[0-9][0-9]//' files_with_errors.txt > paths_without_line_numbers.txt # Find and replace instances of "ERROR in " with nothing, run several matchers to remove trailing line and column numbers on the path strings that take like something like "/path/to/some/file.ts:10:11".
@joekrump
joekrump / cloudSettings
Last active August 5, 2020 16:19
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-08-05T16:19:21.986Z","extensionVersion":"v3.4.3"}