Ruby/html trick: wrap long strings with invisible wordwrap characters
def wrap_long_string(text,max_width = 20)
(text.length < max_width) ?
text :
text.scan(/\S{1,#{max_width}}/).join(“<wbr>“)
end
I blog here occasionally. I hope you like it.
Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!
Reach me at yan at pritzker.ws
def wrap_long_string(text,max_width = 20)
(text.length < max_width) ?
text :
text.scan(/\S{1,#{max_width}}/).join(“<wbr>“)
end
TechCrunch is reporting on rumors that twitter is leaving Ruby on Rails. Of course the comment threads are covered by a heated debate by people either bashing RoR, suggesting their favorite language and platform as the ‘only possible solution’, or both. Nevermind that Friends For Sale, with 630k active daily users scales just fine on [...]
If you experience problems running single unit tests in TextMate with Rails 2, it may be due to a bug. The problem has something to due with conflicting builder.rb instances in Rails and TextMate. The simplest and least intrusive fix is to add this to the top of your test_helper.rb
$LOAD_PATH.reject! { |e| e.include? ‘TextMate’ }
def self.bot_agent_list
[ "panscient", "larbin", "dummy", "Teoma", "alexa",
"froogle", "inktomi", "looksmart", "URL_Spider_SQL",
"Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK",
"InfoSeek", "WebFindBot", "crawler", "girafobot", "Scooter",
"Baidu", "bot", "Google", "SiteUptime", "Slurp",
[...]
acts_as_versioned is a great plugin for versioning a set of model attributes transparently every time you save. The plugin seems to be built with exclusion in mind (version all except these) but to get it to work only on a specific set of columns, this simple trick can be applied:
class Foo [:description_t]
def [...]
If you find capistrano’s release directory naming conventions hard to use, a great alternative is to base releases on your svn tags. It turns out that implementing this in cap2 is quite simple. Unfortunately I can’t quite figure out how to turn this into a library so at this point it exists as a cut-n-paste [...]
This is a simple trick based on the idea that everything in ruby returns a result. By using the block syntax we can do a series of expensive operations and cache the result somewhere. Here I’ve shown the result cached in an instance variable but it may just as well be something more exotic.
[...]
Recently launched Noobkit is a great new way to get at your Rails API docs. The visual design is pleasing and it’s got an OpenID login system and ability to make bookmarks. It covers the Rails API and many common gems. The look is much more pleasing than the similar gotapi.com which covers more programming [...]
While working on Planypus we recently ran into an issue where something was outputting strange messages to the console. Luckily, Anton Mostovoy figured out a clever dynamic Ruby hack to track who was outputting the message:
$stdout.instance_eval do
alias :inner_puts :write
def write (str)
inner_puts %Q!#{str} was said by #{caller.join(”\n”)}!
end
end
Like Magic!
© skwpspace. Powered by WordPress using a DePo Clean Theme modified by Yan Pritzker.