Monday, August 28, 2006

Why Choose Windows?

  • Choose Bill Gates as your Dark Lord.
  • Choose service packs every three months to fix the 800 bugs introduced in the last one.
  • Choose an assload of obscure shovelware apps and shitty games and an Office suite that needs 18 gigs to write a letter.
  • Choose selling your soul to piracy.
  • Choose cheap ass parts from Korea.
  • Choose Winamp skins that look like snot.
  • Choose the blue screen of death.
  • Choose hordes of 133t skript kiddiez clogging the internet with their shit.
  • Choose running Norton and ZoneAlarm constantly to fight off the newest viruses.
  • Choose using letters for drives while wondering where the hell B:\ went.
  • Choose Steve Balmer jumping across the stage like a gorilla in heat.
  • Choose a damn crapshoot every time you install a program or add a peripheral.
  • Choose Microsoft squashing competitors and finding new ways to take over the world.
  • Choose sitting on your fat ass, mocking Linux users in chatrooms and forums, drowning in your own bile about Intel and AMD who think stealing from others is "innovation".
  • Choose your future.
Choose Windows.

Wednesday, August 23, 2006

Decompiling Java Class Files On-The-Fly

Being a Java developer, I sometimes want to look at the source code of class files just by double-clicking on the class file itself. There are lots of programs out there, such as DJ Java Decompiler, which allow you to do just this, but I was looking for a quick and easy way without the overhead of having to install memory intensive software.

Create ClassViewer.bat

I came up with this simple Windows batch script which uses the Jad Decompiler to decompile any Java class file that is clicked on. It then displays the decompiled code in your favourite text editor e.g. TextPad.

@ECHO OFF
jad -p "%*" > "%*.jad.java"
"C:\program files\TextPad 4\TextPad.exe" "%*.jad.java"
sleep 5
del "%*.jad.java"


Save this script as ClassViewer.bat

Associate Class files with ClassViewer.bat

Open File Explorer and click on Tools > Folder Options > File Types. Scroll down to the CLASS Extension (or if it is not there, add it by pressing the New button) and then press Change. A new window will open up asking you to select the program you want to use to open files of this type. Browse to ClassViewer.bat and hit OK. You have now associated this program with files with the .class extension.

Test it out...

Double-click a Java class file and see it execute the script and display decompiled code in your editor! You can even double-click class files within jars!

Friday, August 18, 2006

Only Apparently Real

I used to believe the universe was basically hostile. And that I was misplaced in it, I was different from it... fashioned in some other universe and placed here, you see. So it zigged while I zagged. And that it had singled me out only because there was something weird about me. I didn't really groove with the universe.

I had a lot of fears that the universe would discover just how different I was from it. My only suspicion about it was that it would find out the truth about me, and its reaction would be perfectly normal: it would get me. I didn't feel that it was malevolent, just perceptive. And there's nothing worse than a perceptive universe if there's something wrong with you.

But this year I realized that that's not true. That the universe is perceptive, but it's friendly...I just don't feel that I'm different from the universe anymore.

- Philip K Dick in an interview, 1974
(from Only Apparently Real)

Thursday, August 17, 2006

Software Review - SlickRun

SlickRun is a must-have program for techies like me, who are used to a *NIX environment and hate having to leave their keyboards to double-click icons on their desktop. I can't even remember what my desktop looks like or what wallpaper I have anymore! (Hmmm... I bet its something to do with Space though.)

SlickRun is a small command-line floating window which sits in the bottom right-hand corner of my screen. I simply press Win+Q and it flies up to my cursor and grabs focus, allowing me to enter any one of my favourite magic words. A "magic word" is basically a shortcut to various frequently used programs. All you do is type it in and press Enter and it launches your program(s). You can set up as many magic words as you like and even pass in arguments to your magic words.

For example, the magic word "firefox" would launch the Firefox browser and typing in "define Supercalifragilisticexpialidocious" would take you to the web definition of the word. (For those interested, "Supercalifragilisticexpialidocious" is the 34 lettered song title from the 1964 movie Mary Poppins. As a song title, it is a proper noun, but the word, and variations, has entered the English language as an adjective. It is one of the longest words in the English language.)

Any Windows commands such as "calc" are magic words anyway, so you don't need to set them up. You can even set up a single magic word to run multiple commands, so that after a reboot, you can simply type it in to start up all your programs.

