Skip to content

Instantly share code, notes, and snippets.

View mguinada's full-sized avatar

Miguel Guinada mguinada

  • BeBanjo
  • Lisbon, Portugal
View GitHub Profile
@mguinada
mguinada / 0_notes.txt
Created January 15, 2012 14:32 — forked from wayneeseguin/0_notes.txt
Wayne Seguin's recomendations on creating a project with RVM
This is an example of using RVM's Project .rvmrc file
to have it automatically bootstrap your environment, including bundler.
This could be further expanded to do anything you require :)
The important thing to remember is that the purpose of these files is
to allow you to very easily have your 'project context' (aka 'environment')
loaded automatically for you when you enter the project in the shell (cd).
You can generate the .rvmrc file below by running:
@mguinada
mguinada / gist:1739133
Created February 4, 2012 17:39 — forked from jnunemaker/gist:217362
example of warden with sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
@mguinada
mguinada / unicorn.conf
Created June 1, 2012 10:32 — forked from pshima/unicorn.conf
Unicorn logrotate
/path/to/unicorn/log/unicorn.stderr.log
/path/to/production/log/production.log
{
daily
missingok
rotate 180
compress
dateext
# this is important if using "compress" since we need to call
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
@mguinada
mguinada / raskell.rb
Created August 16, 2012 15:20 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@mguinada
mguinada / Gemfile
Created August 19, 2012 22:07
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@mguinada
mguinada / SpecRunner.html
Created August 23, 2012 15:08 — forked from OakRaven/SpecRunner.html
Jasmine SpecRunner
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="spec/jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="spec/jasmine/jasmine.css">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="spec/jasmine/jasmine.js"></script>
<script src="spec/jasmine/jasmine-html.js"></script>
@mguinada
mguinada / 0_README.md
Created September 20, 2012 13:05 — forked from josevalim/0_README.md
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

A Backbone.js demo app (Sinatra Backend)

Oct 16 2010

Updates

  • 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments

In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].

@mguinada
mguinada / rgb_cube.rb
Created November 10, 2012 21:46
ANSI RGB color cube
#from: http://stackoverflow.com/questions/1403353/256-color-terminal-library-for-ruby
def rgb(red, green, blue)
16 + (red * 36) + (green * 6) + blue
end
def gray(g)
232 + g
end