Skip to content

Instantly share code, notes, and snippets.

View kigster's full-sized avatar
:octocat:
@repos.select { |r| r.is_a?(Gem) }.publish("https://rubygems.org")

Konstantin Gredeskoul kigster

:octocat:
@repos.select { |r| r.is_a?(Gem) }.publish("https://rubygems.org")
View GitHub Profile
@kigster
kigster / module_madness.rb
Created February 20, 2025 01:56
Ruby Modules and method precedence explained
module A
def foo
"A"
end
end
module Z
include A
def foo
"Z"
@kigster
kigster / concerning-modules.rb
Created January 25, 2025 11:01
Ruby Module/Class Interdependency playground
#!/usr/bin/env ruby
# © 2025 Konstantin Gredeskoul, All rights reserved.
#
# This script is a proof of concept to show how to use ActiveSupport::Concern
# to manage dependencies between modules and classes. The main idea is to use
# the included block to include the dependencies of a module, and the
# class_methods block to define class methods.
#
# Ultimately, the script prints all of the the methods of the Host, Bar, and
# Foo classes and modules to show the result of the concern implementation.
@kigster
kigster / cursor-extension-importer.sh
Created January 22, 2025 02:59
Import VSCode Extensions into Cursor via CLI
#!/usr/bin/env bash
# vim: ft=bash
#
# © 2025 Konstantin Gredeskoul
# http://github.com/kigster | https://kig.re
#
# This script allows you to export the list of your VSCode
# extensions and import them into, eg. Cursor IDE. Or the
# other way around. By the default the script continues on
# import errors because there are typically quite a few.
@kigster
kigster / ec2-bench.sh
Last active January 8, 2025 20:37
AWS Instance Benchmark using sysbench
#!/usr/bin/env bash
# vim: ft=bash
# Uses sysbench on Ubuntu to run CPU, RAM and File IO Tests
# Saves the output into "result-for-<instance-type>-<date>-<time>.txt
#
# You can run this as follows without downloading:
# curl -fsSL https://gist.githubusercontent.com/kigster/3869409f17739461f9d1fb7e0aa5022c/raw | bash
line() {
echo -e "\e[0;33m———————————————————————————————————————————————————————————————————————\e[0m"
@kigster
kigster / ruby-install
Last active February 18, 2025 20:20
Ruby Install Minimal script for MacOS and Linux. You can use it to install a recent Ruby using `rbenv` and `ruby-build`, with Jemalloc & YJIT enabled. Run it like so: `bash -c "$(curl -fsSL https://bit.ly/ruby-install-0-2-1)" -- 3.4.1`
#!/usr/bin/env bash
# vim: ft=bash
#
# © 2025 Konstantin Gredeskoul <kig AT kig.re>
# All rights reserved.
# MIT License.
#
# This script uses rbenv/ruby-build to install Ruby on OS-X or Linux. It configures
# Ruby build flags in such a way to ensure Ruby is linked with libjemalloc (which
# reduces the memory by half) and YJIT enabled. It has been tested on both Linux and
@kigster
kigster / check-my-rubies-for-jemalloc.sh
Last active October 29, 2024 19:00
This script will check all of your rbenv and system built-rubies for presence of Jemalloc library
#!/usr/bin/env bash
# vim: ft=bash
#
# © 2024 Konstantin Gredeskoul <kig AT kig.re>
#
# How to use this:
# curl -fsSL https://bit.ly/rb-jemalloc-check | bash
export rc=/tmp/ruby-check
curl -fsSL -o $rc "https://raw.githubusercontent.com/kigster/bashmatic/refs/heads/main/bin/ruby-check"
@kigster
kigster / ruby-install.sh
Last active October 29, 2024 19:36
Ruby Installer via RBENV on Linux & Mac OS-X (with jemalloc & yjit enabled)
#!/usr/bin/env bash
# vim: ft=bash
#
# This Gist is about installing any version of Ruby using rbenv on Linux or MacOS
# with Jemalloc and YJIT enabled.
#
# To install a ruby run the following command (this will install the ruby version
# defined in the .ruby-version file in the current directory)
#
# curl -fsSL https://bit.ly/rb-rbenv-install | bash
@kigster
kigster / logging_module.rb
Last active July 30, 2024 19:04
Ruby pattern for including a logging module everywhere you want. Just add “include Logging” at the top and you get both class and instance methods for logging such as #info, #debug, #error, #warn, #fatal. The threading at the bottom shows that the Logger is thread-safe and can be used without Mutexes.
# (c) 2024 Konstantin Gredeskoul
# Under the MIT License
#
# This gist documents a frequently thed pattern of decorating multiple classes with Logging methods
# by sharing just one Logger typically at the top of the module namespace (Application) in this case.
# If the concurrency issues come up, each class can be given its own logger, or perhaps the Logging moduloe
# might have decorators for each of the logging methods (eg #info, #debug) by using a Mutex.
#
# The output of this Ruby Code should be as follows:
@kigster
kigster / memcached-test.rb
Created November 8, 2023 20:01
Memcached Multi-Get vs Single Get
# Gemfile
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
gem 'rails', '>= 7.0.4.3'
gem "dalli"
gem "rspec"
gem "rspec-its"
gem "rspec-rails"
gem "awesome_print"
-- This file requires a local SQL file named "json_table_columns.csv" to have two columns:
-- [ "Table", "Column" ]
-- It then loops over records in this table computing the total size of the column in each table,
-- the average size of the column in that table, and finally the percentage that column occupies relative
-- to the entire table (including its indexes).
-- First we import the data
BEGIN;
drop table if exists JSON_TABLE_COLUMNS;