Skip to content

www.rolfje.com

Category: Software

Simple Strict Date Parsing

Posted on 2010-03-06 By rolfje No Comments on Simple Strict Date Parsing

In Java, the DateFormat.parse() method is a funny little critter. It helps you by trying to figure out what date you actually meant when you typed in “35/12/2O10” (note the letter “O” in 2O10). In this case, it will parse the date without errors or warnings, and returns the date “11/12/04” (November 12th, 0004). That’s because it thinks “35” is a month, and “2” is the year, ignoring everything after the letter “O”.

DateFormat tries to convert the “35th month” into 2 years and 11 months, and correct the date accordingly. df.setLenient(false) prevents this, but that still leaves the problem of the parsing stopping at the first wrong character without warning.

I needed a much stricter way of parsing dates, and yesterday I found an elegant solution to this problem. It’s so small I was able to tweet it in less than 140 characters, but I thought it deserved a decent blogpost so here it goes:

public Date parseDateString(String inputDateString) 
         throws ParseException {
  DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
  Date parsedDate = df.parse(inputDateString);

  if (!inputDateString.equals(df.format(parsedDate))) {
    throw new ParseException("Invalid Date", 0);
  }
  return parsedDate;
}

The brilliance here is in the comparing of the formatted date with the original input. The method returns a normal ParseException so you can perfectly replace your original df.parse() calls with it, making them more strict.

Thanks to Bas for this elegant and simple solution.

Software

Flow

Posted on 2009-12-22 By rolfje 3 Comments on Flow

Being “in the flow”. The nicest state of mind known to mankind. You act without thinking, and everyone of your actions is the perfect response to the situation. Riding a motorcycle on a beautiful road without a destination can easily get you into this state. With an empty mind, you see the next 2 corners, feel your bike as your brakes hit the disc, smell the forest, and hear the wind as you start accelerating out of the first corner while naturally placing the bike into position for the next.

Read More “Flow” »

Software

Sonar “Close Connection” warning workaround.

Posted on 2009-10-06 By rolfje 7 Comments on Sonar “Close Connection” warning workaround.

When you use Spring and Ibatis and SQLTemplates, you could have code in your project which looks somewhat like this:

Connection connection = DataSourceUtils.getConnection(getDataSource());
...<do connection stuff here>...
DataSourceUtils.releaseConnection(connection, getDataSource());

Sonar will report that you did not close the connection, while in fact, Spring did that for you. You can not just add a “connection.close()” to the code because the whole point of calling “releaseConnection()” is to have Spring handle all the smart stuff on committing, closing, and returning the connection to the pool if needed.

Read More “Sonar “Close Connection” warning workaround.” »

Software

Transactions and Isolation levels

Posted on 2009-08-29 By rolfje 2 Comments on Transactions and Isolation levels

Safety googlesAt work, we have two applications which connect to the same database. For all kinds of business reasons, we need to make sure that only one of the applications accesses certain data at the same time. To do this, we use a row in a table as a semaphore.

While working on the locking mechanism, we had a closer look at the Transaction Management and the Isolation Levels we were using. There is a lot of good documentation on Transaction and Isolation, but it tends to be over complete, elaborate and therefore hard to read. I’ll try to share our insights with you in a slightly more digestable form (I hope).

Read More “Transactions and Isolation levels” »

Software

Omniplan Progress Tracking Tip

Posted on 2009-08-13 By rolfje 4 Comments on Omniplan Progress Tracking Tip

OmniplanDuring one of my Omniplan sessions at work, I discovered that the resource leveling was acting a bit funny, where people were not planned to do any work for days. I played around with a fake planning and soon discovered the problem and several solutions to it.

Read More “Omniplan Progress Tracking Tip” »

Apple, Software

Starting Java app from Applescript

Posted on 2009-06-11 By rolfje No Comments on Starting Java app from Applescript

Suppose you have a Java Swing application which you can start by typing the following on the command line:

java -jar myTerrificSwingApp.jar

If you want to make that application start from the Finder in OSX, there are a lot of options which range from ugly to convoluted. If you need a quick fix, here’s how to do it.

Read More “Starting Java app from Applescript” »

Apple, Software

Javascript Window Shake

Posted on 2009-03-12 By rolfje 2 Comments on Javascript Window Shake

