RedCloth 4.0 Released: 40x Faster Textile Rendering

Posted 2 days back at Ruby Inside

redcloth.png

RedCloth is a popular Ruby library for converting Textile-formatted text into HTML. Initially developed by WhyTheLuckyStiff, it's now under the guardianship of Jason Garber, who has just released version 4 (RubyForge or Github). This is a significant update, following on from 3.0.4 which was released almost three years ago, and features a handful of significant improvements and changes:

  • New SuperRedCloth (RedCloth 4.0) is a total rewrite using Ragel for the parsing.
  • Markdown support has been removed.
  • Single newlines become <br> tags, just as in traditional RedCloth and other Textile parsers.
  • HTML special characters are automatically escaped inside code signatures, like Textile 2. This means you can simply write @<br />@ and the symbols are escaped whereas in RedCloth 3 you had to write @&lt;br /&gt;@ to make the code fragment readable.
  • HTML embedded in the Textile input does not often need to be escaped from Textile parsing.
  • The parser will not wrap lines that begin with a space in paragraph tags.
  • Rudimentary support for LaTeX is built in.
  • RedCloth::VERSION on a line by itself inserts the version number into the output.
  • Output (less newlines and tabs) is identical to Textile 2 except a few cases where the RedCloth way was preferable.
  • Over 500 tests prevent regression
  • It's 40 times faster than the previous version.

Unless fiddling with the edge version on Github interests you, you can install or update with gem in the usual way - gem install redcloth, etc.

What's New in Edge Rails: Standard Internationalization Framework

Posted 2 days back at Ryan's Scraps

Internationalization (i18n) is a tough nut to crack and has long been handled in Rails by a variety of plugins. Thanks to a concerted effort by the Rails i18n team we now have a standardized framework for providing internationalization.

Rather than rehash what’s already out there, head over to Sven’s writeup of the new Rails Internationalization framework for the skinny.

It’s important to note that this does not provide actual language translations but merely a way for you to plug in other translations and internationalization implementations into your app.

tags: ruby, rubyonrails

FOSCON: Ruby Event in Portland, OR - July 23, 2008

Posted 2 days back at Ruby Inside

foscon.png

FOSCON is a "free, fun gathering" of Ruby developers held alongside the O'Reilly OSCON conference currently taking place in Portland, Oregon. It's tomorrow (Wednesday, July 23) at CubeSpace (near the Oregon Convention Center) from 6pm. The always proactive Portland Ruby Brigade have organized it, and a surprising number of interesting presentations are already planned, including one on IronRuby from John Lam of Microsoft. A live coding competition will also be taking place.

Unix Signals for Live Debugging

Posted 2 days back at igvita.com

It's unit tested, the integration and regressions tests are all green, you even added a set of performance benchmarks, and yet after a couple of hours of production use the process is falling over - we've all been there before. Good instrumentation in these situations is worth its weight in gold. If you're lucky, you may be able to use DTrace, if you're adventurous you may try to attach with GDB, but what if you build this instrumentation into your app right from the start?

System signals for easy debugging

Any UNIX process can respond to a collection of system signals, and what's even better: we can safely define a subset (USR1, and USR2) to invoke arbitrary logic within our process. For example, let's create a worker process which on receipt of a USR1 signal will toggle debug mode on demand:

> debug-mode.rb

require 'rubygems'
require 'log4r'
 
# initialize the logger
@log = Log4r::Logger.new 'log'
@log.outputters = Log4r::StdoutOutputter.new 'console'
@log.level = Log4r::INFO
 
worker = Thread.new do
  while (true) do
    @log.info 'Hello!'
    @log.debug 'Debug!'
    sleep(1)
  end
end
 
# put worker into debug mode via USR1 signal
trap("USR1") {
 @log.level = @log.level == Log4r::INFO ? Log4r::DEBUG : Log4r::INFO
}
 
# cleanly shutdown the thread on Ctrl-C / kill signal
trap("INT") { worker.terminate }
 
# run the worker
worker.join
 

