Rails Reading January 26 2010

The Coast.

Flvorful Bloggage : A Simple Pattern for Ruby’s inject method

Ruby’s inject is an often misunderstood method, but you would be surprised at how much it can help you clean up your code. I see many developers skipping over this method in favor of the non-injectified way, mainly because they dont get how to use inject properly. So we’ll take a look at some common examples and then you will be able to see the pattern that allows you to take advantage of inject.

4294967295 and MySQL INT(20) Syntax Blows - Laughing Meme

If you’re ever debugging a problem and you see the number 42-mumble-mumble-mumble-7295 you’ve run out of 32-bit storage. If you see 2-mumble-mumble-mumble-647 (2147483647) you’ve run out of signed 32-bit storage. 167-mumble-mumble-15 (16777215) you’ve run out of 24-bits and 65-mumble-mumble-35 (65535) you’ve run out of 16-bits of integers.

Chargify: Rails Powered Recurring Billing Service With An ActiveResource API

Over the last couple of months, a new billing and subscription company - Chargify - have been popping up around the Web 2.0, SaaS, and Rails scenes. Notably, Chargify’s CEO is Lance Walley, co-founder of Rails hosting company Engine Yard. Rails developers are a pretty entrepreneurial lot and Chargify have a lot to offer Rails developers who need to set up billing systems.

Pagetest - where web sites go to get FAST!

Welcome. Pagetest allows you to provide the URL of a webpage to be tested. The test will be conducted from the location specified and you will be provided a waterfall of your page load performance as well as a comparison against an optimization checklist. Please visit the PageTest wiki page for more information. Sample results for AOL.com can be seen here.

This tool lets you test web pages that are directly accessible as an URL from the Internet. If you need to test a page inside of a firewall or something more complicated than a web page (an authenticated product like webmail for example) please download the desktop version of PageTest which this is based on.

Tips For Sending Valid E-mails From Websites

E-mails are one of the key elements of a website/web application. They are used in contact forms, sign-ups, notifications, newsletters, etc.

It is a common experience that sometimes e-mails sent from websites go to the junk folders or never reach.

Although it is not always possible to detect the reasons for this, there are several things that we can do to minimize the risk. Here they are:

The Chris O Show: Gravatar default images - a better way

Hey, so at Harmonypark we decided to put gravatars into one of our applications (which is so easy it’s not funny) – and when the time came to select the default images for the gravatar I piped up: “I know how to fix this!” and pointed to a blog post I wrote about it long ago: (You can read it here.)

My colleague Ebony came up with a great solution: “Why not use another gravatar as the default image.”

Which is an utterly brilliant idea – that way the default image gravatar will scale correctly, and we wouldn’t have to mess around with having different image sizes for the different scaled default images. Here’s how we did it:

Find The Right JavaScript Solution With A 7-Step Test - Smashing Magazine

# How stable is the solution?

Is a good alternative available if this one doesn’t work?

# How easy is it to customize?

Do you need to be a JavaScript expert to modify the widget?

# How usable and accessible is it?

Are users who don’t have a mouse or are on a mobile browser blocked?

# Do you understand what’s going on?

Would you be able to fix a problem and explain it to others?

# Is it a contained solution?

Will other scripts be able to interfere with it, or would it contaminate the document?

# How dedicated is the developer?

Will the solution be maintained in the future?

# What is supported, and how can you extend functionality?

A new browser and client request is always around the corner?

InfoQ: Ruby Creator Yukihiro “Matz” about Ruby, Functional Programming and Programming Languages Design

In this interview, Yukihiro Matsumoto talks about programming languages design and decisions he had to take while designing Ruby. He also discusses other programming languages including Haskell, Scala, Python and Clojure. While talking about Ruby language and functional programming, Matz explores opportunities of integrating some of FP into Ruby and imagines a purer IO approach for it.

Tainted Data

“Tainted” objects are those that have come from some type of user input. Either from a file, the keyboard or the network, unless the object is a literal in the program or created by the program directly, it will be tainted. The tainted flag is always there on your objects, all you have to do is check it before you do anything unsafe. If you’ve confirmed that the data is indeed safe, you can then untaint the object.

Agile: In A Flash: Refactoring Inhibitors

With the need to avoid degradation, it’s important to recognize anything that might prevent a team from refactoring as much as they must. This card provides some inhibitors to refactoring that you should watch for.

Open-Source in Action

