Skip to content

Instantly share code, notes, and snippets.

Avatar
🇪🇪
Water, earth and air.

Dmitry Polushkin dmitry

🇪🇪
Water, earth and air.
View GitHub Profile
View gist:267671
module Rack
class LocaleSetter
def initialize app
@app = app
end
def call env
locale = env["HTTP_HOST"].match(/^[a-z]{2}(?=\.)/)
I18n.locale = locale ? locale.to_s : 'es'
@app.call env
View Rails CMS alternatives
Rails CMS alternatives
======================
Note: project activity was checked on 11/26/09 for most of these projects, and the "last update" field has not been kept up to date since then.
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
View datasize.rake
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
View simple_enum_blank_fix.patch
diff --git a/lib/simple_enum.rb b/lib/simple_enum.rb
index 9c1fa3f..68792a1 100644
--- a/lib/simple_enum.rb
+++ b/lib/simple_enum.rb
@@ -165,8 +165,8 @@ module SimpleEnum
# generate setter
define_method("#{enum_cd}=") do |new_value|
- v = new_value.nil? ? nil : values[new_value.to_sym]
- raise(ArgumentError, "Invalid enumeration value: #{new_value}") if (options[:whiny] and v.nil? and !new_value.nil?)
View paperclip_extensions.rb
module Paperclip
class Attachment
class UploadedPath
attr_reader :original_filename, :content_type, :size, :path
def initialize(uploaded_file)
@original_filename = uploaded_file["name"].downcase
@content_type = uploaded_file["content_type"].to_s.strip
@file_size = uploaded_file["size"].to_i
@path = uploaded_file["path"]
View .irbrc.rb
# Put this content to ~/.irbrc file (no extension)
require "rubygems"
begin
require "ap"
rescue LoadError => err
puts "Cannot find awesome_print gem. Please run 'gem install awesome_print' to install it."
end
View cancan.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :admin
can :manage, :all
else
can :read, :all
View Formtastic :as => :textile
module FormtasticExtensions
module Formtastic
module TextileEditor
def self.included(base)
base.class_eval do
@javascript_included = false
end
end
View simple_breadcrumbs.rb
module SimpleBreadcrumbs
module Breadcrumbs
Element = Struct.new(:name, :path, :controller)
class Builder
def initialize(context, elements, options)
@context = context
@elements = elements
@options = {:separator => " » ", :wrapper => nil}.merge(options)
end
View has_many_ids.rb
class ActiveRecord::Base
def self.has_many_ids(association, ids, options={})
options = {:typecast => :to_sym}.merge(options)
method_name = :"#{association.to_s.singularize}_#{ids.to_s.pluralize}"
define_method method_name do
self.send(association).map(&ids)
end