avatarharuki zaemon

Lock Your Screen with LaunchBar

By

Mostly just so I don’t forget, here are some stupidly simple instructions for locking your screen using LaunchBar. (Technically, this actually starts the screen saver but as that is password protected it has the same effect as locking the screen.)

  • Open the the Script Editor, /Applications/AppleScript/Script Editor
  • Enter the text activate application "ScreenSaverEngine"
  • Save it to ~/Library/Scripts/Lock Screen
  • Open LaunchBar > Configuration > Scripts > Options
  • Enable “Home Library Scripts”
  • Save and Rescan

To lock the screen, simply open LaunchBar and type lock screen (on my setup loc is enough) and hit enter. Voila!

Hotkey fans will probably want to consider using something like MenuMaster or iKey to execute the AppleScript.

Values

By

I was chatting with the lads over at Cogent last Friday about our new venture and the discussion turned to company values. Most of us think of company values as those totally nebulous statements CEOs love to have plastered all over the walls in the vain hope that employees will feel as though being made to work ridiculously long hours was all for a good cause. Thankfully, Cogent’s values aren’t much like other’s and in fact Marty made a great point: values should be actionable in some concrete and meaningful way. Cogent’s values certainly appeal to me but I’m sure they won’t appeal to everyone. Financial transparency being one of particular favourites.

One of the less tangible values is “fairness and equality.” That is, treat everyone fairly and equally, as human-beings. Which got me thinking. It reminded me of “treat others as you would yourself” which I’ve always had a bit of an issue with. Not that I disagree with the sentiment, not at all, but something about it never sits quite right. After a little thinking I settled on “hold yourself to a higher standard than you do others”. I think it fits nicely with treating others fairly and equally.

HELP: Developing with WebSphere

By

I have to know. Is it just me or is the compile, deploy, debug cycle with WAS just so ridiculously long and slow that it’s practically impossible to do anything productive with it? Does anyone ACTUALLY use WAS for development? If so, how do you manage? If not, what do you use instead and how do you then make sure that it still runs in WAS when it can take 10 minutes just to re-deploy an application? Is there some secret to determining why WAS silently rolls back transactions, for no apparent reason (WLTC0033W and WLTC0032W), before control has even returned to the container and with no exceptions; doesn’t seem to be able set transaction isolation levels on SQL Server but instead creates extra connections with the correct isolation level (READ_COMMITTED) leaving the original one handed back from the DataSource as the default (REPEATABLE_READ); and mysteriously times-out waiting for Oracle connections from a pool of 10 even it only ever seems to need at most 3 when the maximum pool size is set to 100!

Making del.icio.us work for me

By

I’ve been posting links to del.icio.us for sometime now. Mainly things I can’t get to right now or don’t access frequently enough to warrant cluttering up my bookmarks with but don’t want to loose track of. When I first started, I would tag things with whatever keywords I could think of. After a while of doing this, I ended up with a huge number of tags but still couldn’t find anything. There was just too much random stuff to filter on.

Attempt #2: I decided to whittle my tags down to the smallest set possible. This was better however every time I went to tag something I found needed to sift through the existing tags and decide which one(s) suited, remember if I had used the plural or singular form, etc. and even then, there was just too much stuff to sift through because now all my links were concentrated in only a few tags.

Attempt #3: My most recent attempt, and the one that has been working brilliantly for me now, is to not worry too much about what exact tags I’m using but, rather than tag it with everything I can think of, I instead use exactly the same keywords I would use were I to search for the link on Google. This sometimes means I have tags that wouldn’t seem to make sense as categories on their own.

Now when I want to find something I’ve bookmarked, I go to my del.icio.us page and search through “your bookmarks” – shouldn’t that be “my bookmarks”? – as if I were doing a search on Google. I reckon I have a close to 100% hit rate and at most 2 or 3 results for any given search. I’ve finally managed to make del.icio.us useful!

Even better, I have set up a custom search in LaunchBar: http://del.icio.us/search/?type=user&p=*

Call for Survey Participants

By

I’m looking to do a survey on software quality using source code duplication, cyclmatic complexity and npath complexity as the measure.

The general idea is to take open and closed source projects and measure the “quality”. The results will then be analysed to determine:

  • How open/closed source compare;
  • How individual projects compare to the “norm”; and
  • What, if any, discernible factors have influenced the quality of the code.

Once the data has been compiled and analysed, I will make the results available to the participants and to the general public. The identity of participants, projects, resources and people involved will be completely confidential – indeed even I don’t actually need to know the names of projects nor will I have access to or need access to the source code – and will not be disclosed to third-parties.

At the request of the study participants, I will be more than happy to present the findings – in person if possible – and make any recommendations that may arise. I will also make myself available to perform a repeat survey in 12-18 months time should this be so desired.

For largely pragmatic reasons, there are several requirements for participation:

  • The project MUST be in a subversion repository;
  • The source code MUST be Java;
  • The project SHOULD NOT be using Simain or CPD (or for that matter any other duplicate code checking tool);
  • The project SHOULD NOT be using Complexian (or for that matter any other complexity checking tool); and
  • An environment that can execute Java and Subversion command-line tools.

Participation couldn’t be simpler. After you contact me, I’ll send you a package containing some processing scripts. To run, simply checkout the HEAD of your project’s source tree into a directory using subversion and run one of the batch scripts contained in the package. For Windows use bin\process.bat src_dir cvs_file For *nix, use bin/process src_dir cvs_file. The scripts will process each revision starting from the currently checked out revision to the first revision.

This processing may take considerable time so if you need to interrupt the process at any point you may do so in the usual manner – eg. ctrl+c. You can then re-start the processing at a later date and it will pick-up where it left off.

Once processing has finished, you can email me the CSV file.

If you think you have a project that fits the profile and would be willing to share some processing time, your participation would be greatly appreciated.

Yes, more Rails plugins

By

FWIW, I’ve just created two very new, very simple and VERY BETA Rails plugins.

The first, Simian, is pretty obvious: it adds a couple of rake tasks to run duplicate code checks against your rails project using, you guessed it, Simian.

The second is Restful Transactions. This plugin ensures that your controller’s create, update and destroy actions are wrapped in a database transaction meaning you don’t have to think about it.

As always, you’ll find these plugins and more over at the RedHill on Rails plugin page

UPDATE: The plugin now wraps any action executed as a POST, PUT or DELETE rather than just the create, update and destroy actions.

Out on the Range

By

I’m pretty sure I’ve blogged before about my dislike of prefix/suffix pairs such as from/to and start/end. They smell of a missing abstraction. There are however languages that provide a nice solution.

We have an application that stores a date against a record in the database. At various times, we want to see if that date falls between a specific date range. The initial implementation of the code looked something like this:

def within?(from_date, to_date)@date >= from && @date <= toend

Which you would then be used along the lines of:

puts "Not available" if record.within?(start_date, end_date)

This immediately activated my olfactory senses: Not only do we have some common suffixes, we also have comparison code that looks like pretty much like every other kind of range comparison code you’re ever likely to write.

As it happens, Ruby has a Range class built-in that I don’t see being used nearly as much as I think it deserves. Using a range we could re-write the example to look something like:

def within?(date_range)date_range.includes?(@date)end

And then in the worst case, call it like this:

puts "Not available" if record.within?(start_date..end_date)

I say worst case because here the client code still uses two separate dates which are then converted to a Range for the purposes of the call. (Interestingly the use of use of .. to construct a Range out of two individual values uses the same number of keystrokes as passing the parameters individually!) However, in the best case, we’d have been using a Range to store the dates in the first place.

Content Management Simplicity

By

I’ve been wanting to put together a new website for my Aikido School for some time now and had been looking around for possible tools to help out. Possible choices included: continuing to maintain it by hand with a redesign; use some kind of site generation tool; write a Rails app; or find a CMS tool.

The first wasn’t really an option – I’m time poor as it is. The second didn’t seem like a much better solution either to be honest. And If the first two didn’t seem like attractive solutions the third was possibly even worse. So, it came to finding a CMS tool and after a little investigation, googling, reading forums and talking with friends, colleagues, ISPs and a few drinks I had narrowed the field down to two: Joomla; or Drupal.

(Interestingly, both are built on Perl/PHP – quite frankly the idea of a Java-based CMS running inside a J2EE container makes me feel ill just thinking about it and I couldn’t find any Ruby-based solutions that even rate a mention.)

Both Joomla and Drupal are solid, mature products. Both are open source and have a thriving community. Both support extensions/plugins/modules and both have had books written about them. All good things. But in the end I settled on Drupal for a number of reasons some emotive, some based on other’s experience and some technical – perhaps the fact that Joomla only runs on MySQL could be considered both technical AND emotive.

So far, I’m highly impressed. It was very easy to install and setup. The admin screens even tell me when the underlying OS or database isn’t configured properly and even go as far as telling me how to fix the problem! There are a bewildering number of modules available that do almost everything you can imagine. And when I finally wanted to do something outside the “box” – aggregating images based on taxonomies and displayed in the side navigation of the home page – it was almost trivial to programatically construct the content. My distinct impression is that for many sites I’ve traditionally built as yet another new application, a CMS like Drupal plus some custom code would be sufficient.

I’m still not a huge fan of Perl. I like many of the language features such as built in regular expressions, etc. making it ideal for command-line scripting, but it still feels a little too close to the metal for me and lacks much of the syntactic sugar around objects that make languages like Ruby more attractive. That said, I’ve thus far only needed to write custom PHP code once and I reckon it would make a nice module – assuming I could find the time to publish yet another open source project destined to become abandonware ;-)

If only someone in the Ruby community would put something together that’s as good as these two, I’d consider switching. Perhaps something built around merb however maturity and a strong community are certainly big selling points for me, perhaps making it difficult for a new player to gain traction?

Stripper

By

Yet another ridiculously simple Rails plugin, Stripper removes leading and trailing blanks from attribute values.

Leading and trailing spaces on attribute values can be a problem. They’re almost never wanted nor intended. In fact, oracle actually treats empty strings as NULL. That’s not to say we necessarily think that the database should be messing with our data mind you but it does show that at least someone agrees with us.

A Diamond in the Rough

By

No, for once this has nothing to do with Ruby (deathly silence) rather, it concerns some problems many people have experienced when trying to use JNDI resources from Quartz jobs under Websphere.

In short, Websphere does not propogate any java:comp/env/ JNDI context to application created (ie non-container) threads. This is apparently by design with the upshot being that if you’re using quartz you won’t be able to use JDBC data sources from any jobs.

There a number of forum topics that discuss this problem along with various solutions including “use a 3rd-party connection pool instead.” Hardly music to the ears when you’ve just spend the last 3 months converting a customer’s entire application over to using JNDI resources. However, after much Googling, I happened upon an article that ultimately solved the problem in a Websphere-friendly manner. It even comes with sample code so you can get started almost immediately.

In essence, the solution makes use of Websphere’s Asychronous Beans (and the Work Manager in particular) as a sort of thread pool. We then took this idea and adapted it around the use of Quartz’s pluggable ThreadPool.

The final twist was the need to support both Websphere and Tomcat seamlessly without resorting to either build or deployment time configuration. For this we simply created a ThreadPool implementation that looks up the Work Manager in the JNDI context. If it exists, we assume that we’re in Websphere and go from there; otherwise we use the default Quartz implementation and hope for the best :)

Conventional Validations

By

As part of some other work I’m currently undertaking, I’ve just extracted a VERY new Rails plugin called, you guessed it, Conventional Validations.

As the README says, Conventional Validations is a plugin that attempts to apply validation based on the naming of column. Specifically, the plugin searches for validation methods such that a columnnamed foo or ending in _foo would be validated using a method named validates_foo.

For example, by defining a class method as:

def self.validates_phone(*attr_names)
  validates_format_of attr_names, :with => /[0-9]+(\.[0-9]+)*/, :allow_nil => true
end

Any columns named phone or ending in _phone would be automatically validated.

I’ve only just added it (it’s only available in trunk) and the matching rules are VERY simplistic but if you have company-wide or even project-wide validation and you’re strict about your naming conventions (as I am), consider extracting them into a module and mixing them into ActiveRecord::Base and letting the plugin apply them for you.

There are already some existing plugins such as (off the top of my head) “validates_email” that would most likely just work out of the box.

Enjoy.

FarceBook

By

WOW! It’s been a while since I found something non-politcal to have a good old rant about but dear god what’s with facebook!? After being harassed for months with invitations by people I usually respect, I finally caved and signed up. What a load of bollocks!

So the idea is we want people to find one another. OK I got that. Then you only really want to link to friends. OK that sounds great. Then once we’re connected, we can…send each other messages via a web page. Holy cow! What an idea! I wish I’d thought of that. Even better, when I receive one of these master pieces I get…wait for it…an email telling me there’s a message waiting to be read. Fan-bloody-tastic.

My wife tells me I don’t appreciate it because I’m not “as social as other people” I suspect it’s more because I’m not bored out of my brains at work with nothing better to do with my time or my life for that matter!

Turning Japanese

By

You’ve moved to another country. Used the opportunity to take some time off work and find a place to live. Settle in and get to know your surrounds.html). Indulge a little in the local food, culture and just a few of the local beverages. Your wife get’s bored so you get connected to the internet but resist the temptation to do anything really useful.

Finally, after much um’ing and ahh’ing and hollow excuses as to why it’s still not the right time, you decide you really had better start earning a living again. So, you make sure the VPN still allows you to connect to your customer’s servers, switch to the directory of the project you were working all those weeks (ok months) ago and type svn up. A dozen or so filenames whizz by and then the screen appears to freeze. 5 minutes go by. Then 10. Then an hour. Then two. What the…?!

After a few emails back and forth between the customer’s technical people it becomes apparent that the freeze is a result of downloading a 33M jar file from the repository coupled with the client’s internet connection speed being at least 1/10th if not 1/100th that of my 50M/s ADSL. So what do you do? There’s no studio audenice; it doesn’t make sense to go 50/50; so, I guess I’ll have to phone-a-friend.

A cunning plan emerges. James would update his checked-out version onto his laptop over the LAN at work – resulting in a whopping 1.14G of source material:

james> svn up project

Even zipped this would still be enormous but remembering that good-old SVN keeps two copies (one as a backup) we then deleted all files except those in the .svn (ie backup) directories:

james> find project -type f -not -path '*.svn*' -delete

This was then zipped up resulting in a modest 150M:

james> tar -cvzf project.tgz project

And sent to a server in the US – being a whole lot easier than tunnelling through firewalls and NAT’d routers – from his home connection – being a whole lot faster than the one in the office:

james> scp project.tgz server:

I then downloaded it:

simon> scp server:project.tgz .

Unzipped it:

simon> tar -xvzf project.tgz

Switched the user:

simon> cd projectsimon> svn switch --relocate svn+ssh://james@repos svn+ssh://simon@repos

Restored all files from their backup copies:

simon> svn revert -R .

And finally did an update to be sure:

simon> svn up

Which all makes me wonder if were it not for all these nifty command-line tools with which to play, might there have been an easier solution? Was this perhaps just a little too much technical masturbation? M’eh who cares. It was fun and it worked!

Vanilla Ice Was an Agile Visionary

By

Once and for all could we all just get over pair programming as something novel and thus something about which to be suspicious and fearful. The idea that it’s some new fandangled practice is utter bollocks! It’s called COLLABORATION! and believe it or not, some of us have been pair-programming collaborating with much success for many years now and with no ill effects. You’d be amazed!

Getting people to collaborate takes more than simply mandating pair-programming. If you don’t know how to do it, how about occasionally getting up off your bum and sitting with another developer. Perhaps once in a while you might like to try taking those goddam earphones out, turning around and asking for someone to come and watch what you’re doing. Talk to other members of the team about your work. Involve other people in what you do. Fundamentally that’s what pair programming is about. Yes, there are added benefits such as having your pair catch little mistakes here and there but more than anything it’s the collaboration that comes from sitting with another human being and discussing what you’re doing that makes the biggest difference.

Where I work now we all sit in close proximity, we all listen (whether we know it or not) to what everyone else is doing and all chime in if we believe (rightly or wrongly) we have something to contribute or even just to ask questions because something sounded interesting. Snobs, cowboys, incompetents and the socially-challenged are among those that might fear such behaviour; precisely the people we don’t want on our project.

I highly recommend visiting Jason Yip’s blog (among others) for ways in which you might get your team to collaborate more effectively and yes, pair-programming may well be one.

Leaking Locks

By

Spoiler: JDK 1.5 – and near as I can tell 1.6 even though it’s supposed to be fixed – have a pretty fatal memory leak when using java.util.concurrent libraries.

How do I know?

Well, besides finding the earlier link via our good friends at Google, we recently switched from using the backport to the standard JDK libraries and the throughput of our application under load rapidly approached zero.

After spending some time creating a a quick-and-dirty load test on my own machine, I found I could easily replicate the problem with the added bonus of java.lang.OutOfMemoryErrors in under a minute. Running it under a profiler confirmed as much with the culprit being java.util.concurrent.locks.AbstractQueuedSynchronizer$Node.

“Never” cries the guy we work for. “Doug Lee’s stuff has been around for a long time and I’ll bet his stuff works and you guys have screwed something up!” he continues.

We all agreed and decided to replace the locking code in the class I’d just created (and presumably screwed up) with some good old-fashioned synchronisation.

Nope. The problem persists but it’s not as bad this time. We clearly “fixed” something but not everything. Hmmm.

On further investigation we realised there was still some code in the call chain using the concurrent stuff so we decided, just for laughs, to revert back to using the concurrent stuff but use the backport libraries instead.

Voila! Suddenly the load test exhibited exactly the expected behaviour: no out-of-memory errors; no grinding to a halt; nice see-saw memory usage; and using only 2MB of heap instead of, well, as much as it could get (>64M in our case).

Stunned, we went back to the default JDK version. Yup! Problem is back and not just in our own locking code either, we noticed the problem in much of the concurrent classes including the collection implementations.

The good news is that using backport we now have a build that works.

The scary part is that I can only presume some Sun engineer decided he knew better and screwed the pooch right royally on this one.

Learn to Say "No!"

By

I can take it no longer. If I hear or read about how Getting Things Done (GTD) saved yet another person’s “life” I’m going to scream. This fascination the world (and geeks in particular) have with doing more and more stuff is frightening.

When you feel there is just so much to do in your life that you can’t seem to make it through the day without stressing about something, that your life is spiralling out of control and there seems to be nothing you can do about it, there is an alternative course of action: DLS - Do Less Stuff™

Yes, hard to believe but there is actually no particular need to devise yet more processes in order to deal with the stuff that is ultimately controlling you. Instead, you can actually take control of your life and say “I’m going to do less stuff” and tell those that would foist their agendas upon you to go jam it.

I choose not to reduce my life (and the enjoyment thereof) to a series of prioritised index cards pinned to a wall.

Continuous Integration for Rails Just Got A Whole Lot Easier

By

If you already have a continuous integration (ie build) server (such as Pulse, Bamboo, Hudson, or even the venerable old CruiseControl) and you’ve been trying to include some of your Rails applications then your life just got a whole lot easier.

Enter CI::Reporter. To quote the documentation:

…an add-on to Test::Unit and RSpec that allows you to generate XML reports of your test and/or spec runs. The resulting files can be read by a continuous integration system that understands Ant‘s JUnit report XML format, thus allowing your CI system to track test/spec successes and failures.

So, I simply installed the gem on the build-server and the plugin into my plugins project, configured the build to slurp up the generated XML files and voila! I now get build notifications letting me know how many tests passed and which ones failed.

Thanks Nick!

Installing RedHill on Rails Plugins via HTTP

By

After much installation pain and anguish experienced by some users of our plugins (due mostly to outages with RubyForge SVN servers and the inability of some users to access SVN from behind firewalls), I’ve finally managed to spend some time getting a plugin installer-friendly HTTP mirror up and running.

The root of the mirror can be found at http://www.redhillonrails.org/svn from which you can browse the entire repository.

If you live on the edge, you’ll find them at http://www.redhillonrails.org/svn/trunk/vendor/plugins.

If you’re after are the Rails 1.2 stable compatible plugins, you’ll find them at http://www.redhillonrails.org/svn/branches/stable-1.2/vendor/plugins.

If you’re after the older Rails 1.1.6 versions, they’re available at http://www.redhillonrails.org/svn/tags/release-1.1.6/vendor/plugins.

The mirror is presently refreshed once a day which should be enough for most people.

As always, let me know if I’ve right royally screwed something up. I’ve manually tested all of the above but “it works on my machine” definitely applies in the case I’m sure.

Bug Reporting 101

By

So, you found what you think is a bug in a bit of software and you need it fixed desperately, so desperately that you take advantage of the fact that you have direct contact with the developer(s) and ask for help. Allow me to give you some handy hints as to what kind of information may be useful to said developer(s) when diagnosing a problem experienced intermittently by your lone yak herder in outer-Mongolia:

  • Have you done a quick search on Google? If not, go to jail; do not pass go; do not collect 200 dollars
  • What version of the software are you using?
  • What are the steps necessary to re-create the problem?
  • Is there a stacktrace?
  • Have you changed anything recently? And I mean ANYTHING? You don’t get to decide if it’s important enough to warrant a mention
  • What other software/add-ons are you running at the same time?
  • Which operating system/s and what version/s are you using?
  • Is there a database involved? If so, what platform is it running on and what version are you using?
  • Does this happen locally or only when run remotely?
  • Does it happen in development/test/production/etc?

In fact, the more information you provide the quicker the problem (if in fact there even is one) is likely to be solved because quite frankly, and perhaps contrary to popular belief, not only does “You’re software sucks and we might stop using it if you don’t fix it” not really carry that much currency, it doesn’t really help much either.

UPDATE: As fate would have it, comments seem to be barfing. Feel free to send me your comments via email and I’ll add them manually until the problem is resolved.

Monitoring Java Processes under Mac OS X

By

So today, after I don’t know how many years of doing Java development, I find out there is a command to list all the running Java processes. It’s available on all platforms I could find and it’s called jps. On most platforms it’ll display something like:

1170 Jps -lm1162 org.apache.tools.ant.launch.Launcher -cp  dist

Except under Mac OS X where you’ll get something more like:

1170 Jps -lm1162 -- process information unavailable

Pretty bloody useless!

So, I wrote a little ruby script to simulate the desired behaviour as much as possible (by using the built-in jps to collect the process ids; then filtering the output from ps accordingly):

#!/usr/bin/env rubyrequire 'set'pids = Set.new`#{ENV['JAVA_HOME']}/bin/jps`.each_line do |line|pids.add($1) if line =~ /^(\d+) /end`ps -x -w -w -o pid,command`.each_line do |line|print line if line =~ /^ *(\d+) / && pids.include?($1)end

Which, when run, produces output similar to (line continuation not included):

1162 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java \-classpath /opt/local/share/java/apache-ant/lib/ant-launcher.jar \-Dant.home=/opt/local/share/java/apache-ant \-Dant.library.dir=/opt/local/share/java/apache-ant/lib \org.apache.tools.ant.launch.Launcher -cp  dist

Granted it does produce lots more output than standard jps but it does at least produce something useful to look at when monitoring Java processes. Best of all, it means we can automate the monitoring in a manner that works across most platforms.

If anyone has a Better Way™, I’m all ears.

UPDATE: After a bit of googling I discovered that it’s a bug which is fixed in Java 6 (Mustang) and relates to, wait for it, user names containing an underscore. Go figure!