Skip to content

Instantly share code, notes, and snippets.

View billthompson's full-sized avatar

Bill Thompson billthompson

View GitHub Profile
@jaymcgavren
jaymcgavren / blog.rb
Created October 26, 2017 22:48
Set up Active Record with an in-memory database and model classes, all in a single file.
# Instead of loading all of Rails, load the
# particular Rails dependencies we need
require 'sqlite3'
require 'active_record'
# Set up a database that resides in RAM
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
@ldez
ldez / gmail-github-filters.md
Last active March 15, 2025 21:57
Gmail and GitHub - Filters

Gmail and GitHub

How to filter emails from GitHub in Gmail and flag them with labels.

The labels in this document are just examples.

Pull Request

Filter Label
@splittingred
splittingred / gist:606c6b6b07c8e536dcd7
Last active February 28, 2018 19:37
Things Nick Hates
Things Nick Hates
0) Ann Kitchen
1) non-shallow tests
2) `if !`
3) ants
4) rock stars
5) sunlight off porch windows when drinking coffee
6) people who feed the meter
7) using floats for money
@paulirish
paulirish / what-forces-layout.md
Last active April 8, 2025 12:26
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@charrisbc
charrisbc / interactor_visitor.rb
Created August 25, 2015 15:18
Interactor Visitor debugging helper. Include in an Interactor to wrap with calls to binding.pry
module InteractorVisitor
extend ActiveSupport::Concern
included do
around do |interactor|
binding.pry
''
interactor.call
binding.pry
''
@charrisbc
charrisbc / organizer_visitor.rb
Created August 25, 2015 15:16
OrganizerVisitor debugging helper. Include in an Interactor::Organizer to wrap each interactor in binding.pry calls.
module OrganizerVisitor
extend ActiveSupport::Concern
included do
def call
self.class.organized.each do |interactor|
binding.pry
''
interactor.call!(context)
binding.pry
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 12, 2025 21:24
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@ncancelliere
ncancelliere / prune_git_branches.sh
Created March 25, 2015 14:11
Remove local git branches that have been merged
# Credit to http://snippets.freerobby.com/post/491644841/remove-merged-branches-in-git for the script on which this is based
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching merged branches..."
git remote prune origin
local_branches=$(git branch --merged | grep -v 'master$' | grep -v "$current_branch$")
if [ -z "$local_branches" ]; then
@brianhempel
brianhempel / bench_rails_memory_usage.rb
Last active March 25, 2025 18:43
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@namuol
namuol / INSTALL.md
Last active December 11, 2024 12:21
rage-quit support for bash

rage-quit support for bash

HOW TO INSTALL

Put flip somewhere in your $PATH and chmod a+x it.

Copy fuck into ~/.bashrc.