Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

Rob Bazinet rbazinet

View GitHub Profile
@coolprobn
coolprobn / date_in_preferred_time_zone.rb
Created June 19, 2024 15:18
Convert any DateTime to the timezone you prefer while still keeping the same date and time - Ruby on Rails
def date_in_danish_time(date_time)
date_array =
date_time.strftime("%Y %m %d").split.map { |string| Integer(string, 0) }
danish_date = Date.new(*date_array).in_time_zone("Copenhagen")
# extracting offset from the date will help us in also taking care of Daylight Saving
danish_date_offset = danish_date.formatted_offset
date_time_array =
date_time
.strftime("%Y %m %d %H %M %S")
@dhh
dhh / linux-setup.sh
Last active November 15, 2024 19:55
linux-setup.sh
# THIS LINUX SETUP SCRIPT HAS MORPHED INTO A WHOLE PROJECT: HTTPS://OMAKUB.ORG
# PLEASE CHECKOUT THAT PROJECT INSTEAD OF THIS OUTDATED SETUP SCRIPT.
#
#
# Libraries and infrastructure
sudo apt update -y
sudo apt install -y \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
@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