SlickRun also auto-completes magic words for you and you can use the arrow keys to scroll through your history of previously invoked commands.

The main thing I love about SlickRun, is how simple it is. It doesn't get in your way or take up much CPU power. It just sits innocently in a corner, responds quickly to your commands and allows you to be more productive!

Here are some of my magic words that I thought I'd share with you:
  • define - goes to google definitions
  • eclipse
  • excel
  • firefox
  • google
  • jsql
  • mail - launches Lotus Notes
  • mydocs - goes to My Documents
  • paint
  • pf - goes to C:\Program Files
  • player - Windows media player
  • putty
  • shutdown
  • startup - launches all my programs after a reboot
  • toad
  • weather
  • windiff
  • word
  • xmlspy
  • ymail
  • ymsgr
  • ! - runs cmd /k e.g. ! ipconfig
  • lots of folder/drive shortcut names
Download SlickRun here!

Tuesday, August 15, 2006

Oracle 10g's New Row Timestamps

One of the systems I work on, maintains a cache of data which is reloaded from the database every time an update is made. Using a cache, rather than hitting the database each time, has some significant performance advantages. However, one of the downsides is the time taken to load the cache. Due to the large amount of data involved, sometimes reloading the cache takes up to 15 minutes!

The main reason for this is that because we don't know which rows of data have changed, we end up loading the entire cache each time. This means that we will reload 50,000 rows of data even if only 1 row has changed!

One solution would be to add a "last_updated" column to each of our tables and use that in our cache-refresh query. A better way, however, would be to use an exciting new feature that comes in Oracle 10g...

In Oracle 10g, a new pseudocolumn called ORA_ROWSCN is available on every row which "returns the conservative upper bound system change number (SCN) of the most recent change to the row". This is useful for determining approximately when a row was last updated. Also, the SCN_TO_TIMESTAMP function can be used to convert an SCN to a timestamp!

So coming back to the cache problem, we can determine which rows were modified simply by writing a query which gets all rows having an SCN_TO_TIMESTAMP(ORA_ROWSCN) greater than the time that the cache was last reloaded!

Sadly, we're still on Oracle 9i so will have to wait to use this awesome new feature:(

Example
SELECT ORA_ROWSCN, last_name FROM employees
WHERE first_name = 'FAHD';


UPDATE employees SET salary = salary*10
WHERE first_name = 'FAHD';


SELECT SCN_TO_TIMESTAMP(ORA_ROWSCN), last_name FROM employees
WHERE first_name = 'FAHD';

Reference

Oracle®: ORA_ROWSCN Pseudocolumn

Monday, August 14, 2006

Changing Your Java Classpath at Runtime

Someone recently asked me how they could modify their Java classpath at runtime.

It is not possible to do this, simply by changing your java.class.path property because this property is only read when the JRE is first instantiated. After that, it is not re-read. Therefore, any changes you make to the property don't really do anything to the existing virtual machine!

BUT there is still a way to accomplish this:
  • Get hold of the SystemClassLoader
  • Call its addURL() method. Since this method is protected, you have to use reflection to sneakily change its accessibility in order to invoke it. I love hacks!
try {
File fileToAdd = new File("HelloWorld.class");
URL u = fileToAdd.toURL();
ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
if (sysLoader instanceof URLClassLoader) {
sysLoader = (URLClassLoader) sysLoader;
Class sysLoaderClass = URLClassLoader.class;

// use reflection to invoke the private addURL method
Method method = sysLoaderClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(sysLoader, new Object[] { u });
}
}
catch (Exception e) {
e.printStackTrace();
}


WARNING:
Using reflection to invoke private or protected methods is not good programming practice. Especially for hacking into system classes such as the Runtime ClassLoader!

Sunday, August 13, 2006

My First Post

Hello World!

This is my first post in my first ever blog.

So why have I started blogging?

  • Because everybody else is
  • Because I'm bored and have nothing better to do
  • Because I enjoy talking to myself
  • Because I want to create a stronger web presence
  • Because I want to share my ideas and thoughts with the rest of the world
  • Because I want to connect with other geniuses like myself

And what am I going to blog about?


  • My life - so I have a history of everything I've done
  • My interests - mostly technology and programming
  • Whatever I'm thinking about
  • Whatever I think will be interesting to share with others

Let the blogging begin!