Skip to content

Instantly share code, notes, and snippets.

View borama's full-sized avatar
🥕
Ready for some carrot

Matouš Borák borama

🥕
Ready for some carrot
View GitHub Profile
@borama
borama / ruby_gems_age.rb
Last active October 25, 2023 21:03
A script that collects and prints info about the age of all ruby gems in your project, see https://dev.to/borama/how-old-are-dependencies-in-your-ruby-project-3jia
#!/bin/env ruby
#
# Collects info about the age of all gems in the project
#
require "json"
require "date"
bundle = `bundle list`
yearly_stats = {}
@borama
borama / check_auto_increment_columns_rake.rb
Last active November 9, 2018 09:22
Rake task that warns you when an auto_increment column reaches a maximum value threshold
desc "Warn if an auto_increment column is reaching max value limit"
task check_auto_increment_columns_overflow: :environment do
threshold_percent = (ENV["THRESHOLD"] || "90").to_i
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.columns(table).each do |column|
next unless column.type == :integer && column.extra.to_s =~ /auto_increment/
auto_increment = ActiveRecord::Base.connection.select_one("SHOW TABLE STATUS LIKE '#{table}'")["Auto_increment"]
max_value = column.cast_type.send(:max_value)