Skip to content

Instantly share code, notes, and snippets.

View clemens's full-sized avatar
:octocat:
Getting sh*t done

Clemens Kofler clemens

:octocat:
Getting sh*t done
View GitHub Profile
class DateTimeSelector
include TagHelper
POSITIONS = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
def initialize(date, options={})
@date = date
@options = options
@object = @options.delete(:object)
@object_name = @options.delete(:object_name)
Object.class_eval do
def deep_clone
Marshal::load(Marshal.dump(self))
end
end
Array.class_eval do
def sum
self.inject(0) { |sum, element| sum += element }
end
ActionController::Base.logger.info "[Base] Loading config/initializers/" + File.basename(__FILE__)
class String
def to_permalink
text = self.dup
replacements = {
# replacement special character(s) to be replaced
"A" => [ "À", "Á", "Â", "Ã", "Å"],
"Ae" => [ "Ä", "Æ" ],
"C" => [ "Ç" ],
# config
:number => {
:format => {
:precision => 3,
:separator => '.',
:delimiter => ','
},
:currency => {
:format => {
:unit => '$',
def number_to_human_size(number, *args)
return number.nil? ? nil : pluralize(number.to_i, "Byte") if number.to_i < 1024
options = args.extract_options!
options.symbolize_keys!
defaults, human = I18n.translate([:'number.format', :'number.human.format'], :locale => options[:locale]) || [{},{}]
defaults = defaults.merge(human)
unless args.empty?
[11:21pm] clemensk: my idea is to pretty much remove the DATE_FORMATS constants and deprecate them
[11:21pm] clemensk: like it has been done with the COUNTRIES in the form options helper
[11:21pm] clemensk: and instead have a DEFAULT_FORMATS constant
[11:22pm] clemensk: that holds all the formats that are used internally by rails
[11:22pm] clemensk: like :db, :number and :rfc822
[11:22pm] clemensk: assume someone calles Time.now.to_s(:long)
[11:22pm] clemensk: this would first do a lookup in DEFAULT_FORMATS
[11:23pm] clemensk: and then, if it doesn't find it there, it'd do I18n.localize(self, format)
[11:23pm] clemensk: and if it's not stored in the locale either, it falls back to to_default_s
[11:23pm] svenfuchs: hi peeps
# with :show_sign option and extended :format
def number_to_currency(number, options = {})
options.symbolize_keys!
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :raise => true) rescue {}
defaults = defaults.merge(currency)
precision = options[:precision] || defaults[:precision]
unit = options[:unit] || defaults[:unit]
@clemens
clemens / gist:9188
Created September 6, 2008 19:39 — forked from svenfuchs/gist:9186
Who's up to a post-railsconfeu08-coolest-quotes-tshirt-site?
Rails doesn't scale! (Oscar Wilde)
Look at all the things I'm not doing! (DHH)
Most people don't need Zulu on your website. (Josh Harvey)
Fork this + add your favorite quotest!
@clemens
clemens / gist:9189
Created September 6, 2008 19:42 — forked from svenfuchs/gist:9186
Who's up to a post-railsconfeu08-coolest-quotes-tshirt-site?
Rails doesn't scale! (Oscar Wilde)
Look at all the things I'm not doing! (DHH)
Most people don't need Zulu on your website. (Josh Harvey)
t :rails (Sven Fuchs)
Fork this + add your favorite quotes!
Processing ApplicationController#index (for 127.0.0.1 at 2008-09-13 18:23:53) [GET]
Session ID: BAh7CDoKbW9udGhpDjoJeWVhcmkC2AciCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--0b0ba3c6eee1b81e8ed36c05e8beac6153ec9c3c
Parameters: {}
Rendering template within layouts/application
Rendering /Users/clemens/Rails/Projects/events_moedling/app/views/errors/404.html.erb (404)
SQL (0.2ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
Event Load (1981.6ms) SELECT DISTINCT(taggings.taggable_id), events.*, opening_hours.details AS opening_hours_details, opening_hours.day AS day FROM `events` INNER JOIN `opening_hours` ON `opening_hours`.visitable_id = `events`.id AND `opening_hours`.visitable_type = 'Event' INNER JOIN `locations` ON `locations`.id = `events`.location_id INNER JOIN `cities` ON `cities`.id = `locations`.city_id INNER JOIN `opening_hours` opening_hours_events ON `opening_hours_