Channels
Displaying page 53
Favorite
Posted 6 months ago at Ruby Quicktips

ActiveSupport adds some methods to convert strings into dates/times. It’s very nice, take a look.

Instead of

>> Date.parse('2010-01-12')
=> Tue, 12 Jan 2010

you can do:

>> '2010-01-12'.to_date
=> Tue, 12 Jan 2010

It’s more intuitive and readable!

Check out the api docs.

back to top
Favorite
Posted 6 months ago at Aman King's Bliki

back to top
Posted 6 months ago at A Fresh Cup

Yesterday, I wrote code. So, fewer resources this morning.

  • Trailhead - "Heatmap visualization on the cheap" to help you figure out what parts of your page people look at and click on.
  • Tweetstream - "Easy access to everything you've ever tweeted."

back to top
Posted 6 months ago at Tuxicity

This tip is just a distribution of a piece of code from Steve Yegge's Emacs conf. It swaps the position of two windows. Very handy!

(defun swap-windows ()
  "If you have 2 windows, it swaps them."
  (interactive)
  (cond ((/= (count-windows) 2)
         (message "You need exactly 2 windows to do this."))
        (t
         (let* ((w1 (first (window-list)))
                (w2 (second (window-list)))
                (b1 (window-buffer w1))
                (b2 (window-buffer w2))
                (s1 (window-start w1))
                (s2 (window-start w2)))
           (set-window-buffer w1 b2)
           (set-window-buffer w2 b1)
           (set-window-start w1 s2)
           (set-window-start w2 s1))))
  (other-window 1))

I bound C-c s to the function:

(global-set-key (kbd "C-c s") 'swap-windows)

back to top
Posted 6 months ago at The Geek Talk

Who is Steve Jenson?

A programmer living in San Francisco, CA. I write software in Scala and Ruby at Twitter, Inc where I work on the Infrastructure team.

Ruby or Scala?

Both.

Ruby gives you a lot of flexibility at runtime to change your environment and integrates well into my unix workflow.
Scala gives you wonderful tools for constructing software algebraically and a well tuned runtime for writing servers.

What does your typical day look like?

I’m out the door at 7, on the bus to downtown San Francisco. I work out and and am at my desk by 9:30. I leave the office around 6:30, take a bus back home. I use my commute time to read books and papers. I try to be in bed by 10.

What do you do in your free time?

I like to read and program. I enjoy classic video games: I recently picked up a dreamcast and super nintendo. I like creative games like Space Giraffe.

I spend time with my wife watching movies and eating at restaurants. We also spend time with our cats.

Current favorite apps?

  • Emacs, I use the CVS nightlies on Snow Leopard
  • Ack for finding my way through code. I use it from emacs with full-ack
  • Echofon for reading Twitter
  • Favstar for seeing who likes my tweets
  • Instapaper for reading things later
  • Github for storing my projects

What OS do you prefer?

I use OS X at home and at work. I also run Linux. Forth is also a fun operating system that you can write yourself.

Small picture for your Workplace?

My Desk in my home office

Favorite: Language, JS Framework?

Lisp is the ultimate high-level language.
Forth is the ultimate low-level language.
J is a brain twister with lots of lessons available to be learned.

I wouldn’t say they’re my favorites but they’re great subjects for study.

JavaScript isn’t my thing, I rely on jQuery for any cross-browsing heavy lifting.

Name something that has inspired you recently?

I’ve rediscovered Scheme48. It’s small and the papers around it are wonderful.

Xavier Leroy’s thesis on the implementation of CAML Light (called ZINC in his paper) is really great. If you’ve ever wondered how to efficiently implement a functional language, this is the paper to start with.

What are your personal projects and goals for 2010?

  • Implement a type synthesizer
  • Build a simple theorem prover based on the Calculus of Construction
  • Write a simple JIT for my SECD implementation

As you can tell, I’m interested in programming languages and runtime environments.

back to top
Posted 6 months ago at The GitHub Blog

<!-- -*-Markdown-*- -->

When I initially sat down to write the Network Graph two years ago, I chose Adobe Flash for two primary reasons: 1) I was already familiar with Flash, having worked with it professionally, and 2) plausible alternatives such as Canvas and SVG were poorly supported across browsers, buggy, and slow.