In the example above Log4r provides us with a convenient logging hierarchy: DEBUG < INFO < WARN < ERROR < FATAL. By sending our process a USR1 signal (kill -s USR1 pid), we toggle between the INFO and DEBUG levels, allowing ourselves the luxury of performing live debugging without incurring the cost of redundantly logging debug information when we don't need it. Now you have the tools to perform that open-heart surgery.

INFO log: Hello! < process is started
INFO log: Hello!
INFO log: Hello! < process receives USR1
DEBUG log: Debug!
INFO log: Hello!
DEBUG log: Debug! < process receives USR1
INFO log: Hello!
INFO log: Hello!

For bonus points, check what signals your favorite UNIX processes respond to. For example, did you know that kill -s USR1 mongrel_pid will turn on debug mode on any Mongrel process? Make use of system signals, they're there for reason!

ActionScript: Literal XML

Posted 2 days back at Jay Fields Thoughts

One feature of ActionScript I really like is the ability to use XML within the language. In ActionScript there's no need to use strings to represent XML, you can use XML inline just as you would any other literal (numbers, strings, etc).

Recently I was working on some dynamic code that needed to update based on an XML response. We were just getting started on the card, so instead of worrying about the service, how it was triggered, etc, we added a button to the interface that called the response parsing method and passed in an XML literal as an argument. The code is similar to what's shown below.

parseResponse(<user><firstName>Jay</firstName></user>);

Sure, we had to change the code later and make a real service call, but this quick solution let us keep focusing on the task at hand instead of how to get the XML. In a language like Ruby we could have used a builder or just a string, and given such a small amount of XML it would have been fine. However, the actual XML we were working with was significantly larger than the example and would have been a decent mess of a multiline string or several builder calls. Being able to write XML natively was significantly easier.

The beauty of literal XML is the simplicity. I don't have to represent it in any way other than what it actually is -- XML.

If you aren't a fan of all the angle brackets, that's okay, ActionScript has you covered there also. You can add elements and attributes as you would expect to be able to if you prefer method calls.

var request:XML = <smart_list/>;
request.sort.order = "highest";
request.sort.field = "Average Position";
request.max_results = 10;
request.toXMLString(); // "<smart_list><sort><order>highest</order><field>Average Position</field></sort><max_results>10</max_results></smart_list>"

If you only ever use XML similar to the above syntax, then there may be little value in literal XML, but I don't think you're usage would be limited to the above syntax.

I write tests, a lot of them. I prefer to see the actual XML in my tests, instead of the builder versions of XML. I don't like angle brackets any more than the next programmer, but I strongly prefer testing with expected literals. I find my resulting tests to be more readable and reliable. If you've ever had a test fail because of whitespace issues in your XML, you should know what I mean by reliable.

Literal XML also ensures XML compliance at compile time and encourages IDEs to provide syntax highlighting. Two things that aren't essential, but are definitely nice to have.

ActionScript is the first language I've used with literal XML support, and I'm very happy with the experience. As programmers we spend a lot of time hiding other languages with object relational mappers (orm) and builders, but literal XML is a refreshing step in the other direction. The creators of ActionScript have embraced the fact that XML isn't going anywhere. They built first class support for XML in the language itself instead of hiding the problem with a framework, and that helps me significantly more than any orm or builder ever has.

You See the Invisible Block?

Posted 2 days back at Marc-André Cournoyer's blog



