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
df -Th |
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
# $ tweet Hi mom! | |
# | |
# Put this in ~/.bashrc or wherever. | |
# If it doesn't work, make sure your ~/.netrc is right | |
# | |
# (Thanks to @anildigital and @grundprinzip for curl-fu) | |
function tweet { | |
curl -n -d status="$*" https://twitter.com/statuses/update.xml --insecure &> /dev/null | |
echo "tweet'd" |
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
#!/usr/bin/env ruby | |
def output_config | |
puts <<-END | |
graph_category App | |
graph_title passenger status | |
graph_vlabel count | |
sessions.label sessions | |
max.label max processes |
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
rescue_from ActionController::RoutingError, | |
ActionController::UnknownAction, | |
ActiveRecord::RecordNotFound, | |
ActionView::MissingTemplate, | |
ActionController::MethodNotAllowed, | |
WillPaginate::InvalidPage, :with => :route_not_found | |
protected | |
# 404 |
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 Post < ActiveRecord::Base | |
# ... | |
def to_param | |
"#{id}-#{title.parameterize}" | |
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
# the permalink will be updated from title only if empty | |
before_save do |post| | |
post.permalink ||= post.title.parameterize | |
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
"123".to_i #=> 123 | |
"123-my-permalink".to_i #=> 123 | |
Post.find("123-my-permalink") #=> success! |
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 ApplicationController < ActionController::Base | |
protected | |
def redirect_if_moved(record, param_key = :id) | |
redirect_to record, :status => 301 if record.to_param != params[param_key] | |
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
def redirect_if_moved(record, param_key = :id) | |
canonical = record.to_param | |
if canonical != params[param_key] | |
redirect_to(:overwrite_params => { param_key => canonical }, :status => 301) | |
end | |
end |
OlderNewer