Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
@reu
reu / post.rb
Created July 23, 2011 01:52
Implementação do Enumerable
class Post
extend Enumerable
def self.files
Dir["posts/*.markdown"].sort_by { |file| File.stat(file).ctime }.reverse
end
def self.each
files.each do |entry|
File.open(entry) { |file| yield Post.new(file.read) }
@reu
reu / brackets_or_not
Created July 5, 2011 01:15
Objective-c brackets
- (id)initWithStyle:(id)style
{
...
}
or
- (id)initWithStyle:(id)style {
...
}
source ~/.vim/vimrc
set wrap nowrap
if has("gui_running")
set columns=180
colorscheme railscasts2
if has("gui_mac") || has("gui_macvim")
set guifont=Menlo:h12
@reu
reu / passenger_standalone.rb
Created May 6, 2011 17:59
Capistrano recipe for passenger standalone
set :rails_env, "production"
set :passenger_port, 9292
set :passenger_cmd, "#{bundle_cmd} exec passenger"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{passenger_cmd} start -e #{rails_env} -p #{passenger_port} -d"
end
task :stop, :roles => :app, :except => { :no_release => true } do
#!/bin/sh
# runcocoa.sh - Run any Cocoa code from the command line
#
# Michael Tyson, A Tasty Pixel <[email protected]>
#
ccflags="";
includes="";
usegdb=;
ios=;
while [ "${1:0:1}" = "-" ]; do
@reu
reu / init.d
Created April 6, 2011 17:56
RAILS_ENV=test DISPLAY=:2.0 rake db:migrate spec:acceptance
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
# 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
abstract public class Cliente {
protected double saldo;
public Cliente(float saldo){
this.saldo = saldo;
}
public void depositar(float valor){
this.saldo = this.saldo + valor;
}
@reu
reu / video.rb
Created February 23, 2011 16:24
# 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
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