Several things will now happen, because we contributed back to the open-source library, instead of keeping this “addition” to ourself (and the client):

* other developers facing this same problem can now leverage our code when they use geokit

* other developers can now submit even more functionality, fixes or enhancements to our code, and even better support for problems we may have one day, meaning that we will eventually benefit from this too

* our client now knows that the code they relied on us to develop now has even more developers eyeing it, making sure it works

* our client (through us) is contributing to open-source, and can feel good about using open-source technologies, having fulfilled their part of the agreement they implicitly made, by leveraging the gains (and price) o

alex blabs - UTC vs Ruby, ActiveRecord, Sinatra, Heroku and Postgres

Now that I’m starting to use DelayedJob to perform jobs in the future in my Heroku Sinatra app, its important that they happen at the scheduled time. But unless you pay attention, you’ll find that times get mysteriously changed — in my case, since I’m in San Francisco in the wintertime, by +/-8 hours — which means that some conversion to or from UTC is being attempted, but it’s only working halfway.

Trying to keep a handle on which libraries are attempting, and which are failing, to convert times is a losing battle, so I’m trying to do the right thing and save all my times in the database in UTC, and convert them to and from the user’s local time as close to the UI as possible. Unfortunately, a variety of gotchas in Ruby and ActiveRecord and PostgreSQL makes this trickier than it should be. Here’s a little catalog of my workarounds.

nirvdrum’s Weblog :: On Amazon EC2 Spot Instances

A couple months ago Amazon announced support for EC2 spot instances. In a nutshell, a spot instance is an EC2 instance that you bid on and that Amazon creates and destroys based upon whatever spare capacity is available in a given EC2 availability zone (i.e., supply) and your maximum bidding price versus the current spot instance price (i.e., demand). A spot instance is less flexible than an on-demand or reserved instance is in terms of lifecycle, but could be significantly cheaper if your application can handle that volatility.

This post summarizes my experience with spot instances and how I make use of them.

has_many :bugs, :through => :rails: Active Record Query Interface 3.0

I’ve been working on revamping the Active Record query interface for the last few weeks ( while taking some time off in India from consulting work, before joining 37signals ), building on top of Emilio’s GSOC project of integrating ARel and ActiveRecord. So here’s an overview of how things are going to work in Rails 3.

Rails 3 Reading Material | Medium eXposure

Rails 3 is going to bring a lot of new stuff to the table. Wouldn’t hurt to organize some reading material in categorized and chronological order. So here goes whatever I scavenged so far. Leave comments so I can add more links or if I should mark something as obsolete.

Episode 104: Something New | Rails Envy

Episode #104: Something new. I’m sad to say that this will be the last episode of the Rails Envy podcast. I’m happy to say that Dan and I will be doing The Ruby Show which will follow the same general flow of Rails Envy. There’s no need to update your feeds (though you can if you’d like) because the feed will redirect for the foreseeable future. We’ve also got some other fun stuff planned so stay tuned!

Getting Up To Speed With Rails 3

I’m proud to announce that darwinweb.net is now running Rails 3.0-pre. I undertook the project as part of Bugmash last weekend, but it turned out to be a very deep rabbit hole; a two-day bugmash was too short to really dig into the meat of Rails 3 which is in ample supply.

The scope of changes to Rails is astonishing. There’s a lot of new blood contributing and brilliant ideas are popping left and right. The result is that Rails 3 represents a major maturation inflection point. It’s graduating from the scrappy, opinionated upstart to a very modular and full-featured framework containing what may once have been considered a disturbing amount of enterprise-readiness. It’s bittersweet and perhaps a bit ironic that the internals have acquired so many moving parts, but as a professional Rails developer the new flexibility and modularity is far too awesome to denounce in any way.

How to Make a Heatmap – a Quick and Easy Solution | FlowingData

In case you don’t know what a heatmap is, it’s basically a table that has colors in place of numbers. Colors correspond to the level of the measurement. Each column can be a different metric like above, or it can be all the same like this one. It’s useful for finding highs and lows and sometimes, patterns.

On to the tutorial.

Step 0. Download R

When should you store serialized objects in the database? | MySQL Performance Blog

A while back Friendfeed posted a blog post explaining how they changed from storing data in MySQL columns to serializing data and just storing it inside TEXT/BLOB columns. It seems that since then, the technique has gotten more popular with Ruby gems now around to do this for you automatically.

Perfection kills » Optimizing HTML

