Skip to content

Instantly share code, notes, and snippets.

@dhh
dhh / pagination_controller.js
Last active October 9, 2024 20:23
HEY's Stimulus Pagination Controller
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>
@tekin
tekin / .gitattributes
Last active July 9, 2024 20:31
An example .gitattributes file that will configure custom hunk header patterns for some common languages and file formats. See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details.
# Stick this in your home directory and point your Global Git config at it by running:
#
# $ git config --global core.attributesfile ~/.gitattributes
#
# See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details
*.c diff=cpp
*.h diff=cpp
*.c++ diff=cpp
*.h++ diff=cpp
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@jacobsmith
jacobsmith / git checkout fuzzy match
Created October 31, 2016 13:20
Allow fuzzy matching of contiguous letters (i.e. `co mas` would do `git checkout master`)
branch=$( git branch | tr -d '*' | grep $1 )
current_branch() {
echo $(git rev-parse --abbrev-ref HEAD)
}
starting_branch=$(current_branch)
# This function lists all branches with an index (starting at 1)
list_all_branches() {
#!/usr/bin/env ruby
require 'pathname'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:
@unixmonkey
unixmonkey / pre-commit
Last active August 1, 2018 20:34
git pre-commit hook to prevent check-in of debugger stuff
#!/usr/bin/env ruby
# This pre-commit hook aims to prevent you from *accidentally* committing debugger
# statements if installed in your project. You can force a commit if necessary with:
# `git commit --no-verify`.
# Install by copying it to <your-project-dir>/.git/hooks/pre-commit'
hits = []
rb_debuggers = ['binding\.pry', 'binding\.remote_pry', 'debugger', 'focus: true', ':focus => true', 'save_and_open_page', 'save_and_open_screenshot']
js_debuggers = ['console\.log', 'debugger']