Skip to content

Instantly share code, notes, and snippets.

View netrusov's full-sized avatar
👽

Alexander netrusov

👽
View GitHub Profile
class FilterFilter
InvalidFilters = Class.new(StandardError)
OP_AND = :'$and'
OP_NOT = :'$not'
OP_OR = :'$or'
def self.available_filters
@available_filters ||= {}
end
@netrusov
netrusov / lru_cache.rb
Last active April 26, 2025 10:52
Threadsafe LRU cache implementation in Ruby
class LRUCache
def initialize(limit:)
@limit = limit
@store = {}
@mutex = Mutex.new
end
def size
@store.size
end
@netrusov
netrusov / 00-readme.md
Last active January 5, 2022 15:06
sidekiq independent fork workers

usage

configure server

# config/initializers/sidekiq.rb

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add(Sidekiq::Middleware::ForkWorker)
 end
@netrusov
netrusov / .gitlab-ci.yml
Created January 26, 2021 11:55
run RSpecQ in Gitlab CI pipeline with Docker executor
default:
image: ruby:2.7.2
tags:
- docker
services:
- postgres:12.4-alpine
- redis:6.0-alpine
variables:
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: "true"
POSTGRES_HOST_AUTH_METHOD: "trust"
@netrusov
netrusov / attachable.rb
Last active March 10, 2022 08:51
paperclip attachments with polymorphic associations
# frozen_string_literal: true
module Attachable
extend ActiveSupport::Concern
included do
class_attribute :attachment_class, instance_writer: false
end
class_methods do
@netrusov
netrusov / .pam_environment
Last active January 27, 2021 07:19
ssh-agent + systemd configuration
SSH_AUTH_SOCK DEFAULT="${XDG_RUNTIME_DIR}/ssh-agent.socket"
#!/usr/bin/env bash
# set -x
source ${HOME}/*_$(hostname -s).env > /dev/null
[[ $? != 0 ]] && { echo '!! Failed to source environment file. Must exist in the format "SID_HOSTNAME.env"'; exit 1; }
b_type=${1}
d_type=${2}
[[ -z ${b_type} ]] && { echo "Please specify backup type: { arch | full | lvl0 | lvl1 }"; exit 1; }
@netrusov
netrusov / hutch.service.erb
Last active April 22, 2019 08:27
capistrano tasks for systemd
[Unit]
PartOf=<%= fetch(:systemd_master_service) %>
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes
[Install]
WantedBy=<%= fetch(:systemd_master_service) %>
use IO::Socket::INET;
# auto-flush on socket
$| = 1;
my $PORT = shift @ARGV // '10051';
# creating a listening socket
my $socket = new IO::Socket::INET (
LocalHost => '0.0.0.0',
CREATE TABLE customers
(
id INT PRIMARY KEY
, first_name VARCHAR2(20)
, middle_name VARCHAR2(20)
, last_name VARCHAR2(20)
, ptr$names_domain VARCHAR2(1)
);
BEGIN