This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bundler Integration | |
require "bundler/capistrano" | |
# Application Settings | |
set :application, "yourapplicationname" | |
set :user, "serveruser" | |
set :deploy_to, "/home/#{user}/rails-applications/#{application}" | |
set :rails_env, "production" | |
set :use_sudo, false | |
set :keep_releases, 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
n = 100000 | |
klass = Benchmark | |
Benchmark.bm do |b| | |
b.report do | |
n.times { "visit_#{(klass.name || '').gsub('::', '_')}" } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewYachtModel < ActiveRecord::Base | |
belongs_to :new_yacht | |
has_many :contents, :class_name => 'NewYachtTopicContent' | |
has_many :topics, :class_name => 'NewYachtTopic', :through => :contents | |
accepts_nested_attributes_for :contents | |
end | |
class NewYachtTopic < ActiveRecord::Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Shell script to install your public key on a remote machine | |
# Takes the remote machine name as an argument. | |
# Obviously, the remote machine must accept password authentication, | |
# or one of the other keys in your ssh-agent, for this to work. | |
ID_FILE="${HOME}/.ssh/id_rsa.pub" | |
if [ "-i" = "$1" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FormHelper | |
def nested_form_for(object, *args, &block) | |
concat form_for(object, *(args << { :builder => NestedFormBuilder }), &block) | |
execute_after_nested_form_callbacks | |
end | |
def execute_after_nested_form_callbacks | |
@after_nested_form_callbacks ||= [] | |
@after_nested_form_callbacks.inject(String.new.html_safe) do |output, callback| | |
output << callback.call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :page, lambda { |number| | |
per_page = 2 | |
limit(per_page).offset(per_page * ([number.to_i, 1].max - 1)) | |
} do | |
def per(number) | |
limit(number).offset(offset_value / limit_value * number) | |
end | |
def num_pages | |
(except(:offset, :limit).count.to_f / limit_value).ceil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require "open-uri" | |
class Video < ActiveRecord::Base | |
class YoutubeVideoValidator < ActiveModel::Validator | |
def validate(record) | |
unless record.youtube_code.include? 'youtube.com/watch?v=' | |
record.errors[:base] << "URL não é um endereço válido de um vídeo do youtube" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract public class Cliente { | |
protected double saldo; | |
public Cliente(float saldo){ | |
this.saldo = saldo; | |
} | |
public void depositar(float valor){ | |
this.saldo = this.saldo + valor; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
module ApplicationHelper | |
def sharing_on_social_networks(subject) | |
social_networks = {} | |
social_networks[:twitter] = "http://twitter.com/share?text=Estou vendo #{truncate(subject, :length => 60)} na página da Soulfitness. Veja também em&url=http://www.soulfitness.com.br" | |
String.new.html_safe.tap do |output| | |
social_networks.each_pair do |key, value| | |
output << link_to(image_tag(key.to_s + ".png", :width => 21, :height => 21), value, :class => key, :target => "_blank") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ISPLAY=:2.0 | |
NAME=Xvfb | |
INSTALL_DIR=/usr/bin | |
DAEMON=$INSTALL_DIR/$NAME | |
DAEMON_ARGS="-ac -screen scrn 1024x768x24 $DISPLAY" | |
PIDFILE=/var/run/$NAME.pid | |
DAEMON_USER=root | |
DAEMON_GROUP=$DAEMON_USER |