require "rubygems";require "thin";require"markaby"; class Invisible
HTTP_METHODS =[:get,:post,:head,:put,:delete];attr_reader :request,
:response, :params; def initialize(&block); @actions =[]; @with=[];
@layouts={};@views={};@helpers=Module.new;@app=self; instance_eval(
&block) if block end; def action(method, route, &block); @actions<<
[method.to_s, build_route(@with*"/"+route),block] end;HTTP_METHODS.
each{|m|class_eval "def #{m}(r='/',&b); action('#{m}', r, &b) end"}
def with(route); @with.push(route);yield;@with.pop end; def render(
*args,&block);options=args.last.is_a?(Hash)?args.pop: {};@response.
status=options.delete(:status)||200;layout=@layouts[options.delete(
:layout)||:default];assigns={:request=>request,:response=>response,
:params=>params,:session=>session};content=args.last.is_a?(String)?
args.last : Markaby::Builder.new(assigns,@helpers, &(block||@views[
args.last] )).to_s ; content = Markaby::Builder.new( assigns.merge(
:content => content), @helpers, &layout).to_s if layout; @response.
headers.merge!(options);@response.body=content end;def layout(name=
:default, &block); @layouts[name]=block end; def view(name,&block);
@views[name]=block end; def helpers(&block);@helpers.instance_eval(
&block ) ; instance_eval(&block)  end;  def session;  @request.env[
"rack.session"]end; def use(middleware, *args);@app=middleware.new(
@app,*args) end; def run(*args);Thin::Server.start(@app, *args) end
def call(env); @request = Rack::Request.new(env); @response =Rack::
Response.new; @params = @request.params; if action = recognize(env[
"PATH_INFO"], @params["_method"] ||env["REQUEST_METHOD"]); @params.
merge!(@path_params);action.last.call;@response.finish; else; [404,
{}, "Not found"]; end; end; def self.run(*args,&block);new(&block).
run(*args) end; def self.app;@app||=self.new end;def self.call(env)
@app.call(env) end; private; def build_route(route);pattern= route.
split("/").inject('\/*') { |r, s| r << (s[0] == ?: ? '(\w+)' : s) +
'\/*' } + '\/*';[/^#{pattern}$/i,route.scan(/\:(\w+)/).flatten] end
def recognize(url, method); method =method.to_s.downcase; @actions.
detect do |m,(pattern,keys),_| method==m&&@path_params=match_route(
pattern,keys,url)end;end;def match_route(pattern,keys,url);matches,
params=(url.match(pattern)||return)[1..-1],{};keys.each_with_index{
|key,i| params[key]=matches[i]};params;end;end; def method_missing(
method, *args,  &block);  ; if Invisible.app .respond_to?(method) ;
Invisible.app. send( method, *args, &block);  else; super; end; end

No!

beauty is fleeting (or why rails-doc isn’t the answer but something else might be)

Posted 2 days back at omg blog!! lol!!

So my last post, for whatever reason, spawned a flurry of posts pointing to rails-doc, a project by a team from Nodeta, claiming that it solved a number of Rails documentation problems. It’s a very nice looking project with a sexy theme (their blog design is especially attractive), but I’m sort of having a problem seeing how this solves any sort of problem that hasn’t been “solved” before.

sexy much?

For those of you too new to Rails to remember, there was (and apparently still is a project) named Rails Manual that does the exact same thing in a less attractive shell.  It’s based on a project named Rannotate, which creates a Rails app from your Ruby project’s documentation and enables adding notes to it.  It garnered a little attention when it first came out, but eventually went the way of the buffalo.

So now we have rails-doc.  Like I said, it looks good, but it strikes me as the exact same thing.  It’s basically the RDoc’s with notes, which solves a piece of the problem, but it’s not anywhere near a total fix for the poor documentation situation (even though I think some people are on the right track!).  If I’d known that all we needed was a good looking RDoc app, I could’ve fixed the problem a while ago.

That’s a screenshot of the design that my Google Summer of Code student (Ian Ownbey) and I are currently working on applying to his project Docbox and my derivative project Docdock (which will be on my Github very soon). 

Docbox is like Rannotate and friends (it lets you add notes, browse, search, etc.) except it also lets users actually edit the documentation in their browser.  It will then take their edits and generate a git commit on its own branch on the backend that the developers can cherry pick back into the mainline documentation.  You want to talk about user contribution?  There it is.  I’m waiting for my student to deploy to a slice and I’ll link that demo site here.  The plan is to let you edit the docs on a sample app and see your changes get pushed straight to a Github project so you can see it happen in near real-time. :)

