Skip to content

Instantly share code, notes, and snippets.

View skatkov's full-sized avatar
🏠
Working from home

Stanislav (Stas) Katkov skatkov

🏠
Working from home
View GitHub Profile
@skatkov
skatkov / forever.sh
Created November 28, 2023 10:48
run tests forever (until they fail)
while bundle exec rake test; do :; done
@skatkov
skatkov / spellcheck.yml
Created May 25, 2023 21:36
Spell Checking with codespell and misspell
name: Spell Checking
on: [pull_request]
jobs:
codespell:
name: Check spelling with codespell
runs-on: ubuntu-latest
strategy:
matrix:
@skatkov
skatkov / application_job.rb
Created May 11, 2023 13:54
Store sample of sql when ActiveRecord::QueryCanceled occured
class ApplicationJob < ActiveJob::Base
include ActiveSupport::Rescuable
# PG::QueryCanceled will be wrapped with ActiveRecord::QueryCanceled errors and it's a direct
# descendant of ActiveRecord::StatementInvalid error.
rescue_from ActiveRecord::StatementInvalid do |exception|
# It's hard to know, on which queries we're seeing statement timeouts -- so we are making this explicit in AppSignal error.
Appsignal::Transaction.current.set_sample_data("custom_data", sql_statement: exception.sql)
raise exception
end
@skatkov
skatkov / test.rb
Last active January 3, 2024 18:20
speed up testsuit by using unlogged tables in PG
# config/environments/test.rb
ActiveSupport.on_load(:active_record_postgresqladapter) do
# For this optimization to work, you need to recreate your test database
self.create_unlogged_tables = true
end
@skatkov
skatkov / schema.sql
Created September 2, 2022 18:21
contact book
CREATE TABLE people ( id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT NOT NULL, last_name TEXT, dob TEXT, name TEXT, photo TEXT, notes TEXT);
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE IF NOT EXISTS "contacts" (
"id" integer NOT NULL,
"type" text NOT NULL CHECK(type in ('work', 'mobile', 'home', 'email')),
"value" text NOT NULL,
"people_id" integer NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("people_id") REFERENCES "people"("id"),
UNIQUE("type","value")
@skatkov
skatkov / .ruby-version
Last active July 11, 2022 12:43
Benchmarking content-type and http_headers/content_type gems
2.7.6
FROM ghcr.io/renderinc/heroku-app-builder:heroku-20 AS builder
# The FROM statement above triggers the following steps
# 1. Copy the contents of the directory containing this Dockerfile to a Docker image
# 2. Detect the language
# 3. Build the app using the appropriate Heroku buildpack. All Heroku's official buildpacks are supported.
# For running the app, we use a clean base image and also one without Ubuntu development packages
# https://devcenter.heroku.com/articles/heroku-20-stack#heroku-20-docker-image
FROM ghcr.io/renderinc/heroku-app-runner:heroku-20 AS runner
@skatkov
skatkov / dep-extract.rb
Created October 12, 2020 12:10
extract Ruby dependencies
#!/usr/bin/env ruby
require 'bundler'
require 'csv'
lock_file = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))
def url_for(spec)
case spec.source
when Bundler::Source::Rubygems
@skatkov
skatkov / ruby_data_object_comparison.rb
Last active September 17, 2020 12:24 — forked from palexander/ruby_data_object_comparison.rb
Benchmark to compare hash, OpenStruct, struct, and classes in Ruby
require 'ostruct'
require 'benchmark'
COUNT = 10_000_000
NAME = "Test Name"
EMAIL = "test@example.org"
class Person
def initialize(name:, email:)
@name = name
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
ruby '2.6.6'
gem 'pronto'