Skip to content

Instantly share code, notes, and snippets.

@dalizard
dalizard / 00-ADVENT-OF-CODE-2022-RUBY.md
Created February 21, 2024 13:07 — forked from skanev/00-ADVENT-OF-CODE-2022-RUBY.md
Advent of Code 2022 in Ruby (sort of)

Advent of Code 2022 solutions in Perl Ruby

Just for kicks, I'm trying to solve them with semi-golfed Ruby. That is:

  • As short as possible, but
  • Have some whitespace to make them somewhat readable
  • Avoid single-letter identifiers to keep them somewhat readable
  • Don't make them too short when they are short enough

Each solution parses the input file and outputs the answer.

@dalizard
dalizard / http_debug.rb
Created February 15, 2024 12:23 — forked from dathanb/http_debug.rb
Print Raw HTTP Request and Response Payload in Ruby
module Net
class HTTP
alias_method(:orig_request, :request) unless method_defined?(:orig_request)
def request(req, body = nil, &block)
puts '===== REQUEST ====='
puts "Request: #{req.method} http://#{@address}:#{@port}#{req.path}"
puts 'Request headers: '
req.each_header do |key, value|
puts "\t#{key}: #{value}"
@dalizard
dalizard / rules for good testing.md
Created November 18, 2016 09:19 — forked from Integralist/rules for good testing.md
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.