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
| # it's possible to print pictures in terminal. iTerm2 works with the usualy image formats, but isn't as powerful as kitty's protocol. | |
| # here's iTerm2 docs: https://iterm2.com/documentation-escape-codes.html | |
| # | |
| # Kitty term documents the "Terminal graphics protocol", here: | |
| # https://sw.kovidgoyal.net/kitty/graphics-protocol/ | |
| # It supports only PNG files directly. For other formats, one has to produce the raw pixel byte data and print that (not in this gist). | |
| # But it is more powerful in the ways in can display and store the images (this gist just displays it using the most simple method). | |
| # | |
| require 'base64' |
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
| # 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 | |
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
| # 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) |
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
| # 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] } | |
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 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 |
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 '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 |
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
| --------------------------------------------- | |
| -- 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'); |
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
| class S3LineLogParser | |
| attr_reader :data, :cursor | |
| def initialize(data) | |
| @data = data | |
| @cursor = 0 | |
| end | |
| def read_all | |
| tokens = [] | |
| while @cursor < @data.length |
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
| 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 = [] |
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
| #!/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', |
NewerOlder