Skip to content

Instantly share code, notes, and snippets.

View bbonamin's full-sized avatar
🕶️

Bruno Bonamin bbonamin

🕶️
View GitHub Profile
@bbonamin
bbonamin / fizz_buzz.rb
Created May 13, 2022 19:43
Ruby Pattern Matching FizzBuzz
def fizz_buzz(number)
r = case {r3: number % 3, r5: number % 5, number:}
in { r3: 0, r5: 0} then "FizzBuzz"
in { r3: 0} then "Fizz"
in { r5: 0} then "Buzz"
else number
end
puts r
end
@bbonamin
bbonamin / Gemfile
Created April 20, 2022 19:08
Rails 7 + esbuild + minitest + system tests with Bitbucket Pipelines
# ...
group :test do
gem "capybara"
gem "selenium-webdriver"
gem "vcr"
# Easy installation and use of web drivers to run system tests with browsers
gem "webdrivers", require: !ENV["CI"]
end
# ...
@bbonamin
bbonamin / app.rb
Created April 4, 2022 18:34
Rails CSV report streaming
# From https://shift.infinite.red/fast-csv-report-generation-with-postgres-in-rails-d444d9b915ab
# Storing here in case the original post ever goes down.
# concern
module DatabaseQueryStreaming
def stream_query_rows(sql_query, options="WITH CSV HEADER")
conn = ActiveRecord::Base.connection.raw_connection
conn.copy_data "COPY (#{sql_query}) TO STDOUT #{options};" do
while row = conn.get_copy_data
@bbonamin
bbonamin / rails_inline.rb
Created July 20, 2020 20:43
Rails Parent -> Child creation
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '6.0.3'
gem 'pg'
gem 'pry'
end
@bbonamin
bbonamin / application.js
Created March 26, 2020 22:43 — forked from thedanbob/application.js
Load cocoon JS with webpacker
// app/javascripts/packs/application.js
import 'cocoon'
@bbonamin
bbonamin / test_rails_exists.rb
Created March 18, 2020 22:51
Rails EXISTS() subquery
# https://github.com/rails/rails/pull/29619#issuecomment-392583498
# Better approach than http://codesnik.github.io/rails/2015/09/03/activerecord-and-exists-subqueries.html
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.2'
gem 'pg'
gem 'pry'
@bbonamin
bbonamin / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Created February 3, 2020 16:00 — forked from stevenharman/00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

@bbonamin
bbonamin / jquery_event_delegator.coffee
Created December 30, 2019 13:07 — forked from kaspermeyer/jquery_event_delegator.coffee
Dispatch jQuery events as regular DOM events
# ~ Dispatch jQuery events as regular DOM events ~
#
# Delegated events are given a new name in the format `jquery:<original event name>`.
# If you delegate `ajax:send` you will be able to listen for `jquery:ajax:send`
# on native event listeners such as Stimulus actions and `EventTarget.addEventListener`.
#
# Notes:
# * The first parameter must be called "event".
# * The parameters can be accessed as members on the `event.detail` object.
#
@bbonamin
bbonamin / sublime-prefs.json
Created July 20, 2018 16:37
Sublime Text 3 Config - July 2018
{
"color_scheme": "Packages/ayu/ayu-dark.tmTheme",
"detect_indentation": false,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.log",
".git/*"
],
"folder_exclude_patterns":
@bbonamin
bbonamin / Brewfile
Last active November 25, 2024 15:47
Capybara Selenium Webdriver: Headless Chrome (with file downloads!) & Headless Firefox
tap "caskroom/cask"
cask "google-chrome"
cask "firefox"
brew "chromedriver"
brew "geckodriver"