or
The power inherent in a page
Recently @aawayne
tweeted that a portion of his day is spent refreshing the OFR public inspection page. Given
the state of the public inspection page up to this point we expect that this was
common behavior for those interested in upcoming Federal Register
content. As we began thinking about this problem a couple months ago we
had users like @aawayne in mind and started asking questions like:
- “What if you could receive email alerts as new documents you are interested in appeared on Public Inspection?”
- “What if you could link to tha...
Continue reading 'The Public Inspection Desk, Document Persistence and Open Data'
or
Liquid Robotics turns a 300 day trip into 2.25 million data points
You may have read some of the coverage yesterday of the PacX Challenge
launched by Liquid Robotics (BBC, NYT, Venture Beat) and the release of 4 Wave Gliders on their journey across the Pacific.
Liquid Robotics has invested the money in the journey for a variety of
reasons and in their own words the most important being, “to ignite everyone’s imagination on what can be discovered and explored when the ocean is networked with sensors”. As a data and robot geek I find the venture quite exciting. I originally met members of Liquid Robotics at Maker Faire this year and was very interested in how it might be possible to get open data from these robots (in particular programs from government agencies like NOAA). So for ...
Continue reading 'Turning oceans into open data'
The Office of the Federal Register and FederalRegister.gov have been cited by the
Administrative Conference of the United States (ACUS) as a success story as
part of their Model Agency Initiative. The success stories will be
considered for the Walter Gellhorn Innovation Award.
We’re honored to be nominated and by the recognition of what the FR2.0 project
hopes to accomplish (see our Champions for Change post on WhiteHouse.gov). While the open source code of Federal Register 2.0
is not immediately reusable by every agency the best practices we’ve put
in place certainly are. The FR2.0 project is not only working to make
Federal Register content more accessible but also to expose what can be
done by adopti...
Continue reading 'FR2.0 Project cited as a model agency success story by ACUS'
without
A flash or busted cache
Effective web applications can be used by a large variety browsers and configurations. Many users, for a variety of reasons, choose to disable JavaScript or must run a browser that does not support it. Progressive enhancement, or starting with the basics and layering on useful additions on top, is the best way of ensuring that everyone can use your site.
For the Federal Register 2.0 project, we wanted to make the advanced search as easy to get to as possible, encouraging its use. For users with JavaScript enabled, we wanted the page to default to hiding the advanced search form and allow users to open it as desired; for users without JavaScript, the form would simply already be open. The simplest way to do this would be to have JavaScript hide the advanced search form. However, for site performance to be at its best, you want to put your JavaScript code at the end of the file, ensuring that the page begins to render before all external JavaScript files finish loading. This leads to...
Continue reading 'Supporting Users without JavaScript'
without
having to think about it every time
SELECTing random records in MySQL can be very slow, far slower than expected. This is because MySQL is fetching all the columns necessary for all rows, then assigning each row a random number, then sorting all the data. As Mathias Meyer pointed out, it is far more performant to calculate the random position when only selecting the primary key, and then JOIN the resulting ids against the full table.
In other words, instead of
SELECT *
FROM articles
ORDER BY RAND()
LIMIT 5
joining a...
Continue reading 'Performant Random Records in ActiveRecord'
or
Methods are better than blocks
- Author
- Andrew Carpenter
- Date
- 03 Oct 2010
- Categories
-
activerecord
named_scopes are a great way to write truly reusable model code in ActiveRecord. However, the syntax for dynamic named scopes leaves much to be desired:
class Shirt < ActiveRecord::Base
named_scope :colored, lambda { |color|
{ :conditions => { :color => color } }
}
end
Instead, you can do the same thing using class methods:
class Shirt < ActiveRecord::Base
def self.colored(color)
scoped(:conditions => { :color => color })
end
end
Not only is the syntax c...
Continue reading 'Class methods instead of named_scopes'
or
I'll take Inheritance over Metaprogramming any day of the week
- Author
- Andrew Carpenter
- Date
- 02 Oct 2010
- Categories
-
activerecord
Rails applications ship with an ApplicationController from which all controllers inherit; this is a handy way of sharing functionality across all your controllers.
However, as many others have noticed, something parallel does not exist for models. However, you can get the exact same thing by simply creating an ApplicationModel to inherit from, setting abstract_class to true:
class ApplicationModel < ActiveRecord::Base
self.abstract_class = true
end
class User < ApplicationModel
...
Continue reading 'ApplicationModel'