Minimize parentheses in Textmate

Posted by jamie Wed, 07 Nov 2007 21:32:15 GMT

Found a handy Textmate shell variable that can be used to remove parentheses when using snippets. I prefer this as I generally don’t use parentheses for assertions in tests and if I want them, I can add them myself.

It will for example, alter the asrt snippet from:


assert_respond_to(object, :method)

to:


assert_respond_to object, :method

Just click the ‘Advanced’ tab in preferences and then ‘Shell Variables’, add a variable named TM_MINIMIZE_PARENS with the value of ‘yes’ and you’re good to go.

Posted in ,  | Tags , , ,  | no comments

Proprietary CSS rules - Are we returning to 1995?

Posted by jamie Tue, 30 Oct 2007 09:45:28 GMT

Call me a cynic, but posts like this one on the Surfin’ Safari blog worry me a little. Let me explain…

I don’t know if anyone remembers back to the days of Netscape 4 and Explorer 3.5? – It was a time of table based layouts and browser sniffing. Each browser had it’s own “feature” set and this resulted in hacks galore, for example Netscape had “Layers” but Explorer didn’t, Explorer had feature X but Netscape didn’t.

Along came Web Standards and the likes of Jeffrey Zeldman fighting for a standards based approach to web development. Over a decade on, it looks like were finally getting there as even Microsoft slowly start to get things right with IE7.

As cool as the CSS Transform stuff looks, I can’t help but think we’re stepping right back into 1995?

Posted in ,  | Tags , ,  | 5 comments

Rails: Using Autotest with UnitRecord

Posted by jamie Wed, 05 Sep 2007 20:00:06 GMT

Myself and a colleague have just managed to waste away a good couple of hours trying to figure out Autotests strange ‘style’ mechanism to add the ability to test in the way Jay Fields explains using UnitRecord.

You can grab our plugin to enable UnitRecord when using Autotest below:

http://svn.soniciq.com/public/rails/plugins/iq_autotest

By default, running autotest in the Rails directory will run the unit tests. To run the functional tests, do: AUTOTEST='functional' autotest

I hope this saves some people some time!!

Posted in ,  | Tags , , , ,  | 3 comments

SonicIQ Hiring! - UK, Ruby on Rails Developer Required

Posted by jamie Tue, 28 Aug 2007 00:01:21 GMT

We are looking for a Ruby on Rails, XHTML & CSS Developer to join our team at SonicIQ. Head over to 43folders job board to view our ad.

These are exiting times with projects like Propel’r in the pipeline, along with the ever-growing opportunities for new and interesting client projects.

If you are a highly motivated developer and can see yourself in a Ruby on Rails position in sunny (sometimes) Bournemouth, UK then apply at 43folders.

Posted in , ,  | Tags , , , ,  | no comments

Using Rcov to measure the test coverage of Rails plugins

Posted by jamie Fri, 24 Aug 2007 18:44:35 GMT

To view the coverage of your plugins using Rcov, first install the rcov gem with sudo gem install rcov, then copy and paste the following onto the end of the Rakefile inside your plugin directory:

desc 'Measures test coverage using rcov'
task :rcov do
  rm_f "coverage"
  rm_f "coverage.data"
  rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib"
  system("#{rcov} --html #{Dir.glob('test/**/*_test.rb').join(' ')}")
  system("open coverage/index.html") if PLATFORM['darwin']
end

You can now simply run rake rcov from inside your plugin directory which will generate a coverage directory with the results. Open coverage/index.html (if you are on OSX this will open automatically) in a browser to view the results.

Thanks to Mike Clark for his Rcov rake task for Rails which this task is based on.

Posted in , ,  | Tags , , , ,  | 1 comment

Ruby Ternary operator re-written with Boolean operators

Posted by jamie Thu, 23 Aug 2007 12:09:34 GMT

Just noticed something interesting (well not that interesting). Ternary operators in Ruby can be re-written using Boolean operators e.g.

method = object.respond_to?(:foo) ? :foo : :bar

would become…

method = object.respond_to?(:foo) && :foo || :bar

Simply replace ? with && and : with ||

I don’t know if there is any performance gain here, anyone care to investigate?

Posted in  | Tags , , ,  | 8 comments

Typo 4.1 slow comment posting

Posted by jamie Fri, 17 Aug 2007 00:38:07 GMT

Is anyone else having problems with Typo 4.1 taking ages to process new comments. If anyone has any suggestions I would love to hear them (If you can be bothered to wait for the comment to go through!)

Posted in , ,  | Tags , ,  | no comments

Autotest Growl Fail/Pass Smilies

Posted by jamie Mon, 30 Jul 2007 14:19:37 GMT

John Nunemaker posted a handy tip on setting up autotest to work with Growl

I use this all the time now however I didn’t like the ugly smilies (call me shallow if you like). I used Wolfgang Bartelme’s Smily Devkit to make a couple of PNG’s slightly more pleasing to the eye.

Autotest Fail image Autotest Pending image Autotest Pass image

The zip file can be downloaded here: autotest_images.zip

Update 17-08-07: Added ‘pending’ image for RSpec as requested by Aslak Hellesøy

Posted in , , ,  | Tags , , , ,  | 6 comments

A Ruby reject! that returns the rejected items

Posted by jamie Wed, 25 Jul 2007 10:15:58 GMT

I often need to do a reject! and return the rejected items instead of the modified collection. This saves having to do a select beforehand.

An example of how accomplish this:

options = { :a => 1, :b => 2, :c => 3 }
rejects = Hash[*options.select { |k, v| k == :b && options.delete(k) }.flatten]

assert_equal { :a => 1, :c => 3 }, options
assert_equal { :b => 2 }, rejects

This could be written as a method of the Hash class and an alternative for Array.

For Hash, the code would look something like:

class Hash
  def extract!
    Hash[*self.select { |k, v| yield(k, v) && self.delete(k) }.flatten]
  end
end

options = { :a => 1, :b => 2, :c => 3 }
rejects = options.extract! { |k, v| k == :b }

assert_equal { :a => 1, :c => 3 }, options
assert_equal { :b => 2 }, rejects

If I am missing something obvious in Ruby that accomplishes the same, please leave a comment.

Posted in  | Tags , ,  | no comments

TheLucid Typo theme now works with version 4.1

Posted by jamie Tue, 24 Jul 2007 23:03:00 GMT

TheLucid Typo theme finally works with version 4.1 of Typo.

Please bear in mind that this is quick-fix and and there will still be a Version 2 release sometime in the near future.

The new release can be downloaded below:

lucid-typo-theme-1-1.zip

There are a couple of improvements such as cookies remembering which colour scheme and layout have been selected along with some IE fixes.

Thanks to everyone who notified me of browser issues etc. and I hope to release v2.0 as soon as possible (for both Typo and Mephisto).

Posted in , ,  | Tags , , ,  | 12 comments

Older posts: 1 2 3 4