IT Poetry


Wicket headeaches
March 26, 2008, 12:38 am
Filed under: Programming

After using Wicket for some time i think its really good, but here is a summary of what could be better.

Problems with Wicket

  • Pages and components are forced to derive from a base page which can not even be instantiated without a special test environment.
  • The provided test tool, feels fairly immature and can not be used to test pages that need more input than what’s given in the constructor. (Tester does setupRequestAndRespones before startPage, which deletes changes to parameters.)
  • There’s a strange problem that you get a PageExpiredException if the visibility of component in onDetach(). This is an example of the unintuitive problems that I’ve run into when trying to do a bit more advanced things.
  • The test utilities has no/strange support for cookies.
  • The test utilities assumes that localization should be done according to the environment of running the tests, which means that assumptions regarding content can not be made without dealing with localization.
  • The logic programmer have to declare all components explicitly, and must allways instantiate all of them. The wicket could have defaulted to invisible if not instantiated, and should be more flexible in how components can be put on the page. It takes quite some effort to dynamically put content on the page.
  • Template pages are difficult to customize by special pages.
  • Wicket lacks some essential components, for example the programmer have to create his own components to insert an image tag to an external image!
  • I had to create my own page plumbing to serialize some XML to the user! (Even there was a suggested way to do this, there was no documentation to stop me from spending a lot of time with it. So either its the documentation or Wicket’s fault. I lost time, so I don’t care which one.)
  • Wicket uses final methods everywhere. -What’s the point? This just gives me head aches when I can’t mock like I want to!
  • At least to me, Wicket encourages a component model oposite to MVC. After my first bigger refactoring, I realized that I could simplify both the code and testing a whole lot by forcing a bit of separation of concern into my web app.

Some impressive things to balance with:

  • Good job with warning of serializable members. Pages should probably not have serializable members annyways! (Log4j, though)


Bash script to export and backup online data
February 7, 2008, 11:10 am
Filed under: Internet, Productivity

Even though most sites probably save more data than we’d need for longer than we care (or want). It’s allways nice to keep your own data some place safe. Its also nice to automate backing up your online data, so for your convenience here’s a bash script to back up your online data from del.icio.us, wordpress.com and bloglines.
I’m using the script in linux and cygwin, but it should work with regular bash+wget.
The script works by getting the login page with wget and saving the login cookie. The script asks for your password, but you’re only required to enter it the first time you log in.

updateMyBackups.sh

#!/bin/bash
#Bash script to download your online data, use freely no responsibility taken.
#Author Hugo Hallman, http://itpoetry.wordpress.com/
#License GPL, Please post your updates in comments on the blog.
#USAGE: Either change the function calls at the bottom,
#or write a new script importing this one, calling the export functions.
#EG:
#file: myOnlineBackups.sh
# . updateMyBackups.sh
# noninteractive=0;
# wordPressExport "username" "blogname";
# deliciousExport "username";
# bloglinesExport "me@mail.com";
# end file.

# Set to 1 if you don't want the script to ask questions
noninteractive=0;

function wordPressExport() {
	wpuser=$1;
	wpblog=$2;
	[ "$wpuser" == "" ] && echo "wordpress.com: please give user name" && return 1;
	[ "$wpblog" == "" ] && echo "wordpress.com: please give blog name" && return 1;

	echo "Exporting WordPress: $wpblog by $wpuser";

	mkdir -p temp
	cf=temp/auth_wp;
	touch $cf

	if [ "$noninteractive" != "1" ]; then
		echo "If you want to renew login cookie, type wordpress password: ";
		read wppwd;
		if [ "$wppwd" != "" ] ; then
			echo "Logging in to wordpress.com";
		    wget --keep-session-cookies --save-cookies $cf --quiet --output-document=/dev/null "http://${wpblog}.wordpress.com/wp-login.php";
		    wget --keep-session-cookies --load-cookies $cf --save-cookies $cf --output-document=temp/login.html --quiet \
				--post-data="log=${wpuser}&pwd=${wppwd}&rememberme=on&redirect_to=wp-admin%2F&testcookie=1&wp-submit=Log%20in%20%26raquo%3B" \
				"http://${wpblog}.wordpress.com/wp-login.php";
		fi;
	fi;

	target=${wpblog}.xml;
	out=temp/${target};
	if grep ".wordpress.com" $cf | grep "$wpuser" > /dev/null ; then
		rm -f $out;
		echo "Downloading export to $out";
		wget --quiet --load-cookies $cf --output-document=$out \
			"http://${wpblog}.wordpress.com/wp-admin/export.php?download=true&submit=Download%20Export%20File%20»"
		if test -f $out && grep ' /dev/null && grep ' /dev/null; then
			mv $out $target;
			echo "Exported ${target}";
		else
			echo "Failed to export ${target}";
		fi;
	else
		echo "Not logged in to wordpress.com";
	fi;
}

