Skip to content

Instantly share code, notes, and snippets.

View ixti's full-sized avatar
😂
forever blowing bubbles

Alexey Zapparov ixti

😂
forever blowing bubbles
View GitHub Profile
@ixti
ixti / print-ar-missing-options.rb
Created October 21, 2021 02:26
Print missing options for ActiveRecord associations
require_relative "config/environment"
Rails.application.eager_load!
Rails.root.glob("app/models/**/*.rb").each { |f| require_relative f }
has_xxx_required_options = %i[dependent inverse_of].freeze
belongs_to_required_options = %i[inverse_of].freeze
needs = Hash.new { |h, k| h[k] = Set.new }
ActiveRecord::Base.descendants.each do |klass|
# frozen_string_literal: true
module ActiveRecord
module Schema
class Context
class Table
class Index
attr_reader :columns, :options
def initialize(columns, **options)
@ixti
ixti / bulky-sidekiq.rb
Last active June 5, 2021 01:16
[POC] Sketch sidekiq bulk push enhancement
module Sidekiq
module Bulky
class Collector
def initialize(accumulator)
@accumulator = accumulator
end
def perform_async(*args)
@accumulator[nil] << args
end
@ixti
ixti / aws-cli-filtering.md
Created March 22, 2021 18:00 — forked from carlessanagustin/aws-cli-filtering.md
Filtering AWS results

Via AWS CLI using jq

(https://github.com/mwilliamson/jq.py)

aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.KeyName == "MyKey") | select(.State.Code != 48) | select(.Tags[]|select(.Key=="Name")|select(.Value=="InstanceName")) | [ .PublicIpAddress]'
 
aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.KeyName == "MyKey") | select(.State.Code != 48) | select(.Tags[]|select(.Key=="Name")|select(.Value=="InstanceName")) | [ .PublicIpAddress, (.Tags[]|select(.Key=="Name").Value)]'

aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.KeyName == "MyKey") | select(.State.Code != 48) | select(.Tags[]|select(.Key=="InventoryGroup").Value) | [ .PublicIpAddress, (.Tags[]|select(.Key=="Name").Value)]'
# frozen_string_literal: true
require "net-telnet"
class Jacinto
include Enumerable
# Array(slab_id, items_count)
SLABS = /^STAT items:(\d+):number (\d+)$/
@ixti
ixti / gemfile-upgrade-plan.rb
Last active December 28, 2022 18:47
Small script that to print CSV that can be used to plan gem upgrades
# frozen_string_literal: true
require "bundler/inline"
require "csv"
STDOUT.sync = STDERR.sync = true
gemfile do
source "https://rubygems.org"
gem "http"
@ixti
ixti / mongo-changelog.rb
Created September 3, 2019 21:57
Brain-damaged "see changes on releases page" idiocy to changelog converter for mongo ruby driver
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "http"
end
gh_project = "mongodb/mongo-ruby-driver"
@ixti
ixti / mongoid-changelog.rb
Last active September 3, 2019 13:57
Build all in one changelog from fucked-up mongoid releases on GitHub
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "http"
end
HTTP.persistent("https://api.github.com") do |http|
# Copyright (c) 2009 Eric Todd Meyers
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
def print_result(desc)
result = yield
puts "#{desc} class=#{result.class} inspect=#{result.inspect}"
rescue => e
warn "#{desc} fail: #{e}"
end
def test(obj)
puts "\n== #{obj.inspect} == "