Skip to content

Instantly share code, notes, and snippets.

View mikehoward's full-sized avatar

Mike Howard mikehoward

View GitHub Profile
@mikehoward
mikehoward / gist:3233464
Created August 2, 2012 04:20
Response to Array Iteration Interview Prob
def add1(arr, val, n)
return arr.map { |x| x == val ? x + 1 : x } if n == 0
lim = arr.length
if n > 0
return arr.map { |x| x == val ? x + 1 : x } if n >= lim
idx = 0
while idx < lim do
if arr[idx] == val
arr[idx] += 1
n -= 1
@mikehoward
mikehoward / gist:2012377
Created March 10, 2012 18:22
re-write of MiniMagick

This is a rough outline rewrite the internals of MiniMagick - a ruby gem for using ImageMagick and GraphicsMagick from ruby scripts. MiniMagick's most prominent feature is creating appropriate shell commands which are run as subprocesses - thereby making the gem less fragile w.r.t. the graphics libraries and changes to the *Magick routines.

the Image Class.

The MiniMagick image class does too much. I propose that the Image class should be responsible for the image files only and not be involved in running *Magick commands.

Image#new(path = nil)

If path is nil, creates a temporary file using

@mikehoward
mikehoward / conways-life.rb
Created December 4, 2011 02:07
A Conway's Game of Life implementation
class Grid
# dynamic, auto-adjusting grid size
class << self
attr_accessor :min_x, :max_x, :min_y, :max_y
end
attr_accessor :hash
def initialize
self.hash = {}