function deliciousExport() {
	user=$1;
	[ "$user" == "" ] && echo "del.icio.us: please give user name" && return 1;

	echo "Exporting del.icio.us tags for $user";

	mkdir -p temp
	cf=temp/auth_delicious;
	touch $cf

	if [ "$noninteractive" != "1" ]; then
		echo "If you want to renew login cookie, type del.icio.us password: ";
		read pwd;
		if [ "$pwd" != "" ] ; then
			echo "Logging in to del.icio.us";
			wget --keep-session-cookies --save-cookies $cf --quiet --no-check-certificate \
				--post-data="user_name=${user}&password=${pwd}&action=login" --output-document=temp/login "https://secure.del.icio.us/login" ;
		fi;
	fi;

	target=delicious.html
	out=temp/${target};
	if test -f $cf && grep ".del.icio.us" $cf | grep "_user" > /dev/null ; then
		rm -f $out;
		echo "Downloading export to $out";
		wget --quiet --no-check-certificate --load-cookies $cf --output-document=${out} \
			--post-data="export=export%20to%20html&showtags=on&showextended=on" \
			"https://secure.del.icio.us/settings/${user}/bookmarks/export";
		if test -f $out && grep '' $out > /dev/null; then
			mv $out $target;
			echo "Exported $target";
		else
			echo "Failed to export $target";
		fi;
	else
		echo "Not logged in to del.icio.us.";
	fi;
}

function bloglinesExport() {
	user=$1;
	[ "$user" == "" ] && echo "bloglines.com please give user name" && return 1;

	echo "Exporting bloglines subscriptions for $user";

	mkdir -p temp
	cf=temp/auth_bloglines;
	touch $cf

	if [ "$noninteractive" != "1" ]; then
		echo "If you want to renew login cookie, type bloglines.com password: ";
		read pwd;
		if [ "$pwd" != "" ] ; then
			echo "Logging in to bloglines.com";
	        wget --keep-session-cookies --save-cookies $cf --quiet --no-check-certificate \
				--post-data="email=${user}&password=${pwd}&signin=Log%20In" \
				--output-document=temp/login \
				"http://www.bloglines.com/login" ;
		fi;
	fi;

	target=blogs.opml;
	out=temp/${target};
	if test -f $cf && grep ".bloglines.com" $cf | grep "BloglinesTracker" > /dev/null ; then
		rm -f $out;
		echo "Downloading export to $out";
		wget --quiet --load-cookies $cf \
			--output-document=$out \
			"http://www.bloglines.com/export";
		if test -f $out && grep ' /dev/null && grep ' /dev/null; then
			mv $out $target;
			echo "Exported $target";
		else
			echo "Failed to export $target";
		fi;
	else
		echo "Not logged in to bloglines";
	fi;
}

#Export from wordpress
wordPressExport "username" "blogname";
wordPressExport "username" "secondblogname";

#Export from del.icio.us
deliciousExport "username";

#Export from bloglines
bloglinesExport "me@mail.com";


A fragment of Qi4J
November 22, 2007, 12:09 am
Filed under: personal, Programming | Tags: , , , , ,

Qi4J logoI had the pleasure of attending the Oredev conference here in Sweden last week. Where Richard Oberg (Öberg, founder of JBoss) introduced the concept of Composite Oriented Programming (COP), specifically Qi4J with slogan “Classes are dead, long live interfaces”.

Composite oriented programming is about fragmenting the constraints, concerns, side effects and actual behavior of your beans into fragments (implemented by “Mixins”) which are brought together by a composite.

These are some things you can do with composites:

  • A typical constraint of a bean is to not allow null values. -Move this constraint to a generic constraint checking for null or empty values in the setters.
  • A typical side effect of a bean is to invalidate a cache when invoking a setter or logging invocations that take an unexpectedly long time. -Move these side effects to generic mixins.

These examples look very much like Aspect oriented programming, but I think that fragmentation should be applied on a higher level in the application design. Another difference with AOP is that control of the aspects of an object is moved from the AOP rules into the definition of a composite, which should give more transparency and flexibility.

If you are interested, the Qi4j website is still quite immature, and it is quite frustrating trying to penetrate the essence of the framework, but i recommend starting with a Composite Example.

The most interesting part of the Qi4J initiative is the model in which it is developed. After their presentation, I got a chance to speak with the guys from Jayway which have sponsored the project so far. Qi4j is hosted on OPS4J (Open Participation Software for Java), which is working like a “Wiki brought to coding”. The idea with the OPS4J hosting is that anyone should be able to contribute without having to be accepted by the group. The commits will be moderated like on Wikipedia. This is probably a fantastic way to get people to start contributing. But I suppose it is very risky not having control over the commiters to steer the project towards a road map. It shall be very interesting to follow Qi4J, and as the Jayway people said: “Now we are what the Spring framework was in 2003″.



Information hubs
November 20, 2007, 3:24 pm
Filed under: Internet

Flickr is a pretty interesting online photo sharing service.

  • It has pretty lousy user pages with almost no control over the page appearance
  • It has some lousy discussion features, where discussions are organized either by latest comment or chronologically
  • It has a groups system where you can post your pictures.
  • You can comment on pictures, make the photographer a “friend” and add photos to your “favourites”. Even still it is not super convenient to keep track of photographers of interest.
  • (It has geotagging with integration with Yahoo maps, which is cool and slowly getting useful. Will probably explode in popularity when GPS is embedded in the cameras)

