Rails Reading - November 24, 2009

University of Birmingham - Aston Webb

An Engineer’s Guide to DNS (Yahoo! Developer Network Blog)

The Domain Name System (DNS) is part of the “dark matter” of the internet. It’s hard to observe the DNS directly yet it exerts an obscure, pervasive influence without which everything would fly apart. Because it’s so difficult to probe people tend to take it for granted, which I think is a mistake. DNS problems can hurt the speed and reliability of your applications without you even noticing. In this article we’ll take a look at the behavior of the DNS and walk through some experiments you can run to gather valuable data about your users’ network performance.

Serializing custom ActiveRecord attributes as JSON - Missing Feature Labs

I’m not a big fan of ActiveRecord’s serialize. But I have kept it together until I learned about DataMapper’s custom serializers for custom types. At that point, I was ready to cry. I was saved by the following inspiration.

I’ve been looking for a fast (no YAML) and framework agnostic (no classname stored) way to serialize a custom object into an ActiveRecord attribute. Here’s my simple hack to create custom serializers in Rails using composed_of.

John Pignata - Converting Rails application data from MySQL to PostgreSQL

One of our projects had a pending chore in Tracker to move its backend to PostgreSQL from MySQL. This project has about a quarter of a million rows of production data and around a hundred tables in its schema which needed to be exactly migrated into PostgreSQL.

Forklifting the data proved more complicated than expected due to incompatibilities in the two DBMS’ syntax such as in the way string escaping worked, how booleans were represented and a bunch of other small but painful differences. Despite MySQL’s mysqldump utility including a command-line option to write statements in PostgeSQL format, it became clear that it wasn’t going to be simple to create a repeatable procedure to do this work across our environments.

Giles Bowkett: Personal Git Punch Card Grapher

Say you like GitHub’s punch card graphs, but you want more info. This hack, based on blatantly stolen code, allows you to generate punch card graphs from the command line.

HTML Sanitization In Rails That Actually Works | Viget Extend

Assuming you don’t want to simply escape everything, sanitizing user input is one of the relative weak points of the Rails framework. On SpeakerRate, where users can use Markdown to format comments and descriptions, we’ve run up against some of the limitations of Rails’ built-in sanitization features, so we decided to dig in and fix it ourselves.

Racksh: A Rails-Console-A-Like for Rack-Based Ruby Apps

Have you ever yearned for something like Rails’s script/console or Merb’s merb -i in your other Rack based apps? If so, then Marcin Kulik’s racksh, inspired by Heroku’s console, might be for you.

Racksh is a console for Rack based ruby web applications. It allows you run a console in the context of an application environment for Rails, Merb, Sinatra, Camping, Ramaze (or even your own framework) provided there is a rackup file in the root directory.

Railscasts - Embedded Association

Learn how to set up a one-to-many or many-to-many association which is entirely embedded into a single column through a string or bitmask.

Ruby Best Practices - Learning From Bad Ideas

When we know something is ugly or “evil”, we’re quick to replace it with what we know to be a better solution. But if we don’t know why the solution is better, it makes it hard for us to investigate those things that look reasonable on the surface, yet have weaknesses just beneath the skin.

I’ll run through a quick example of what I mean, and then, it’ll be your turn to run with it and report back here. While I don’t use this approach all the time, I find it’s a neat tool to have handy when you’re trying to push your understanding of your code just a little bit farther.

Testing key events with Culerity : validates_presence_of :purpose

The application I’m writing depends heavily on key events. When you press enter in a specific text field, some other field opens, when you press tab, the text fields moves, etc. Of course I need to cover this in my cucumber integration tests. The Celerity API is a bit thin for this purpose: You can fire a, let’s say, keydown event - but it doesn’t pass through the specific key code.

Actually it’s easy when you know how. You can execute any javascript directly on the Culerity RemoteBrowserProxy object. In order to fire a specific key event, you have to create a KeyboardEvent, initialize it with whatever you want, and dispatch it on the element.

Full Frontal conference in Brighton, England (Yahoo! Developer Network Blog)

