Skip to content

Instantly share code, notes, and snippets.

View AlexB52's full-sized avatar
👋
hello

Alexandre Barret AlexB52

👋
hello
View GitHub Profile
@AlexB52
AlexB52 / timezoned_records.rb
Last active April 29, 2024 22:24
Rails time zoned models
require "bundler/inline"
gemfile do
gem "rails"
gem "sqlite3"
gem "debug"
end
require "debug"
require "sqlite3"
@AlexB52
AlexB52 / uniquely_generated_code.rb
Last active March 8, 2024 05:32
How to secure a unique random code in Rails without hitting a race condition
# Made as an answer to the question is rails forums
# https://discuss.rubyonrails.org/t/how-would-you-handle-gracefully-validating-a-generated-unique-code-until-its-guaranteed-to-be-valid/84919/9
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails"
gem "sqlite3"
@AlexB52
AlexB52 / list_with_enumerable.rb
Created February 1, 2023 00:48
Difference between Enumerable and Grizzly::Enumerable
class List
include Enumerable
attr_reader :items
def initialize(items)
@items = items
end
def a_thing_to_do
@AlexB52
AlexB52 / README.md
Last active April 19, 2024 11:44
Testing ActiveRecord Concerns

Testing ActiveRecord Concerns

This gist illustrates the full spec suite of the example used in Testing ActiveRecord Concerns

Copy the testing-concerns.rb file and run rspec testing-concerns.rb

The output should look something like

... bundling ...
@AlexB52
AlexB52 / timezone-do.rb
Last active September 7, 2020 22:02 — forked from mphalliday/timezone-do.rb
Rails timezone cheat sheet do's and don'ts, from https://www.varvet.com/blog/working-with-time-zones-in-ruby-on-rails/
2.hours.ago # => Fri, 02 Mar 2012 20:04:47 JST +09:00
1.day.from_now # => Fri, 03 Mar 2012 22:04:47 JST +09:00
Date.today.to_time_in_current_zone # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Date.current # => Fri, 02 Mar
Time.zone.parse("2012-03-02 16:05:37") # => Fri, 02 Mar 2012 16:05:37 JST +09:00
Time.zone.now # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Time.current # Same thing but shorter. (Thank you Lukas Sarnacki pointing this out.)
Time.zone.today # If you really can't have a Time or DateTime for some reason
Time.zone.now.utc.iso8601 # When supliyng an API (you can actually skip .zone here, but I find it better to always use it, than miss it when it's needed)
Time.strptime(time_string, '%Y-%m-%dT%H:%M:%S%z').in_time_zone(Time.zone) # If you can't use Time#parse
@AlexB52
AlexB52 / fb_sdk_turbolinks.md
Last active March 21, 2017 00:13
Implementing Facebook SDK with Turbolinks

Heroku Command line

Commands Actions
Basics ---
heroku update Update comman-line tool
heroku help Help
Get started ---
heroku create --stack cedar [<appname>] Create app
git push heroku master Deploy app