shiningthrough

Using Dropbox to share Snippets between computers

25 July 2010
I think Snippets is the best code snippets application for Mac OS X, and I have it setup with Dropbox so my snippets can by synchronised between multiple machines. There are some instructions on the fuelcollective.com website, but they didn't work for me, the following steps show how I did it. If your running Snippets, first quit the application. Create a new Folder in Dropbox, I called min...

A comparison of Ruby pass by reference and C++ pass by reference

12 April 2010
Take the following Ruby and C++ applications: def do_something(text) text = "bar" end text = "foo" do_something(text) puts text The Ruby program above outputs "foo" Variable "text" holds address of String object containing "foo" Call do_something function passing in address of String object containing "foo" Address of String object containing "foo" gets copied to local variable "text" Lo...

Simple way to profile your Ruby application

05 April 2010
start = Time.now # Place code here to time its execution. puts "#{ Time.now - start } seconds to execute."

Ignoring Ruby On Rails files with Git, on OS X, and using TextMate

03 April 2010
I thought I would share which files I ignore with Git, while developing Ruby On Rails applications using TextMate on Mac OS X. There are 2 ways to ignore files using Git: Specify the files to ignore in a .gitignore file that can be created in any Git directory, but is most commonly created just once in your root Git directory. This file gets included in your git repository, it's for ignoring...

A simple example of using Modules with Ruby On Rails

28 March 2010
A module provides a means of grouping together classes, methods and constants. This is advantageous for two reasons: It provides a namespace to avoid name clashes. It allows you to "mixin" the contents of the module into an existing class so that the module functions behave as if they were methods of the class. Lets see this in action with a simple example: We create a module called TextSta...

Apple with Alan Partridge, ah ha!

23 March 2010
How did Alan Partridge get into a 1970's Apple Advert?

Dynamic multiple image uploads with Ruby on Rails

23 February 2010
This tutorial explains how to create a simple web application that allows a user to upload one, or multiple images. It makes use of the paperclip plugin, Ajax using RJS and new multi-model form functionality that has arrived with Rails 2.3.3 in the form of accepts_nested_attributes_for. Make sure your up to date with Rails, you will need at least 2.3.3 Lets start by making a new rails applica...

AuthLogic

14 July 2009
I know that it is rather old news by now, but I just discovered the wonders of Authlogic. If you have any sort of private interface to your app, whether it is adding products to your store or just adding comments to a forum, you may want some sort of authentication to keep the Viagra-toting spam-hordes at bay. The great thing about Authlogic is that it is very light and adaptable, especially...

Install RMagick and ImageMagick on Leopard OS X, quickly and simply

15 February 2009
RMagick is a Ruby interface that allows access to the ImageMagick image processing library. When I started out developing in Ruby on Rails, installing RMagick was quite an endeavour, which was one of the reasons I used ImageSciene in preference. The installation has now become very simple indeed. Go to the RMagick download page, and download the rmagick-osx-installer (at the time of writing, t...

Install ImageScience on OS X Leopard

15 February 2009
I couldn’t find a tutorial that took me through this process successfully, in the end I combined information from several other articles to provide these simple steps. Prerequisites I used a clean fresh Install of Leopard to begin with. Make sure you have installed Xcode from the Leopard disk. Install ruby_inline Open a terminal, and enter: sudo gem install RubyInline Install FreeIm...

Use Photoshop to remove Mac OS X Leopard window shadows from screenshots

02 December 2008
Whilst i was writing a recent article it was necessary for me to take some dialog screenshots from OS X Leopard. There are several ways of doing this: Using the grab utility that comes with OS X. Holding Apple, ctrl, shift and 4, release, then press space. Entering "screencapture -ic" on the command line, then press space. (This appears to be the same capture as above) Use one of the man...

Reindex spotlight in OS X Leopard

15 December 2007
I recently upgraded to OS x Leopard, and afterwards noticed that spotlight was failing to find certain applications. It was necessary to delete the index database in order to force reindexing. This is done using the mdutil application. You can find out what it does by opening a terminal window, and typing: man mdutil But, if you just want to straight ahead and remove the index database, open a ...

Safari 3 bugs

22 June 2007
Like over a million others (at time of writing) i have upgraded to Safari 3. There are some great new features which are covered in other blog posts, but i am also encountering a few problems... Apple's new browser crashes on me at least once today, but it is still only a beta, but one problem i found was its lack of support for the pseudo-class, :last-child. First Child Second Child The above ...

GET and POST in Ruby on Rails

24 May 2007
Lets start with the basics..... What are GET and POST? GET and POST specify the two main ways by which the browser sends a form's data to the server for processing. The Get method contacts the server, and sends the forms data in a single transmission step. The browser appends the data to the forms action URL, separated by the question mark character. With the POST method, the browser sends ...

Select helper methods in Ruby on Rails

01 May 2007
It can get quite confusing when it comes to using the different select helpers, select, select_tag and collection_select and in my opinion there is a lack of adequate documentation. For my own use if nothing more, i have done my best to compare the different form helper methods available, and when and how to use them. First we will look at the html for a basic selection box: <select name="...

Simple debugging in ruby on rails

24 April 2007
I often find while writing a ruby on rails applications that i need to display the contents of a variable quickly and easily, this is straight forward in a view, but not so easy in a controller or model. There are a couple of ways to do this: logger.debug "variable" will write to the development.log file, or if your using webrick as your development server, you can use: STDERR.puts "variable...

My first post!

18 April 2007
My first blog post! and i am quite pleased with myself. I wrote this blog application from scratch using Ruby on Rails, its kind of an experiment, i get to try out new features, and generally use this site to mess around with. In addition the XHTML and CSS that are used to make the layout are also a first for me. You'll notice that the grass always sticks to the bottom of the site, and the pag...