Wednesday, September 07, 2011

Very simple Java puzzle

I spent a good minute figuring out what was going on. See if you like solving this one:

The piece of code I will be showing in a second receives a String that might have a single digit at the end. I need to extract that digit and increment by one. If you wondered, the code is actually a content automation tool that runs inside the Apache Jackrabbit (it's actually Adobe Day CQ/CRX) and it's messing with the content nodes and their attributes. Sibling nodes have unique names and CQ simply adds the _x, where x increments with every new node of the same original name. My script needs to do the same and so I am looking at an existing node and trying to parse out it's "x" to further increment it. It goes like this:

if (Character.isDigit(nodeName.charAt(nodeName.length() - 1))) {
    colNumber = Math.max(colNumber , Integer.valueOf(nodeName.charAt(nodeName.length() - 1)) + 1);
} else {

and for a nodeName of colctrl_1 is says the next number is ... 50.

if I do like this:

if (Character.isDigit(nodeName.charAt(nodeName.length() - 1))) {
    colNumber = Math.max(colNumber , Integer.parseInt(nodeName.charAt(nodeName.length() - 1)) + 1);
} else {

I will get a compilation error because there's not parseInt(char). so I change it to look like this:

if (Character.isDigit(nodeName.charAt(nodeName.length() - 1))) {
    colNumber = Math.max(colNumber , Integer.parseInt("" + nodeName.charAt(nodeName.length() - 1)) + 1);
} else {

now it reports the next number is 2.

I am sure you know why, I now do too. Still, will you tell me?

p.s. Here's a nice read from Alex Miller on the Integer.valueOf():

Tuesday, August 23, 2011

Just a day in life: "In and Out"

4:00am - alarm goes off on my iPhone.
4:10am - my cab is already upfront. first time on time
4:20am - in the cab. I am sure Frank is the only white driver in Atlanta, really nice guy, works all nigths. He moved here from Arizona more than 10 years ago. He tells me it's a paradize there. I know it's not, I've been there three times when I had a project with a client down there. It was 110 early in June! That's above 40 in centigrades! It's very dry down there so you don't have that humid air like you do in south east, but the heat still kills you. The brain starts melting afer a short five minutes walk. You basically spend your summer (and it's not a three months summer, believe me) indoors to enjoy the rest of the year outside. I guess some people just tend to like their home places most of all...
4:55am - at the airpot. I-75 goes straight through thre downtown. nice ride in the morning
5:15am - past the security gate (ATL is a way better than PHL on Monday mornings. I would spend good 40 minutes back there)
5:30am - Quiznoss, as a business, was once reported to do much worse than Subway but their subs are much better still. breakfest time.
5:40am - one thing I like about morning flights is that the pllane is always at the gate
5:55am - no one is about to start boarding us yet
6:00am - here they come
6:30am - taxing out of the gate. on time.
7:50am - wow, a good one hour of sleep. It rarely happens to me on the plane and I always wish it did
8:20am - landed. we're 20 minutes earlier so now need to wait for the gate to become available.
8:50am - immigration control. flying to Canada feels much like flying domestic US except immigration. here you remember you actually are about to cross the border.
9:10am - in the cab on my way to the office. flying without luggage with same day return is the fastest. No need to wait at the carousel at a baggage claim and then again at the rental car counter... it also feels better in the back seat of a limo than in the front seat driving a Hynday Accent "compact"
9:40am - Morning cofee and I am back online (mentally too). Flying short distances feels a lot like riding a bus or a train. Just a lot more expensive :) One guy once told me why it should be so. He said (rising his hand up above his head with the palm flat facing down illustrating a flying airplane) - "magic", then he lowered the hand below his waist with the palm this time illustrating driving on the surface of the earth - "no magic", back up again - expensive, back down again - cheap. Magic, no magic, expensive, cheep.
10:00am - meeting, more like a working session, nothing special
12:00pm - done with the meeting. btw, don't you think the "pm" after 12 is a little weird? 11pm is almost midnight, then it's 0:00am the next day. 11am is almost noon and then comes the 12... pm followed by 1pm and all the way up to 11pm. weird...
12:40pm - over with the lunch and back to work. follow-up emails, skype calls, full recursive check-out of the SVN HEAD revision...
2:00pm - meeting. it started more like a working session but then slightly transitioned into a fight. I am currently right in the middle of a rather large content-centric project that I am delivering with the team of about fourty. That's only on our end. There are other partners and vendors and things balance on the edge: from very tough to extremely challenging. The whole thing is very fragile and as things heat up so does the temperature int he room. What was scheduled to last for two hours lasted for about three and a half and we only have gone through half the agenda.
5:30pm - in a cab. on my way back to the airport. it doesn't look like these guys accept credit cards so I will have to pay cash. You can pay US dollars but you should only expect canadians as a change. Will spend it here next timme, no big deal. My Mondays will likely all become like this one for a few months to come.
5:50pm - dragging through traffic on 401 West. I should be fine, my flight will only start boarding at about 7:50pm. Hope to grab a bite at the aitport and do some followup emails. Unlike Atlanata, Toronto offers free wi-fi in the airport. I first time encountered free wi-fi in Ireland's Shanon back in 2004. It's 2011 and not all major airports do that. You can pay $9.99 a month and have it with Bingo, they have hotspots everywhere and ten bucks a month is nothing... still, wi-fi at the airport should be free. They charge us, passenmgers, enough through the fees they charge airlines which we end up paying anyway.
6:05pm - through with the traffic. should be at the gate in five
6:50pm - done with the immigration and security control. It would indeed feel like a bus ride if not these two things on the way in and out.
6:55pm - there's a nice pub two gates away. will grab a bite, get some beer, do some emails. I have a good hour before my flight starts boarding. I wish they had chargers under every dining table.
8:10pm - boarding
10:20pm - landed in Atlanta
11:30pm - made it home. it's when I opened the door I actually felt how much I missed my family. Everybody is asleep by now. Will see them tomorrow in the morning. Dennis started his 4th school year on Aug 15th and his bus is picking him up at 7:08am. We will be up by 6:20 tomorrow. Have a good night you all.

Sunday, March 20, 2011

A train set and a two story bed

What would you name if I asked you to recall a few things you had badly wanted as a kid but had never had?

Mine are a train set toy and a two story bed.

Train set. A metal one, from the East Germany, the ultimate gift I, a six year old boy in the USSR, could have wished for. It was expensive, would likely cost a good part of what my dad was making a month, if you could find it. No store had it. Your family should have had connections to get it delivered from the place of origin.

Two story bed. I was growing up with my younger brother and we were sharing the room for as long as I remember myself, up to the point when I left to start my own family. As a kid I saw a two story bed once or twice and it must have penetrated my memories so deep I still cannot get it out.

My son is eight and a half. He had number of different train sets made of metal and wood and plastic and stopped playing them all a while ago. His younger sister is two and a half and they rarely share a bedroom but he enjoys the second story of his two story bed. I told him how much I once wanted to have one when I was a kid so he offered me the second story on the night it was brought in and assembled. I let him enjoy it and kept my memories :)

Last winter I took my whole family skiing up north in New Hampshire. We shared a nice big house right on the mountain with two other friend families, our rooms where on the first floor and one had a two story bed in it. The bed was higher than usual, my son found it uncomfortable to be too close to the ceiling so I took it. Next night I sprained my ankle getting down at night, must have missed a rung or something. Did not enjoy much climbing it back and forth in the upcoming few days but still love my memories of not having it as a kid :)

Care to share your story?