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 / .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
Last active May 23, 2025 10:06
Rails solid_queue / solid queue alive server livenessProbe readinessProbe health check 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"
@amkisko
amkisko / database_token.rb
Last active January 14, 2025 19:10
Azure Container App Managed Identity token authentication for Rails PostgreSQL adapter
require "net/http"
require "json"
module AzureTokenAuthentication
module Config
# NOTE: https://learn.microsoft.com/en-us/azure/app-service/overview-managed-identity#rest-endpoint-reference
class << self
# endpoint example: "http://localhost:42356/msi/token"
def endpoint = ENV.fetch("IDENTITY_ENDPOINT")
#!/usr/bin/env bash
if [ $# -ne 1 ]; then
echo "Usage: $0 YYYY-MM-DD"
exit 1
fi
TARGET_DATE=$1
if ! [[ $TARGET_DATE =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
@amkisko
amkisko / deploy-heroku.sh
Created December 18, 2024 15:43
Heroku deploy script for multi-stage docker containers with Rails
#!/bin/bash
app_name="my-heroku-app"
environment="production"
db_migrate_container="migrate"
app_containers="web worker"
app_url="https://amkisko.github.io"
github_org="amkisko"
github_repo="my-app"
@amkisko
amkisko / diff_coverage_reporter.rb
Last active December 11, 2024 07:45
rspec helper for reporting missing test coverage for changed lines according to git diff with selected branch and simplecov json resultset
class DiffCoverageReporter
attr_reader :coverage_file, :default_branch
def initialize(file_path: "coverage/.resultset.json", default_branch: "master")
@coverage_file = Rails.root.join(file_path)
@default_branch = default_branch
end
def coverage_report
JSON.parse(coverage_file.read).dig("RSpec", "coverage")
end
@amkisko
amkisko / error_reporter.rb
Last active December 11, 2024 07:46
rspec errors collector and reporter to Slack
class SuiteErrorsReporter
def self.report_errors(link_url:, link_label:, slack_webhook_url:, errors: fetch_examples_with_errors)
return if errors.empty?
WebMock.allow_net_connect! if defined?(WebMock)
message = "Test suite failed in <#{link_url}|#{link_label}>"
locations = errors.map(&:location)
Net::HTTP.post(
URI(slack_webhook_url),
{
class SimpleCovMerger
def self.report_coverage(base_dir:, ci_project_path:, project_path:)
new(base_dir: base_dir, ci_project_path: ci_project_path, project_path: project_path).merge_results
end
attr_reader :base_dir, :ci_project_path, :project_path
def initialize(base_dir:, ci_project_path:, project_path:)
@base_dir = base_dir
@ci_project_path = ci_project_path
@amkisko
amkisko / create_missing_translations.rb
Last active August 20, 2024 11:36
Rails i18n create missing translations using page HTML span hints in pair with rspec to automate the process fully
findings = [["translation missing: en.admin_dashboard.sprint_widget.sprint", "Sprint"]]
create_translations(findings, locales = ["en", "fi"], dry_run: false)
# rspec usage: I18N_CREATE_MISSING=1 bundle exec rspec
@amkisko
amkisko / crowdin_translate.rb
Created August 20, 2024 09:46
ruby crowdin-api machine translation script
def crowdin_translate(sentence, from_locale, to_locale)
require "crowdin-api"
config = Data.define(:api_token, :organization_domain, :project_id, :mt_id).new(
api_token: ENV["CROWDIN_API_TOKEN"],
organization_domain: ENV["CROWDIN_ORGANIZATION_DOMAIN"],
project_id: ENV["CROWDIN_PROJECT_ID"],
mt_id: ENV["CROWDIN_MT_ID"]
)
client = Crowdin::Client.new do |crowdin|
crowdin.api_token = config.api_token