Times have changed, however, and the HTML5 Canvas draft specification is now almost fully implemented on the latest versions of Chrome, Safari, and Firefox. Opera supports Canvas but not the text API. Canvas is missing entirely from Internet Explorer, but the word on the street is that IE9 will finally offer support. In the meantime, the open source community has created excanvas, a way to get Canvas support on current versions of IE.

Given the current status of Canvas and the impending release of Apple's iPad (which will have no Flash support at all), I finally decided to bite the bullet and do a complete rewrite of the Network Graph in JavaScript and Canvas. All told, it took about four full days of coding to get all of the features of the Network Graph reimplemented.

To make the job as simple as possible, I decided to make the Canvas version of the Graph as much like the Flash version as possible. With the exception of a few tiny details, the Canvas version should behave identically to the Flash version, and it's unlikely that you'd even notice the difference unless you were looking for it. In fact, I pushed the Canvas graphs to production yesterday, right under your noses! For now, browsers with proper Canvas support will see the Canvas version and everyone else will see the Flash version. For an example, see Ernie's Network Graph.

I'm quite pleased with the outcome of the project. I was a bit worried about how the JavaScript would handle the complex parts of the code, but modern JS implementations are so fast that performance is as good or better than the Flash equivalent.

As I was coding the new Network Graph, I jotted down a few notes about how Canvas compares to Flash. There are some areas where Canvas is a breath of fresh air compared to Flash, and others where Flash is clearly more refined. I expect many other developers will be doing Flash to Canvas conversions of their own in the coming months, and so I present to you a collection of these thoughts, in case they are helpful.

Where Canvas/JavaScript is better than Flash

Fewer lines of code and smaller deliverable size

The Flash version of the Network Graph was comprised of 1,215 lines of code while the Canvas version comes in at 1,064 lines. Not a huge difference, but less code is less code. Where Canvas really shines is in the final deliverable. The compiled SWF file clocks in at 111k compared to the minified Canvas version at just 25k!

Flash works badly on Linux (and friends)

Flash is not well supported on Linux and a variety of other operating systems. Compared to many sites, we have a disproportionately high percentage of Linux users. Because of this, it's been a long-running complaint that we use Flash for the Network Graph. With excellent Canvas support in the latest versions of the browsers that Linux users use the most, Flash becomes increasingly less desirable.

Inspectable/debuggable via browser

Many of today's modern browsers have excellent inspectors and debuggers. It's great to be able to use these to see what's going on in your Canvas project. Getting log output from an embedded Flash component is a huge chore, but with Canvas you can simply use console.log to output status messages to the inspector.

No compilation step

With JavaScript and Canvas, you can modify code in your text editor and then simply reload the browser page to see the results. With Flash, there is always a compilation step that gets in the way. I suppose there are workflows that mitigate this problem, but since I was using haXe for my source, I always ended up compiling the SWF file from the command line.

Better cursor handling

I'm not at all happy with how Flash handles cursors. Changing the cursor always seems to result in a laggy cursor that ruins the user experience and makes the entire Flash component feel shoddily done. With JavaScript I can change the cursor to a variety of built-in options that behave as they should. Custom cursors are still a problem in browsers since most do not respect the hotpoint in the cursor file, but just having access to a standard set of responsive cursors is a huge win.

No need to focus to receive keyboard events

Since canvas is a proper HTML element, it can receive mouse and keyboard events without any extra hassle. This is quite nice for the Network Graph since it allows you to scroll left and right with the keyboard as soon as the page loads, instead of having to focus the Flash component first.

Where Canvas/JavaScript is worse than Flash

Have to handle clipping and redraw manually