Mister Bleigh - Rails Quick Tip: Readable Conditional Validation

This is something that many may already use as a best practice, but if not it’s something simple and convenient to add to your repertoire. Sometimes you may have a model that requires additional information if a certain condition is met. For example, I may require a user to add more information about themselves if they wish to be listed publicly, whereas I would not if they do not wish to be listed. By combining ActiveSupport’s Object#with_options and ActiveRecord’s conditional validations, we can implement this behavior in a straightforward and readable manner (assuming here that there is a boolean field called “listed” in the database that is exposed as a checkbox or similar to the user):

PostageApp - Benefits & Features

Josh, The Rails Guy - Ruby, Rails & 5 Ways to Improve Performance

When I was speaking last night at the BIMA & Ultraspeed Virtualisation event on virtualisation and web application development, I was surprised to find that not a lot of people know about the simple ways that you can improve performance without much development or systems administration time at all.

In fact, most of the techniques that I’m going to go over aren’t new, and are pretty well publicised. Both Google and Yahoo! both go over them in tonnes of detail.

omgbloglol

This post is kicking off a series that I’m doing about moving your skills and migrating your code to Rails 3. I’ll be sharing some practical insights and covering some pretty in-depth topics as we go along (I’ve got some notes for entries about upgrading plugins, taking advantage of new features like the agnosticism, migrating applications, and so on), but before I go into a lot of specifics, I thought it might be useful to go over some of the high-level philosophical and architectural changes that have gone on in the Rails code between versions 2 and 3.

LukeW | Development Tools From An Event Apart

The An Event Apart conference in San Francisco, CA last month introduced me to a lot of interesting projects, frameworks, and tools for Web development. Though some of these have been around for a while, seeing them all together (compiled across all the speaker’s presentations) got me really excited about what can be done online. So you can share in that excitement too, here’s the list.

Sometimes It’s The Little Things « Grumpy Old Programmer

From time to time I trawl through my blog subscriptions: some are defunct while others may have changed their feed details sufficently that they’re no longer being picked up. I have about 270 subscriptions, which makes the job a chore and hence it doesn’t get done very frequently. The upshot is, for the case where the blog hasn’t just died, I sometimes miss something.

What should we do with tedious manual activities? Automate! I went and did some investigation.

Wait till I come! » How I build my data.gov.uk mashup – UK-House-Prices.com

UK-House-Prices.com is a web site to see how the prices in a certain area changed over the years using a data set released by the UK government as part of the data.gov.uk initiative.

ActiveWarehouse: Extract-Transform-Load Tool

The ActiveWarehouse ETL component provides a means of getting data from multiple data sources into your data warehouse. The links in the side bar provide additional information on ETL.

How To Create an IE-Only Stylesheet | CSS-Tricks

If you read this blog, there is a 99% chance you’ve had a hair-pulling experience with IE. But if you are worth your salt as a CSS coder, you should be able to deal with it. I am of the opinion that you can handle anything IE can throw at you without the use of hacks. Hacks are dangerous, since they are based on non-standard exploits, you can’t predict how they are going to behave in future browsers. The tool of choice for fighting IE problems is the conditional stylesheet. IE provides comment tags, supported all the way up to the current IE 8 to target specific versions, as well as greater-than/less-than stuff for targeting multiple versions at once.

Free Website Uptime Monitor: Uptime Robot

Uptime Robot is a totally free service which monitors your websites every 5 minutes & alerts you if they go down.

It allows you to monitor up to 50 websites & alerts can be received via e-mail or SMS

UK Launches Open Data Site; Puts Data.gov to Shame

A new website dedicated to making non-personal data held by the U.K. government available for software developers has launched today with the help of Sir Tim Berners-Lee, the inventor of the World Wide Web. Data.gov.uk is being slammed with traffic but six months after the U.S. government opened its Data.gov site the U.K. site already has more than three times as much data than the U.S. site offers today.

Ruby on Windows: Connecting to One of Many Open Documents

word = WIN32OLE.connect(’Word.Application’)

That works great if you have just one instance of the application running, with one or multiple documents open. But suppose you have multiple instances of the application running? How can you be sure that you connect to the instance with Document B, and not the instance with Document A?

nvie.com » Blog Archive » A successful Git branching model

In this post I present the development model that I’ve introduced for all of my projects (both at work and private) about a year ago, and which has turned out to be very successful. I’ve been meaning to write about it for a while now, but I’ve never really found the time to do so thoroughly, until now. I won’t talk about any of the projects’ details, merely about the branching strategy and release management.

