Skip to content

Instantly share code, notes, and snippets.

View mchail's full-sized avatar

Steve McHail mchail

View GitHub Profile
@mchail
mchail / pry_me_a_river.rb
Last active July 14, 2022 18:49
ruby pry tips
# getting context – what can this thing do?
show-source
$ Sidekiq
$ Sidekiq.queues=
ls Sidekiq
cd Sidekiq
whereami
ls
@mchail
mchail / discs.json
Last active June 5, 2020 20:51
Discs
{
"locations": ["My bag"],
"discs": [
{
"mold": "Reko",
"manufacturer": "Kastaplast",
"plastic": "K3",
"numbers": "3 3 0 1",
"color": "white",
"notes": null,
require 'json'
Disc = Struct.new(
:plastic,
:weight,
:color,
:quantity,
)
WIDTH = 16
REKO_MODEL_ID = '16569'
@mchail
mchail / airport_code_word_finder.rb
Created April 2, 2018 23:01
Make words out of airport codes
# https://twitter.com/xor/status/978793975590150144
require 'open-uri'
require 'csv'
class PrefixTreeSearch
attr_reader :codes, :words, :root
attr_accessor :found
MAX_LENGTH = 12
@mchail
mchail / find_jordans_pr.rb
Created October 30, 2015 21:52
find Jordan's last PR
require 'json'
require 'httparty'
class FindJordansPR
def auth
{
username: :mchail,
password: ENV['pw']
}
@mchail
mchail / keybase.md
Created April 8, 2015 04:43
keybase

Keybase proof

I hereby claim:

  • I am mchail on github.
  • I am mchail (https://keybase.io/mchail) on keybase.
  • I have a public key whose fingerprint is 0217 CCDB A934 DCD5 7444 F922 21F5 B443 568B 6E57

To claim this, I am signing this object:

@mchail
mchail / pirates.rb
Created March 23, 2015 03:33
Pirate Scrabble word finder
#!/usr/bin/env ruby
#
# Usage: ruby [filename] [word]
# Will return a list of up to ten words from the system dictionary
# that could be played before the provided word. It is up to the user
# to manually filter for "root" constraints.
# e.g.
# ruby pirates.rb marquisotte
class Yarr
@mchail
mchail / errbuddy_shufflin.rb
Last active December 13, 2022 19:33
Calculate probability that a hand of cards is dealt shuffled
class Dealer
def initialize
@deck = new_deck
end
def deal(size)
if @deck.size < size
@deck = new_deck
end
@deck.pop(size)
@mchail
mchail / interval_merger.rb
Last active August 29, 2015 14:11
Interval merger
class IntervalMerger
def initialize(*intervals)
@intervals = intervals
end
def merge
# TODO: return the reduced set of intervals
end
end
@mchail
mchail / recover_ad_images.rb
Created December 12, 2014 19:19
recover ad images
a = Ad.find "53c354433486db904c000010"
s = a.site
ads = []
s.ads.each{|a| begin; open a.image.url; rescue; ads << a; end}
def move(a)
source_key = Paperclip::Interpolations.interpolate "ads/:attachment/:id_partition/:style/:filename", a.image, :original
target_key = Paperclip::Interpolations.interpolate "images/:hash/:style.:extension", a.image, :original
m = MigrateAds.new
moved = m.instance_variable_get(:@s3).buckets[m.instance_variable_get(:@bucket_name)].objects[source_key].copy_to(target_key, :acl => :public_read)
end