Skip to content

Instantly share code, notes, and snippets.

View MollsReis's full-sized avatar

Molly Reis MollsReis

View GitHub Profile
@MollsReis
MollsReis / 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
@MollsReis
MollsReis / 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
@MollsReis
MollsReis / 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
@MollsReis
MollsReis / 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
@MollsReis
MollsReis / session_fun.rb
Created April 25, 2012 20:28
Guessing game fun using sessions with Sinatra
require 'sinatra'
require 'haml'
require 'json'
enable :sessions
get '/' do
session[:answer] = %w[A B C D].sample
haml :index
end
@MollsReis
MollsReis / longpoll.rb
Created November 27, 2012 17:23
example of long polling using sinatra and jquery
require 'json'
require 'haml'
require 'sinatra'
get '/' do
haml :view
end
get '/request' do
content_type :json
@MollsReis
MollsReis / .bash_profile
Last active December 20, 2015 16:18
git prompt
source ~/git-prompt.sh
source ~/git-completion.bash
PS1='\u:\w\[\033[32m\]$(__git_ps1)\[\033[0m\]$ '
@MollsReis
MollsReis / .gitconfig
Created January 10, 2014 16:29
Git Config
[user]
email = <YOUR EMAIL>
name = <YOUR NAME>
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
@MollsReis
MollsReis / my_parser.rb
Created April 22, 2014 07:37
An example grammar/parser using the Ruby gem Treetop
require 'treetop'
module Mine
class IntegerLiteral < Treetop::Runtime::SyntaxNode
def to_i
text_value.to_i
end
end
@MollsReis
MollsReis / start.sh
Created November 14, 2014 19:31
Express + Forever start script
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
"$DIR/node_modules/.bin/forever" start \
--watch --watchDirectory ${DIR} \
--watchIgnore "$DIR/.*/*" \
--watchIgnore "$DIR/public/*" \
--watchIgnore "$DIR/logs/*" \
--append -l "$DIR/logs/app.log" \
--minUptime 1000 \
--spinSleepTime 1000 \