ThinkingSphinx exits, enters ActsAsSolrReloaded | Diego Carrion

Annoyed with the situation of the project, I decided to fork the fork I liked the most and created a new repository called acts_as_solr_reloaded, with new features. This way, I hope the project gets easier to be found and that it gives more trust. I’m also compromising myself to keep the repository up to date and to pull contributions.

As today, the new features acts_as_solr_reloaded comes with are:

* support for dynamic attributes

* geo-localization or geo-spatial search

* integration with acts-as-taggable-on

* highlighting

* relevance ranking

jQuery Lint – James Padolsey

jQuery Lint is a simple script you can download and use with jQuery. It works over the top of jQuery and diligently reports errors and any incorrect usage of jQuery. It will also, to some extent, offer guidance on best practices and performance concerns.

Unlike JSLint, jQuery Lint is a runtime reporter.

Web Security: Are You Part Of The Problem? - Smashing Magazine

Website security is an interesting topic and should be high on the radar of anyone who has a Web presence under their control. Ineffective Web security leads to all of the things that make us hate the Web: spam, viruses, identity theft, to name a few.

pivotal’s refraction at master - GitHub

Luke Melia » Redis in Practice: Who’s Online?

Redis is one of the most interesting of the NOSQL solutions. It goes beyond a simple key-value store in that keys’ values can be simple strings, but can also be data structures. Redis currently supports lists, sets and sorted sets. This post provides an example of using Redis’ Set data type in a recent feature I implemented for Weplay.

Weplay members were told us they wanted to be able to see which of their friends were online, so we decided to add the feature. Let’s look at how Redis was instrumental in this functionality.

Should You Use JavaScript Library CDNs? « Lickity Split

JavaScript Library CDNs seem like a performance no brainer. Use the service, your site is loads faster and consumes less bandwidth. This post will explore if and under what conditions does a JavaScript Library CDN actually improve web performance.

Importing Legacy Data in Rails - blah blah woof woof | tim riley

ur current work project is a long-overdue rebuild of a critical business system as a modern Rails web app. We’re building this thing according to agile practices to the best of our ability. Each week we provide a new, working release that is an incremental improvement on the last. We’re not looking to replace the current system in a single swoop, and expect the new system to work alongside the old one for quite a while.

This means that we’ll need to maintain the same data in both systems for the duration of their lives together. We don’t want the new Rails app to access the data directly from the old app’s database, since this would prevent us from following the conventions that makes working with Rails so pleasant. Instead, we’ve come up with a way to import the legacy data into a new database.

airblade’s paper_trail at master - GitHub - sconover-code

PaperTrail lets you track changes to your models’ data. It’s good for auditing or versioning. You can see how a model looked at any stage in its lifecycle, revert it to any version, and even undelete it after it’s been destroyed.

Simple named_scope Searching | Viget Extend

One of the coolest aspects of named_scopes in ActiveRecord is their ability to chain together. One can chain a number of named_scopes onto each other, and the result is a single SQL query. Using this feature, I’ve come up with an easy way to do some simple searching.

jQuery 1.4 Released: The 15 New Features you Must Know | Nettuts+

jQuery 1.4 was recently released. This wasn’t simply a maintenance release as some had speculated; there are many new features, enhancements and performance improvements included in 1.4! This post covers the new features and enhancements that you may find beneficial.

Nginx Development Script for Passenger | Free PeepCode Blog

But even with the minimal configuration needed to create a new Passenger app, it’s inconvenient for spontaneous apps or small demos. If I want to try out a Rails 3 application with Passenger, I don’t want to configure a new virtual host for just a few minutes of experimentation.

At RailsCamp 6, PeepCode author Pat Allan showed a beautiful solution. It’s a script that starts Nginx from any directory3 using a shared configuration file. I modified it ever so slightly and posted a screencast above with a walkthrough.

On-the-fly image handling with Dragonfly @ Bamboo Blog

Dragonfly, a Rack-based ruby gem for processing/encoding on the fly.

Making Friends with FFI | Atomic Spin