My project is slightly less glamorous.  Docdock is essentially a client facing application based on Docbox.  Projects like Rails or a company with a closed source Ruby product could use Docdock to have an API site that users can visit, add notes to, and get involved with that looks good but without allowing everyone to edit it.  Larger or proprietary projects probably don’t want their official doc site to be totally editable. :)  The good thing about Docdock is that it can actually hook into the same database as Docbox, so you can have an instance of Docbox running on the backend for your team and an instance of Docdock running on the front end for your users.  This will probably just create a separate connection to keep everything separate except for the documentation objects, but I haven’t gotten quite that far yet.

So, there you go.  Two documentation tools geared towards user contribution.  Oh, and did I mention they’re both totally open source and applicable to any Ruby project, not just Rails?  I didn’t bring them up before because I didn’t know how interested people would be, but if people get excited about a resurrected Rannotate with dcov and search thrown in, then surely people will find these tools useful.

RubyFringe == Awesome

Posted 2 days back at Marc-André Cournoyer's blog


RubyFringeNick Sieger though us about Jazz, Giles Bowkett got a standing ovation, Zed Shaw sang “Matz can’t patch” and “Don’t fuck Chad’s community”, Geoffrey Grosenbach was wearing a kilt, Hampton Catlin presented Haml for Javascript, Damien Katz made me cry and Tom Preston-Werner is my new hero.

Better reviews

Starling: A Ruby Persistent Queue Server That Speaks Memcached

Posted 2 days back at Ruby Inside

starling.png

It's been around for a while now, but Starling is a "light-weight persistent queue server that speaks the MemCache protocol." Starling makes it ridiculously easy to set up a network-accessible queue (or many queues) for, say, asynchronous job processing between multiple processes and machines. It was developed by Twitter to handle the heavy amount of queueing necessary to keep their service ticking over. Starling is proven in production, with not only Twitter using it in anger, but FiveRuns too. FiveRuns have even created their own fork that, they say, is significantly faster.

Why the sudden interest in Starling? Well, Glenn Gillen has written an excellent introductory guide to setting up Starling over at RubyPond.com. He walks through the process of using Starling (and Workling, a Rails plugin to make using Starling easier) from installation, through to actually adding things to the queue and processing them.

An interesting alternative to Starling is also presented within the comments on Glenn's post - RudeQ. RudeQ uses the same API as Starling but is ActiveRecord / database based, meaning there's no extra process to monitor. I suspect it's nowhere near as fast, but if you'd rather avoid the headache of monitoring another persistent process or don't have the option of having a persistent process at all (shared hosting, perhaps) it's worth checking out.

Post supported by Brightbox: Brightbox is a specialist European Rails hosting company. Each Brightbox server includes an optimised Ruby on Rails stack, SAN storage and access to a managed MySQL database cluster. They also manage dedicated clusters for large scale Rails deployments. Click here to learn more...

Google Introduces Binary Encoding Format: Protocol Buffers

Posted 2 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Google caused a stir by releasing Protocol Buffers, a binary serialization format. We take a look at what exactly Protocol Buffers are and what alternatives are available in ASN.1 or Facebook's Thrift. By Werner Schuster

Databases Roundup: Data Sharding for ActiveRecord and Faster Postgres IO

Posted 2 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

In this databases roundup we take a look at DataFabric, FiveRun's recently open sourced data sharding plug-in for ActiveRecord. Also: a look at speeding up Postgres data access using the asynchronous client API and Ruby 1.9's Fibers. By Mirko Stocker

RubyFringe Roundup: The Best Ruby Conference Ever?

Posted 3 days back at Ruby Inside

rubyfringecrowd.png
(Photo credit: Kieran Huggins)

RubyFringe - described as a "pricey, limited-attendance smoozefest" by Ruby documentation co-ordinator James Britt or as "an avant-garde conference for developers that are excited about emerging technologies outside of the Ruby on Rails monoculture" by the organizers - went ahead last week and appears to have been a significant hit. A small conference with a reasonably high ticket price (though far less than RailsConf Europe!), RubyFringe was set to be a very unique sort of conference with parties, drinks and out-of-hours entertainment laid on, and a limited number of tickets made available to ensure a more intimate gathering. The gamble appears to have paid off.