The success of a conference these days seem to be dependent on two things: the passion of the organizers and if it manages to focus on the subject. The first Full Frontal conference in Brighton, England had both of these and therefore turned out to be a massive success.

InfoQ: Pimp My Architecture

Dan North discusses an example of rearchitecting an application without rewriting it from scratch, and explains general strategies for a holistic rearchitecture such as changing the team culture, removing obsolete technologies, allowing mistakes to be made (and learned from), transitional architectures, introducing bounded contexts, refactoring and emergent simplicity, and rotating through roles.

InfoQ: Jonathan Dahl on Programming and Minimalism

In this interview taped at FutureRuby, Jonathan Dahl explains ways to write clear Ruby code and how to use minimalism as a guiding principle.

InfoQ: Polyglots Unite!

In this talk from FutureRuby, Foy Savas explains how to approach the concept of polyglot programming. Hint: an open mind helps.

State of Ruby VMs: Ruby Renaissance - igvita.com

In a short span of just a couple of years, the Ruby VM space has evolved to more than just a handful of choices: MRI, JRuby, IronRuby, MacRuby, Rubinius, MagLev, REE and BlueRuby. In fact, keeping up with all of the most recent developments within each VM is now easily a full-time job. For that reason, and with RubyConf ‘09 in full swing, let’s take a quick survey of the space and where it’s taking us.

Scheduling Crons with DelayedJob - Missing Feature Labs

I didn’t want to run & monitor a separate system to manage my periodic tasks, so I wrote a few lines of code to reschedule jobs every so often. It goes something like this.

Exporting MySQL database [Article] « elc technologies

mysqldump database_name -r dump.sql

Setup Ruby Enterprise Edition, nginx and Passenger (aka mod_rails) on Ubuntu | Zen and the Art of Programming

The following is a very short guide on setting up Ruby Enterprise Edition (REE), nginx and Passenger, for serving Ruby on Rails applications on Ubuntu. It also includes a few quick and easy optimization tips.

has_many :through - RubyConf 2009 Lightning Talks

Last night it was my great pleasure to host the Lightning Talks session at RubyConf 2009. We had an amazing series of 20 talks that took just over 2 hours. The tech gremlins seemed to be off drinking somewhere and none of the presentations failed.

Here’s a list of all the speakers and links to their stuff.

Falling Leaves (Argument from Design’s Blog)

Vines is a (very small currently) bundle of useful general step definitions for Cucumber, it’s not currently rails specific, and I may make rails-specific steps a different include so it can be used for regular ruby projects.

Anachronic went straight to plugin; in integration testing Paperclip I wanted to know whether deleting site images (my model wrapper for a paperclip image attachment) was cleaning up files correctly. I wanted to do it in Cucumber, and I wanted the steps to be simple.

Adman65’s AccessControl at master - GitHub

Announcing Caliper Community Statistics – The Devver Blog

For the past few months, we’ve been building Caliper to help you easily generate code metrics for your Ruby projects. We’ve recently added another dimension of metrics information: community statistics for all the Ruby projects that are currently in Caliper.

Optimizing asset bundling and serving with Rails - GitHub

We spend a lot of time optimizing the front end experience at GitHub. With that said, our asset (css, javascript, images) packaging and serving has evolved to be the best setup I’ve seen out of any web application I’ve worked on in my life.

Originally, I was going to package what we have up into a plugin, but realized that much of our asset packaging is specific our particular app architecture and choice of deployment strategy. If you haven’t read up on our deployment recipe read it now. I cannot stress enough how awesome it is to have 14 second no downtime deploys. In any case, you can find the relevant asset bundling code in this gist

High Scalability - High Scalability - 10 eBay Secrets for Planet Wide Scaling

You don’t even have to make a bid, Randy Shoup, an eBay Distinguished Architect, gives this presentation on how eBay scales, for free. Randy has done a fabulous job in this presentation and in other talks listed at the end of this post getting at the heart of the principles behind scalability. It’s more about ideas of how things work and fit together than a focusing on a particular technology stack.

Coding an Infrastructure Test First

Now that we outlined the programming languages for automating shell scripting, virtual machine creation ,network provisioning and os installation and beyond, I bet you as a devops are eager start writing your infrastructure code.

