Skip to content

Instantly share code, notes, and snippets.

We couldn’t find that file to show.
@yaroslav
yaroslav / attachment_fu_spec_helper.rb
Created August 26, 2008 09:14
attachment_fu spec helper
# attachment_fu spec helper.
#
# Usage:
#
# before(:all) do
# before_attachment_fu(Avatar)
# end
#
# it "should do weird stuff with avatar" do
# avatar = Avatar.new
@yaroslav
yaroslav / simple.rb
Created August 29, 2008 11:14
i18n SimpleBackend: supporting lambdas for pluralization
# Picks a pluralization rule specified in translation tables for a language or
# uses default pluralization rules.
#
# This is how pluralization rules are defined in translation tables, English
# language for example:
#
# store_translations :'en-US', {
# :pluralize => lambda { |n| n == 1 ? :one : :other }
# }
#
@yaroslav
yaroslav / simple.rb
Created August 30, 2008 14:53
Ruby i18n: SimpleBackend support for CLDR-style "standalone" and "format" monthnames and daynames
LOCALIZE_ABBR_MONTH_NAMES_MATCH = /(%d|%e)?(\s*)(%b)/
LOCALIZE_MONTH_NAMES_MATCH = /(%d|%e)?(\s*)(%B)/
LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH = /^%a/
LOCALIZE_STANDALONE_DAY_NAMES_MATCH = /^%A/
# Acts the same as +strftime+, but returns a localized version of the
# formatted date string. Takes a key from the date/time formats
# translations as a format argument (<em>e.g.</em>, <tt>:short</tt> in <tt>:'date.formats'</tt>).
def localize(locale, object, format = :default)
raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
@yaroslav
yaroslav / ubiquity.yandex-lingvo.js
Created September 8, 2008 13:04
Ubiquity command for searching Yandex Lingvo translation service
makeSearchCommand({
name: "Lingvo",
url: "http://lingvo.yandex.ru/en?text={QUERY}&st_translate=1",
icon: "http://slovari.yandex.ru/favicon.ico",
description: "Searches Yandex Linvo for a translation",
});
@yaroslav
yaroslav / attachment_fu_regenerate_thumbnails.rb
Created September 15, 2008 10:50
Regenerate/update thumbnails for attachment_fu Model
def update_thumbnails
temp_file = create_temp_file
attachment_options[:thumbnails].each { |suffix, size| create_or_update_thumbnail(temp_file, suffix, *size) }
save
end
@yaroslav
yaroslav / sessions.rake
Created November 2, 2008 19:16
Rake task for Ruby on Rails for cleaning up ActiveRecord session store table from expired sessions. A bit lame (talk about logger.info not working in production) but still.
namespace :db do
namespace :sessions do
desc "Clean up expired Active Record sessions (updated before ENV['EXPIRE_AT'], defaults to 1 month ago)."
task :expire => :environment do
Rails.logger.info "Cleaning up expired sessions..."
puts "Cleaning up expired sessions..."
time = ENV['EXPIRE_AT'] || 1.month.ago.to_s(:db)
rows = CGI::Session::ActiveRecordStore::Session.delete_all ["updated_at < ?", time]
Rails.logger.info "Expired sessions cleanup: #{rows} session row(s) deleted."
puts "Expired sessions cleanup: #{rows} session row(s) deleted."
module PluralizedConsts
P = self
def const_missing(sym)
return super(sym) if Thread.current[:pc_const_missed]
begin
super(sym)
rescue NameError => e
begin
Thread.current[:pc_const_missed] = true
# by http://ptitov.ru/
if ($http_user_agent ~ "libwww|BlogSearch|picsearch|WebAlta|Gigabot|ping\.blo\.gs|Aport|Feedster|Blo
gPeople|Accelatech|RSSCrawler|blogoonbot|ia_archiver|ichiro|RSS_READER|RSS Crawler|blogfan|lwp|Java\
/|MaplogCrawler|sproose|Technoratibot|Moreoverbot|Jakarta|wadaino\.jp|MJ12bot|Sensis|msnbot|DepSpid|
Twiceler|Mail\.Ru|Slurp|Yandex/1\.01"){
set $limit_rate 300;
}