2.hours.ago # => Thu, 27 Aug 2015 14:39:36 AFT +04:30
1.day.from_now # => Fri, 28 Aug 2015 16:39:36 AFT +04:30
Time.zone.parse("2015-08-27T12:09:36Z") # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current.utc.iso8601 # When supliyng an API ("2015-08-27T12:09:36Z")
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z").in_time_zone # If you can’t use Time.zone.parse (Thu, 27 Aug 2015 16:39:36 AFT +04:30)
Date.current # If you really can’t have a Time or DateTime for some reason (Thu, 27 Aug 2015)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
namespace :migration do | |
task rename: :environment do | |
Dir['db/migrate/*'].sort.each do |filename| | |
sleep 1 | |
File.rename( | |
filename, | |
filename.sub(/[0-9]+/, Time.current.strftime('%Y%m%d%H%M%S')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "reset sequences for a specific table or all tables" | |
task reset_sequence: :environment do | |
sql = <<-SQL | |
SELECT 'SELECT SETVAL(' || | |
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) || | |
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' || | |
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';' as query | |
FROM pg_class AS S, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def offset_in_hours(time_zone) | |
TZInfo::Timezone.get(time_zone).current_period.offset.utc_total_offset.to_f / 3600.0 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const winston = require('winston'); | |
const Logger = (function() { | |
var instance; | |
function Logger() {} | |
Logger.prototype.logger = new winston.Logger({ | |
exitOnError: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq/api' | |
# 1. Clear retry set | |
Sidekiq::RetrySet.new.clear | |
# 2. Clear scheduled jobs | |
Sidekiq::ScheduledSet.new.clear |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo chown -R mysql:mysql /usr/local/mysql | |
sudo chmod -R 755 /usr/local/mysql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xcode-select --install | |
gem install nokogiri |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
around_action :user_time_zone, if: :current_user | |
def user_time_zone(&block) | |
Time.use_zone(current_user.time_zone, &block) | |
end |