One way to do this is to use bundler to scaffold our gem:
bundler gem my_gem
I prefer to put tasks meant to manage the gem itself in lib/tasks
, and tasks the gem is meant to provide to gem users in lib/my_gem/tasks
.
One way to do this is to use bundler to scaffold our gem:
bundler gem my_gem
I prefer to put tasks meant to manage the gem itself in lib/tasks
, and tasks the gem is meant to provide to gem users in lib/my_gem/tasks
.
/* | |
Copy this into the console of any web page that is interactive and doesn't | |
do hard reloads. You will hear your DOM changes as different pitches of | |
audio. | |
I have found this interesting for debugging, but also fun to hear web pages | |
render like UIs do in movies. | |
*/ | |
const audioCtx = new (window.AudioContext || window.webkitAudioContext)() |
<?php | |
function base64url_encode($binary_data) { return strtr(rtrim(base64_encode($binary_data), '='), '+/', '-_'); } | |
function apns_jwt_token($team_id, $key_id, $private_key_pem_str) | |
{ | |
if (! function_exists('openssl_get_md_methods') || ! in_array('sha256', openssl_get_md_methods())) throw new Exception('Requires openssl with sha256 support'); | |
$private_key = openssl_pkey_get_private($private_key_pem_str); | |
if (! $private_key) throw new Exception('Cannot decode private key'); |
#!/usr/bin/env ruby | |
=begin | |
A hook to make sure that all staged .rb files are syntatically correct. | |
The hook tries to run `ruby -c file_path` for all those files and | |
prints outs the errors if any and halts the commit. | |
If you want to use this pre-commit, simply copy the code and create a | |
file called 'pre-commit' inside your .git/hooks directory. |
// This code is to be used with https://turbo.hotwire.dev. By default Turbo keeps visited pages in its cache | |
// so that when you visit one of those pages again, Turbo will fetch the copy from cache first and present that to the user, then | |
// it will fetch the updated page from the server and replace the preview. This makes for a much more responsive navigation | |
// between pages. We can improve this further with the code in this file. It enables automatic prefetching of a page when you | |
// hover with the mouse on a link or touch it on a mobile device. There is a delay between the mouseover event and the click | |
// event, so with this trick the page is already being fetched before the click happens, speeding up also the first | |
// view of a page not yet in cache. When the page has been prefetched it is then added to Turbo's cache so it's available for | |
// the next visit during the same session. Turbo's default behavior plus this trick make for much more responsive UIs (non SPA). |
class Comment < ActiveRecord::Base | |
belongs_to :post, counter_cache: true | |
end |
def current_ability | |
@current_ability ||= begin | |
current_ability = Ability.new(current_user) | |
controller_names.to_a.each do |controller_name| | |
model_name = controller_name.classify | |
model_ability = "#{model_name}Ability".constantize rescue nil | |
if model_ability.present? && model_abilities[model_ability].nil? | |
model_abilities[model_ability] = model_ability.new(current_user) | |
current_ability.merge(model_abilities[model_ability]) | |
end |
# I have lots of projects. As I do the rails upgrades I collect the pin changes and other adjustments here | |
# towards the end of upgrading all the projects it gets easier and easier because of these commands. | |
❯ ./rails-upgrade | |
Commands: | |
rails-upgrade apple_touch # add blank apple-touch icons | |
rails-upgrade application_record # adds ApplicationRecord and replaces all references to ActiveRecord::Base with it | |
rails-upgrade asset_precompile_check # look for assets that need to be added to the assets initializer precompile list | |
rails-upgrade assigns_check # the assigns method has been extracted to a gem, check if it is used, and add the gem | |
rails-upgrade before_filter # change before_filter to before_action in controllers |
desc 'Find routes that will raise a routing error when requested' | |
task unroutable_routes: :environment do | |
# A lot of this code was taken from how `rake routes` works | |
# https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/commands/routes/routes_command.rb | |
require 'action_dispatch/routing/inspector' | |
unroutables = Rails.application.routes.routes. | |
map { |r| ActionDispatch::Routing::RouteWrapper.new(r) }. | |
reject { |r| r.internal? || r.engine? || r.path.starts_with?('/rails/') || !r.controller }. |