Probably the biggest difference between Canvas and Flash is the level of abstraction available. Canvas is really just a low-level 2D graphics API. There are no objects or layers or groups or anything beyond what you need to draw various shapes and lines and text on the canvas. Flash, on the other hand, gives you all kinds of constructs that make it conceptually simpler to work with objects.

For the Network Graph this is a huge difference. With Flash I can simply draw all the commit dots and connection lines onto a single, large layer and then position that layer to reflect the current viewing region. But with Canvas I have to manually redraw the Graph any time the state changes. In addition, to keep things snappy, I have to calculate which commits and connections are currently viewable and ONLY draw those. This results in a substantial amount of code that is completely unnecessary in Flash. Flash computes all that for me.

It is certainly possible to create a framework that takes care of these details, and over time I expect some very good options to arise. For now, there is CAKE and my own Primer, but neither of those were suitable for this project. I do plan to work more on Primer and eventually convert the Network Graph to use it, but that will take time.

No embedded font support

With Flash, you can embed fonts right in the SWF and you don't have to worry about how fonts will render. With Canvas you're once again at the mercy of the browser. Depending on what fonts are available to the browser, the final rendering may be drastically different.

No built-in multiline text wrap

The Canvas spec does not include any way to automatically wrap text within a bounding box whereas Flash makes this task easy. It's not too hard to write a simple line wrapper in JavaScript, but I feel it's something that would be better served as part of the API.

No HTML fragment rendering

Flash allows you to render HTML fragments to the screen. Canvas does not. Though the draft spec does have this to say:

A future version of the 2D context API may provide a way to render fragments of documents, rendered using CSS, straight to the canvas.

So Canvas may get this functionality in the future, but for now we're out of luck.

Back to dealing with browser implementation differences

One of the biggest benefits of Flash is that you only have to target one implementation: Adobe's. With Canvas, you have to worry about what API methods are implemented on each browser, what bugs each browser introduces that may not be problems on other implementations, etc. As web developers, we're used to this already, but that never makes it feel any better. Fortunately, the browsers I tested all seem to obey the Canvas spec rather well, and I didn't hit any show-stopper differences between implementations. Hopefully as Canvas matures, this statement will remain true.

Conclusion

Canvas is the future of 2D (and possibly 3D) graphics on the web. Sure, it has a few shortcomings, but as time passes, it will only get better.

You can write it with the same language (JavaScript) as the rest of the interaction logic on your web page. It's fast and getting faster. Once a few competent frameworks appear, it will be just as easy to use as Flash for a huge variety of tasks. And once the iPad ships, Flash will become a liability.

My advice for web developers: if something on your site CAN be done in Canvas, it SHOULD be done in canvas.

back to top
Posted 6 months ago at Riding Rails - home

If you have been in the Rails community for a little while, you have more than likely noticed the love/hate relationship that is entertained by the community vis-à-vis the Enterprise. Some people hate the enterprise and publicly tell it to go f*ck itself (49:39), on the other hand, these same people are also proud to mention that some major players in the industry use Ruby and Rails.

