Skip to content

Instantly share code, notes, and snippets.

View bbonamin's full-sized avatar
🕶️

Bruno Bonamin bbonamin

🕶️
View GitHub Profile
@bbonamin
bbonamin / Brewfile
Last active March 19, 2024 14:54
Capybara Selenium Webdriver: Headless Chrome (with file downloads!) & Headless Firefox
tap "caskroom/cask"
cask "google-chrome"
cask "firefox"
brew "chromedriver"
brew "geckodriver"
@bbonamin
bbonamin / Gemfile
Created November 27, 2013 19:15
Bundler with multiple gemfiles. If your Gemfile becomes too big, you might want to split it.
source 'https://rubygems.org'
gemfiles = [ 'Gemfile1', 'Gemfile2' ]
gemfiles.each do |gemfile|
instance_eval File.read(gemfile)
end
@bbonamin
bbonamin / galleries.rb
Created April 3, 2012 00:33
ActiveAdmin relationships and related models
# encoding: utf-8
ActiveAdmin.register Gallery do
menu :label => 'Galerías'
# => Índice
index do
column :name
column :description
column :date
default_actions
@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 / 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 / gist:808a55efb746d8a10430
Created February 18, 2016 10:50
OS X Homebrew with multiple users
http://apple.stackexchange.com/a/45003
Is this considered bad? I thought one of the advantages of using /usr/local/ for your installs was that you don't need sudo. But clearly we do.
Homebrew, by default, sets itself up for single-user access to /usr/local. So you need to open up the permissions on the directory tree for it to be administered by more than one person.
People don't need to run sudo here to administer homebrew. You just need to change some permissions. Since you already have:
All users who would need to modify Homebrew are members of admin group.
You need to do two more things:
@bbonamin
bbonamin / Gemfile
Created October 3, 2011 01:52
rails3-jquery-autocomplete in ActiveAdmin?
source 'http://rubygems.org'
gem 'rails3-jquery-autocomplete'
@bbonamin
bbonamin / gist:96be60bad7fa5164a092
Created July 7, 2015 10:06
SSL in Development with Nginx + Rails
  1. Install nginx brew install nginx
  2. Cd into the nginx directory /usr/local/etc/nginx
  3. Create a ssl directory, change and generate a dummy ssl cert: mkdir ssl cd ssl penssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout server.key -out server.crt (just accept the default empty settings)
  4. Go back to the nginx directory cd ..
  5. Create or edit nginx.conf with the following settings:
events {