Skip to content

Instantly share code, notes, and snippets.

View norman's full-sized avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
$ gem install date-performance
Building native extensions. This could take a while...
ERROR: Error installing date-performance:
ERROR: Failed to build gem native extension.
/Users/norman/.rvm/rubies/ruby-1.9.1-p378/bin/ruby extconf.rb
creating Makefile
make
gcc -I. -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/i386-darwin10.2.0 -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/backward -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -pedantic -Wall -Wno-long-long -Winline -o date_performance.o -c date_performance.c
class Sitemap
attr_accessor :entries
def add(array, &block)
array.map do |a|
if entry = block(a)
@entries << entry
end
end
require "mocha"
Factory.define :post do |p|
p.title "first post"
p.after_build do |post|
slug = Slug.new(:name => "first-post", :sequence => 1, :sluggable => post)
post.stubs(:slug).returns(slug)
end
end
$ irb
ruby-1.9.1-p378 > string = "Jürgen Müller"
=> "Jürgen Müller"
ruby-1.9.1-p378 > string.force_encoding("BINARY").encode("UTF-8", :invalid => :replace, :replace => "")
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
from (irb):2:in `encode'
from (irb):2
from /Users/norman/.rvm/rubies/ruby-1.9.1-p378/bin/irb:17:in `<main>'
ruby-1.9.1-p378 >
module MyApp
module Friendly
def self.included(base)
base.has_friendly_id :custom_slug, :use_slug => true, :approximate_ascii => true
end
def custom_slug
if @custom_slug.present?
From a62b79e86cb2ad973578be43d93f79890ed0ab4d Mon Sep 17 00:00:00 2001
From: Norman Clarke <norman@njclarke.com>
Date: Wed, 7 Apr 2010 16:21:41 -0300
Subject: [PATCH] Make tidy_bytes work on 1.9 and improve its performance. [#4350 state:resolved]
---
.../lib/active_support/multibyte/chars.rb | 85 +++++++++++++++----
activesupport/test/multibyte_chars_test.rb | 73 +++++++++++------
2 files changed, 114 insertions(+), 44 deletions(-)
From 059e245874dd38843986a8c0226c4dfad835bfff Mon Sep 17 00:00:00 2001
From: Norman Clarke <norman@njclarke.com>
Date: Mon, 12 Apr 2010 12:44:25 -0300
Subject: [PATCH] Improve reliability of Inflector.transliterate. [#4374 state:resolved]
---
.../lib/active_support/inflector/transliterate.rb | 61 ++++++++++++--------
activesupport/test/inflector_test_cases.rb | 5 +-
activesupport/test/transliterate_test.rb | 50 ++++++++++++++++
3 files changed, 91 insertions(+), 25 deletions(-)
# Ruby surprisingly clears the value of the $1 variable after a return
def test_gsub
result = "a".gsub(/(a)/, "b")
p $1
result
end
test_gsub
p $1
I18n.backend.store_translations(:foo, :test => {:a => "b"})
I18n.backend.store_translations(:foo2, :test => lambda {|*args| args.join(", ")})
p I18n.t 'test', :locale => :foo # {:a=>"b"}
p I18n.t 'test', :locale => :foo2 # "test, "