So where are we at?

  • First things first, Rails was not designed for the enterprise or for the enterprise's needs. It was extracted from a successful startup project and has grown with the contribution of people using Rails daily. But Rails is also based on Ruby which became very popular and started to be used in different places, including NASA, for instance.
  • 37signals still does NOT need "Enterprise features" and therefore don't expect any 37signals engineers to write an Oracle Adapter or a SOAP layer for ActiveResource and push for their adoption.
  • Rails is far more than a framework used by 37signals. It is an Open Source project with code being contributed daily by people on other projects. Most of the code does not directly benefit 37signals.
  • The Enterprise is evolving: economic crisis, a new generation of developers, new management, insane deadlines. Ruby and Rails have quickly become very attractive for the Enterprise and having big companies acting as startups is often something a lot of managers dream of. As a matter of fact, here is a quote from Sony Computer Entertainment America's President & CEO, Jack Tretton: "Be like a multi-billion dollar company on the outside, and act like a startup on the inside". This change has taken a while because the Enterprise is a big mammoth (or insert another of your favorite gigantic, slow-starting animal here), but it's happening.
  • Communication with/in big companies is not as straight forward as when dealing with startups who need/thrive for the outside attention and who don't have all the red tape of a PR department, etc. Here is a simple example: I work for Sony Playstation. My job description mentioned Redis, MongoDB, EventMachine and many other technologies I did not know Sony was using in production. I did not realize that my default production stack would be built on Ruby 1.9. Communicating when you're a part of a big company is more challenging than when you are a team of 5 engineers working on a cool project, and therefore a lot of people don't know what technologies are being used by Company X or Company Y.

  • Rails is used by lots of big companies. It might not be obvious and you might have to look at the job offers but people like AT&T, Sony and many others are always looking for talented Ruby developers. And, even though Java and .NET are still ruling the Enterprise kingdom, dynamic languages are slowly but surely catching up. Rubyists are climbing the social ladder and are now in positions to push the language they love.

Understanding the Enterprise's needs

It's kind of hard to define "the Enterprise's needs", however I can testify that the needs and requirements of a so called "Enterprise app" are slightly different than those encountered when you work on a startup app. What the Enterprise needs/wants:
  • reliability
  • support
  • performance
  • advantage over the competition
  • integration and transition path

Reliability

I think that it was proven many many times that Rails scales and can be very reliable as long as you know what you are doing. We are not talking anymore about a buzz framework that just got realized and that cool kids play with but rather, a stable platform used by some of the most popular web applications out there.

Support

This point is something the Rails community can be proud of. We have lots of forums, blogs, books, local meetings, conferences... Yes, Rails is OpenSource and you can't buy yearly support from the core team but you will find all the help you need out there. (If you can't, feel free to contact me and I'll direct you to people who can help, and if you are new to Rails, take a look at http://railsbridge.org/)

Performance

Based on my own experience, the level of performance we have using Ruby and Rails is more than enough for the Enterprise world. This is especially true with Ruby 1.9 greatly improving performance and Rails3 optimizations. If you really need part of your code to run as fast as C code, writing a C extension for Ruby is actually quite easy and will solve your speed issues.

Advantage over the competition

Rails comes with certain ways to do things, conventions that will get you up and running in much less time. Ruby as a language is natural, intuitive and easy to maintain. By choosing the right tools for your project, you will definitely be able to get more done in less time and increase your business value faster. Let's not forget the strong value of testing in the community that will push your team to write tested code and more than likely improve the overall code quality of your products.

Integration and transition path

This is probably the part that is the most challenging when you live in the Enterprise and look into using Ruby & Rails. I was recently talking to someone from Google who used to do a lot of Ruby before joining the Mountain View-based company. We were talking about how he loves Ruby but had such a hard time integrating with existing Enterprise solutions. He mentioned how he got frustrated by the lack of great XML tools, bad/complicated SOAP libraries and a few others I can't remember. The truth is that when my friend was using Ruby this all was true. REXML and soap4r are useful but might not perform that well. Luckily as the community has grown, new tools have come up and today Nokogiri (developed and maintained by AT&T engineer's Aaron Patterson) can easily be used instead of REXML and many libraries are known to be better than soap4r such as savon, handsoap and others. The other good news is that major IT companies such as Apple, Microsoft and Sun(RIP) have adopted Ruby and you can now write your code in Ruby and use native libraries from other languages such as Java, .NET or Objective-C. The transition path can be done smoothly without having to commit to a total rewrite.

Database-wise, Oracle is still a viable option for Rails developers thanks to the Oracle ActiveRecord adapter (by R.Simanovskis). Note that your DBA might curse you for not doing optimized queries using bind variables and all the Oracle Magic spells, in which case you can use Sequel, a great ORM supporting Oracle, and some of its unique features.

