Skip to content

Instantly share code, notes, and snippets.

View kigster's full-sized avatar
:octocat:
Pushing AI automation into production.

Konstantin Gredeskoul kigster

:octocat:
Pushing AI automation into production.
View GitHub Profile
@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;
@kigster
kigster / ruby-memory-env.sh
Created April 23, 2022 01:34
Ruby 2+ environment variables to tune GC and memory bloat to a minimum on large apps
# Discourse Settings
export RUBY_GC_HEAP_INIT_SLOTS=997339
export RUBY_GC_HEAP_FREE_SLOTS=626600
export RUBY_GC_HEAP_GROWTH_FACTOR=1.03
export RUBY_GC_HEAP_GROWTH_MAX_SLOTS=88792
export RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=2.4
export RUBY_GC_MALLOC_LIMIT=34393793
export RUBY_GC_MALLOC_LIMIT_MAX=41272552
export RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR=1.32
export RUBY_GC_OLDMALLOC_LIMIT=39339204
@kigster
kigster / Makefile
Last active November 19, 2022 06:08
Makefile for Exporting and Restoring VSCode Extensions
# © 2019-2021 Konstantin Gredeskoul, MIT License.
# vim: ft=make
#
# Place this file anywhere.
#
# 1. To create a backup of your vscode settings, keybindings and extensions, run
# $ make save
# This backs it all up to your ~/Documents/VSCode folder.
#
# 2 To restore VSCode configuration:
@kigster
kigster / datadog-local.sh
Last active January 15, 2021 10:56
This file should be sourced in before running any Datadog-Instrumented application. It sets several automatic tags such as @username, @developer, @osname, @Branch and more so that multiple engineers can differentiate between their data. It also open the browser with the @username filter enabled.
#!/usr/bin/env bash
# vim: ft=bash
#
# Author: Konstantin Gredeskoul, https://github.com/kigster
#
# Copyright © 2021, MIT License
#
# This file should be used by applications wanting to stream APM information about the runtime behavior of the
# app to their Datadog APM account.
#
@kigster
kigster / build-intellij-bazel.sh
Last active March 22, 2020 10:54
Basic build helper script for building IntelliJ Plugin from sources. See http://bit.ly/intellij-bazel-plugin-from-sources for more info.
#!/usr/bin/env bash
set -ex
function intellij::build() {
local intellij_product="$1" # eg, "intellij-ue-2019.3"
local shortcut=$(echo ${intellij_product} | sed 's/-.*$//g')
local plugin_base=
case $shortcut in
intellij)
@kigster
kigster / bazel-intellij-exception.md
Last active March 2, 2020 23:54
IntelliJ IDEA Ultimate 2019.3.3 + Bazel Plugin — Import Project exception: No SyncPlugin present which provides a default workspace type.

Bazel Plugin Exception when Importing a Project

Steps Involved

  1. Install Plugin (tried two methods, same result — see below)
  2. Restart IDEA
  3. Select Import Bazel Project
  4. Point "workspace" to the folder with the WORKSPACE file.
  5. When asked to create project build file, I tried "create from scratch" and "import from BUILD file" — same result.
  6. I can't seem to move past this stage, and I don't see any other method to enable Bazel support for a project.
@kigster
kigster / datadog.rb
Created February 21, 2020 22:18
Datadog Rails Configuration
# config/initializers/datadog.rb
require 'ddtrace'
require 'redis'
Datadog::Tracer.log = Logger.new(nil)
# This is the port we have configured in the /etc/datadog/datadog.yml (apm_config)
Datadog.tracer.configure(port: 9126, enabled: true)
# TODO: change me
@kigster
kigster / ruby-jemalloc-check.sh
Last active August 12, 2022 19:41
Detect if MRI Ruby is built with jemalloc library or not, download with `curl -fSL http://bit.ly/ruby-jemalloc-check > ruby-jemalloc-check.sh`
#!/usr/bin/env bash
# vi: ft=sh
#
# https://gist.github.com/kigster/8ddebf9fddff25620e64d558dd4d56b7
#
# © 2019-2022 Konstantin Gredeskoul, Inc., All rights reserved.
# MIT LICENSE
# ————————————————————————————————————————————————————————————————
# This script verifies that the ruby interpreter (either the one in
# the $PATH, or the one specified by the -r / --ruby option) is linked