Skip to content

Instantly share code, notes, and snippets.

View DAddYE's full-sized avatar

Davide D'Agostino DAddYE

  • Endor Labs
  • San Francisco
View GitHub Profile
error do
exception = request.env['sinatra.error']
Hoptoad::Notifier.send_error exception, params, request.env if %w(staging production).include?(ENV['RACK_ENV'])
erb :five_hundred
end
# Before/After filters in padrino
SimpleApp.controllers :posts do
# These are public actions, no authentication required
get :index do; ... end;
get :show, :with => :id do; ... end;
# These actions require being authenticated
# Variant 1
@DAddYE
DAddYE / blog_tutorial_1.sh
Created March 18, 2010 17:19 — forked from nesquena/blog_tutorial_1.sh
Padrino generator output
$ padrino-gen project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord
create
create config/apps.rb
create config/boot.rb
create config.ru
create public/favicon.ico
create .gitignore
create public/images
create public/javascripts
create public/stylesheets
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"

Merb

  • Has routes.rb like rails, Padrino not

  • Merb define controllers in class and routes in def like rails, Padrino use sinatra blocks.

  • Merb has not admin, Padrino has some thing like django-admin

  • Merb has slices that are 1:1 equals to Rails Engines, Padrino apply the same concept of DJango where you build a project and then apps.

  • A full merb stack require some like 56 gems Padrino if Im not wrong 16 gems.

  • Padrino has full support to I18n like rails/django, Merb not

  • Merb has DataMapper as preferred orm, Rails ActiveRecord, Padrino “NONE”

  • Our rendering is only an enhanced version of Sinatra rendering (but Merb didn’t support haml :foo, erb :bar)

@DAddYE
DAddYE / install_homebrew.rb
Created February 22, 2012 15:26 — forked from mxcl/install_homebrew.markdown
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
@DAddYE
DAddYE / mountain-lion-brew-setup.markdown
Created March 20, 2012 12:55 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

before all uninstall all previous version of xcode 4.4.

sudo uninstall-devtools –mode=all

All developers tools under xcode 4.4+ are self-contained into XCode.app, before 4.4. all stuff was installed into /Developers

This command cleanup a bit your env.

module EventMachine
def self.system3(cmd, *args, &cb)
cb ||= args.pop if args.last.is_a? Proc
init = args.pop if args.last.is_a? Proc
# merge remaining arguments into the command
cmd = ([cmd] + args.map{|a|a.to_s.dump}).join(' ')
new_stderr = $stderr.dup
@DAddYE
DAddYE / simple_fiber_concurrency.rb
Created November 26, 2012 19:55
Simple example of concurrency in Ruby with Fiber.
require "fiber"
f1 = Fiber.new do |f2|
while true
puts "A"
sleep 2
f2.transfer
end
end
# config/initializers/source_maps.rb
if Rails.env.development?
module CoffeeScript
class SourceMapError < StandardError; end;
class << self
def compile script, options
script = script.read if script.respond_to?(:read)