Skip to content

Instantly share code, notes, and snippets.

@Capncavedan
Capncavedan / sample.rb
Created April 25, 2024 16:15
Removing orphaned sidekiq-unique-jobs digests
> SidekiqUniqueJobs::LockDigest.new({
'class' => 'SidekiqQueuesMetricsWorker',
'queue' => 'system_critical',
'lock_args' => [],
}).lock_digest
# => ":c9e4f70a93ec7b29f57842219285f439"
> r = Redis.new
# => #<Redis client v4.8.1 for redis://hostname....
@Capncavedan
Capncavedan / Ruby script
Created April 9, 2012 15:45
Ruby script to show OS X battery info at command line
#!/usr/bin/ruby
ioreg_data = IO.popen("ioreg -w0 -l").readlines().join
ioreg_data.sub!(/.*(\+\-o AppleSmartBattery.*?\+\-o).*/m, '\\1')
ioreg_data.gsub!(/\s+\|/, "")
ioreg_data.gsub!(/\s\s+/, "\n")
battery = Hash.new
ioreg_data.split(/\n+/).each do |line|
key, value = line.split(' = ')[0..1]
next if key.nil? || value.nil?
@Capncavedan
Capncavedan / find.sql
Created March 27, 2018 16:06
Find corrupt/invalid Postgresql indexes
SELECT pg_class.relname
FROM pg_class, pg_index
WHERE pg_index.indisvalid = false
AND pg_index.indexrelid = pg_class.oid;
@Capncavedan
Capncavedan / gist:2844679
Created May 31, 2012 16:46
Analyze MySQL binary log file
# from http://dzone.com/snippets/analyse-binary-log
# cat /bin/mylog
#!/bin/sh
# usage:
#$ mylog /mysql-bin-log/db-bin.000223
# 2132 insert into customers
# 1887 update userlog_access
# 788 insert into gn_commission
# 718 insert into con_tab
Ruby and Ruby and Rails still feel fresh and new to me, but (surprise!) Ruby is over 20 years old, and Rails is nearly 12.
A lot's happened in the ecosystem over time, practices have changed, gems have shot up the charts and later fallen out of favor, and new programming techniques have come on the scene.
Keeping up with this can be a challenge, especially for those working on long-term projects and/or on stable teams with few newcomers: how do you get your job done and ship a product while also continually refining your skills and learning about new solutions & professional best practices?
You know there are twitterers, podcasts, courses, books, and even blogs (yes, people still do those!) - but how do you find them, and which are worthwhile to invest your time and money in?
Let's pool our knowledge and share!
@Capncavedan
Capncavedan / TI list.txt
Created March 16, 2017 17:05
Trans Iowa packing list from 2016
Rain gear
-----------
rain jacket, w/bag
rubberized gloves
shower cap?
in dry bags:
extra jersey
extra undershirt?
extra shorts
extra socks
Great panniers: http://www.arkel-od.com
Great fenders and headlights: http://planetbike.com/page/
Great taillight: https://www.ridepdw.com/goods/lights/danger-zone-usb
@Capncavedan
Capncavedan / timezonezipificator.rb
Created January 5, 2014 03:37
Script to add time zone where possible
This file has been truncated, but you can view the full file.
require 'zip-codes'
time_zones_by_zip = {
"00501" => "America/New_York",
"00544" => "America/New_York",
"01001" => "America/New_York",
"01002" => "America/New_York",
"01003" => "America/New_York",
"01004" => "America/New_York",
"01005" => "America/New_York",
@Capncavedan
Capncavedan / example.rb
Created October 28, 2013 19:16
Number to currency calculator, faster than ActiveSupport (due to no translation?)
def quick_number_to_currency(num)
left, right = sprintf("%.2f", num).split('.')
1 while left.sub!(/(\d)(\d\d\d)\b/, '\1' + ',' + '\2')
"$#{left}.#{right}"
end
it "turns 1000 into $1,000.00" do
@rt.quick_number_to_currency(1000).should eql("$1,000.00")
end
@Capncavedan
Capncavedan / gist:4157673
Created November 27, 2012 22:41
Powerball stats 7 Jan 2009 to 27 Nov 2012
Getting Powerball drawing data from 11/27/2012 back to 01/07/2009 ...
Got 641775 bytes of Powerball data. Stand by for parsing.
Examining results of 406 drawings...
Top 5 numbers: 20, 41, 32, 59, 22
Top Powerball: 23

Detail:

Regular numbers