Skip to content

Instantly share code, notes, and snippets.

# i18n
en:
activerecord:
models:
topic: Topic
attributes:
topic:
posts_body: Body
# topic
@raecoo
raecoo / gist:184436
Created September 10, 2009 09:18
many methods to validate association model in rails
# validation method 1
if @user.save && @order.save && @city.save
...
else
...
end
# validation method 2
@raecoo
raecoo / action.xml.nokogiri
Created November 1, 2010 19:10
xml builder by Nokogiri
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") { |feed|
feed.title("#{user.name}'s Private Notification Feed")
feed.link(:href => "http://#{account.subdomain}.domain.com/feeds/#{user.email_alias}.xml", :rel => "self")
feed.link(:href => "http://#{account.subdomain}.domain.com")
}
@raecoo
raecoo / gist:1347351
Created November 8, 2011 09:20
gmusic spider
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'mechanize'
require 'cgi'
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
@raecoo
raecoo / vim-commandt-flush
Created January 13, 2012 12:55
auto flush for vim + command-t
" insert into the .vimrc file.
augroup CommandTExtension
autocmd!
autocmd FocusGained * CommandTFlush
autocmd BufWritePost * CommandTFlush
augroup END
@raecoo
raecoo / gist:1815373
Created February 13, 2012 09:16
enalbe the debug stack for IIS server
# modify the CallStack="true", <customErrors mode="Off" /> and <compilation debug="true"> in web.config file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
...
<SharePoint>
<SafeMode MaxControls="200"
CallStack="true"
DirectFileDependencies="10"
TotalFileDependencies="50"
@raecoo
raecoo / gist:1931468
Created February 28, 2012 09:12
Sass load path
Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
load_paths << "#{Rails.root}/app/assets/stylesheets/lib"
end
@raecoo
raecoo / gist:2429429
Created April 20, 2012 15:04 — forked from Sutto/gist:943752
Resque Daemon Controller
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= 'development'
require File.expand_path('../../config/environment', __FILE__)
require 'daemon_spawn'
class ResqueWorkerDaemon < DaemonSpawn::Base
def start(args)
@worker = Resque::Worker.new('*') # Specify which queues this worker will process
@raecoo
raecoo / deploy.rb
Created April 21, 2012 01:48
Capistrano Recipe
require 'bundler/capistrano'
load 'deploy/assets'
set :domain, "example.com"
set :application, "application"
set :user, "deploy"
set :password, "secret"
set :use_sudo, false
set :deploy_to, "/home/#{user}/www/#{application}"
set :shared_path, "#{deploy_to}/shared"
@raecoo
raecoo / iptables-default-rules.sh
Created April 22, 2012 04:25
iptables default rules (Debian tested)
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
# You could modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and MySQLconnections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT