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/bash | |
# | |
# Download and install libevent and memcached from source on Debian Etch or | |
# Debian Lenny. | |
# | |
# Assumptions | |
# - libevent and memcached have not been installed from apt repositories | |
# - memcached is not already running | |
# - it is ok to clobber scripts at | |
# /etc/memcached.conf |
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
(function($) { | |
$.fn.myPlugin = function(settings) { | |
var config = {'foo': 'bar'}; | |
if (settings) $.extend(config, settings); | |
this.each(function() { | |
// element-specific code here | |
}); |
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
before_validation :clear_empty_attributes | |
protected | |
def clear_empty_attributes | |
attributes.each do |key,value| | |
self[key] = nil if value.is_a?(String) && value.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
class AvatarUploader < CarrierWave::Uploader::Base | |
include CarrierWave::RMagick | |
storage :file | |
def store_dir | |
"assets/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | |
end | |
version :thumb do | |
process :resize_to_fill => [60, 60] |
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
# To stop apache2 for this session only: | |
sudo /etc/init.d/apache2 stop | |
# To remove apache2 permanently from startup scripts: | |
sudo update-rc.d apache2 remove | |
# To reinstate apache2 in the startup scripts: | |
sudo update-rc.d apache2 defaults | |
# Or edit /etc/default/apache2 as root and set NO_BOOT to 1. |
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 title(title = t('.title')) | |
@page_title = title | |
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 |
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
"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
# the permalink will be updated from title only if empty | |
before_save do |post| | |
post.permalink ||= post.title.parameterize | |
end |