Skip to content

Instantly share code, notes, and snippets.

View wbotelhos's full-sized avatar
💭
I'm not my code.

Washington Botelho wbotelhos

💭
I'm not my code.
View GitHub Profile
# 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'))
@wbotelhos
wbotelhos / pg_reset_sequence.rake
Created May 25, 2017 23:40
Postgres Reset Sequence
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,
@wbotelhos
wbotelhos / timezone_offset_in_hours.rb
Created May 18, 2017 04:56
Timezone Offset in hours
def offset_in_hours(time_zone)
TZInfo::Timezone.get(time_zone).current_period.offset.utc_total_offset.to_f / 3600.0
end
@wbotelhos
wbotelhos / winston-singleton-prototype.js
Created April 27, 2017 18:12
Winston Singleton (Prototype)
const winston = require('winston');
const Logger = (function() {
var instance;
function Logger() {}
Logger.prototype.logger = new winston.Logger({
exitOnError: false,
@wbotelhos
wbotelhos / clear-sidekiq-jobs.sh
Last active April 2, 2024 10:04
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@wbotelhos
wbotelhos / libreadline_6_not_found.sh
Created November 29, 2016 20:42
Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
@wbotelhos
wbotelhos / fix_error_1018_hy000.sh
Created November 4, 2016 20:48
ERROR 1018 (HY000): Can't read dir of './schema_env/' (errno: 13 - Permission denied)
sudo chown -R mysql:mysql /usr/local/mysql
sudo chmod -R 755 /usr/local/mysql
@wbotelhos
wbotelhos / nokogiri.sh
Last active February 6, 2020 14:09
ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
xcode-select --install
gem install nokogiri
@wbotelhos
wbotelhos / time_zone.md
Created September 22, 2016 20:45
How to use Time Zone

Do

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)
@wbotelhos
wbotelhos / user_time_zone.rb
Created September 21, 2016 19:38
Setting TimeZone per current_user
around_action :user_time_zone, if: :current_user
def user_time_zone(&block)
Time.use_zone(current_user.time_zone, &block)
end