Skip to content

Instantly share code, notes, and snippets.

View EvilScott's full-sized avatar

Molly Reis EvilScott

View GitHub Profile
@EvilScott
EvilScott / image_resizer.rb
Created April 20, 2012 19:54
Image processing server using Sinatra and MiniMagick
require 'mini_magick'
class ImageResizer
attr_accessor :height, :width, :padding, :stretch, :grayscale
def initialize(path)
@image = MiniMagick::Image.open(path)
end
@EvilScott
EvilScott / jimson-sinatra.rb
Created April 11, 2012 15:33
Jimson and Sinatra playing together
require 'sinatra'
require 'jimson'
class Api
extend Jimson::Handler
def get_data
{'foo' => 'bar'}
end
end
@EvilScott
EvilScott / apprunner.rb
Created February 13, 2012 22:44
Use Sinatra to open a browser window (and close Sinatra when the window closes)
%w[sinatra watir-webdriver].each { |gem| require gem }
class MyApp < Sinatra::Base
get('/') { "hello world" }
end
class AppRunner
def initialize
@EvilScott
EvilScott / diagonals.rb
Created February 6, 2012 23:04
Retrieve diagonals from array of arrays in Ruby
class Array
def diagonals
[self, self.map(&:reverse)].inject([]) do |all_diags, matrix|
((-matrix.count + 1)..matrix.first.count).each do |offet_index|
diagonal = []
(matrix.count).times do |row_index|
col_index = offet_index + row_index
diagonal << matrix[row_index][col_index] if col_index >= 0
end
all_diags << diagonal.compact if diagonal.compact.count > 1