JavaScript and APIs at RailsConf 2011
A big trend of RailsConf 2011 has been the presence of JavaScript, whether it be talk of CoffeeScript, node.js, Sproutcore, backbone.js, etc. I attended Yehuda Katz’s talk on Building Rails Apps for the Rich Client on Day 4 of the conference.
Part 1: Rails versus Sinatra Smackdown
Yehuda gave a two part talk about developing API-heavy applications. The first bit addressed why to develop in Rails rather than Sinatra if your application is API-heavy and doesn’t appear to be utilizing valuable parts of Rails? This is fairly applicable to a couple of Sinatra projects that I’ve done at End Point — I like Sinatra a lot, but at some point you begin to replicate parts of Rails. Yehuda explained that because it’s easy to develop web applications efficiently using Rails conventions, developers can become forgetful/ignorant of the underlying functionality of Rails that doesn’t ship with something like Sinatra, much like how working with an ORM can breed developers who aren’t familiar with the underlying database interactions. The checklist for things that Rails manages we might forget about includes:
- ActionDispatch internals
- Session deserialization
- Browser standards mode
- Cookie abstraction …
conference javascript rails
Only Try This At Home
Taken by Josh 6 years to the day before the release of 9.1 beta 1
For the record, 9.1 is gearing up to be an awesome release. I was tinkering and testing PostgreSQL 9.1 Beta 1 (… You are beta testing, too, right?) … and some of the new PL/Python features caught my eye. These are minor among all the really cool high profile features, to be sure. But it made me think back to a little bit of experimental code written some time ago, and how these couple language additions could make a big difference.
For one reason or another I’d just hit the top level postgresql.org website, and suddenly realized just how many Postgres databases it took to put together what I was seeing on the screen. Not only does it power the content database that generated the page, of course, but even the lookup of the .org went through Afilias and their Postgres-backed domain service. It’s a pity the DBMS couldn’t act as the middle layer between those.
Or could it?
That’s a shortened form of it just for demonstration purposes (the original one had things like a table browser) … but it works. For example, on this test 9.1 install, hit http://localhost:8000/public/webtest and the following …
database postgres python
Sass at RailsConf 2011
With the inclusion of the Scss gem in Rails 3.1, RailsConf is a nice time to get a refresher on Sass/Scss functionality. Sass defines itself as syntactically awesome stylesheets, or a CSS meta language built to provide more powerful functionality to manipulate website appearances with efficiency and elegance. Note that Sass has two syntaxes and the examples presented in this article use the newer Scss syntax. Around the time of RailsConf two years ago, Sass was a included in Spree, an open-source Ruby on Rails ecommerce framework that End Point supports. At the time, I was skeptical about Sass inclusion in Spree because it wasn’t being leveraged to it’s full potential and had hopes of taking advantage of Sass, but a few months later it was removed from the core. Since then, I haven’t worked with Sass on other projects but hope to do so moving forward after being reminded of it’s features and of the fact that it will be included in Rails 3.1 as a default. I attended Chris Eppstein’s talk on Sass and explain a few features related to real-life use cases of CSS manipulation.
Variables
While working on a new feature, your client says, “I want this to be the same red that we use all …
conference ecommerce rails
Rails 3 at RailsConf 2011
A keynote by DHH kicked off Day 2 of RailsConf, where much of his talk was spent discussing new asset behavior in Rails 3.1. Here’s a run down of a few topics I found worth noting:
Asset Pipeline
DHH started by explaining how although a Rails application has lovely organization in terms of Ruby files, the assets (stylesheets, images, and JavaScripts) have become a junk drawer where junk continues to pile in. Once there’s more than a handful of files, the broken window theory applies and no one tries to maintain organization of those assets. This gets nasty, like a honey badger.
With Rails 3.1, the asset pipeline addresses the junk drawer. Assets directories (images, stylesheets, and JavaScripts) are now created in the app, lib, and vendor assets directories as they pertain to the main app, plugin dependencies, or introduce new library dependencies like a jquery calendar date select plugin. There’s also the introducton of appending to config.assets.paths, which allows you to add new directories that store these assets in arbitrary directories. The new asset pipeline allows you to store these assets in different organization, which encourages JavaScript files to be stored based on …
conference ruby rails
RailsConf 2011 — Day One
Today was the first official day of RailsConf 2011. As with most technical conferences, this one spent the first day with tutorials and workshops. For those of us without paid access to the tutorial sessions, the BohConf was a nice way to spend our first day of the four-day event.
BohConf is described as the “unconference” of RailsConf. It’s a loosely organized collection of presentations, mini-hackathons and barcamp-style meetings. I spent the first half of Monday at the BohConf. Of particular interest to me was Chris Eppstein and Scott Davis’ introduction to Sass and Compass. I’ve dabbled with Sass in the past but only recently learned of Compass.
Sass is a great way to construct your CSS without the tedious duplication that’s typical of most modern spreadsheets. Introducing programming features like variables, inheritance and nested blocks, Sass makes it easy to keep your source material concise and logical. Once your source declarations are ready, compile your production spreadsheets with Sass or Compass.
Compass is effectively a framework for easy construction and deployment of spreadsheets using Sass. To hear Scott describe it, “Compass is to Sass as Rails is to Ruby”. …
conference hosting ruby rails
DBD::Pg and the libpq COPY bug
(image by kvanhorn)
Version 2.18.1 of DBD::Pg, the Perl driver for Postgres, was just released. This was to fix a serious bug in which we were not properly clearing things out after performing a COPY. The only time the bug manifested, however, is if an asynchronous query was done immediately after a COPY finished. I discovered this while working on the new version of Bucardo. The failing code section was this (simplified):
## Prepare the source
my $srccmd = "COPY (SELECT * FROM $S.$T WHERE $pkcols IN ($pkvals)) TO STDOUT";
$fromdbh->do($srccmd);
## Prepare each target
for my $t (@$todb) {
my $tgtcmd = "COPY $S.$T FROM STDIN";
$t->{dbh}->do($tgtcmd);
}
## Pull a row from the source, and push it to each target
while ($fromdbh->pg_getcopydata($buffer) >= 0) {
for my $t (@$todb) {
$t->{dbh}->pg_putcopydata($buffer);
}
}
## Tell each target we are done with COPYing
for my $t (@$todb) {
$t->{dbh}->pg_putcopyend();
}
## Later on, run an asynchronous command on the source database
$sth{track}{$dbname}{$g} = $fromdbh->prepare($SQL, {pg_async => PG_ASYNC});
$sth{track}{$dbname}{$g}->execute();
This gave the …
dbdpg open-source perl postgres
Locally served YUI3
For the vast majority of sites serving static JS and CSS files such as those required by YUI (or jQuery etc.) from a CDN makes great sense: improved performance through caching and geography, reduced load, improved uptime, leveraging some large corporations’ resources, etc.
Unfortunately as soon as you hit an SSL secured page you can’t use a CDN’s resources securely, a common thing with e-commerce sites and administration panels. In the YUI case that means doing at least a little bit of extra configuration and maintenance of an installed library base, an all-too-common task in typical server-side development that’s becoming more common as libraries are maintained for client-side usage as well.
Toss in “combo loading” and all of a sudden it feels like the software development cycle can’t just be discarded ’cause you are working on the web. Maybe this is really what they meant by Web 2.0. But I digress…
Since I’m familiar with and working on YUI3, here is how we have it working for non-CDN based serving for an administration panel developed for a newer generation of an Interchange site. Our custom application uses YUI3 (core), modules from the YUI3 Gallery, and a few modules …
javascript
Benchmarking in Perl: Map versus For Loop
Last week, I was coding in Perl for an Interchange project. I’ve been in and out of Perl and Ruby a lot lately. While I was working on the project, I came across the following bit of code and wanted to finally sit down and figure out how to use the map function in Perl on this bit of code.
my @options;
for my $obj (@$things) {
push @options, {
value => $obj->{a},
label => $obj->{b}
};
}
return \@options;
I’m a big fan of Ruby’s inject method and in general a fan of the Enumerable Module, but I have a brain block when it comes to using the map method in both Perl and Ruby. I spent a little time investigating and working on a small local Perl script to test the implementation of the map method. I came up with the following:
return [ map {
{
value => $_->{a},
label => $_->{b}
}
} @$things ];
After that, I wanted to make sure the code change was justified. The Interchange application that is the source of this code is built for performance, so I wanted to ensure this change didn’t hinder performance. It’s been a while since I’ve done benchmarking in Perl, so I also had to refresh my memory regarding using …
performance perl