Skip to content

Instantly share code, notes, and snippets.

View amkisko's full-sized avatar
😺
Hymyillen suora selkä!

Andrei Makarov amkisko

😺
Hymyillen suora selkä!
View GitHub Profile
@amkisko
amkisko / calculatable_attributes.rb
Created April 24, 2025 16:14
Calculatable attributes concern for ActiveRecord models
module CalculatableAttributes
extend ActiveSupport::Concern
class_methods do
def calculate(attribute, &block)
attr_name = attribute.to_s.delete("?")
attr_block = block
@@calculate_methods ||= {}
@@calculate_methods[name] ||= {}
@amkisko
amkisko / active_admin.rake
Created April 19, 2025 09:41
ActiveAdmin v4 tailwind v4 compat
namespace :active_admin do
desc "Build Active Admin Tailwind stylesheets"
task build: :environment do
command = [
Rails.root.join("bin/tailwindcss").to_s,
"-i", Rails.root.join("app/assets/stylesheets/active_admin.tailwind.css").to_s,
"-o", Rails.root.join("app/assets/builds/active_admin.css").to_s,
"-m"
]
@amkisko
amkisko / bump-version.rb
Last active April 11, 2025 08:11
CHANGELOG.md application version bump script suitable for ruby, Rails, npm and Flutter projects
#!/usr/bin/env ruby
tag_prefix = "version/"
changelog_path = "CHANGELOG.md"
changelog = File.read(changelog_path)
if changelog.empty?
puts "No changelog found in #{changelog_path}"
exit
end
@amkisko
amkisko / README.md
Last active April 22, 2025 11:47
Capybara playwright rspec with nodejs 14 version for building assets, nodenv github ci multiple node versions

We are going to fix the situation by using nodenv capabilities with npx wrapper and use env variable to select desired nodejs version whenever we need it, default local version will stay 14, on demand we select 22.

@amkisko
amkisko / debug_helper.rb
Last active April 23, 2025 08:24
Amazing debugging for grape-ruby, rspec test examples, show SQL traces, show stack calls and all exceptions in stack, helper to find out which spec file stuck, store logs to files
require "amazing_print"
class Debug
def self.print_message(message, output_path: nil)
if output_path
File.open(output_path, "a") do |file|
file.puts(message)
end
else
ap(message)
end
@amkisko
amkisko / debug.rb
Created April 4, 2025 11:03
Amazing Rails debug with TracePoint and sql.active_record notifications
require "amazing_print"
class Debug
def self.trace(with_sql: false)
if with_sql
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |event|
payload = event.payload[:sql]
next if payload.match?(/^(SELECT|SET|SHOW|BEGIN|COMMIT|ROLLBACK|RELEASE|SAVEPOINT)/)
# next if payload.include?("audits")
event.payload[:type_casted_binds].each_with_index do |bind, index|
@amkisko
amkisko / example_spec.rb
Created March 28, 2025 13:08
ActiveRecord SQL logger helper, shows only INSERT/UPDATE/DELETE
it "does something" do
log_sql do
request
expect(create_call).to_not raise_exception
end
end
@amkisko
amkisko / api_logging_spec.rb
Last active March 12, 2025 10:37
Customizable logger for grape ruby
require "rails_helper"
require "stringio"
require "json"
RSpec.describe API do
include Rack::Test::Methods
def app
API
end
@amkisko
amkisko / .pryrc
Created March 3, 2025 10:30
Remote Rails console user tracking & history management, console prompt to show commits-diff and environment
require "amazing_print"
AmazingPrint.pry!
app_id =
ENV["APP_ID"].presence ||
Rails.application.class.name.deconstantize.parameterize
app_env = ENV["ENVIRONMENT"].presence || Rails.env
commit_sha = ENV["GIT_COMMIT_SHA"]&.slice(0, 7)
commit_sha = `git rev-parse --short HEAD`.strip unless Rails.env.production?
@amkisko
amkisko / solid_queue_alive.rb
Created January 25, 2025 05:56
Rails solid_queue alive server livenessProbe readinessProbe kubernetes helper
class SolidQueueAliveServer
def initialize(host: nil, port: nil, engine: nil, logger: nil)
@host = host || "0.0.0.0"
@port = port || 7433
@engine = engine || "puma"
@logger = logger || Rails.logger
end
def run!
require "rackup"