Assertive Code | Virtuous Code

Self-confident code does not ask questions about the data given to it. It enforces validity, asserts that its expectations are met, or ignores data which isn’t up to its standards. Previously we’ve looked at some methods for enforcement, using fetch() and Array(). Today I want to talk about the second tactic, assertions.

Protecting your ~/.gem directory « coderrr

If you accidentally run gem install without sudo you’ll end up with the gem installed into your ~/.gem directory instead of your system gem path. This can cause annoyances, one of which I mentioned here.

To protect yourself from your own stupidity just deny yourself access to the directory:

chmod -R u-w ~/.gem

25 Tips for Intermediate Git Users : Andy Jeffries : Ruby on Rails, MySQL and jQuery Developer

I’ve been using git for about 18 months now and thought I knew it pretty well. Then we had Scott Chacon from GitHub over to do some training at LVS, a supplier/developer of betting/gaming software (where I’m currently contracting) and I learnt a ton in the first day.

As someone who’s always felt fairly comfortable in Git, I thought sharing some of the nuggets I learnt with the community might help someone to find an answer without needing to do lots of research.

Brightbox Blog - Ruby on Rails Hosting – Clearing out Rails Sessions

As I’m sure you’re aware, Rails can be told to use ActiveRecord (and hence the MySQL database) to store session data. (New Rails apps use the cookie store by default—See the rails sessions guide for more info on both.)

However, this session data is never deleted, which means your session table continues to grow and grow forevermore. Your old sessions are left stored in the database, and although the table is indexed to help with finding sessions, it will eventually fill the disk up.

Scraping HTML documents that require POST data with YQL (Yahoo! Developer Network Blog)

YQL is a great tool to scrape HTML from the web and turn it into data to reuse. This is not an illegal act as it can be very useful to reuse information maintained for example on a blog. My personal portfolio page http://icant.co.uk gets most of its data from my blog hosted elsewhere.

YUI Theater — Allen Rabinovich: “YUI 3 Infographics” » Yahoo! User Interface Blog (YUIBlog)

Allen Rabinovich spoke at YUICONF 2009 last month about the future of the YUI Charts project. He and colleague Tripp Bridges are hard at work on the next generation of the product, and in this session Allen talks through the thinking behind the new architecture and what we can expect as the YUI 3 version comes to fruition.

GWT 2.0 RC1 Released | Pathfinder Development | Software Developers | Blogs

Well, GWT 2.0 RC1 (yes!) is out. I was going to wait for a while with some of my new projects until switching them over to GWT 2.0, but given the pace of the GWT 2.0 project, I may just switch them over now rather than going through a painful migration.

RubyPulse :: Episode 0.19 - racksh - "racksh (Rack::Shell) is a console for Rack based ruby web applications.. " - Marcin Kulik

“racksh (Rack::Shell) is a console for Rack based ruby web applications.. ” - Marcin Kulik

Les Hill — Ensure With Explicit Return

Quick! What does the following method do when thing.method_that_might_raise! raises SomeAppException? And why is this a code smell?

1 def some_method

2 thing.method_that_might_raise!

3 ensure

4 return thing

5 end

Hey, what smells like blue?: Easy Partials in Rails

I created something at my job that has proven to be extremely useful that I think many people could benefit from. I like to call it Easy Partials, and the goal is to make using partials a bit easier (in case the name didn’t make that glaringly obvious). The problem is that rendering a partial requires method calls when a little extra work will allow simpler and more readable partial invocation via convention.

Learning Advanced JavaScript

Learning Advanced JavaScript

1) Our Goal

2) Defining Functions

3) Named Functions

4) Functions as Objects

5) Context

6) Instantiation

7) Flexible Arguments

8) Closures

9) Temporary Scope

10) Function Prototypes

11) Instance Type

12) Inheritance

13) Built-in Prototypes

14) Enforcing Function Context

15) Bonus: Function Length

CSS Mixins vs. multiple classes — Wynn Netherland

A growing number of CSS meta-frameworks provide support for mixins. While CSS mixins provide a number of benefits, for me, they come with trade-offs.

Jammit: Industrial Strength Asset Packaging for Rails Apps

