Skip to content

Instantly share code, notes, and snippets.

View jaydorsey's full-sized avatar
💊
Ruby on Rails

Jay Dorsey jaydorsey

💊
Ruby on Rails
View GitHub Profile
@jaydorsey
jaydorsey / ublock
Last active April 17, 2024 15:12
uBlock for LinkedIn
# Block things on LinkedIn with uBlock Origin that LinkedIn won't let you block
# Choose "Options" in uBlock Origin with a right-click, and add these to
# "My filters"
# ADDING YOUR OWN FILTERS
#
# Using Linkedin.com as an example
#
# 1. Open up the webpage
# 2. Find some text you want to block
@jaydorsey
jaydorsey / app_models_user.rb
Created March 25, 2024 12:44
Add a Trait to skip callbacks in a FactoryBot factory
# app/models/user.rb
#
class User
after_create :foo
private
def foo
# ..something we don't do very often
end
@jaydorsey
jaydorsey / gist:b56529c2403bf4162cd9e51a025be045
Created February 26, 2024 20:34
Remove annotate gem annotations
For some reason, I couldn't get the annotate gem to remove the file annotations
I used SublimeText w/ the following regex:
Find: `(?s)# == Schema Information\n(.*?)\n((# :nodoc:\n)?class)`
Replace: `class` (just adds back what I grabbed above)
@jaydorsey
jaydorsey / nokogiri.md
Last active February 26, 2024 14:37
WARNING: Nokogiri was built against libxml version

My setup

For reference only:

  1. rtx-cli
  2. Ruby 3.2.0
  3. Most dependencies installed via Homebrew
  4. macOS 14.2.1
  5. M3 Max chip
@jaydorsey
jaydorsey / private_bundle_install_gist.md
Created May 25, 2022 01:22
Setting up a github/bundle token for privately hosted repos

If your Gemfile has a privately hosted package referenced similar to this:

gem 'sekret', git: 'https://github.com/my-private-group/sekret.git', branch: 'main'

You may see a prompt when running bundle install, or other bundler commands, to enter your github username & password.

To resolve this, you need to generate a token and add it to your system.

Generating a token

@jaydorsey
jaydorsey / example.rb
Created February 16, 2024 14:39
Storing images as base64 representations
require 'base64'
file = File.open('path/to/file.ext', 'rb') # Read the image as binary
base64 = Base64.strict_encode64(file.read) # This gives you a string you can assign to a constant/variable
tmpfile = Tempfile.new(Base64.strict_decode64(base64)) # Decode and create a temporary file
Digest::MD5.file(tmpfile).base64digest # This is one way to create a checksum on the file
File.size(tmpfile) # You can also get a file size
@jaydorsey
jaydorsey / my_stuff.rb
Created January 26, 2024 14:06
RSpec Rails.logger block test
# frozen_string_literal: true
class MyStuff
OOPS = 'Oops'
def self.call
Rails.logger.warn { OOPS }
end
end
@jaydorsey
jaydorsey / example_spec.rb
Created November 15, 2022 13:47
Using stub_const to hijack a constant
# Lines marked with pry are just for testing in a rails console
require 'rspec/mocks' # pry
include RSpec::Mocks::ExampleMethods # pry
# This bypasses the warning that the method isn't called inside of a test
RSpec::Mocks.with_temporary_scope do # pry
stub_const(
'MyClass',
instance_double(
@jaydorsey
jaydorsey / Aptfile
Last active October 25, 2022 21:10
Notes on Poppler/ActiveStorage on Heroku
libgirepository-1.0-1
libgirepository1.0-dev
libpoppler-glib-dev
@jaydorsey
jaydorsey / bar.rb
Last active August 19, 2022 14:41
Ruby modules, classes, and instance methods
# An example of class/instance methods w/ modules
module Foo
def self.included(base)
base.extend(ClassMethods)
end
def foo
puts 'Bar.new.foo prints this'
end