Skip to content

Instantly share code, notes, and snippets.

@mgates
mgates / 05.rb
Created December 6, 2019 05:59
advent 2019 day 5
class Thing
def do_it(inp, *input)
nums = input.dup
pos = 0
while true
if nums[pos] < 10
case nums[pos]
when 99
return nums
@mgates
mgates / 04.rb
Created December 5, 2019 05:05
advent 2019 day 4
class Foo
def do_it
count = (256310..732736).find_all do |num|
(num.to_s[0].to_i <= num.to_s[1].to_i && num.to_s[1].to_i <= num.to_s[2].to_i && num.to_s[2].to_i <= num.to_s[3].to_i && num.to_s[3].to_i <= num.to_s[4].to_i && num.to_s[4].to_i <= num.to_s[5].to_i) &&
(num.to_s[0].to_i == num.to_s[1].to_i || num.to_s[1].to_i == num.to_s[2].to_i || num.to_s[2].to_i == num.to_s[3].to_i || num.to_s[3].to_i == num.to_s[4].to_i || num.to_s[4].to_i == num.to_s[5].to_i)
end
puts count.inspect
puts count.count
end
@mgates
mgates / 03.rb
Created December 5, 2019 04:38
advent 2019 day 3
require "set"
class Wires
def do_it(wire_1, wire_2)
w1 = wire_1.split(",")
w2 = wire_2.split(",")
points1 = Set.new
points2 = Set.new
loc = [0,0]
@mgates
mgates / 02.rb
Created December 5, 2019 04:38
advent 2019 day 3
class Thing
def do_it(pos_1, pos_2, *input)
nums = input.dup
nums[1] = pos_1
nums[2] = pos_2
pos = 0
while true
case nums[pos]
when 99
@mgates
mgates / 02.rb
Created December 4, 2019 03:19
advent 2019 day 2
class Thing
def do_it(pos_1, pos_2, *input)
nums = input.dup
nums[1] = pos_1
nums[2] = pos_2
pos = 0
while true
case nums[pos]
when 99
@mgates
mgates / 01.rb
Last active December 1, 2019 14:15
advent 2019 day 1
class Do
def calc(val)
(val / 3.0).floor - 2
end
def calc_2(val)
f = [(val / 3.0).floor - 2, 0].max
(f += calc_2(f)) if f > 0
f
end
Verifying that +mgates is my blockchain ID. https://onename.com/mgates
@mgates
mgates / gist:eee93a87a8394d93bba7
Last active August 29, 2015 14:10
To add tempfile method to Rack::Test::UploadedFile to make it like ActionDispatch::Http::UploadedFile

The CSV.foreach method cexpects a string of a file to open. ActionDispatch::Http::UploadedFile has a #tempfile method which is good enough to pass into File.open like CSV.foreach does. Rack::Test::UploadedFile doesn't (and probably won't: rails/rails#799, rack/rack-test#30).

I added it like this:

# in spec/support/add_tempfile_to_test_uploaded_file.rb

class Rack::Test::UploadedFile
  def tempfile
    @tempfile
 end
@mgates
mgates / gist:a72a0a01915f122de3c8
Created October 14, 2014 15:03
If you need to change the backtrace silencers...
You can put this in an initializer
bc = Rails.backtrace_cleaner
bc.remove_silencers!
bc. add_silencer { |line| (line !~ bc.class::APP_DIRS_PATTERN && line !~ %r[^/?(vendor/gems/internal_gem)])}

Partage API

The Partage API provides a simple and limited interface to the Partage brokerage system.

The latest version of this document can always be reached at http://gopartage.com/api.

Authentication

For now, authentication is done with an API token that is connected to your company.