Earlier this year on Ruby Inside, we wrote about Sprockets - a Ruby library from 37signals that could take the various JavaScript files used in your project and compress them down on the fly into smaller portions to be more easily sent over the wire. Now, however, say hello to Jammit, an “industrial strength” asset packaging library for Rails that handles not only JavaScript, but also CSS and inline images.

nested relations in ActiveRecord | this oughta be interesting…

I personally don’t think this is all that exciting — but I see this question asked a lot and just want something to point at from now on.

madhatted.com::ShardTheLove - Horizontal Scaling For ActiveRecord

ShardTheLove is a library we use in both Ruby frameworks, Rails and Merb, for scaling our MySQL databases. The code has been humming on our servers for over a year now. There is an alternative library named DataFabric that has similar functionality to ShardTheLove, but the configuration felt clunky and the codebase was getting less maintenance than Mike looks to be giving it today. ShardTheLove is built with support for migrations, testing/RSpec, a flexibility of partitioning patterns, a simple syntax, support for Rails & Merb, and a great name :-) .

Case-insensitive validates_uniqueness_of slowness | Floorplanner Tech Blog

Watch out when using validates_uniqueness_of :field, :case_sensitive => false. Rails transforms this in a query that cannot be supported by an index, which will really slow validation down if the underlying table grows larger.

Practical Metaprogramming with Ruby: Storing Preferences: MicroISV on a Shoestring

Metaprogramming allows you to cut down on boilerplate code, making your programs shorter, easier to write, easier to read, and easier to test. Also, it reduces the impact of changes.

I’m going to demonstrate this using actual code from my PrintJob class, which encapsulates a single request to print out a set of bingo cards in Bingo Card Creator. PrintJobs can have any number of properties associated with them, and every time I implement a new feature the list tends to grow. For example, when I added in the ability to print in color, that required adding five properties. This pattern is widely applicable among many times of one-to-many relationships where you never really look at the many outside of the context of their relationship to the one — user preferences would be an obvious example.

John Resig - Deep Tracing of Internet Explorer

I typically don’t write about most performance analysis tools because, frankly, most of them are quite bland and don’t provide very interesting information or analysis. dynaTrace provides some information that I’ve never seen before - in any tool on any browser.

dynaTrace Ajax works by sticking low-level instrumentation into Internet Explorer when it launches, capturing any activity that occurs - and I mean virtually any activity that you can imagine. I noticed very little slow down when running the browser in tracing mode (although it’s sometimes hard to tell, considering the browser). However all of the tracing is recorded and saved for later, making it easy to record sessions for later analysis.

corey - Bundle(r) Yourself… and Get Ready to Cruise!

On a current project, we’ve just switched from GemInstaller to Bundler for managing our application’s gems.

All in all, the transition was painless… in our development environments. Of course, in order to keep things on running smoothly on the continuous integration box, we amended our rake cruise:spec task to start by running sh “gem bundle”.

A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 3 – The Devver Blog

In part 1 and part 2 of this series, we took a look at some of Ruby’s built-in ways to start subprocesses. In this article we’ll branch out a bit, and examine some of the tools available to us in Ruby’s Standard Library. In the process, we’ll demonstrate some lesser-known libraries.

Key-Value Stores in Ruby: The Wrap Up | Engine Yard Blog

This last article in our key-value series will briefly cover a few interesting topics that could each have had full articles of their own. This means that if they seem interesting to you, follow the links that I provide to get more information on them. Lastly, I’ll wrap up by introducing Moneta, written by Yehuda Katz, which provides a unified API for a wide variety of different Key-Value Stores. If you want to write code that allows the user to choose the store to use, you’ll want to pay attention to Moneta.

Brightbox Blog - Ruby on Rails Hosting – Expiring an entire page cache tree atomically

As you’ll all know, Rails has page caching baked right in – the first time an action is hit, it writes a html file of the result to the filesystem. Subsequent hits are served direct from the html file at high speed by the web server without ever involving your Rails app.

Expiring the cache is just a case of deleting the html file. But what if you want to expire an entire tree of cache files? Say you change something in a header or footer, so every single page needs expiring at once.

