Posts tagged: programming

Rails: Rendering Dynamic SVG Images in respond_to

SVG is a vector image described in XML. This post shows how to to render SVG images inline with Rails.

Android: Consuming a Remote JSON API with Volley

In the previous tutorial, you learned how to use Volley’s built-in networking tools to quickly download a network resource and display the results. Volley removes lots of boiler-plate code, and lets you concentrate on the details of your app rather than dealing with low-level networking technologies.

Android: Getting Started with Volley

Volley is a library developed by Google for fast, easy networking in Android. It wraps up a lot of boiler plate code that you would normally have to code yourself when connecting to servers, queuing requests, handling errors, caching, etc.

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.

Android: Getting Started with Databases and ContentProviders Part 1

Clone the code from GitHub

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.

Testing Rendered Views with RSpec2, Capybara and Rails 3.

While view tests are brittle, easily breaking when the design of a page changes, they are undoubtedly handy for checking the important parts of a page are rendered. I usually check for page titles, model attributes/tables or forms, and footer element, and so on.

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.

Android: Spinner-Like UI for Selecting Multiple Options

Rails 3: How to Simulate Paperclip Attachments With FactoryGirl

In developing the next phase of, 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.

Lightweight Web Apps: Getting Started With Sinatra

For many reasons, I’m a huge fan of Rails for building web software, and by implication, coding in Ruby. When you’ve spent a little time working with Ruby, it’s difficult to go back to more traditional languages such as PHP.

Android: Double Taps on a MapView with Overlays

Download the source code for this post PushPin.tar.gz,

Building apps with Rails 3, RSpec, FactoryGirl and Mocha.

Clone the source code from github.

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: Getting the id of form fields inside a fields_for block

Something that seems to crop up a lot when working with nested forms is the need to access the id of an input field generated inside a fields_for loop. The problem is that the FormBuilder object doesn’t expose its index attribute, so you can’t specify the full id of the field. For example:

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.

Code: Being Conventional

Moving to Ruby on Rails has been great for helping to develop my coding skills, and I’m now adapting what I produce in other languages and projects to take advantage of the patterns used in Rails. One of the most useful has been convention over configuration:

Rails: Abstract Models - ActiveRecord Without Tables

I recently hit a situation where I needed an ActiveRecord model with no corresponding database table. The model had to represent a collection of other event-type models - for example: Birthdays, Weddings, Anniversaries, etc.

Rails: Building Complex Search Filters with ActiveRecord and ez_where

With the release of Rails 3, the plugins and code described below no longer works. Read the updated post on building dynamic complex queries with composed scopes.

Rails: Building Complex Search Filters with ActiveRecord and ez_where - Part 2

With the release of Rails 3, the plugins and code described below no longer works. Read the updated post on building dynamic complex queries with composed scopes.

Rails: Building Complex Search Filters with ActiveRecord and ez_where

With the release of Rails 3, the plugins and code described below no longer works. Read the updated post on building dynamic complex queries with composed scopes.

Rails: Retaining select_tag's Selected Option

Working with Rails’ select_tag helper to build a search form, I needed to retain the user’s selected value after a form get, and was using the options_for_select helper:

Rails: Writing DRY Custom Validators

It is well know that Rails can quickly validate user input using validators such as validates_presence_of. What happens, though, when you need to write your own custom validations, whilst keeping things DRY?

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: Upgrading test_helper.rb for Rails 2.3

Keen to be using the latest code and features of Rails, I installed Rails 2.3 for development today. So far, most of the app has worked fine after a running a rake rails:update. However, today I came across an error when running my unit tests:

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:

Rails Projects - Call For Advice

I’m about to start working on a large Rails project at work, and hoped to seek advice on working with larger projects using the framework. Most of the tutorials and books I’ve read are written for a single developer working on the code; our project, though, will be worked on by several developers and other staff. One of the decisions I think we need to get right from the start is structuring our development database environment.

Agile Development Course

This week I attended a workshop on agile development - Crawl Before You Leap: An Introduction to Agile Development run by AgileLab. The course leaned towards agile project management more so than agile coding practice, and stressed the use of stories and iterations, tests and reflection. As I am normally more focussed on the code-aspects of agile practice, there were some great new concepts and new angles for me - as well as a bunch of handy tips.

PostgreSQL: Cast a String to Timestamp in PostgreSQL

If storing a date/timestamp in a varchar or text field in postgres, the to_timestamp() function will let you access the value as a ‘real’ date. The second parameter tells the function the format of your string:

Cocoa: Cocoa Bindings and NSPopUpButton

A frustrating problem I came across today when I tried binding an NSPopUpButton’s selection key to an NSArrayController’s selection was that the NSPopUpButton would always display a ‘ghost’ object -one of the opaque classes internal to Cocoa/Core-Data Bindings(_NSControllerObjectProxy... or similar).

Running Aptana Jaxer on Ubuntu 8.04

I’ve not had any time to try out Jaxer yet, but the idea of a single platform for both client and server-side processing sounds good.

Javascript: Singleton Pattern in Javascript

At work, I have been developing a custom framework loosely based on my experience with the symfony and Propel. One of the requirements for the application under development is to store the application’s state both on the server and the client, so that information can be passed by means of AJAX requests.

Gmail Contacts API

I noticed today that Google has finally launched an API for its contacts application. I’m sure I’m not alone in wanting to easily and properly synchronise contact data amongst Gmail, Address Book, mobile, etc. and use Gmail contacts as a single repository.

Core Data: Cached Transient Properites

In writing HostManager 2.0, I’ve come up against a lot of problems caused by the dark magic that is Cocoa bindings and key-value observing. One of the most troublesome of these has been with transient (calculated) properties.

Unfaulting Core Data Objects After Load

Hours of searching for an answer were beginning to lead me to the conclusion that it was impossible to unfault transient properties of an NSManagedObject after loading them from a datafile.

AS2.0 Charting Components

Pie Chart

J2ME Uploading Images to PHP Script

8 March 2011 Kutay Ozdogru has posted a recent, complete example of how to upload images via J2ME to PHP on the Nokia forums.

Final Project and Space Exploration

My first prototype applet for the Production of Space Practice is now working. Currently, the J2ME applet connects to surrounding devices (via Bluetooth). These connections are then visualised to show your social connection; your presence in the social space. As you move around the physical world, your social connectivity changes, morphing the visual connections.