Skip to content

Instantly share code, notes, and snippets.

View landovsky's full-sized avatar

landovsky

  • Applifting
  • Prague
View GitHub Profile
@landovsky
landovsky / upgrade.md
Last active March 21, 2023 11:08
Upgrade postgresql 14 to 15 on Macos using brew and pg_upgrade

Stop old postgres

brew services stop postgresql@14

Install new postgres and make sure it is stopped

brew install postgresql@15

brew services stop postgresql@15

Perform upgrade

  • optionally add --check argument to test upgradability between versions
@landovsky
landovsky / gem_maintanability_check.rb
Created September 8, 2020 09:48
Check last built date of gems in your Gemfile to find out how old is the most recent gem version.
def check_for_old_dependencies
outdated_gems = list_gems
parsed_gems = parse_outdated_gems outdated_gems
results = check_age parsed_gems
ordered = results.sort_by { |gem| gem[1] }
File.open('results.json', 'w') { |f| f.write JSON.dump(ordered) }
print_results ordered
end
def list_gems
@landovsky
landovsky / custom_ransacker.rb
Last active March 18, 2020 04:37
Custom ransacker for Active Admin
# Custom search ransacker
# models/concerns/ransackers
module Ransackers
module Candidate
extend ActiveSupport::Concern
included do
ransacker :candidate_approved_at,
formatter: proc { |date|
@landovsky
landovsky / gist:6a1b29cbf13d0cf81bad12b6ba472416
Last active September 16, 2018 11:30
Iterate v. reduce over array of hashes
module Test
def self.iterate(array)
Hash.new(0).tap do |result|
array.each do |hash|
hash.each do |key, val|
result[key] = result[key] + val
end
end
end
end
@landovsky
landovsky / frozen.rb
Last active March 19, 2018 14:07
Why does Ruby modify frozen array?
a = [
{ entity: [1, 2], other: 1 },
{ entity: [2, 3], other: 3 }
]
def copy_examples_to_entities(array_of_examples)
array_of_examples.map do |example|
entities = example[:entity]
if entities.count > 1
@landovsky
landovsky / random_account_generator.rb
Last active March 20, 2018 15:33
Generator of random bank account numbers (Czech, CZ) / Generátor čísla bankovního účtu
# based on https://k3a.me/mod11.php
# limited to 10 digit account numbers
module RandomAccountGenerator
WEIGHT = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6].reverse.freeze
class << self
def call
loop do
account_number = guess_number
@landovsky
landovsky / add_signature_fields_to_delayed_jobs.rb
Last active November 21, 2023 08:47 — forked from synth/add_signature_fields_to_delayed_jobs.rb
Prevent Duplicates with Delayed Jobs
class AddFieldsToDelayedJobs < ActiveRecord::Migration
def change
add_column :delayed_jobs, :signature, :string, index: true
add_column :delayed_jobs, :args, :text
end
end