Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Nikitochkin miry

View GitHub Profile
@miry
miry / Rakefile
Last active May 26, 2022
Rake task to run minitests in batches
View Rakefile
namespace :test do
desc "Parallel tests. Use TEST_WORKERS and TEST_WORKER_NUM." \
"TEST_WORKER_NUM in range from 1..TEST_WORKERS"
task :parallel do
workers = ENV.fetch("TEST_WORKERS", 1).to_i
worker = ENV.fetch("TEST_WORKER_NUM", 1).to_i
buckets = Array.new(workers) { [] }
# Fill the buckets
i = 0
@miry
miry / README.md
Last active May 24, 2022
Run minitest tests in batches
View README.md

Usage

It requires two environment variables:

  • TEST_WORKERS - Total number of workers or batches. It uses to identify a total number of batches, that would be run in parallel. Default: 1
  • TEST_WORKER_NUM - Current worker id. The value is between 1 and TEST_WORKERS
$ bundle exec rake test:parallel TEST_WORKERS=5 TEST_WORKER_NUM=1
@miry
miry / logger.cr
Last active Apr 19, 2022
Crystal logger
View logger.cr
# The `Logger` class provides a simple but sophisticated logging utility
# that you can use to output messages.
# Level verbosity from 0 - nothing and high with more traces.
# NOTE: Modified version of https://github.com/crystal-lang/logger.cr/blob/10dc2ef847e2f662abafb75f9e7dff21509adb85/src/logger.cr
#
# log = Logger.new(STDOUT, level: 0)
class Logger
property level : Int8
@miry
miry / client.rb
Created Mar 14, 2022
Testing toxiproxy
View client.rb
require 'socket'
require 'timeout'
require "toxiproxy"
hostname = 'toxiproxy'
port = 16379
# Setup
Toxiproxy.host = "http://#{hostname}:8474"
@miry
miry / import_photos.sh
Last active Jan 9, 2022
Organize photos in Synology
View import_photos.sh
#!/bin/bash
set -e
echo "Started: $(date)"
export MAGICK_TMPDIR=~/tmp
mkdir -p $MAGICK_TMPDIR
orgdir="/var/services/homes/miry/work/cloned_photos"
@miry
miry / Gemfile
Last active May 22, 2021
Sidekiq gracefull startup and shutdown in Kubernetes
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gem "sidekiq"
@miry
miry / .overcommit.yml
Last active May 8, 2021
Overcommit configuration for Crystal projects
View .overcommit.yml
# Sample configuration for https://github.com/sds/overcommit to support Crystal projects
---
verify_signatures: false
PreCommit:
# NOTE: LineEndings does not work with git versions < 2.x
# LineEndings:
# enabled: true
YamlLint:
enabled: true
@miry
miry / materilize_view_migration.rb
Last active Mar 19, 2021
Example of Migration to create a table with cached results: Materialised view table
View materilize_view_migration.rb
class MaterialisedView < ActiveRecord::Migration[5.2]
def change
execute <<-SQL
CREATE TABLE mv_complex_query
COMMENT 'Updated every 5m by the mv_complex_query event'
SELECT * FROM big_table
SQL
execute <<-SQL
CREATE EVENT dump_mv_complex_query
@miry
miry / kube_clean_staging_deployment.yml
Created Feb 19, 2021
A Kube resources to automaticaly to remove old kube resources that were deployed to staging
View kube_clean_staging_deployment.yml
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: deployments-gc
name: deployments-gc
namespace: pnd-staging
@miry
miry / sidekiq_mem_killer.rb
Last active Feb 17, 2021
Gracefull sidekiq worker killer for kubenernetes clusters
View sidekiq_mem_killer.rb
require 'fileutils'
require 'open3'
# Usage:
#
# Sidekiq.configure_server do |config|
# config.server_middleware do |chain|
# chain.add MemoryKillerMiddleware if ENV['SIDEKIQ_MEMORY_KILLER_MAX_RSS']
# end