Saturday, November 12, 2011

Restful urls and spring mvc

Spring 3.0 boasts of Rest support. One aspect of this is using resource-based urls. For example, using /hotels/hilton/suiteNo1 instead of /hotels?hotel=hilton&room=suiteNo1.

So how do we achieve this? The typical fashion of using spring mvc is to map all the incoming requests that match some pattern (e.g. *.form) to spring's DispatcherServlet like this -


    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.form</url-pattern>
    </servlet-mapping>


This mandates that our application urls are like /hotels/hilton.form. This is not what we want here. We'd rather drop the .form if we can.

So lets map everything to the dispatcherServlet instead of just .form requests, shall we?



    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


This enables us to drop the .form extensions. But there's a problem lurking here. A request for a static public resource like an image also goes via the dispatcherServlet. And since there won't be a controller defined for that, it'll throw a 404. We don't really want to map css and image requests to the spring servlet.
The problem can be summarised as follows : We want to map all requests except css/image/js requests to the dispatcherServlet.


How do we achieve this? Tuckey's urlrewrite comes to the rescue. In principle, its simply a Filter that lets us rewrite urls based on certain patterns. The order of processing is important. The filter will kick in _before_ the container chooses which servlet gets to handle the request. So what we need to do in the tuckey urlrewrite filter is to 'mark' all the urls which we want spring to handle with a certain prefix (say /myapp) and leave the css/image/js urls untouched. Furthermore, we configure the spring servlet to handle only those urls with that myapp prefix in them. Here's how the tuckey configuration looks:


    <rule>
        <name>Jsp Rule</name> 
        <from>**/app/**/jsp/**</from> 
        <to last="true">$1/$2/jsp/$3</to>
    </rule>
    <rule>
        <name>Css Rule</name>
        <from>**/css/**</from>
        <to last="true">$1/css/$2</to>
    </rule>
    <rule>
        <name>Js Rule</name>
        <from>**/js/**</from>
        <to last="true">$1/js/$2</to>
    </rule>
    <rule>
        <name>Spring Rule</name>
        <from>**</from>
        <to>/app/$1</to>
    </rule>

There is some duplication here - maybe all the resources can be moved under a common directory. But I'll leave that to all you responsible developers.
The 'last=true' bit is important - and something that was missing from many other blogs. Without it, tuckey just falls through to the next rule after one rule matches. So after matching /css/style.css it'll fall through to the spring rule and change it to /app/css/style.css. Won't do. The last=true means tuckey will not process subsequent rules if there is a match on that particular rule.

And there we have it. Beautiful urls.

Wednesday, November 9, 2011

Television

I am not a big TV fanboy. I generally prefer the outdoors instead. However, these days, for better or for worse, I've been watching a bit of TV. My focus is mainly on the wildlife, travel and sports ones. My favourite channel without a doubt is National Geographic HD. The astronomy-related shows are superb. They're also based on fairly cutting-edge and recent research. So its mostly stuff that you'd probably not know via other means unless you are working in a related field. Did you know there's a jet of water shooting from one of Saturn's moons? The wildlife shows are a good reminder of what is out there and we're missing. From seeing the annual migration of the wildebeest to understanding why the shark is nature's greatest killing machine ever built - maybe you can get by without knowing. But again, you're missing out. Other favourites are TLC (Travel and Living). Their shows provide a great insight into so many different cultures. I find it very interesting. As far as sports on TV are concerned, I don't have much time left to watch any more than the occasional Soccer and Cricket. There are definitely better ways to spend your time, but its not all bad.

Tuesday, June 28, 2011

The Vicious Circle Conundrum

I skipped work today. Officially speaking, its a sick leave. But I am not really sick. (I'm positively sure my boss won't see this) Demotivated, perhaps.
So I was trying to figure out why I am demotivated. Its not that hard really. When you bang your proverbial head against a wall 8 hours a day, 5 days a week, you feel demotivated. Nothing motivates you like making progress in whatever you are doing. The feeling of 'getting somewhere' is innocuously powerful - however small the increment may be. Its probably why people suddenly start walking faster when they feel they are close to their destination. Some people think its appreciation that motivates - I disagree. Appreciation ostensibly seems to motivate - but the real cause is that it gives us a feeling of making progress. Undeserved appreciation is actually scary.
So then the answer to demotivation (and preserving your sick leaves for real illnesses) is to make progress. But hey, you can't make much progress unless you are motivated in the first place! Thats the vicious circle I'm talking about.
The only way out - as far as I can see - is to get a burst of energy when you are demotivated to propel you out of the rut and make enough progress to feel motivated again.
Good thing I'm going on a 3 week vacation in August.

We are surrounded by many such circles. E.g. Its hard to find friends unless you have some friends to start with.

Are you stuck in a circle too?

Friday, February 18, 2011

Cricket World Cup

A speculation, albeit incorrect, does not go to waste. Here, the end result is not the point. Its the stimulation of discussion and thoughts that matters.
So. Here are mine.
History shows that the cup has been won by (a) An overwhelmingly strong team OR (b) a well-settled team having strong leadership and which is on the rise and in good form.
'75, '79 - West Indies. Its no understatement that they were far ahead of the rest of the pack.
'83 - India. This was a team on the rise and in high spirits, after giving WestIndies a run for their money just before the tournament started.
'87 - Australia. Again, a team in good form and a positive mood leading to the cup.
'92 - Pakistan had just beaten WestIndies at home. Which was no mean achievement even in 1991
'96 - Sri Lanka. Strong leadership of Arjuna Ranatunga and a team on a high after beating Australia in ODIs.
'00, '03, '07 - Australia were strong favourites and dominated world cricket during this period.

So what does that mean for this tournament? For one, there aren't any overwhelming favourites. Lets look at the teams.
Pakistan look too unsettled for my liking, in spite of wining against NZ on their home turf.
England lost by a long way to Australia in the ODIs and the joy of winning the ashes has worn off. They're plagued by injuries too.
NZ got thrashed 5-0 in India. Admittedly by one of the favourites, but its hard to envisage them picking up the pieces from here.
West Indies is a team in flux. Not to mention they have loads of players who don't have much experience of playing in the subcontinent. Unlikely.
Bangladesh is an interesting one. They've beaten Zimbabwe and NZ at home. They're playing in familiar conditions. But do they have the firepower to go all the way? I don't think so. Not yet. In the series against NZ, their top batsmen was Shakib Al-Hasan, averaging 71. The next best was 34. Less than half! They are reliant on a few good players and thats not good enough to win the world cup.
Zimbabwe have lost miserably in the recent past to South Africa and then Bangladesh.

So, ignoring the minnows, we're left with Australia, India, Sri Lanka, South Africa in no particular order.
Thats the likely semis lineup for me. From here, it gets hard. It calls for a closer look. Maybe later.

Sunday, January 23, 2011

ProperNounisation

ProperNounisation (figure of speech): Capitalisation of a common noun to stress upon a recurring pattern.
e.g.
If your girlfriend finds out about this, you're in Big Trouble.
I'll be in the mall around 6 doing some General Loitering.

Thursday, January 20, 2011

Classical guitar

For a long time, my classical guitar skills were quite limited. I've mostly been dabbling with an electric or (non-classical) acoustic sounds. But in the last 6-8 months or so, I've been drawn to classical guitar. I happened to come across this video of Capricho Arabe (by the legendary Francesco Tarrega) and I was blown away. This degree of expressiveness using a single instrument is basically unheard of in rock/metal circles. imho. No entourage of bassists/drummers/vocalists, no distortion pedals to muddy the waters, just pure unadulterated music.
Soon thereafter, I got my first real classical guitar. The Almansa 434. I just had to do it.
Now I'm learning some of Francesco Tarrega's other songs. Also planning to take proper classical lessons from a well-known local guitarist, Anthony Garcia.
Where is this going to lead me?
PS: Never 'drink and blog'. Or this may happen to you.

Wednesday, January 19, 2011

Unsocialising

Unsocialising (n): Reducing or eliminating your social footprint in the cyber world.
Although I acknowledge the human need to socialise, I just don't find it appealing to have my personal details paraded on some server belonging to some company I don't really know well enough to trust.
So; I have decided to unfacebook and ungoogle myself.
As far as fb is concerned, I don't have much there thats personal, but I will have to remove my name-tags from a few photos. Boy I hate that feature.
UnGoogling will be a more difficult task - their apps actually provide value to me. Maybe a mobileme subscription... I need to think about this. Now is not the best time. I am drinking irish whiskey.

Saturday, July 3, 2010

Guitar notes

I had all but stopped playing. But this guitar piece has changed things a bit. As I try to play and improve, I find myself going through the same thought processes which I went through a few years ago. I wish I had them noted somewhere. The next time I play after a break, I am going to read this.
1. Concentrate. Clear the mind of other thoughts (including vacuuming your messy room)
2. Listen hard to your playing
3. While listening don't forget to think ahead, of the next chord.
4. Before performing a troublesome chord shift, look at the frets you want to be at before your hands go there. The hands should follow the eyes. Not go together with them.
5. For classical pieces like this one, walk into the chords. i.e. Not all notes are plucked together so focus on the notes which are played first before getting the whole chord position right with the left hand.
6. Left hand improvement is like exercising in the gym. You can do a lot for a few days and burn yourself out or do a significant amount regularly and build lasting strength.
7. Enjoy what you are doing. Or stop.

Thursday, May 13, 2010

Why GMail-in-a-browser is better than MS Outlook-on-your-desktop

1. Search actually works quickly. Or should I say, it works at all.
2. Threaded conversations are way more intuitive than RE: and FW: style psuedo-conversations.
3. In spite of being in a browser, it actually has better keyboard-shortcut support than Outlook. Try moving emails into folders in outlook using only the keyboard. Now try applying labels in Gmail. Way easier.
4. In spite of being in a browser, its actually faster than the bloated desktop Outlook client as far as I've seen and used.
5. I don't want to install 200MB worth of bloat to just check my email!
6. I don't have to re-install the bloat if I use multiple operating systems.
Too tired to think now, but I have a feeling there are many more.

Saturday, May 8, 2010

HorrendousPasswordCriteria

Saw this on a website :
Please make sure following criteria are met while entering password :
> New password and confirm password should match

> New password should contain atleast 1 uppercase , 1 lowercase,
1 numeric , 1 special character and minimum 8 characters


> Current password must be correct

What???
If only I could provide feedback, it would be thus -
1. I have enough passwords to remember, thank you. I don't want to create a new password so obscure that I will never be able to remember it.
2. Are you generally this insecure about life? Given that you don't really store creditcard numbers or any such confidential info, do you seriously think someone is trying to hack your passwords? GMail doesn't have that strict a criteria, and theres way more confidential information in there.
3. You have just dissuaded me from registering on your website. Ever.

From prosumer to SLR...

So why do people go from the world of compact cameras to the bulky SLR ones? Having been bitten by the bug very recently, I am compelled to articulate.
Simply put, its the desire to take better pictures irrespective of the situation you happen to be in. I quite liked my prosumer Lumix FZ-18. I captured some pics, especially landscapes in broad daylight, which I still feel happy about. But once I took the next step and started to use the manual controls more, the deficiencies started showing. Every so often, while taking a portrait against a not-so-plain background, I'd think - oh how I wish I could throw the background out of focus like the pros do. Or, while shooting indoors, I wished I could do it without using the flash and destroying all the ambient light. And when focussing on thin, delicate objects, I wished the manual focussing was a little more usable. And the list went on.

So now that I have one, how is it different?
Having a DSLR is a lot different from having a consumer/prosumer camera. When I was still living in the 'compact' world, I had little idea of how these differences would affect how I took pictures.
The first and the most tangible difference is really the speed. It takes sub-second time to startup and start clicking. Saving pics to the card is pretty much instantaneous too. And manual focus is a breeze using the lens' focussing rings. Where it slows u down is while changing lenses, if you have to. But then most of the time, you have a good general idea of what kind of shots you'll be taking in a given situation, so the need to hurriedly change lenses shouldn't really exist.
Next, and very importantly, is image quality. The automatic white balance is more accurate in general (if you don't prefer to set it yourself), you can achieve beautiful bokeh (blurring) of background in portraits (depending on the lens you've got), easier focussing means that you capture exactly what you want, how you want.
There are a few things I miss from the Lumix though - the compactness of course... and the fact that the lens cover is not attached to the body of the camera but has to be (clumsily) handled every time I want to go into photo-taking mode. Minor annoyances.
So if you are at (what I call) the threshold of your compact camera, like I was, maybe it is time.

Monday, April 26, 2010

Digital SLR

After tinkering with my prosumer Lumix FZ-18 for a couple of years, I have finally decided to take the leap and get a DSLR. Having said that, the Lumix has definitely performed to my expectations. I still look at some of the pics I took with it and think, thats not bad for a prosumer camera.
The first choice was of course which system to buy. I asked a few people, the local camera-shop guy, and of course, dpreview.com and concluded that it had to be Canon. The best DSLR body within my budget was the Canon EOS 550D (or the RebelT2i in the USA). Another reason for this choice was that it allowed me to save enough for the lenses. The whole point of getting a DSLR is to have good lenses, after all.
When it came to buying lenses, the camera-shop guy's advice was loud and clear. Pretty much everything you'd want to do, as a beginner DSLR user, can be done with the twin-lens-kit which one can get with the 550D. But I checked the reviews and found that the 18-55 mm lens included in the kit isn't quite that great a choice. After checking out a few other canon lenses, I found the 85mm f1.8 prime lens. This lens is primarily for portraits (and specialises in indoor and lowlight situations) and had consistently positive reviews.
For the second lens, I decided to go with the 55-250, as it seemed to give good bang for the buck.
So then thats the combo I've gone with. Now I need to find a good case, maybe a lens hood and a SD card. More about that later...

Saturday, March 20, 2010

How to configure TogaII chess engine for Raptor on Mac OS X Snow Leopard

Yesterday I was trying to configure a chess engine for my FICS client, Raptor. My first attempt was to download Rybka, as a lot of people in the FICS community seemed to use that engine. Well, I soon realised I couldnt; Rybka only supports Windows platform. Second crack - Toga II. And thankfully, it was a breeze -
  • Download the mac binaries from the toga website.
  • Go to Raptor preferences -> Chess Engines and select the downloaded (and extracted) file.
  • Enter a nickname for the engine and click Apply.
  • Now bask in the glory of a 2900 something engine's analysis :)

Wednesday, February 3, 2010

Why should one archive old emails in Gmail?

One very good reason is that when you try to use an external client (like the one on my MacBook), it doesn't start downloading 10,000 items.
Not to mention the warm, fuzzy, i-have-nothing-left-to-do feeling of having an empty inbox.

Saturday, January 9, 2010

The Vs and Ws. Pronunciation of Indians

It wasn't long ago that my girlfriend pointed out that I pronounce V and W in some English words incorrectly. After a feeble attempt at denial, I realised that indeed, its quite accurate. I tried to trace the root cause in Marathi (my mother tongue). Marathi has a single letter which denotes both W and V sounds depending on the context. Moreover, its fairly common, and quite acceptable, for people to use one sound instead of the other. Hindi, the national language, and Sanskrit, the language of ancient India and the origin of many Indian language, share the same (Devanagri) alphabet. So its hardly surprising. She even pointed out that most Indians (even those who use English everyday) are blissfully oblivious of this problem.
A few days ago, I noticed the same mistake in pronunciation in a SriLankan colleague at work. I don't know Sinhalese, but I wouldn't be surprised if it didn't distinguish between V and W either.
Luckily, its not hard to correct. All it takes is some conscious effort to touch the front teeth to the lower lip while saying V (like we do when saying F). Ws, on the other hand, call for the lips to form a circle (like the one while saying O).
I think I've fixed my problem. Of course, she disagrees.

Friday, December 25, 2009

Where are computers leading us?

I spend pretty much all of my 8-10 hours at work looking at a computer screen. I then come home and check my personal email, pay bills, check the news etc. All while staring at a computer screen. The internet allows you to do so many things from the comfort of your home, but the caveat is that it involves the discomfort of staring at a screen. An iPhone screen is still a screen. I go to bed feeling exhausted from all this staring.
I have a bad feeling about this. Maybe I'm being paranoid, but is this modern-day geekery keeping me from seeing the "real world"? Will I forget how it is to queue up to pay a bill? To take a walk and buy a newspaper? To even actually talk to people? True, there is nothing which actively stops me from doing all these things without using a computer. But I think the convenience of not having to step out of the house is just too much to forsake. And then we have to go to these gyms to get the only exercise we ever do.
Something is not right.

Saturday, December 5, 2009

Respect the user's bandwith

The quintessential internet surfer does what he knows best - unearths an obscure webpage from the bowels of the internet. He is impressed by the content - its a subject he is deeply interested in. But then suddenly he is disturbed by the sound of music emanating from his measly laptop speakers. Yes, the page contained a youtube video which auto-started on page-load. The content of the video has nothing to do with the subject of the website. The surfer loses concentration, nervously glances at the video (which is embedded in a tiny 100x100 px frame btw). He has long lost the context of the real content of the website. He frowns in dismay when he realises that the video is almost 10 minutes long. He hits middle click on the tab in the browser. The music stops. He is no longer thinking about his subject of interest. He thinks, why. "Why should I be forced to download a video which has nothing to do with the real message of the website? Why is that video started automatically on page-load, thereby nullifying any chance of stopping it from being downloaded by the browser, apart from completely leaving the website itself? Why can website designers not be more bandwidth conscious?
He stops and starts writing this blog. Every new technology can be abused.

Tuesday, September 8, 2009

Just using cool new technologies doesn't solve the problem

This point is missed too often. So I just wanted to say it out aloud again. One can write clean code using good old Java and messy code using Groovy (or Ruby or whatever). I have a feeling this is common amongst ResumeAdorners. I'll leave the details of that word for another post.

Saturday, August 29, 2009

Buying books in Australia

There is a good reason not to buy (especially technical) books from Borders.
Unix Power Tools costs AUD 127 on Borders as opposed to AUD 80 on FishPond.

Borders:











FishPond:







Borders, of course, has the overhead of maintaining huge stone shops and a fancier website. But a staggering 58% difference?! I find it hard to fathom how its going to be competetive in the long run.
Amazon does it for USD 47, but the US is a different story altogether; and at the moment, uncomparable. I wonder when will the day arrive in Australia when we can buy books at rates similar to the USA.

Tuesday, September 2, 2008

Will chrome change the www?

I am really excited waiting for the release of Chrome. Reading the book, it seems like its going to be significantly different from all current browsers.