Skip to content

Instantly share code, notes, and snippets.

View chumakoff's full-sized avatar

Anton Chumakov chumakoff

View GitHub Profile
@chumakoff
chumakoff / postgres_update_json
Created July 12, 2018 12:25
postgres_update_json.sql
update table_name set data = (jsonb_set(to_jsonb(data), '{foo,bar,baz}', '1', false))::json where data->'foo'->'bar'->>'baz' = '0';
Sidekiq::RetrySet.new.clear
Sidekiq::ScheduledSet.new.clear
Sidekiq::Stats.new.reset
Sidekiq::DeadSet.new.clear
Sidekiq::Stats.new.queues.each do |queue_name, count|
next if count == 0
Sidekiq::Queue.new(queue_name).clear
end
@chumakoff
chumakoff / unmask_rails_csrf_token.rb
Last active January 29, 2018 09:44
Unmask Rails Form Authenticity Token (CSRF Token) to get the original token stored in session[:_csrf_token]
def unmask_authenticity_token(authenticity_token)
# this must be the same as ActionController::RequestForgeryProtection::AUTHENTICITY_TOKEN_LENGTH
token_length = 32
masked_token = Base64.strict_decode64(authenticity_token)
one_time_pad = masked_token[0...token_length]
encrypted_csrf_token = masked_token[token_length..-1]
bytes = encrypted_csrf_token.bytes