Skip to content

Instantly share code, notes, and snippets.

#!/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
(function($) {
$.fn.myPlugin = function(settings) {
var config = {'foo': 'bar'};
if (settings) $.extend(config, settings);
this.each(function() {
// element-specific code here
});
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
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]
# 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.
def title(title = t('.title'))
@page_title = title
end
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
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
"123".to_i #=> 123
"123-my-permalink".to_i #=> 123
Post.find("123-my-permalink") #=> success!