Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

Rob Bazinet rbazinet

View GitHub Profile
@hopsoft
hopsoft / Dockerfile
Last active May 17, 2023 19:58
Dockerize your Rails app
FROM ruby:3.0-alpine
RUN apk add --no-cache --update \
ack \
bash \
build-base \
curl \
git \
htop \
less \
@soffes
soffes / test_case.rb
Created March 11, 2021 15:01
Simple ActiveRecord query counter
class TestCase < ActiveSupport::TestCase
def setup
super
DatabaseCleaner.start
@queries = []
ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload|
@queries << payload[:sql] unless payload[:name].in? %w[CACHE SCHEMA]
end
end
@obie
obie / application_controller.rb
Created October 5, 2020 05:15
Workaround solution for having to restart Rails server to pickup changes to ViewComponent templates (Rails 6.1)
class ApplicationController < ActionController::Base
after_action :clear_view_component_cache, if: -> { Rails.env.development? }
def clear_view_component_cache
ViewComponent::CompileCache.cache = Set.new
end
end
@stympy
stympy / app-models-application_record.rb
Created July 16, 2020 20:39
Simple change tracking for Rails models. It also works for non-database-backed models with optional change tracking.
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
include ActivityLogger
end
@andrewmcodes
andrewmcodes / Gemfile
Created July 11, 2020 21:25
HEY's Gemfile annotated with annotate_gem
# Generated with https://github.com/ivantsepp/annotate_gem/
ruby '2.7.1'
# Full-stack web application framework. (https://rubyonrails.org)
gem 'rails', github: 'rails/rails'
# Timezone Data for TZInfo (https://tzinfo.github.io)
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# ==== Action Text ====
@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
@peterc
peterc / rss-to-s3.rb
Created May 23, 2020 15:56
RSS to S3 Ruby Lambda Function
require 'json'
require 'aws-sdk-s3'
require 'open-uri'
# Ideally put these in environment variables
# but since this is just for us, who cares.
BUCKET = "RETRACTED"
REGION = "RETRACTED"
def do_newsletters
@joshuap
joshuap / rails_lamby_notes.md
Last active February 21, 2022 09:00
Deploy a new Rails app to AWS Lambda using Lamby
@sivers
sivers / podcast.rb
Created October 29, 2019 21:30
Podcast RSS generator in Ruby
#!/usr/bin/env ruby
require 'date'
require 'xml'
def htmlit(infile)
lines = File.readlines(infile)
/<!--\s+(.+)\s+-->/.match lines.shift
lines.unshift('<h2>%s</h2>' % $1)
html = ''
lines.each do |line|
@michaelminter
michaelminter / csv_to_s3.rb
Created April 29, 2019 17:40
Upload CSV stream from Rails to S3
def query_results
ActiveRecord::Base.connection.execute('SELECT name FROM accounts;').to_a
end
# @params [Array<Hash>] records
def generate_csv(records)
attributes = records.first.keys
CSV.generate(headers: true) do |csv|
csv << attributes