Kill All Rinari Buffers in Emacs (2009-03-30)

I've been using Emacs for development for a few months now and am pretty happy with it.

I use the Rinari mode to provide some help when I'm working on Rails projects. Once I'm finished for the day (or changing to another project, I used to use the kill-some-buffers command and go through them one by one.

Here's some elisp that I've written and put in my .emacs file that just kills all buffers that link to files that are in the current rinari-root. It's probably not perfect, but it seems to work most of the time.

  1. ;; some rinari helpers
  2. (defun kill-buffers-in-subdir (subdir buffer)
  3. "Kills the given buffer if it is linked to a file in the current rinari project."
  4. (if (buffer-in-subdir-p subdir buffer)
  5. (kill-buffer buffer)))
  6. (defun buffer-in-subdir-p (subdir buffer)
  7. "Returns true if buffer belongs to the current rinari project"
  8. (and (buffer-file-name buffer)
  9. (string-match subdir (buffer-file-name buffer))))
  10. (defun kill-all-rinari-buffers ()
  11. "Kills all buffers linked to the current rinari project"
  12. (interactive)
  13. (let ((path (rinari-root)))
  14. (if path
  15. (dolist (buffer (buffer-list))
  16. (kill-buffers-in-subdir path buffer)))))

Omniweb Using Webkit From Safari 4 (2009-03-12)

I'm a big fan of the Omniweb web browser. I've had some problems with it being a bit slow in the past, but that seems to have been fixed with the latest Nightly Builds. The latest build has brought in the same Webkit as used by Safari 4, so it's fast. Really fast.

Add that to all the features I like, and I'm a happy web browser. Things I miss when I'm not using Omniweb.

  • Vertical Tab Bar - I have a wide screen, and a lot of tabs open
  • Workspaces - I can put my house hunting links in one workspace, then keep them handy, but hide them while I work
  • Mac (?) font rendering. Something about Firefox's font just looks wrong
  • Built in ad-blocking. It's no Adblock Plus, but I don't mind seeing ads. It's just the flashing ones I hate
  • Location bar hides, shows when I hit Apple-L, then hides again. I don't know what I'm doing wrong on other browsers, but I can never get this to work reliably.
  • And heaps more...
It's a good browser. It's good enough I paid for it, but it's free now. Nice one OmniGroup.

Blog Running on Webby (2009-02-19)

The server this blog runs on hosts a few things for - email, a few sites and some git repositories. It's got 512mb or ram, but rubygems and even git can get pretty greedy at times. I finally had enough.

Typo and mysql were only being used for the blog and were taking up a heap or ram. I looked around and Webby seemed a good fit.

I've managed to convert the old articles and comments to Webby and Disqus format. There's currently some problems with the comments not displaying, so I'll have to fix that, but I can live with that for now.

Anyway if anybody notices any problems, please leave a comment and I'll get it fixed up. Unless it's a problem posting comments.

Update: Comments are display fine now. Wooh.

Time To Go (2009-02-10)

I've just released my first iPhone application.

Time To Go is designed to be the quickest way to tell when the train you need to catch leaves. I use it just before I leave work to know whether I need to run to the station to catch the next train.

There'll be a dedicated page up to log any timetable errors soon, but for now please leave any errors or suggestions in the comments for this blog post.

iTunes Store URL

Screenshot:

Badged Dock Icon for IPhone XCode development (2009-01-21)

Dr Nic made a good suggestion on Twitter for a way to badge the XCode icon with the one currently in use.

Here's my attempt: http://gist.github.com/49767

It relies on ImageMagick being installed (port install ImageMagick) and should be run from the project's directorin in the terminal.

Element.insert, Prototype and named anchors (2008-11-25)

This was a strange one.

HTML:

  1. <a name="questions">
  2. <div class="questions">
  3. </div>

JS:

  1. Element.insert("questions", { bottom : "<div>Test</div>" })

With that setup, IE compains and says "Invalid source HTML for this operation". It turns out that prototype was trying to put the div into the a tag. I guess I can see how it happened, but I sure didn't expect it.

Anyway I removed the a tag completely and everything works fine. Weird.

Random wallpaper from socwall.com (2008-09-01)

I quite like http://socwall.com. They have a rss feed for recent posts, but I wrote a small script to download a random selection instead.

On OSX I could then set my desktop background to be a random picture from a folder. In my case that folder was /Users/brad/Pictures/Wallpapers/ but that could be easily changed.

  1. #!/usr/bin/ruby
  2. require 'rubygems'
  3. require 'hpricot'
  4. require 'open-uri'
  5. require 'Pathname'
  6. URL = 'http://socwall.com/browse/index.php?wpSortby=8'
  7. DEST = "/Users/brad/Pictures/Wallpapers/"
  8. def clear_old_images
  9. Pathname.new(DEST).children.each { |f| f.delete }
  10. end
  11. def download_images(count)
  12. count = count.to_i
  13. while count > 0
  14. doc = Hpricot(open(URL))
  15. doc.search("div.wpThumbnail").each do |thumb|
  16. next if count == 0
  17. thumbnail = thumb.at("img")['src']
  18. image = thumbnail.gsub(/\/tb_/, '/')
  19. image = image.gsub(" ", "%20")
  20. remote_image = open(image, "User-Agent" => "Ruby/#{RUBY_VERSION}")
  21. local_image = open("#{ DEST }/#{ count }.png", 'w')
  22. local_image.write(remote_image.read)
  23. remote_image.close
  24. local_image.close
  25. count -= 1
  26. end
  27. end
  28. end
  29. count = ARGV[0] || 10
  30. clear_old_images
  31. download_images(count)

ZSH (2008-06-27)

I've been zsh lately. I get the feeling most shells have similar features, but somehow I stumbled across a good config file for this one. It's so good I think it is worth sharing.

Features that I like in zsh:

  • Standard aliases, reverse search, history work as normal
  • Typos in command names and directories are fixed automatically
  • Auto 'cd' if you just type the directory name.
  • Completion of command options (so the - and -- options!)
  • Copletion of rake task names. This might the same as above, but it's still handy.
  • Completion of remote paths over scp. It's a bit slow for regular use, but can be good if you've forgotten the name of one dir.

My zshrc is available here on github: http://github.com/bradx3/dotfiles/tree/master/.zshrc

performSelector in RubyCocoa (2008-04-22)

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:

  1. 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 (2008-03-12)

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:
  1. sql = "select * from #{ MyModel.table_name }"
  2. MyModel.connection.execute(sql) do |handle|
  3. handle.fetch do |row|
  4. # row is an array of values
  5. ... export row ...
  6. end
  7. end

Named SQL Server Instances with FreeTDS (2008-03-10)

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:
  1. [def]
  2. host = abc
  3. instance = def
  4. port = 1433
  5. client charset = UTF-8
  6. tds version = 8.0

Using Javascript Code for RJS Instead of IDs (2007-11-05)

Some info on how to make RJS output code like:
  1. new Insertion.Bottom($$('p.welcome b').first(), "Some item"
http://sentia.com.au/2008/03/using-javascript-code-for-rjs.html

Redish Greenish for ZenTest (2007-09-29)

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:

  1. require 'autotest/redgreen'

to
  1. 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

  1. PASSED = :blue
  2. FAILED = :yellow
  3. require 'autotest/redishgreenish'

Valid values for colours are

  1. :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white

Haml & Sass Editors 0.5.4 (2007-07-06)

These editors have been merged into the Aptana project. Please don't post any error reports here.

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 (2007-06-21)

These editors have been merged into the Aptana project. Please don't post any error reports here.

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.