Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Howard mikehoward

View GitHub Profile
@mikehoward
mikehoward / gist:3233464
Created Aug 2, 2012
Response to Array Iteration Interview Prob
View gist:3233464
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 Mar 10, 2012
re-write of MiniMagick
View gist:2012377

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 Dec 4, 2011
A Conway's Game of Life implementation
View conways-life.rb
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 = {}
You can’t perform that action at this time.