Skip to content

Instantly share code, notes, and snippets.

View cveneziani's full-sized avatar

Cecile Veneziani cveneziani

View GitHub Profile
@swanson
swanson / .irbrc
Last active March 3, 2024 17:14
.irbrc color coding Rails console by environment
# Add color coding based on Rails environment for safety
if defined? Rails
banner = if Rails.env.production?
"\e[41;97;1m #{Rails.env} \e[0m "
else
"\e[42;97;1m #{Rails.env} \e[0m "
end
# Build a custom prompt
@pcreux
pcreux / README.md
Last active October 10, 2020 18:44
Failsafe: degrade user experience and notify when something goes wrong.

Failsafe

When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure

Usage

Wrap non mission critical code:

@juliends
juliends / turbolinks.md
Created February 19, 2020 13:16
Turbolinks notes
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active April 19, 2024 04:06
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@kule
kule / mini_rspec.rb
Created September 11, 2018 09:37
Simplified example of how rspec works
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'colorize'
end
class MatcherInterface
def initialize(some_object)
@some_object = some_object

Fixing Webpacker 3.3.0 + Rails 5.1.5

Heroku hosting trouble

Heroku may not detect a correct buildpack for your JS dependencies, then you have to set it manually:

heroku buildpacks:add heroku/nodejs -i 1
heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-ruby
@ssaunier
ssaunier / README.md
Last active December 17, 2019 12:45
Use ES6 in your Rails Asset Pipeline

Rails 5.1 introduces a new way of coding JavaScript. You would use yarn, webpack and a new folder, app/javascript.

Setup

If you want to stick with the "old" way (before 5.1) and use the asset pipeline, you need to do this:

# Gemfile

gem 'sprockets', '>= 3.0.0'
@printercu
printercu / rails-5.0-integration-tests-speedup.md
Last active March 7, 2022 01:20
Speed up Rails 5 integration tests

Speed up integration tests in Rails 5 app

Rails 5 recompiles templates on every request in test env. Fix will be released only in 5.0.2.

Add this lines to test helper to get the performance now (I've got x2 improvement):

class << ActionView::LookupContext::DetailsKey
 def clear
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@mehowte
mehowte / gist:08f7e842b393efd583a1
Created March 4, 2015 13:16
Why I'm speaking at Wroc_love.rb despite their lack of Code of Conduct
I'm a speaker at [Wroc_love.rb](http://www.wrocloverb.com/).
 
Personally I would prefer the place to be more inclusive But I won't
support bullying the organizers into making decisions against their will.
 
Making the conference (especially virtually non-profit one like
wroc_love.rb) is a huge amount of work And I know that because I've been
selecting diverse set of speakers for two Railsberry conferences before it
was even cool.