Praise

I'm not quite sure exactly what went down (I had to pull out of attending) but all references I've seen have been almost over-the-top with excitement and praise:

Soleone says: "Rubyfringe was amazing! So many good talks and great people. Best talk: Giles' presentation on computer generated music. Laughed my ass off!"

Rob Sanheim says: "rubyfringe was a blast, and now i can't sleep."

Lennon Day-Reynolds says: "RubyFringe after-party unsurprisingly turned out to be awesome."

Josh Merchant described it as "an amazing - inspirational - creative- experience."

Heck, there are far too many positive mentions to read on Twitter.

Mark McGranaghan of TechCrunch wrote directly to Ruby Inside:

RubyFringe was a huge win. Unspace set out to raise the bar for software conferences, and I think that they succeed. I hope that RubyFringe does for web conferences what Rails did for web development; show others that there is a better way, that it does not require corporate sponsorship, and that it can fun, artistic, and productive all at the same time.

Content

There are over 1000 photos from the event on Flickr.

Joey deVilla has put together some handy notes for most of the presentations.

Rowan Hick has put together a list of his RubyFringe highlights.

InfoQ attended the event and, I am told, will be putting up videos of several presentations on their site soon. Until then, the content of the talks is summarized here.

The next RubyFringe?

With such success, it's inevitable another RubyFringe conference will take place within the next year. If you're interested, Pete Forde suggests joining the Google group, and keeping an eye on RubyFringe.com for more info (although it'll be here at Ruby Inside too). It remains to be seen if the success of RubyFringe will encourage "avant garde" conferences elsewhere in the world or for non Ruby communities generally, but Ruby Inside wants to hear about them if so.

hasiphone.com now with US map

Posted 3 days back at OnRails.org

Thanks to the Degrafa library I was able to add a “US Map of iPhone 3G” Availability in an hour to the hasiphone.com application.

20080721_hasiphoneusmap.png

Also I automated the extraction part of the data and check every hour if new data is there. I was assuming that the data changes only once a day and therefore all the delta (the + and – next to the availability) are based on previous day. This morning there were only four stores with iPhones, and hour ago 76 and now 78. So it seems that the data is updated more frequently or I have a bug in my extraction routing. Whatever the situation I am leaving on vacations for the next two weeks and won’t take my notebook with me, so hopefully the data is correct. My good friend Sol will keep an eye on the extraction process to see that we get some daily data. Thanks Sol, ya da man.

Enjoy! Daniel.

is cool

Practical Prototype and script.aculo.us book hot off the presses

Posted 3 days back at mir.aculo.us - Home

Practical Prototype and script.aculo.usPrototype Core team member Andrew DuPont’s new book Practical Prototype and script.aculo.us is now available, and it’s a super no-nonsense guide to getting up to speed with the libraries, fast.

Andrew, being a UI developer by heart, doesn’t mess around and gives you hands-on examples for just about everything you can do with the “fraternal twins” Prototype and script.aculo.us.

You’ll learn how to really use all those fancy Prototype collection helpers (like each, detect, select, reject, partition, etc.), master the cool new custom events system, and seriously mess with the DOM; and how’ll see how Prototype can help you with everyday programming tasks with its extensions to functional programming and OOP. Plus of course how to make the most of Ajax and JSON. Last but not least, visual effects are explained, and also how they work by taking advantage of the DOM and how web browsers render websites.

The very interesting closing chapter shows you why things are as they are in Prototype, and will help you read the source code—and write JavaScript, Prototype-style.

Internet Explorer 6 on its way out (or not)?

Posted 3 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Since attaining a peak of about 95% usage share during 2002 and 2003, Internet Explorer 6 (IE6) has been rapidly losing market share. As the end of 2008 approaches, significant online services, vendors and web frameworks are dropping support for IE6. Will this year be the end of IE6 and what does this signify for Web 2.0 developers? By Dionysios G. Synodinos


1 2 3 4 5 ... 474