Skip to content

Instantly share code, notes, and snippets.

@andrepiske
andrepiske / cert.sh
Last active October 22, 2025 12:36
SSL and certificates
# View PEM / .crt info
pbpaste | base64 -d | openssl x509 -inform PEM -text -noout
openssl x509 -in certificate.crt -text -noout
echo | openssl s_client -connect x.com:443 -servername x.com 2>/dev/null | openssl crl2pkcs7 -nocrl -certfile /dev/stdin | openssl pkcs7 -print_certs -text -noout
@andrepiske
andrepiske / permanent_delete_s3_versioned.rb
Created August 13, 2025 12:56
permanent_delete_s3_versioned.rb
# params:
# - bucket: String, the name of the bucket
# - key: String, the file name in S3 ("key" in S3 naming scheme)
def permanently_delete_key(s3_client, bucket, key)
# One can get the s3 client from the ActiveStorage instance,
# or if not using ActiveStorage, just instantiate one with:
# s3_client = Aws::S3::Client.new
obj_versions_resp = s3_client.list_object_versions(bucket:, prefix: key)
@andrepiske
andrepiske / sidekiq_workers_meta.rb
Last active March 3, 2025 12:29
sidekiq_workers_meta.rb
# IMPORTANT: when running this in dev mode, you'll have to set eager_load=true in config/application.rb
# Returns all classes that include the Sidekiq::Job module.
worker_classes = []; ink=Module.instance_method(:include?); isa=Object.instance_method(:is_a?); ObjectSpace.each_object { |o| if isa.bind_call(o, Class) && ink.bind_call(o, Sidekiq::Job); worker_classes << o; end }; worker_classes.length
workers_by_queue = worker_classes.group_by{ |x| x.sidekiq_options.with_indifferent_access[:queue] }
@andrepiske
andrepiske / terminal_iterm.rb
Created August 14, 2024 17:34
terminal_iterm.rb
def iterm2_downloadfile(name, content)
size = content.b.length
print("\x1B]1337;File=size=#{size};name=#{Base64.strict_encode64(name)}:#{Base64.strict_encode64(content.b)}\x07")
end
@andrepiske
andrepiske / logical_replication_dumpr.rb
Created December 4, 2023 16:35
logical_replication_dumpr.rb
require 'pg'
require 'timeout'
require 'time'
require 'json'
THE_QUERY = <<SQL
SELECT
sum(table_size) AS table_size,
sum(indexes_size) AS indexes_size,
sum(total_size) AS total_size
@andrepiske
andrepiske / pg logical replication.sql
Last active October 17, 2025 19:59
pg logical replication
---------------------------------------------
-- Create logical replication:
--
-- on source:
CREATE PUBLICATION db_copy FOR ALL TABLES;
-- optional:
SELECT pg_create_logical_replication_slot('db_copier', 'pgoutput');
-- then use it in subscription with:
-- WITH (create_slot=false, slot_name='db_copier');
@andrepiske
andrepiske / S3LineLogParser.rb
Created September 5, 2023 19:36
S3LineLogParser
class S3LineLogParser
attr_reader :data, :cursor
def initialize(data)
@data = data
@cursor = 0
end
def read_all
tokens = []
while @cursor < @data.length
@andrepiske
andrepiske / my_memory_tracker.rb
Last active July 4, 2023 14:01
my_memory_tracker.rb
class MyMemoryTracker
attr_reader :klasses, :memories, :obj_ids
def initialize(perform_gc=false, save_object_ids: false)
@save_object_ids = save_object_ids
@default_perform_gc = perform_gc
@my_obj_ids = {}
@iterations = 0
@klasses = []
@andrepiske
andrepiske / co
Last active January 26, 2023 19:56
Set iTerm2 tab color
#!/usr/bin/env ruby
# Codes at https://iterm2.com/documentation-escape-codes.html
# License: MIT License, text at https://mit-license.org/
color_table = {
'blue' => '#2d74ef',
'blue-2' => '#5bb0d8',
'red' => '#f22e2e',
'red-2' => '#d17777',
'yellow' => '#f2e235',
@andrepiske
andrepiske / GetPercentageRounds.rb
Created January 25, 2023 18:40
GetPercentageRounds
# That damn GetPercentageRounds function I keep seeingin LinkedIn and Twitter
# but in ruby, refactored, without telling why or whether is morally good or bad.
# Just a function.
def GetPercentageRounds(v)
x = [10, [0, (10 * v).to_i].max].min
'🔵' * x +('⚪️' * (10 - x))
end
# irb(main):053:0> bar(0.1)
# => "🔵⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️"