Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
#!/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 / 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
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 / brackets_or_not
Created July 5, 2011 01:15
Objective-c brackets
- (id)initWithStyle:(id)style
{
...
}
or
- (id)initWithStyle:(id)style {
...
}
@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 / gist:1211986
Created September 12, 2011 18:24
iptables
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT
-A INPUT -p udp -i eth0 --sport 53 --dport 1024:65535 -j ACCEPT
-A OUTPUT -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p tcp -i eth0 --dport 22 --sport 1024:65535 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -i eth0 --dport 80 --sport 1024:65535 -m state --state NEW -j ACCEPT
-A OUTPUT -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED -o eth0 -p tcp -m multiport --dport 80,443 -m multiport --sport 1024:65535
-A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED -i eth0 -p tcp
-A INPUT -j DROP
@reu
reu / routes.rb
Created September 18, 2011 19:59
Dynamic root_url based on the user being logged or not
root :to => "home#show", :constraints => UserLoggedConstraint.new(false)
root :to => "profile#show", :constraints => UserLoggedConstraint.new(true)
@reu
reu / gist:1244065
Created September 27, 2011 01:41
AR::Relation with attr_encrypted monkey patch
module AttrEncryptedRelation
def self.included(base)
base.class_eval do
alias_method_chain :build_where, :attr_encrypted
end
end
private
def build_where_with_attr_encrypted(opts, other = [])
class String
def encrypt(options = {})
crypt :encrypt, options
end
def decrypt(options = {})
crypt :decrypt, options
end
private
class User
has_many :posts
end
class Post
belongs_to :user
has_many :comments
def self.search(comment_description)
joins(:comments).where(:comments => { :description => comment_description })