Skip to content

Instantly share code, notes, and snippets.

View Kallin's full-sized avatar

Kallin Nagelberg Kallin

View GitHub Profile
@Kallin
Kallin / bowling.rb
Created August 8, 2024 20:55
bowling.rb
FRAME_COUNT = 5
class Frame
PIN_COUNT = 10
def initialize(final_frame = false)
@rolls = RollList.new
@final_frame = final_frame
reset_pins
@Kallin
Kallin / callback_counter.rb
Created February 2, 2024 18:38
count how many callbacks per model in your Rails app
require 'csv'
# ensure all classes have been laoded
Rails.application.eager_load!
def calc_callback_counts
models = ApplicationRecord.descendants
class_callback_counts = {}
CALLBACKS = [
'before_validation',
'after_validation',
'before_save',
'around_save',
'before_create',
'around_create',
'after_create',
'after_save',
'after_commit',
#!/usr/bin/env ruby
current_branch = `git symbolic-ref --short HEAD`.chomp
if current_branch != "master"
if $?.exitstatus == 0
puts "WARNING: You are on branch #{current_branch}, NOT master."
else
puts "WARNING: You are not on a branch"
end
puts
#!/usr/bin/env ruby
current_branch = `git symbolic-ref --short HEAD`.chomp
if current_branch != "master"
if $?.exitstatus == 0
puts "WARNING: You are on branch #{current_branch}, NOT master."
else
puts "WARNING: You are not on a branch"
end
puts
def num_to_digits(num)
digits = []
until num == 0
digits << num % 10
num = num / 10
end
digits
def find_descendants(person)
descendants = []
stack = person[:children]
until stack.empty?
current_node = stack.pop
children = current_node[:children]
if children
children.each do |child|
def find_descendants(person)
descendants = []
children = person[:children]
if children
descendants << children
children.each do |child|
descendants << find_descendants(child)
class Vegetable
attr_accessor [
:rarity
]
def ferment
# let's make some vegetable jam!
end
@Kallin
Kallin / branch_clean.rb
Created February 27, 2015 17:14
delete selected branches in ruby
delete_branches = [
'branch_a',
'branch_b',
'branch_c',
]
delete_branches.each do |branch|
system "git branch -D #{branch}"
system "git push origin --delete #{branch}"
end