Deployment-wise, you can deploy on IIS, Tomcat, Glassfish, Apache, Nginx, or almost anything mainstream you are already using. Using Passenger, deployment is as easy as deploying a PHP app and you also get a series of great tools such as Capistrano, Vlad etc...

So basically, thanks to passionate Rubyists working 'for the man' such as Aaron Patterson, Raimonds Simanovskis and others, using Ruby in the Enterprise is much much easier. Ruby and Rails were not initially designed with the Enterprise in mind but with time, the integration has become smoother and both parties can now enjoy reciprocal benefits.

back to top
Posted 6 months ago at Engine Yard Ruby on Rails Blog

In past summers, student interns working on Ruby and Rails projects have made significant contributions to the core code of today’s ecosystem. Just last summer, summer intern projects, under the Google Summer of Code umbrella, funded merging ActiveRelation into ActiveRecord, a rewrite of the the Rails generators to allow for support for RSpec, Haml and DataMapper in the default generators, and the creation of ActiveModel.

The projects were all HUGE milestones and technical upgrades that have dramatically changed the landscape in Rails. As such, we are, together with Ruby Central and members of the Ruby on Rails core team, pleased to announce the first Ruby Summer of Code!

The project is accepting donations and sponsorships starting right now, and the more money we raise, the more intern stipends we can afford. This is a great opportunity for individual contributors and companies alike to give back to the Ruby and Rails communities. The mentor application window is also open, and student applications will be accepted starting April 5th.

Congratulations to everyone who worked to launch Ruby Summer of Code; we’re looking forward to seeing the results!

back to top
Posted 6 months ago at A Fresh Cup

Another night of sleep deprivation thanks to small children.

  • Sinatra 1.0 Released - And congratulations to all involved.
  • jQuery UI 1.8 - Speaking of significant releases.
  • Ruby Summer of Code - Rails didn't get approved for Google Summer of Code this year, but now the ruby community has their own alternative. Alas, I don't see any sign that the contributions are tax-deductible, which is a shame.
  • MTR - Nice combined alternative to ping and traceroute. Here are instructions to get it running on OS X.
  • TinyMCE for Rails - Lots of upgrades to this project lately.
  • Web Design Checklist - Another look at HTML5 and CSS3 support levels in various browsers.

back to top
Posted 6 months ago at The Geek Talk

Who is Karl Swedberg?

By day I’m a web developer at Fusionary, specializing in client-side interaction. I love my job and the people who work there. I’m also the husband of a beautiful woman and the father of a 9-year-old boy and 7-year-old girl. I grew up outside of Philadelphia, spent some time in Virginia and Seattle, and ended up in Grand Rapids, Michigan, where I’ve remained for the past 15 years, despite the relentlessly brutal winters.

About Learningjquery?

Learning jQuery is a blog I started in 2006 as a way to keep a record of things I was learning. When I started the site, I had only been programming for a few months, so I had very little idea what I was doing. I figured a good way for me to learn would be to put things in writing and expose it to the scrutiny of others who might stumble upon it. After a while, as jQuery gained in popularity and the blog’s readership grew and my skills developed a bit, the site naturally became more outwardly focused, helping others learn. Quite a few other people have posted articles on the site in recent months, which is a great thing since I haven’t had as much time to devote to it as I’d like to.

What does your typical day look like?

During the week I spend the day at Fusionary, doing the web thing. Occasionally I take a peek at what’s going on in jQuery Land — see who’s tweeting, what’s happening in the forum, which comments need moderating on the API site — but most of the time it’s nose to the grindstone, cranking out the code. After work, I hang out with my family, read a bit, chat with the neighbors, and catch up on jQuery stuff that I may have missed during the day.

What do you do in your free time?

When I’m not feeding my internet addiction, I like to read and occasionally watch TV series via Netflix. I enjoy doing just about anything with my family. And a couple times a week I let out some physical aggression through karate (Okinawan Shorin Ryu). I have a thousand and one interests, but almost no time at all to pursue them. Or so it seems.

