Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
@practicingruby
practicingruby / bmp_writer.rb
Last active December 18, 2023 12:29
bmp_writer.rb
# coding: binary
class BMP
class Writer
PIXEL_ARRAY_OFFSET = 54
BITS_PER_PIXEL = 24
DIB_HEADER_SIZE = 40
PIXELS_PER_METER = 2835 # 2835 pixels per meter is basically 72dpi
def initialize(width, height)

Fork this gist, and then replace this document with your Markdown formatted rulebook for the game Pressman.

@practicingruby
practicingruby / mrdi.md
Created December 19, 2012 22:29
Models, Roles, Decorators, and Interactions -- A modest proposal for a toned done version of DCI that isn't as janky as Concerns.

Models, Roles, Decorators, and Interactions

A modest alternative to DCI that might be worth further thought

One of the problems with advancing the discussion on DCI is that we lack a comparable alternative pattern that has the same goals, but favors a low ceremony approach. The closest thing we have to that is Rails concerns, but they are more like distant relatives of the DCI concepts rather than first cousins, and that makes comparisions between the two approaches not especially fruitful.

I am considering the idea of experimenting with my own paradigm that captures the intent and purity of DCI, but with the convenience of concerns. Please note that this is just the starting point of a conversation, it is NOT a promise of comercially available cold fusion or a cure for cancer. It's just a gist with an idea on it I'd like to hear your thoughts on.

What if we had a top-level topology that was split into Models, **Rol

Start every day coding, end every day thinking.
1. Warmup exercise (30 mins)
Make sure to have these ready the night before, pick stuff
that you can work on right away without having to study
in advance.
They can either be book exercises or stuff
from other sources, but they should be self-verifiable
@practicingruby
practicingruby / bmp_reader.rb
Last active January 17, 2019 12:28
bmp_reader.rb
# coding: binary
class BMP
class Reader
PIXEL_ARRAY_OFFSET = 54
BITS_PER_PIXEL = 24
DIB_HEADER_SIZE = 40
def initialize(bmp_filename)
File.open(bmp_filename, "rb") do |file|
require 'socket'
module EventEmitter
def _callbacks
@_callbacks ||= Hash.new { |h, k| h[k] = [] }
end
def on(type, &blk)
_callbacks[type] << blk
self

This is my Manifesto!

A long winded philosophical statement that is meant to tug at the heart strings, but is still written in business speak suitable for someone staring off into the middle distance.

"A quote from someone notable for doing a thing a few decades ago" -- Some Dude

A sharp statement that really 'gets to the point' but doesn't really.

  • A list of things on the left that are established practices
  • A list of things on the right that are the same practices using new words
def computation(number)
raise "Amount cannot be negative" if number < 0
# do something here.
end
require "pdf/inspector" # gem install pdf-inspector
text = File.binread("2016WayneCountyTaxLiens.pdf")
text_analysis = PDF::Inspector::Text.analyze(text)
File.write("dump.txt", text_analysis.strings.join)
# For more, see https://github.com/prawnpdf/pdf-inspector
# and also https://github.com/yob/pdf-reader
#
class BrokenNumber
def initialize(num)
@num = num
end
def method_missing(m, *a, &b)
@num.send(m, *a, &b)
end
def coerce(other)