The interesting part of its success (2 billion uploaded photos) is its open API. Letting you delegate trust in a controlled way to third parties without giving out your password. You can also revoke access whenever you feel like from a list of all active permissions.

One aspect I don’t like is how flickr give out programmatic access to “public” content to anyone on the internet without explicit permission from its users. (Remember the days when “public” ment public to only the community users?) I don’t think this affects flickrs popularity since its something you don’t realize until its too late and you’re already using the service.

Well, the features that flickr lack is available through third party “addons”. Like FlickSlidr, where you can create embeddable slideshows for with your or somebody elses photos. Or a yahoo pipes implementation, where you can see your “contacts” favourite pictures. BigHugeLabs has a vast collection of tools like these.

Esentially, flickr is like an online hard drive of photos, where applications are on the Internet.

Similarly, I hope that the online document editors that are emerging will open up to something similar. It would be utterly convenient to have an online document storage where I could place my documents to be edited with the best online editing tools. The storage solution could specialize in storage-centric features, (that we all would love on our hard drives) like versioning, tagging, indexing, sharing, available time windows, branching/merging, licensing, backup to own hard drive, and other cool storage features.

Amazon S3 is a cool service where Amazon is sellining its great storage solution to others. But since it doesn’t have these features, all i’ve seen it being used for is as a backup solution.



Loose the task bar
November 18, 2007, 4:24 pm
Filed under: Productivity

Lets build on our work so far with shortcuts in the path, by adding shortcuts to the keyboard. (Like the ones that come with “multimedia keyboards” but more powerful)

The idea is to make all your commonly used programs available as keyboard shortcuts, so that you can switch between them without using alt-tab. The programs will even be started for you if they aren’t runing. This will save time and add predictability. You will also get the benefit of being able to start dragging an object, pressing the application shortcut then drop the object into the application that magically appeared as you dragged the object! (It’s no longer really a drag, but a pin, hover, focus new application, drop)

The method I use and recommends builds on the excellent tool, AutoHotkey (windows scripting freeware).

  1. Download and install AutoHotkey,
  2. AutoHotkey will be installed with a default script that you can edit. (If you’re ambitious, you can modify the autorun link to run a script in your documents folder)
  3. Start your script with the following line:
    SetTitleMatchMode 2
  4. For each application that you commonly use, decide on a shortcut and enter code following this template.
  5. The titles will have to be customized according to the language of your windows installation.

#n::
IfWinExist Untitled - Notepad
     WinActivate
else
     Run Notepad
return

This script will make sure you have an unsaved notepad document whenever you press [Windows]+N.
This says, when pressing the [Windows]+N keys, activate a window called ‘Untitled – Notepad’ if it exists. Otherwise run the Notepad application which is available on the path.

Since I have a link to Microsoft Outlook in my c:\path directory I can get to my inboxy by typing [Windows]+M


#m::
IfWinExist Microsoft Outlook
     WinActivate
else
     Run outlook
return

And I get my browser by typing [Windows]+I

#i::
IfWinExist Mozilla Firefox
     WinActivate
else
     ;assumes that ff is a shortcut on the path pointing to firefox.
     Run ff
return

Autohotkey is an excellent free scripting tool, also featured in lifehacker.com and lifehack.org.
Many other resources on Google.



Delicious links
November 18, 2007, 4:16 pm
Filed under: Productivity

Daunted by your link collection?
I used to be, as I had a few hundred links in my link collection, partly organized in folders. The funny thing is, Google is much better at finding the right page from the entire web, than I was at finding the right link from my own link collection. Even still, it is comforting to “save” the gems of the web for later.
Enter del.icio.us!
Delicious is a catalog of tagged links where you can save links with keywords on the web. No need to synchronize computers, and links are easy to find by keywords. This way, you can tag pages with “todo” keywords or similar.

Its not necesarry, but much snappier to use with a plugin for firefox.

Firefox 3 apparently has some similar features in the making.



Loose the Start Menu
October 30, 2007, 3:45 pm
Filed under: Productivity | Tags:

First atual post:

Here’s a time saver. It saves me about 0.75 seconds about a hundred times a day, and adds predictability and control to the office experience. What it does, is letting you run your programs with keyboard short cuts. Setup time is about 4 minutes.

  1. Create the folder c:\PATH (or something similar)
  2. Right-click the my-computer icon, and choose properties
  3. Select the Advanced tab and click Environment Variables.
  4. Add’;c:\PATH;‘ to the end of the Path environment variable in the System variables group.
  5. Add shortcuts to your favourite items in the path folder. These should have simple and short names.
  6. DONE! -You no longer need the start-menu.

Now you can run the shortcuts just by typing [Windows]+R, and filling the run-dialog with the name of the shortcut you put in the c:\path folder. I recommend putting a shortcut to the c:\path folder in the folder itself. This way it will be easy to add shortcuts.




Follow

Get every new post delivered to your Inbox.