Skip to content

Instantly share code, notes, and snippets.

@slayer
slayer / redis-database-usage.rb
Created October 6, 2023 11:38
Get Redis database usage (per database)
require 'redis' # gem install redis (4.8.x in my case)
15.times.each do |db|
redis = Redis.new(url: "redis://localhost/#{db}") # or whatever
total = 0
redis.scan_each.each do |key|
size = redis.send(:send_command, [:memory, :usage, key])
total += size
# puts " DB#{db} #{key} => #{size}b"
@slayer
slayer / phone_masks_by_country.json
Last active April 19, 2023 17:01
Phone number masks by country ISO code
{
"AF": "##-###-####",
"AX": "(###)###-##-##",
"AL": "(###)###-###",
"DZ": "##-###-####",
"AS": "(684)###-####",
"AD": "###-###",
"AO": "(###)###-###",
"AI": "(264)###-####",
"AQ": "1##-###",
@slayer
slayer / some_controller_spec.rb
Last active June 21, 2022 19:18
Rails Rspec helper for turbo (hotwire)
require 'rails_helper'
RSpec.describe SomeController, type: :controller do
context 'turbo' do
include_context 'turbo_requests'
it 'should be successful' do
post :action
expect(response).to be_successful
@slayer
slayer / auto-delete-failed-pods-cronjob.yaml
Created December 2, 2021 11:59
Auto delete failed pods in Kubernetes
# Auto delete pods with status.phase=Failed via CronJob
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sa-auto-delete-failed-pods
namespace: kube-system
---
kind: ClusterRole
@slayer
slayer / gcp-copy-disks-between-projects.sh
Last active December 10, 2020 07:20
Google Cloud copy disks (images) between projects
#!/bin/bash
# Setup your projets and zones
SRC_PRJ="company-staging"
SRC_ZONE="northamerica-northeast1-b"
DST_PRJ="company-production"
DST_ZONE="us-central1-b"
DISKS="$@"
@slayer
slayer / aws-s3-du.sh
Last active August 11, 2019 15:54
AWS S3 du (disk usage) script
function aws-s3-du() {
local buckets=$@
if [ -z "$buckets" ]; then
buckets=$(aws s3 ls | awk '{print $3}')
fi
for bucket in $buckets; do
echo -ne "${bucket}\t\t"
aws s3 ls s3://${bucket} --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024/1024" GB"}'
done
}
@slayer
slayer / config
Created March 19, 2019 12:54
i3wm config
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
@slayer
slayer / cloudflare-delete-all-records.sh
Last active March 21, 2024 10:17
Delete all DNS records for specified zone
#!/bin/bash
TOKEN="xxxxxxxxxxxxxxxxxxx"
ZONE_ID=2222222222222222222222222
# EMAIL=me@gmail.com
# KEY=11111111111111111111111111
# Replace with
# -H "X-Auth-Email: ${EMAIL}" \
# -H "X-Auth-Key: ${KEY}" \
@slayer
slayer / gist:fb299c846fedaeac9fef47d468da9526
Created October 13, 2016 20:23 — forked from evtuhovich/gist:1134998
Список вопросов для собеседования
Ruby
принципиальное различие скриптовых и “обычных” языков
3 принципа ООП
реализация множественного наследования в ruby
duck typing
многопоточность в ruby
Rails
что такое MVC и зачем это нужно
локига в контроллере, должна ли быть и почему
синхронные и асинхронные операции — предложить варианты решения

ruby-1.9.3-p448 cumulative performance patch for rbenv

(I guarantee nothing. No warranty I am not responsible blah blah blah. Seems to work great for me so far. Thanks to Tyler Bird who I forked this from.)

This installs a patched ruby 1.9.3-p448 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements