Skip to main content

Posts

Fantastic Contraption - a great flash game for anyone with an engineering mind

I've found a flash game that I just have to share! It's called Fantastic Contraption and it's brilliant fun for anyone with an engineering mind, it's just so addictive. The goal is to transport a red ball from it's starting point into a red goal area using your 'contraption' - your self-built vehicle made out of wheels, sticks and water power. Below is a screenshot of my 'flatbed' truck in mid-flow: Give it a go but don't try it at work, you will not be able to do anything else for the rest of the day! I found this via the Arantius blog, thanks Anthony Lieuallen! Technorati Tags: Engineering , Flash , Game , Fantastic Contraption , Anthony Lieuallen , Arantius , Andrew Beacock

How to test Exceptions and verify Mock Objects using EasyMock

Let's say you are unit testing, using EasyMock to verify the behaviour of your code under test and now you want to test that your method throws a particular exception: @Test(expected = SQLException.class) public void parseThrowsException() throws SQLException { ResultSet mockResultSet = createMock(ResultSet.class); expect(mockResultSet.next()).andThrow(new SQLException()); mockResultSet.close(); replay(mockResultSet); ResultReporter reporter = new ResultReporter(); reporter.parse(mockResultSet); verify(mockResultSet); } As you can see this is another test from my previous EasyMock post on how to use EasyMock's expect method when unit testing . We are now testing that when we call the next method it throws an SQLException (to simulate the database going down). We expect that the next method call will throw an exception and then we are expecting that close will be called. If you run this test then you will find that it passes with green flying c...

Setting up HD/Progressive Scan on a Sony PlayStation 2 (PS2) with Component cables

I recently upgraded my television from a Philips 28" widescreen tube to a 1080p Panasonic 42" plasma . My old Sony PlayStation 2 was now looking a little weak when upscaled to 42" so I decided to invest in some component cables to take advantage of the best output that the PS2 had to offer as well as enabling "Progressive Scan Mode" in some supporting games (Guitar Hero 2 for example). Here are my step by step instructions on how to HD-enable your PlayStation2. Buy a quality component cable My PS2 came with some SVIDEO-style connectors and a SCART block to plug them in to. The image quality on my old TV was fine but needless to say on a 42" HD plasma things looked a little different! I spent a lot of time reading all sorts of reviews of PS2 component cables and it seemed that people were having mixed results with the cables in the £5-£15 bracket. After some searching about I found a PS3 to 5 RCA (component) cable from IXOS which also works with the PS2...

Write simpler equals & hashCode Java methods using EqualsBuilder & HashCodeBuilder from Apache Commons

Last week I posted about how to implement a Hibernate-safe equals() method using instanceof and accessors (getters) in Eclipse . This showed that you don't want to be comparing the member variables directly but should use the accessor methods to protect against Hibernate's use of proxy objects. My old colleague Guy Francis pointed out that rather than using Eclipse's generated (lengthy and rather ugly) equals and hashCode methods I should take a look at the Apache Commons EqualsBuilder and HashCodeBuilder . Both of these builders have a very useful reflection-based equals/hashcode method but that does a deep internal comparison of member variables so that is no good for use with Hibernate objects. One use that they don't really explain clearly (and hence the reason for this blog post) is whether you can use accessor (getter) methods instead of direct variable access when using these builders... ...well you can! You create a new EqualsBuilder object inside your e...

How to implement a Hibernate-safe equals() method using instanceof and accessors (getters) in Eclipse

When coding in Java you often want to check to see if two objects are 'equal'. This might range from a check to see if just one attribute is the same (the ID for example), or a complete comparisons of all attributes all the way up to ensuring that two objects are referencing the same instance of a particular class. There is a lot of information out on the internet about how to write a correct equals() method (and the corresponding hashCode() ) but I think Joshua Bloch's explanation from his excellent Effective Java book is the best. Here are some tips that I learnt the hard way today when trying to test some JPA/Hibernate-backed objects for equality: Don't use the default settings of Eclipse's built-in generator for equals() and hashCode() - it generates equals methods based on checking whether the two objects are from the same class (using getClass()), Hibernate proxies everything so this will never match Don't use Eclipse's built-in generator at all - ...

Hibernate Tip: How to view the values of Bind Variables

If you use Hibernate then you will have probably wanted at some point to see the underlying SQL that was being run. One solution is to enable SQL logging by increasing the Log4J logging levels of the org.hibernate packages . There are two issues with this technique though: At DEBUG level you see the SQL but all bind variables are displayed as a ? At TRACE level you get everything and the kitchen sink, SQL, bind variables, results, etc. - it's very verbose! Wouldn't it be nice if you could see the SQL and the bind variables without all the other Hibernate excessive tracing? Well my ex-colleague and good friend Andy Kayley has blogged about a solution that he found recently - check out his blog post: How to Print Out Bind Variables in Java Prepared Statements I've not tried it yet, but the next time I need to see the bind variable values I certainly will be! Technorati Tags: Spring , Hibernate , Java , Prepared Statement , Bind Variable , Andy Kayley , Andrew Beacock

How to use EasyMock's expect method when unit testing

I recently blogged about getting started with EasyMock - a simple framework for taking the pain out of creating and using mock objects when unit testing your java code. In the example I showed that we were expecting the next() method to be called and we wanted the mock ResultSet to return false: expect(mockResultSet.next()).andReturn(false); What I didn't explain was that you use the expect() method when you are expecting the mock to return a value. If the method doesn't return a value (such as ResultSet.close() ) then there is no need to wrap it in an expect() method call: mockResultSet.close(); Remember: any methods that you call on your mock prior to the replay() method call are setting up it's expectations not actually calling the methods. After the replay() method is called the mock is in 'live' mode, recording activity and returning any predefined values when it's methods are called. So here is the same example with the additional expected close() ...

Getting started with Java Mock Objects using EasyMock

If you are familiar with unit testing and test driven development then you are most probably aware of Mock Objects . The EasyMock website states that: A Mock Object is a test-oriented replacement for a collaborator. It is configured to simulate the object that it replaces in a simple way. In contrast to a stub, a Mock Object also verifies whether it is used as expected. Mock Objects were introduced at XP 2000 by Tim Mackinnon, Steve Freeman and Philip Craig with the Endo-Testing: Unit Testing with Mock Objects paper. So how do you use them? Basically you want to test some code that depends on a number of other objects. Some of these objects might have unwanted side effects like talking to a database, or accessing an external URL. Rather than passing in the real implementation (with the above side effects) you would pass in a mock or stub instead. The mock can be pre-wired to expect a number of calls to it's methods from the code under test and will record these calls for ver...

How to enable Line In Pass Through to your speakers with Realtek Audio on Windows XP

If you are having problems hearing anything after you have plugged a sound source into the 'Line In' socket of a Realtek soundcard (or motherboard onboard sound) then read on... Plug your MP3 player (or other sounds source) into the 'Line In' socket and then go to the control panel and start the 'Realtek HD Sounds Effects Manager'. If you click the 'Audio I/O' tab you should see something like: The highlighted part indicates that the Realtek HD Audio Manager knows that you have plugged a 'Line In' device in. You should now be able to record what is being played but you most probably won't be able to hear it! A lot of audio cards give you the option of passing the line in through to the line out so that you can hear it on your speakers but this isn't the case with the Realtek audio. What you have to do is ensure that the 'Rear Blue In' channel is not muted and has some volume as well as the 'Line In': It took quite a bit...

Searching in Eclipse without the annoying CTRL-F Find Box

I've been using IntelliJ's IDEA IDE for the past few years for any Java development work. I've recently moved to a new company who are standardising around Eclipse so I'm slowly getting used to it's way of working and it's many different keyboard shortcuts . Inline code searching is a big plus in my book and my good friend Bill Comer has figured out how to do it - read his post on In line searching in Eclipse & IE7 . If you just want to know the answer then here it is: CTRL-J Technorati Tags: Eclipse , Java , Search , Bill Comer , Andrew Beacock

Colour Linux & Cygwin console searches with Colourised Grep

Grep is a wonderful tool useful for searching for all kinds of stuff but sometimes what you are searching for gets lost: To get your console shell to add a little colour to your grep search terms add the following to your .bashrc or .profile or the like: export GREP_OPTIONS='--color=auto' export GREP_COLOR='1;33' Now if you perform the same search again your output should be a little clearer: And as an added bonus this works on Cygwin (the Windows Unix shell) as well as Linux! Technorati Tags: Cygwin , Linux , Console , Shell , Colour , Grep , Andrew Beacock

Ever had your DVD or CD drive completely disappear in Windows XP?

I recently installed DaemonTools so that I could fire up an Ubuntu ISO without burning it to disk first but it didn't seem to work properly so I uninstalled it. That is when the problems started, my DVD drive completely disappeared from XP - it wasn't in Windows Explorer and didn't show up via Device Manager either! I tried the "Add Hardware" wizard via the Control Panel but that didn't recognised my drive either so I was starting to get rather worried. After a search on the net I came across a thread on Annoyances.org regarding "all my CD rom drives suddenly dissappeared" . This pointed to a solution script from the rather talented Doug Knox who has a script available to restore CD-Roms and DVDs in Windows . Follow the above link and then save the page with the script on it to your desktop, then just double-click the script and it should pop up the following message: Now just reboot and your DVD/CD drive should have been restored! Technorati...

My excuse for why I didn't blog much in March...

The goal from the beginning for this blog was to write a post a week, that's the incentive that kicks me each week nagging me to write a post even though sometimes I don't want to. I've seen a number of blogs simply fade into the past after a month or two once the initial novelty has worn off - writing informative well-versed (I hope!) posts is a difficult thing to do in one's free time. I managed the grand total of one post in March but I did have a valid excuse: I had the "new job search" machine on full throttle and was spending every evening pouring over JobServe and various job blog sites. If I wasn't searching for jobs on the internet then I was either preparing for face-to-face interviews or being telephone interviewed and I just didn't have the bandwidth to blog as well. I'm pleased to say that I accepted a new development position a few weeks ago and so I'm finally leaving the mobile telecoms industry after ten years (wow, I'...

Ever wanted to test your website on every version of Internet Explorer (IE)?

If you develop websites then you will be well aware of the browser incompatibilities that cause a whole world of pain when you are trying to get something to look the same in all browsers. Normally you will be testing against IE 6 or 7, Firefox and Safari. Due to IE 7 introducing a load of new behaviour you would also want to test it on IE 6 but you can't have two different versions of IE installed on any one PC. You could turn to a number of virtualised Windows instances with different versions of IE installed but that sounds like a lot of work to me ;-) What if you could install a simple program and then have the following versions of IE available?: Internet Explorer 3.0 Internet Explorer 4.01 Internet Explorer 5.01 Internet Explorer 5.5 Internet Explorer 6.0 Here you go then: MultipleIEs A blog post about installing multiple versions of IE on your PC by TredoSoft was the source of my information and it's got a lot more information about how it works and what doesn...

How to control another PC without a KVM using Synergy

If you sometimes have your laptop next to your desktop PC you might find that you are hopping from one keyboard/mouse/trackpoint to the other. After a while this gets a little uncomfortable so wouldn't it be cool if you could use your desktop PC's mouse and keyboard on your laptop? Synergy is one such utility, this is how the Synergy team describe it: Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems without special hardware. It's intended for users with multiple computers on their desk since each system uses its own display. Download Synergy from sourceforge and install it as normal on both you desktop PC (the server) and your laptop (the client). On your desktop PC, start Synergy (Start -> Programs -> Synergy -> Synergy) you will be presented with the following screen: Click "Share this computer's keyboard and mouse (server)" then click "Configure..." to set up the lay...

My all new Ruby Database Script Runner - now with Objects!

Back in December I blogged about how to access ActiveRecord & Migrations outside of Ruby on Rails . It was a little to scriptish for my liking so I've refactored it in a couple of classes instead. Before you had to copy the code to a new file and add your database migration inside the Script.run method. I've now broken this up into a DatabaseScript class that extends ActiveRecord's Migration and has the guts of how and where to run any database commands and then any number of script classes that do the actual work. The classes that you write on a day to day basis are now similar in style to the standard Rails Migrations: require 'database_script' class UniqueScriptName def self.run # your migration code goes here end end For example I want to update my_table and set all the updated column for all rows to be true : require 'database_script' class UpdateMyTable def self.run execute('update my_table set updated = true') end end I...

A great new Oracle database resource

My colleague Mark Lishman has recently started blogging about all things Oracle over on Lishblog . He really knows his stuff and has a habit of explaining it so that mere database mortals such as myself can understand it. He's only just started but already has an excellent post on how to use external tables in Oracle . This is really handy when you have a massive CSV file and want to query it but can't be bothered to write in input script in Ruby or something because you will be scrapping it soon. He's a great Oracle DBA and his blog will no doubt be well worth subscribing to! Technorati Tags: , Oracle , Database , Mark Lishman , Andrew Beacock

How to restore "Escape closes windows" shortcut in Pidgin (using Ubuntu Linux)

I use Gaim/Pidgin as my IM client as it can connect to all other IM services (AIM, MSN, Yahoo, GTalk, etc.) but keeps them all within one tidy app. My favourite feature is that when you want to close a conversation window you simply just hit 'Esc' and it's gone. A collegue asked recently why his Escape shortcut was not working any more after an upgrade to Ubuntu Gutsy . It appears from Pidgin's release notes that this 'feature' was changed in version 2.0.0 (5/3/2007) : Removed "Escape closes windows;" default key binding is now Ctrl-W This hadn't happened to my version (I'm also running Gutsy) but I had to get to the bottom of it. After a little searching in .purple (the home of Pidgin's user configuration) within my home directory I was able to find the following uncommented in my accels file: (gtk_accel_path " /Conversation/Close" "Escape") In my collegue's ~/.purple/accels file he just had to change <Con...

Has Althea UK Ltd. gone bust? (aka Bathrooms Italia / Period Bathrooms)

Note: This is a non-technical post that I'm making to see if anyone else is searching for information regarding any outstanding bathroom orders - if so, please leave a comment so we can pool our collective wisdom! We placed an order through Bathrooms Italia for a new bath back in January and after repeated phone calls inquiring about the whereabouts of the bath we have found this morning that the site appears to not be avilable anymore and they are not answering their phone - 01845 577 432. After a little digging about it appears that Period Bathrooms are also not answering their phone - 01274 660 770. Both of these companies seem to be public consumer websites for Althea UK Ltd. , their number is the same as Bathrooms Italia - 01845 577 432 which is never answered. A quick search on Credit Gate shows the following suspect activity : REGISTERED OFFICE CHANGED ON 22/01/08 FROM:KC HOUSE, BRETTON STREET DEWSBURY WEST YORKSHIRE WF12 9BJ SECRETARY'S PARTICULARS CHANGED ON 21/...

A hint when working with Rails Migrations and legacy databases (ID columns)

Had an interesting problem recently when writing some Rail migrations scripts for an old non-Rails MySQL database. After writing the migration and running it via Rake we found that it was erroring with a complaint about the primary key. We checked that the table had an id column, it did but instead of id it was ID . ActiveRecord is very specific in what it looks for and so was not viewing this ID column as the primary key that it required when adding new rows to the table. A quick lookup in the ActiveRecord documentation pointed out the solution: use set_primary_key in your ActiveRecord class: class SomeLegacyTable set_primary_key :ID end Technorati Tags: Rails , Migrations , ActiveRecord , MySQL , Andrew Beacock