Skip to content

Instantly share code, notes, and snippets.

View mchail's full-sized avatar

Steve McHail mchail

View GitHub Profile
@mchail
mchail / hubot_deliboard.coffee
Created April 15, 2014 07:29
Hubot Deliboard plugin
# Description:
# Prints today's deliboard menu
#
# Dependencies:
# "cheerio" : "https://github.com/cheeriojs/cheerio",
#
# Commands:
# deliboard menu
#
# Notes:
@mchail
mchail / math_eval_with_ooo.rb
Created October 3, 2014 23:35
evaluate expression from string (and follow order of operations)
require 'json'
class StringCalc
def initialize(str)
@tokens = str.split('')
# puts @tokens.to_json
end
def run
@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
@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 / 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 / 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 / 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 / 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 / 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