performSelector in RubyCocoa

Posted by Brad Tue, 22 Apr 2008 05:01:00 GMT

I had a lot of trouble finding documentation for this. If you want to make a call on the main thread in RubyCocoa, the format is something like:

performSelectorOnMainThread_withObject_waitUntilDone('method_name:', object, true)

So two things that took me a while:

  1. method_name has a trailing colon.
  2. The object the has the method you want to call should be the second argument. I got it in my head it should be the first for some reason.

Read table row-by-row in ruby

Posted by Brad Wed, 12 Mar 2008 01:00:00 GMT

I needed to export some data from a huge data table. Iterating through MyModel.find took too long and too much ram, so I went straight to the db instead.

Example code was tough to find, so here's an example:
sql = "select * from #{ MyModel.table_name }"
MyModel.connection.execute(sql) do |handle|
  handle.fetch do |row|
    # row is an array of values
    ... export row ...
  end
end

Named SQL Server Instances with FreeTDS

Posted by Brad Mon, 10 Mar 2008 08:31:00 GMT

A helpful post on accessing named sql server instances using freetds

I was having a lot of trouble doing that. Turns out the 'instance' key exists. As far as I could find it wasn't in the doc anywhere, so this is just a post in the hope that it'll save somebody else some time in the future.

From the post:
[def]
host = abc
instance = def
port = 1433
client charset = UTF-8
tds version = 8.0

Using Javascript Code for RJS Instead of IDs

Posted by Brad Mon, 05 Nov 2007 01:31:00 GMT

Some info on how to make RJS output code like:

new Insertion.Bottom($$('p.welcome b').first(), "Some item"
http://sentia.com.au/2007/11/5/using-javascript-code-for-rjs-instead-of-ids

Redish Greenish for ZenTest

Posted by Brad Sat, 29 Sep 2007 03:26:00 GMT

ZenTest is a great tool. I use it and its redgreen plugin a lot to easily keep an eye on my tests.

I use a green terminal background though, so when my tests pass, rather than a green line, I have to rely on a lack of a red line. This isn't so bad, but I thought it could be improved with a little effort.

Redish greenish is an extension of redgreen that allows you to specify the colours used for tests passing and/or failing.

To use it, save this file into your autotest lib directory. (Mine is GEM_PATH/1.8/gems/ZenTest-3.6.1/lib/autotest/). To enable redishgreenish, you'll need to modify your autotest config file. Open "~/.autotest" and change the line:
require 'autotest/redgreen'
to
require 'autotest/redishgreenish'

At this point, autotest will behave exactly the same as if redgreen was used. To change the colour of the lines used to signify tests passing and failing, your autotest config file should look like
PASSED = :blue
FAILED = :yellow
require 'autotest/redishgreenish'

Valid values for colours are
:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white

Haml & Sass Editors 0.5.4 12

Posted by Brad Fri, 06 Jul 2007 03:49:00 GMT

Last release didn't go so well. For some reason I figured other people had tried to install Aptana, had it fail and then given up on it like me. Turns out I was alone haha.

So I spent a bit of time figuring out what changed in RDT and fixed things up. I've tested this with a straight out of the box install of Aptana m8, so hopefully it'll work for others too.

If anybody does try it, please let me know if it works or not. I'm going to use this blog post as a bit of a test before I post to the Haml mail list. Thanks in advance to anyone who replies!

(Oh yeah, the update site is still http://haml.lucky-dip.net/).

Haml & Sass Editor For Eclipse 17

Posted by Brad Sun, 24 Jun 2007 04:58:00 GMT

I did some very basic editors for Haml and Sass a while back. At the time I was interested in Haml. It's elegant to write, and the automatically formatted html it outputs just made it a match made in heaven.

Fast forward a few months and now I'm actually using Haml and Sass. It's as good as I ever hoped it would be. With Haml and a little bit of FormBuilder magic I'm making useful forms in four short lines. Too good.

Anyway coming with using it is the chance to see some shortcomings in my own editors, so I've spent a bit of time updating them. I've set up a proper Eclipse update site, so you can just add 'http://haml.lucky-dip.net' via the 'Help - Software Updates - Find and Install' menu option. That should help minimize a few errors with the various versions of Eclipse and RDT around. All references to the RadRails plugins have been removed. There was a bit of code that I pulled into my plugin, but with RadRails/Aptana in heavy dev it's easier for me to forget about trying to keep up for a while.

Also added is code folding. There's a bit of work still to do on this one. You can currently only fold top level elements. This can be a pain when you've got all your code in one file, but if you're using layouts and partial in a sensible way it should hopefully be of some use.

One thing I found a bit tricky was figuring out which element I was under when I was editing. Some people might like turning on space markers (can you actually do that in Eclipse?), but I figured a character matcher would do the trick. So now as you move around in the editors there'll be a blue box around the element you are currently in. At the moment it just highlights the first letter of the element. I'm going to see if I can get the whole element happening for the next release.

So I hope it works well for people. Set up an Eclipse update site of 'http://haml.lucky-dip.net' and that should keep you informed as new versions come out.