Posts tagged: tips

Android: Using Gradle

On a couple of Android projects I’m working on, I’ve switched to using the new Gradle Build system. The idea of storing the entire build configuration in one place is great.

Rails 3: Storing Model Metadata Attributes with ActiveRecord::Store

I recently discovered the excellent ActiveRecord store method whilst researching the best-practice for storing optional, flexible metadata against a record. store lets you keep simple key/value data into a single text column on your model.

Android: How to test Local Web Apps on an Emulated Device (AVD)

Android AVD running local Web App

Rails 3: How to Autoload and Autorequire your Custom Library Code

Every time I start a new Rails 3 project, I’m always caught out by its autoloading behaviour. Rails 3 will only require (and so autoload) a module when it is first encountered within the application code, for example by a call to include or require.

Ubuntu 11.04 Beta - How to test Unity in VirtualBox 4

Ubuntu 11.04 Beta ScreenshotIf you like to test out the latest and greatest builds of Ubuntu, you might like to try the latest 11.04 beta in VirtualBox.

Rails 3: How to Dynamically Build Complex Queries with Composed Scopes

In previous posts, I wrote how to build complex search queries in Rails 2 using the ez_where plugin. In Rails 3, such plugins and long-winded code is completely unnecessary thanks to the powerful ActiveRelation query interface.

Rails 3: How to Simulate Paperclip Attachments With FactoryGirl

In developing the next phase of markstocks.com, I needed to simulate a file upload attribute in my FactoryGirl factories. A quick Google revealed some promising code, but everything out there was based on Rails 2.

Rails: Multiple default scopes for ActiveRecord

Default scopes were introduced in Rails 2.3 to allow a default set of options to be applied to any find methods. The common example is to always order a set of results by a given column, e.g:

Rails: Writing library code

Plugins are great in Rails, but sometimes they seem a bit much for certain tasks, such as writing a quick utility mixin. In a previous post on writing DRY validators, I discussed putting the validation mixin code inside Rails’ config/initializers directory.

Rails: Validating Unique Attributes with acts_as_revisable

I’ve been using the acts_as_revisable plugin in my Rails apps to store a revision history of ActiveRecord models. The plugin automatically versions your models, and allows you to navigate revisions; branch and merge changes, and perform bulk changesets.

Rails: Upgrade Passenger for Rails 2.3.3

I recently upgraded a project from Rails 2.3.2 to 2.3.3, after which I started getting strange the following error from Passenger:

Chroming Firefox 3.5

Firefox Chromed

Updating Wordpress to Feedburner's New Feed URL

Feedburner Plugin Settings

Rails: Setting Default Attributes on an ActiveRecord Model

Update 28 June 2009: Rollo Tomazzi noted in the comments that the method described below will not work for hash-value attributes. He has written a review of the various methods for setting default attribute values on his blog.

Rails: Unit Testing Rails Single-Table Inheritance Models

I recently spent not an insignificant amount of time trying to get my unit tests to comply with Rails’ single-table inheritance. Single table inheritance allows you to map a hierarchy of classes to a single table in the database, so from one user table I can have an Employee and a Manager. They both inherit from a User model in Rails, and are stored in the users database table. A manager, though, might have more properties (fields) and methods than an Employee, which can be defined in manager.rb:

How to stop rsync overloading your wireless/LAN

I am currently using rsync as a backup solution between two computers and an external backup drive, all operating across my wireless LAN. However, every so often - and always when syncing a lot of files - rsync has knocked out my wireless internet. Today, I decided to find out what was going on, and found the solution:

Check your language for GMail IMAP?

Like quite a few others, I was pleased to hear that Google has finally got round to adding IMAP to its GMail service. IMAP means checking and dealing with emails from multiple sources is a lot simpler, as any changes are synchronised back to the server. I patiently waited for the IMAP tab to appear in my settings panel, as Google had announced it would take a few days to activate. After a couple of days, though, I began to wonder if they had forgotten about my one lonely GMail account, and starting browsing the help pages for any hint of what might be happening. By sheer luck, I happened upon this little nugget of info: