Skip to content

Instantly share code, notes, and snippets.

@albertoleal
albertoleal / deploy.rb
Created November 8, 2010 00:37
Capistrano Recipe - Deploy a Rails App to Webbynode
set :application, "your_application_name"
set :ip_address , "000.000.000.000"
set :scm, :git
set :repository, "git@github.com:albertoleal/OlaMundo.git"
set :branch, "master"
set :deploy_via, :remote_cache # Deploy only the changes you have made since last deploy.
set :user , "albertoleal"
set :deploy_to, "/home/albertoleal/#{application}"
@albertoleal
albertoleal / deploy.rb
Created November 8, 2010 00:39
Capistrano Recipe - Deploy a Sinatra App to Webbynode
set :application, "myapp"
set :ip_address , "000.000.000.000"
set :scm, :git
set :repository, "git@github.com:albertoleal/Sinatra-Template.git"
set :branch, "master"
set :deploy_via, :remote_cache
set :user , "sinatra"
set :deploy_to, "/home/sinatra/#{application}"
@albertoleal
albertoleal / install_mq_ubuntu
Created November 12, 2010 11:35
Installing MQ on Ubuntu
$ less ./licenses/LA_en
$ sudo mkdir -p /tmp/mq_license/license/
$ sudo touch /tmp/mq_license/license/status.dat
$ sudo rpm -iavh --nodeps --force-debian ./MQSeriesRuntime-7.0.1-3.i386.rpm
Preparing... ########################################### [100%]
1:MQSeriesRuntime ########################################### [100%]
$ sudo mkdir -p /tmp/mq_license/license/
$ sudo touch /tmp/mq_license/license/status.dat
$ sudo rpm -iavh --nodeps --force-debian ./MQSeriesJava-7.0.1-3.i386.rpm ./MQSeriesClient-7.0.1-3.i386.rpm ./MQSeriesServer-7.0.1-3.i386.rpm ./MQSeriesSDK-7.0.1-3.i386.rpm ./MQSeriesSamples-7.0.1-3.i386.rpm ./MQSeriesTXClient-7.0.1-3.i386.rpm
Preparing... ########################################### [100%]
@albertoleal
albertoleal / gist:949282
Created April 30, 2011 00:34
Couch Rest model
=begin
shop = ShoppingCoupon.new(:name => 'Shop', :description =>"Clothes",
:items => [{:name => 'shirt', :price => 2.50}, {:name => 'pants', :price => 5}],
:purchased =>2011/03/21, :amount => 43.2)
shop.save
=end
class Items < Hash
include CouchRest::Model::CastedModel
@albertoleal
albertoleal / gist:949289
Created April 30, 2011 00:43
Couch Rest model - error
=begin
shop2 = ShoppingCoupon.new(:name => 'Shop', :description =>"Clothes",
:items => [{:name => 'shirt', :price => 2.50}, {:name => 'pants', :price => 5}],
:purchased =>2011/03/21, :amount => 43.2)
shop2.save
=end
class ShoppingCoupon < CouchRest::Model::Base
use_database CouchServer.default_database
class Fixnum
def is_dividable_by?(*numbers)
result = numbers.inject(0){|k,v| self%v if k == 0}
result == 0 ? true : false
end
end
output = {}
(1..100).each do |number|
output[number] = if number.is_dividable_by?(3,5); "ping pong"
@albertoleal
albertoleal / gist:987933
Created May 24, 2011 00:35
Avoid double-raised exception in Ruby
module NoDoubleRaise
def raise(*args)
if $! && args.first != $!
warn "There is already one exception #{caller.first} raised"
exit! false
else
super
end
end
end
@albertoleal
albertoleal / hook_inherited.rb
Created June 7, 2011 11:30
Getting all subclasses
class SimpleBaseClass
def self.inherited(new_subclass)
puts "Hey #{new_subclass} is now a sublcass of #{self}!"
end
end
class SubClass < SimpleBaseClass
end
@albertoleal
albertoleal / rails.watchr
Created September 24, 2011 14:04
WatchrValidation
watch('^app/assets/stylesheets/(.*\.scss)') { |m| WatchrValidation.check_sass(m[1]) }
class WatchrValidation
@@image_root = "~/Development/autotest_images"
def self.check_sass(sass_file)
result = system("clear; sass --check app/assets/stylesheets/#{sass_file}")
image = if result
"#{@@image_root}/pass.png"
TEST'EM 'SCRIPTS!
Open the URL below in a browser to connect.
http://localhost:7357
━━━━━━━━━━━━━━┓
PhantomJS 1.5┃ Chrome 19.0 PhantomJS 1.5
0/0 ◟ ┃ 0/0 ◞ 0/0 ◞