Null is Love » Blog Archive » Rotating Rails Log Files

One of the chores I dislike most is cleaning up and clearing out the log files in my Rails applications. On some of my higher profile sites, I get a lot of spiders probing my applications for security holes. They don’t succeed (knock on wood) but they do fill up my log files with errors.

I finally decided to get smart and get lazy (the two best traits a programmer can have), and I set up automatic log rotation on all of my Rails applications. The idea behind log rotation is simple: make a back up of the current log file, continue logging into a new or cleared log file, and discard log files that are older than a certain date.

remi :: Creating your own RubyGems

Now that GemCutter is becoming the standard host for gems, deploying gems couldn’t be easier!

We no longer need tools like hoe, newgem, bones, jeweler or others. Sure, these tools may still be useful, but we don’t need them to create simple gems!

remi :: Integrating Twitter into Rails

So, back when all I needed to do with many Twitter apps was to authenticate against Twitter’s OAuth and that was it, I created and screencasted the original Rack::OAuth gem.

After coding a few Twitter apps that needed more integration, and in response to feedback about the first gem, I’ve totally revamped Rack::OAuth so it now …

* is easy to do GET/POST to Twitter as the authenticated user

* is easy to save the user’s token so you can make requests, offline

* supports multiple OAuth providers

* is tested

* is better documented

* is simpler

The usage is nearly the same! Here’s a partial Rails-based example …

Robby on Rails : Sending email: Controllers versus Models

Fairly typical Rails code. Nothing alarming here, but I wanted to evaluate the call to the mailer in this scenario. When it comes to sending emails from your application, you can choose to do it from the controller as in the example above or in your models. Our team prefers to do this from our model via a callback as we are considering this to be part of our business logic.

What makes a good API wrapper? — Wynn Netherland

As cool new RESTful services crop up practically each day, I find myself using or writing a lot of Ruby API wrappers. So much that I’ve seen some common approaches emerge, each with their own pros and cons.

I had been considering this topic for some time when Zach’s comment on a recent post spurred me to write about it. Rattling around in the back of my head is Chad Fowler’s post from 2007 about Facebooker v. RFacebook and writing APIs to wrap APIs, so I’d like to start there.

11 Things to Consider Before Deploying Your Rails Application | Vinsol

At VinSol, we have been developing and deploying Rails applications for more than four years. During this period, we have identified some best practices that we prefer to follow while deploying rails application to production server.

Below is the checklist of these practices:

Three implicit contexts in Ruby - 世界線航跡蔵

As I mentioned in an old article, though I’m sorry about it is written in Japanese, Ruby always has three implicit contexts: self), so called `klass’ and the constant definition point. Yehuda is confusing self with `klass’.

Metaprogramming in Ruby: It’s All About the Self « Katz Got Your Tongue?

After writing my last post on Rails plugin idioms, I realized that Ruby metaprogramming, at its core, is actually quite simple.

It comes down to the fact that all Ruby code is executed code–there is no separate compile or runtime phase. In Ruby, every line of code is executed against a particular self. Consider the following five snippets:

How can I go from noob programmer to Ruby web app developer in a month? : ruby

heya

I have some basic understanding of HTML, PHP and CSS… I wouldn’t call myself a programmer, and I haven’t done a degree in compsci. However I’m planning to create a web app within the next month or two and hope to get to the point sometime in the future where I can program any kind of web app prototype.

Any idea/links/tips on how I can learn and put together a web app in Ruby within a month?

cheers

flyerhzm’s rails_best_practices at master - GitHub

Google will factor page load speed into search result rankings

t has come out that Google is seriously considering using page loading time as a factor when returning search results. This isn’t some unsubstantiated rumor, either; it comes from none other than Matt Cutts, the high-profile Google employee who works on Google’s web spam team.

WNYC - Radiolab: Sperm (November 21, 2008)
Finally somebody points out how obnoixious “Only in America” is.
2009-01-03 - Today’s Ruby/Rails Reading
2009-02-13- Today’s Ruby/Rails Reading

This entry was posted on Tuesday, November 24th, 2009 at 11:41 pm and is filed under Ruby on Rails. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.