Skip to content

Instantly share code, notes, and snippets.

View hadrienblanc's full-sized avatar

Hadrien Blanc hadrienblanc

  • Paris, France
View GitHub Profile
# Returns nils and strings
Model.where(:url.ne => "").count
# Returns strings and ""
Model.where(:url.ne => nil).count
# Returns strings, nils and ""
Model.where(:url.ne => ["", nil]).count
Model.where(:url.nin => ["", nil]).count

Fizz Buzz ruby

Objective

Write a fonction or an object of your design called FizzBuz that takes input integer n and prints all the numbers from 1 up to n in a new line.

  • if the number is divisible by 3 then print "Fizz"
  • if the number is divisible by 5 then print "Buzz"
  • if the number is divisible by both 3 and 5, print "FizzBuzz". Otherwise just print the number.

Assuming that total_seconds = 3600

Option 1:

distance_of_time_in_words(total_seconds) #=> "about 1 hour"

Option 2:

Time.at(total_seconds).utc.strftime("%H:%M:%S") #=> "01:00:00"
x = [1, 1, 2, 4]
y = [1, 2, 2, 2]
# intersection
x & y # => [1, 2]
# union
x | y # => [1, 2, 4]
# difference
heroku config:get TZ -a heroku_app_name
heroku config:add TZ=Paris -a heroku_app_name
heroku builds:cancel BUILD_ID -a application
class Testo
def run
puts "hello world !"
puts my_var
puts my_var
puts my_var
end
class BundleDeleteService
def initialize(relative_path:)
@relative_path = relative_path
end
def delete
bucket_objects.each(&:delete)
end
def bucket_objects

TimeZone (and Rails)

UTC : What is that ?

https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 describes representation of dates and times as an international standard

Time zones in ISO 8601 are represented as local time (with the location unspecified), as UTC, or as an offset from UTC.

Z ?

Model.where('created_at >= ?', Time.zone.now.beginning_of_day)