Make friends. If you want your C code to play nicely with the other VMs out there, then FFI (foreign function interface) is the answer. FFI is built-in to JRuby and MacRuby; MRI requires a compiled gem for FFI access. After a night of experimentation, I was able to get C code from the Chipmunk Physics library running in Ruby via FFI (chipmunk-ffi). Just tell FFI what function to attach, what arguments it takes, what the return type is, and it will take care of the rest. FFI is a great tool that any Ruby developer should have in their tool belt and consider against writing a C extension.

Magic

Ruby FFI wrapper to the “magic” library, that determines content type and encoding of files and strings. The library does three types of tests: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be returned.

Using Geokit with Searchlogic - Binary Logic

For those of you that don’t know, geokit is a great little gem that allows you to geocode addresses. It adds in very easy to use options in the ActiveRecord find method. Ex:

# will return all venues within 10 miles of the 10018 zip code

Venue.find(:all, :origin => “10018″, :within => 10)

The problem is that you can’t use geokit options in a named scope. Since searchlogic is named scope driven this presented a problem. So I wrote a little module that transfers geokit options from named scopes to the actual arguments of the method:

How to Create Facebook Style Footer Admin Panel | Web Resources | WebAppers

Trend All the Fucking Time (TRAFT?) | James on Software

My new years resolution was to measure more. For a while now, I’ve wanted to get a better picture of our systems and our business, and hopefully, how they relate.

So, my first day back at work after the holidays, I started looking for the right tool to gather data with. After investigating some of the options, I wound up settling on munin.

I say settling because I was quite dissatisfied with the available options. I tried everything from collectd to reconnoiter and found all of the solutions horribly lacking in some way. This is an enormous market just waiting for a startup to revolutionize it.

In any event, we were already using munin to trend our system metrics. So, now it was just a matter of figuring out how to get our business metrics in there. Here’s how we did

Powerful Color Manipulation with Sass : Nex3

There’s a lot of exciting stuff coming down the pipeline for Sass 2.41. I want to keep folks up-to-date on what they have to look forward to, so I’m starting a series of blog posts detailing the new features I’ve been working on.

New Color Functions

One of the new features I’m most excited about is a huge expansion in the color-manipulation capabilities of Sass. Sass has always supported arithmetic with colors, allowing them to be added, subtracted, and even multiplied. For example, #f00 + #00f = #f0f in Sass.

Ruby 1.9 character encoding field notes · Fingertips

As you probably already know the String class became encoding aware in Ruby 1.9. This makes it possible to manipulate strings on the character level instead of on byte level. However, it’s still a general purpose API which means writing a few lines of code to get stuff done.

It’s common to choose one internal representation for character data in an application and convert all incoming strings to this representation. For example, in modern applications strings are often encoded in UTF-8 or UTF-16. I took some time to figure out how to do this in Ruby 1.9.

ActiveModel: Make Any Ruby Object Feel Like ActiveRecord « Katz Got Your Tongue?

Rails 2.3 has a ton of really nice functionality locked up in monolithic components. I’ve posted quite a bit about how we’ve opened up a lot of that functionality in ActionPack, making it easier to reuse the router, dispatcher, and individual parts of ActionController. ActiveModel is another way we’ve exposed useful functionality to you in Rails 3.

zerosum dirt(nap) - Resque Mailer

Following in the footsteps of DelayedJobMailer, ResqueMailer allows you to shift processing of your existing mailers to an async Resque worker without doing pretty much anything. Just install the gem in your Rails project (via Gemcutter) and then mix the Resque::Mailer module into your mailer.

Website Performance: What To Know and What You Can Do - Smashing Magazine

The good news (and hard truth) about performance is that 80 to 90% of poor performance happens in the front end. Once the browser gets the HTML, the server is done and the back-end developer can do nothing more. The browser then starts doing things to our HTML, and we are at its mercy. This means that to achieve peak performance, we have to optimize our JavaScript, images, CSS and HTML, as well as the back end.

Phusion Passenger 2.2.9 released « Phusion Corporate Blog

Phusion Passenger is under constant maintenance and development. We are pleased to announce Phusion Passenger version 2.2.9.

Fixed compatibility with Rails 3.

What’s up with the Gem Bundler?

Fixed support for ActiveRecord subclasses that connect to another database.

[Nginx] Fixed PCRE URL.

The U.S. Supreme Court has a Sarah Palin moment.
Interesting post on how flickr deals with character encoding in photo metadata
2009-01-21 - Today’s Ruby/Rails Reading
2009-01-03 - Today’s Ruby/Rails Reading

This entry was posted on Tuesday, January 26th, 2010 at 11:32 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.