This evening I came accross the window.moveBy() JavaScript function and thought it would be cool to shake the browser window when a user fails to log in. It turns out that I was not the only one thinking this, but none of the examples worked for me. Some had no proper delays, others only worked from the page header, and some were plain unreadable.

I’m no Javascript guru, but I hacked this together which is working pretty nicely. It is in fact almost undistinguishable from the Apple login window shake at a login failure:

<script type="text/javascript">
if (window.moveBy) {
	delay = 70;
	shakes = 3;
	window.moveBy(-10, 0);
	for (j = shakes; j > 0; j--) {
		setTimeout( "window.moveBy(20, 0)", j*delay );
		setTimeout( "window.moveBy(-20, 0)", 
					j*delay+(delay/2));
	}
	setTimeout( "window.moveBy(10, 0)", (shakes+1)*delay );
}
</script>

In my case, I surrounded this code with a Tapestry @Conditional and made it into a reusable Tapestry component so that I can make any window shake as soon as it contains an error.

The code will work anywhere on your page, but I advise you to put it at the bottom of the HTML. This will make sure that the content is shown in the browser before you shake it.

It’s visually much stronger than just adding an errortext to the page. If people log in a couple of times a day, they don’t even notice extra text on the screen. This will “shake” them awake 🙂

Have fun!

Fun, Software

DLNA on OSX, done right

Posted on 2009-01-31 By rolfje 60 Comments on DLNA on OSX, done right

Sony PS3 LogoMy wife bought me a playstation 3 last year, and I’ve enjoyed many hours of gaming on it, finishing Tomb Raider underworld, and now making decent progress in Ratchet and Clank: Tools of Destruction.

DLNA logo

I was a bit sceptical about the DLNA capabilities of the PS3, because I read a lot of bad news on this fairly new  “Interoperability Guidelines” concept. It sounded like a lot of trouble to go through to simply watch the photos and home videos on a TV. For weeks, I was not able to find a single site telling me how to install a DLNA server on my Mac, or where to find a decent one.

Altgough they’re hard to find, there are a few OSX DLNA servers out there. One of them is actually very good. Here’s what I found:

Read More “DLNA on OSX, done right” »

Apple, Software

Remote Desktop Connection updated

Posted on 2009-01-25 By rolfje 1 Comment on Remote Desktop Connection updated

Remote Desktop Connection icon

“Remote Desktop Connection.app” allows you to see the desktop of a remote Windows machine on your mac. This application will not update itself automatically, unless you have it installed as part of the Microsoft Office for Mac suite. If you’ve downloaded the 1.0.3 version you probably did not notice that “Remote Desktop Connection.app” was updated somewhere last year by microsoft.

You can find the latest version of Remote Desktop Connection on the Microsoft Mactopia site. Version 2 is an improvement over 1.0.3 (which I had). Notable differences are:

  • Nicer configuration screens, makes configuring your resolution and shares easier.
  • Now a Universal Binary, which should improve performance on Intel Macs. I have not noticed improvement, but that’s probably because the network is the bottleneck.
  • Supports the new RDC 6.0 protocol used by Vista.
  • Can do authentication of the remote machine (if it’s a Vista machine).
  • Your Mac printer can be exposed to the Windows machine so you can print documents on your local printer.

I played with it for a while, and apart form the new looks I can not say it’s very different from the 1.0.x version. It could load my old RDC 1.0.3 configuration files. If you need to connect to a Windows desktop from your Mac, this does the job just fine.

Apple, Microsoft, Software

Automount network shares

Posted on 2009-01-18 By rolfje No Comments on Automount network shares

Bonjour Mounter iconThere is a nice and clean way to automatically mount network shares each time you log into your Mac. It’s called the “Bonjour Mounter”, a simple application which runs on login, and mounts the drives you configured it to mount. No more, no less.

Apple, Software

Posts navigation

Previous 1 … 4 5 6 … 14 Next
         

Recent Comments

  • rolfje on Exit WordPress
  • Guus on Exit WordPress
  • rolfje on Exit WordPress
  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?

Tags

Apple backup design DIY DRM eclipse environment fix Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote linux modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software technology Time Machine Twitter Ubuntu usability Utilities vacation vista windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (15)
  • Software (138)
  • Uncategorized (68)
  • Workshop (20)

Archives

Brought to you without adds, banners, cookies or tracking. This one is on me. Yes, life can be this good. Pay it forward.

Copyright © 2026 www.rolfje.com.

Powered by PressBook WordPress theme