Current favorite apps?

TextMate is a favorite, mostly because I live in it much of the day. TextMate is like a Swiss Army Knife of text editing, but most of the apps I like just do one thing and do it well. I’d be lost without Quicksilver. Skitch is great for quick screenshots with annotations. MarcoPolo (http://www.symonds.id.au/marcopolo/) opens and closes certain apps for me and connects to various resources depending on where I am physically at the time.

What OS do you prefer?

Mac OS X. I worked for Microsoft a long time ago, and I felt a strong sense of loyalty to the company for many years after I left, so I stuck with Windows 95, 98, 2000, and XP until I just couldn’t bear it any longer. I’ve heard some nice things about Windows 7, but I don’t think I’ll be switching back any time soon.

Small picture of your Workplace?

Here is my office:

And here is where I do most of my work at home:

Favorite: JS Framework? and why?

You probably won’t be surprised to read that my favorite is jQuery. When I first came across it, I was able to put it to use fairly quickly for little sprinklings of progressive enhancement here and there — and that was with little more than a firm understanding of HTML and CSS. I’ve learned a ton since then and have even written a couple of books on jQuery, but it still amazes me and I’m still learning things all the time just by looking at the source.

To be honest, I haven’t spent a lot of time with other JavaScript frameworks. I’ve used Prototype, mostly when maintaining legacy code from former employees at my day job. And I’ve mucked around a bit with Mootools and Dojo. I’d love to explore Mootools and Dojo more, but I can’t see how I’d find the time unless a project demanded it.

Name something that has inspired you recently?

Last summer I bought 25 goldfish at the grocery store for 10 cents apiece and dropped them in a makeshift pond that I dug in my backyard. I didn’t expect them to survive more than a month or two, let alone all winter. But last week when the temperature climbed above freezing and the ice that had been covering the pond for the past four months finally melted, there they all were — every single fish, alive and swimming around. That was one of the most inspiring things I’ve seen in a long time.

Shaun White on the half pipe, too. Totally blew me away.

What are your personal projects and goals for 2010?

I guess my main goal is to continue meeting the increasing demands of my “web life” without neglecting my physical life and especially my family life. On a less abstract level, I’ve been really focused lately on the online jQuery documentation, which is now based on the book that I co-authored, jQuery 1.4 Reference Guide. I’m working on JSONP output that should make for really fast and flexible querying of the jQuery API. Also, I started digging into Jörn Zaefferer’s API browser the other day and hope to update the XSLT to work with the new XML format. Other than that, I’m speaking/presenting more at conferences and teaching more classes on jQuery (mostly throughideafoundry.info). And I have a bunch of old, crusty plugins that are in dire need of an update. When I find a few minutes..

back to top
Posted 6 months ago at Riding Rails - home

Rails participated in Google’s summer of code program for the first time last year. We got four great projects and three long-term contributors from the effort, including Josh Peek and José Valim, who’ve both joined Rails core, and Emilio Tagua, who revitalized Arel and integrated it with Active Record.

We applied again this year but didn’t make the cut, so we moped for a day then thought, why not make this happen ourselves. So here we are kicking off the first Ruby summer of code together with Engine Yard and Ruby Central.

Head over to rubysoc.org to get started and start following @rubysoc for news.

We’re following Google’s example closely:
  • students are paid a $5000 stipend to work full-time during their summer break
  • a group of Ruby gurus volunteer their time as mentors
  • mentors vote on student proposals based on usefulness, benefit to the Ruby community, and history of motivated open source contribution

We’re looking for full- and half-summer sponsors as well as individual donations. We’ll fund as many students as we can. Donate this week and our Aaron aka tenderlove will match it! Donate now!

Ruby gurus, consider mentoring a student this summer. Volunteering to guide the next generation of Ruby developers is a challenging and rewarding effort.

Students: start your engines! Check out our ideas list and start brainstorming. Applications begin on April 5!

back to top
Posted 6 months ago at Tuxicity

As everyone new to Emacs know, adapting to Emacs key binding takes quite a while. When I first started using Emacs, even though I found for example C-x k a quite odd key binding, I tried to learn it, no questions asked.

As I got more comfortable with Emacs I adopted more and more Emacs standard key bindings. But there was this one thing I just couldn't understand why to use. I'm talking about the movement keys: C-n, C-p, C-f, C-b, M-f and M-b.

I read books and tutorials on Emacs and everywhere it said these are the movement keys in Emacs. But more importantly, none of them mentioned why you should use them.

I never found out why by reading any Emacs material. The way I found out was by just starting to use them. I thought, if I use Emacs, I should go the whole nine yards. So I started using the movement keys and after a while I realized why you should use them.

These are the main reasons why you should use the movement keys instead of the arrow keys:

  1. Using the arrow keys is highly inefficient! They are way off from where your fingers are when you type. Moving your hand over each time you want to move the cursor, is like getting a cop of coffee each time you create a new paragraph.
  2. It is much more comfortable to use the movement keys.
  3. They fit together much nicer with other Emacs key bindings.

I really hope this post help you drop those inefficient, ugly and stupid arrow keys!

Ps. Using the movement keys involve a lot of Ctrl-key usage, which kills you little finger. Read about how you can save it

back to top
Posted 6 months ago at Ruby Inside

In November 2007, we casually mentioned a new Ruby webapp library called Sinatra. It took a year to capture the imagination of the Ruby community as a whole and we eventually covered it in more depth but today we're proud to (exclusively) announce that Sinatra has today reached its landmark 1.0 release!

Impromptu release party in the official #sinatra channel on irc.freenode.net, anyone? :-)

Sinatra is well known in the Ruby community for providing developers with a simple way to put together Web apps big and small. The canonical ultra-simple example:

require 'rubygems'
require 'sinatra'

get '/hi' do
  "Hello World!"
end

Sinatra's lead developers — Ryan Tomayko, Simon Rozet, and Blake Mizerany — have done a great job, along with about 50 other contributors, to produce a slick and powerful Web application DSL for Rubyists. Their ideas have even inspired similar frameworks in other languages (such as Sammy in JavaScript). Satish Talim put together a great piece, 20+ Rubyists are using Sinatra - Do you?, last year that got a good feel for how Sinatra's being used for Web apps both big and small by a collection of Rubyists.

What's New?

As an avid user of Sinatra 0.9, I asked Blake Mizerany what the biggest changes were going to 1.0:

I think the biggest changes are what we cleaned up. Tilt is a great new under-the-hood addition. Sinatra has matured; we're done messing around. It's super solid. The extension API has matured to something really killer. Extensions are ridiculously simple to create now - you can easily install helper methods, DSL methods, and install new routes on apps, and the user need only require 'sinatra/your-extension' - that's it.

Unsurprisingly, the official changelog also provides useful information to existing Sinatra developers.

A more significant longer-term change for Sinatra over the past year has been in how it integrates with Rack. In Sinatra Rack And Middleware, Ben Schwarz looks at how Sinatra interacts with Rack and how you can use Rack's middleware and multi-application features with Sinatra. A key aspect of this is the ability to produce "modular" Sinatra applications by subclassing Sinatra::Base to separate discrete applications or application portions:

require 'rubygems'
require 'sinatra/base'

class MyApp < Sinatra::Base
  get '/' do
    "Hello world!"
  end
end

And then, in a Rackup file:

require 'my_app'
run MyApp

Installing and Trying Sinatra

If you're not yet using Sinatra and want to give it a quick try, you can install it with RubyGems:

gem install sinatra

Put the following basic example into a file, say example.rb:

require 'rubygems'
require 'sinatra'

get '/hi' do
  "Hello World!"
end

Then run the Ruby file in the usual way, and a request to http://localhost:4567/hi should get you a "Hello World!" response.

Learn More Online and on IRC

The examples shown above are as basic as Sinatra gets, but it goes a lot deeper than that (such as embedding Sinatra apps inside Rails apps) and the Sinatra Web site has some great code examples of where you can go next. There's also solid documentation available and if you want to take a look at lots of existing Sinatra projects to get a feel for the patterns and techniques involved, there's a great list of Sinatra apps and extensions too.

Lastly, if you're interested in asking questions about Sinatra or just hanging out with Sinatra's developers and users, head along to the #sinatra channel on irc.freenode.net. There's usually between 50-100 people hanging out there.

back to top
Favorite
Posted 6 months ago at Ruby Quicktips

This is a simple application helper that shaunchapman wrote to reduce the tediousness of linking stylesheets for each controller. It will link the controller’s stylesheet (located at public/stylesheets/[controller_name].css) if it exists but it won’t complain if it doesn’t. It is a nice way to keep things organized and it’s super simple to set up.

Simply add this to your application helper (located at app/helpers/application_helper.rb):

def controller_stylesheet_link_tag
  stylesheet = "#{params[:controller]}.css"
    
  if File.exists?(File.join(Rails.public_path, 'stylesheets', stylesheet))
    stylesheet_link_tag stylesheet
  end
end

…and put this in your application layout (located at app/views/layouts/application.html.erb):

<%= controller_stylesheet_link_tag %>

back to top
Favorite
Posted 6 months ago at Ruby5

In this episode we cover the Ruby 1.9.2 release schedule, Sproutcore 1.0, scaling Ruby, Rack::Throttle , WebMock, and last but certainly not least, Blue Light Special.

Listen to this episode on Ruby5

This episode is sponsored by the Red Dirt Ruby Conference
The Red Dirt Ruby Conference is Oklahoma's first Ruby conference. It is a single track, two day event covering the topics of Ruby, Rails 3, NoSQL, and Servers. Check out the awesome line up of talks over at Red Dirt Ruby Conference Schedule.

Ruby 1.9.2 Release Schedule Aims at August for Final Release
Last week, the official release schedule for Ruby 1.9.2 was revised and released. If all goes to plan, then we should see a Release Candidate at the end of June, and an official release one month later, at the end of July or early August.

SproutCore 1.0 Released
SproutCore 1.0 was released this past Friday. SproutCore is a JavaScript Web Application Framework that allows for development of single-page web applications that mimic desktop applications. If you're looking for a real-world example of it in action, check out Apple's MobileMe service.

Ruby Scales, AND It’s Fast – If You Do It Right!
Surprise, surprise... I guess Ruby can scale. Last Friday, Kirk Haines posted on the Engine Yard blog a pretty detailed explanation of how he scale a Redmine installation on a single server to handle around 280 million requests per day. Every major piece involved was written in pure Ruby, the benchmark hit multiple pages, and exercised both read and write requests. Nearly 3300 requests per second ain't too shabby.

Rack::Throttle - Rate Limiting for Rack Applications
This week, Arto Bendiken and Brendon Murphy released Rack::Throttle, which is a Rack middleware that implements rate limiting. It works with either Memcached or Redis and allows you to define allowed request intervals (like one per second) or even larger daily limits, it even allows for customization of unique user identification. This solution is very similar to the one presented by Steve Huffman of Reddit at FOWA Miami.

Stubbing and Setting Expectations on HTTP Requests Is Now Easy With WebMock
When testing and stubbing external service calls, we often turn to FakeWeb or even Sinatra. But neither of those solutions give you the ability to define formal call expectations or easily match POST requests by the body or request headers. So, to address those and other issues, Bartosz Blimke created WebMock a new stubbing and expectation library for Net::HTTP-driven remote services.

Blue Light Special
This past week, the team at Envy Labs released their highly opinionated and expanded version of Thoughtbot's Clearance gem, creatively titled Blue Light Special. It acts as a strong starting point for a new application, providing user authentication, impersonation, integration with MadMimi, and background jobs with Delayed::Job.

back to top