“Before you speak, listen. Before you write, think. Before you spend, earn. Before you invest, investigate. Before you criticize, wait. Before you pray, forgive. Before you quit, try. Before you retire, save. Before you die, give.”

Monday, September 5, 2011

Preparing for Amsterdam

This autumn I will again go to Amsterdam with my wife. She has to deliver a presentation for European Respiratory Society .. and I just have to bike.
Which brings me to realize how not rich I am. In order to do anything there they will require you to show a credit card or block a huge amount on your debit card.
So my choice is to get a credit card .. again just to rent a bike and sit at a hotel room.
Which officially pulls me away from the debt-free crowd I managed to join. If the credit card is approved that is.

One more financial setback : Our country's government has decided that you cannot drive a car without proper winter tires starting with November 1st. While I have to agree with the safety reasons I wonder how much of this decision was for safety reasons (we have one of the deadliest roads in Europe) and how much was for supporting the tires sales ?
Of course paying 700 Euros for tires and rims - almost twice the average salary in Romania is a huge setback for most . I can survive without too much issues but still I can only think about my father driving his old Dacia 1300 1978 model for almost 30 winters (years) on icy/snow filled roads without winter tires. And he never crashed the car. I drove the car for 3 winters as well (I have a 2008 Dacia Logan equipped with ABS) without loosing control .I just do everything gently and try to be aware of the conditions around me when accelerating,braking, turning.
And winters are getting milder each year...
There is something else that worries me : The lack of common sense of drivers that do not know how to drive gently. I already see them every day as I bike to work : furiously accelerating between traffic lights only to brake even more furiously at the next. Sitting in traffic jams for minutes does not cause them to drive slower when they get out of them. Don't get me started at the ones that drive on highways at twice the legal speed and expect you to just vanish if you are trying to pass another vehicle at a decent 130km/h (legal speed).
No winter tires will save you if you are trying to drive into a corner with 100 km/h or into a tighter curve at 200 km/h
Further more you might be inclined to do so one you have "winter" tires. Can the government legislate common sense ? I don't think so.

What else is new ? My weight was yesterday (after a 30km ride) at 107.6 kg not close to the weight I wanted to have (~95 kg) but at least is under 110 kg.
I had stopped drinking Coca-Cola and also reduced the consumption of coffee a bit .. probably should switch to tea. I am almost happy.
My plan is to be at ~100kg .. or at least less than 105kg in Amsterdam and bike .. a lot like 8 hours /day.
Of course there are other interesting things to do in Amsterdam but since I am both married and on a budget I will stick to biking :).

Now regarding the professional side things are slowly improving. I have read yet again the "Pragmatic Thinking and Learning" book and started applying the lessons in combination with " The Pomodoro Technique".
Of course the Pomodoro technique is pretty effective (using it right now for writing on the blog) but you have to actually increase the duration to 40 minutes for any complex activity .. or even more. Why is that ? You need to first load context into your brain ..and this needs at least 20 minutes (without interruptions).
I experimented with durations and 40 minutes with a 10 minute brake seems ok. Of course my Android application would not allow more ... which brings me to the next news :
I have also bought an Android phone (in a moment of desperation which is going to cost me another 2 years of subscription payment when my old Nokia 6234 had another malfunction - the volume button) - an HTC Desire S which is a very expensive Pomodoro clock :) (using Pomodroid). Of course I use other applications on it mainly my Gmail Account , GTasks for managing tasks, Adobe Reader, Google Maps .. ,Youtube and many others.
Of course I also use it as a portable game console : Angry Birds,Alien Invasion,Fruit Slice and other tools for waisting my time are installed.
I found the phone a good laptop replacer for short web navigation and reading email. I still cannot write on the damn touch keyboard ... I find this post by Jeff Atwood totally relevant.

Now regarding the Ruby skills .. well since being very busy with my work project (and starting to enjoy it) I found my Ruby and RoR skills slowly decaying which is bad for my Pragmatic Investment Plan ( a portfolio of skills suggested by the Pragmatic Programmers in their books). My Project Euler problems are still at 27 which means I am still not advancing.
So what I need to do is to allocate a chunk of time and prepare to work on these issues because you need to make time ..but somehow the mental energy is missing at the end of the day and uninterrupted time is a rare commodity for me recently.
This concludes my post .. as always it is an interesting experience to put your mind online ..






Sunday, June 5, 2011

More fitness and coding


So .. as in my weird diet here is my latest data. Managed to run 3.2 km (almost 2 miles) every day and bike around 20 km. And I was not yet fired .. my job is ok.
I started dieting at 120.6 kg (May 19 th) and today I am at 114.3. A bit behind my optimistic schedule .. but it is better to be late then never :).
So I do believe that dieting and exercise (together) help. It's just that it is hard to balance them and be also balanced enough .to eat just right and not over-eat. And regarding sleep I am again at 7-8 even 9h /day. Life can be good.

Sunday, May 22, 2011

About fitness and coding

First things first .. I was always a fat guy and people acknowledge that. But as a programmer (since 2002 :) ) I thought it was not relevant. I also thought programmers should drink tons of coffee and oceans of Coca-Cola.
After reaching a disastrous .. mortal obesity area at around 140 kg(roughly 312 pounds) due to the sedentary life style and being chronically tired I started to change my lifestyle and lost some pounds .. at a more normal 120kg.
In January 2010 I had 95.5 kg .. an almost normal not overweight condition. Still the hardest thing for me to give up was Coca-Cola and coffee . Whenever I was tired I would add more coca Cola and more coffee.

Meanwhile I had started a desperate cross-traininig running 1km (with this bodyweight what can you expect ... ) and biking 15 km. I could not see any relevant drops from the 121-122 mark ..
And then Thursday (May 19) I dropped completely Coca-cola and coffee. Yes I was sleepy for a while .. but look at the chart below





Also I am now able to take slow lunches and really chew the food .. something I was not doing before.
And that's not all. My appetite is now normal .. I do not feel the need to eat a lot. And at the last weighting today I had reached 118.5 kg (which I had not reached since January).
My completely distorted image of programmers eating tons of pizza's and drinking lots of Coke's is definitely history. I have met several good programmers that are vegetarians , only drink tea and have a normal attitude towards food.

With the risk of making a full of myself I am writing here my objectives :
June 1st : 115-118 kg
July 1st : 105-110 kg
August 1st 95-100 kg
September 1st 85-90kg
I realize this is pretty ambitious but as a software engineer I need to optimize my body weight first .. before optimizing anything else :).
Why is this related to coding ? Due to sleep apnea you get to actually be tired and fall asleep on the keyboard/laptop.
Sleep apnea is basically a condition that does not allow you to rest at night .. and makes you tired all day long. Your effectiveness during daytime is half lost even as you add more and more coffee .. the problem does not go away. Soon you loose your ability to focus .. you are grumpy and burned out.
Granted I lost a day (which I almost recovered today) programming but it was not a problem as the
benefits outrank the costs. Yes some people do not have that day but I think it would be a good investment to make if you had it.
These last 3 days made me believe that eating healthy food and programming are not excluding each other .. hope I can prove it by completely changing my diet.

Thursday, April 7, 2011

Problem 14 Collatz Ruby vs. Java

Finally after joining the Euler club I have solved the Collatz problem. As it turns out this problem cannot be proven mathematically .. and some mathematicians went nuts trying to prove it.
For me it is intuitively simple .. you divide more than you multiply and that's that.
Anyway I have spent almost 3h on this problem 20m writing a solution in Ruby and ... 2h 30m running it.
On my home machine I have a Ruby 1.8.7 on Windows 7 environment and my computer a Core i7 860 8GB RAM machine (good enough I would say). I gave up at around 1 AM while it was half done.
Here is the code.

def chain_collatz(n,cache)
chain_length=1
puts "-> #{n}"
if n==1
return chain_length

else
if cache[n]!=nil
puts "cache_hit"
chain_length+=cache[n]
return chain_length
end

if n%2==0
n=n/2
else
n=3*n+1
end

chain_length+=chain_collatz(n,cache)
cache[n]=chain_length
return chain_length
end


end

#puts chain_collatz(10100,cache)
#puts "cache"
#puts cache.keys
cache=Hash.new
def get_number(n,cache)
max_chain_length=1
vnumber=13
max_number=1
for i in 13..n
chain_length=chain_collatz(i,cache)
max_number=i if chain_length>max_chain_length
max_chain_length = chain_length if chain_length > max_chain_length

number=i
puts "Done with number #{number}"
end

return max_number
end

puts get_number 1000000,cache


After a lot of pain it ran and gave the correct result. Found it only this morning.
After having the problem solved I rewrote it in Java to see whether I could have it any faster:
The result?

import java.util.HashMap;
import java.util.Map;

public class Collatz {
public static void main(String args[]) {
Map m = new HashMap();
Collatz collatz = new Collatz();
long startTime =System.currentTimeMillis();
System.out.println(collatz.getMaxCollatzTo(1000000l, m));
long endTime =System.currentTimeMillis();
System.out.println (" Execution took" +(endTime-startTime) +" milisseconds");



}

public Long chainCollatz(Long number, Map map) {
Long chainLength = 1l;
if (number == 1) {
return 1l;
} else {
if (map.containsKey(number)) {
// System.out.println("Cache hit" + number);
chainLength += map.get(number);
return chainLength;
}
if (number % 2 == 0) {
number = number / 2;
} else {
number = 3 * number + 1;
}
chainLength += chainCollatz(number, map);
map.put(number, chainLength);
return chainLength;
}

}

public Long getMaxCollatzTo(Long number, Map map) {
Long maxChainLength = 1l;
Long maxChainForNumber = 1l;
for (Long i = 13l; i < number; i++) {
Long chainLength = chainCollatz(i, map);
if (chainLength > maxChainLength) {
maxChainLength = chainLength;
maxChainForNumber = i;
}
// System.out.println("Done with "+i);
}
return maxChainForNumber;
}

}


The Java code took only 50 seconds to run.

Anyway puzzled by this I started optimizing the code in both Ruby and Java .. removing all but essential console outputs.
Finally I got to test it on a Linux OS with similar processing power (Ruby implementation in Windows really sucks I think).
Final result.
Ruby 1.8.7 11.7 seconds
Java 6(1.6.0.22) 1.471 seconds
Tested also with ruby 1.9 and got it down to 3 seconds .
This puts Java on top of my list for Project Euler problems and makes me question the ability of Ruby to run unoptimized code.

But still for prototyping it's great.


Saturday, March 26, 2011

"Limitless" and real life

Last Sunday I went to "Limitless" (trailer here) and enjoyed the movie.
Would I like to be in the "zone" all the time ? Completely focused ? Very calm ? see "50 moves" ahead of everybody else ? Win big in the stock market by making accurate predictions ?
Just take a pill :). The only issue ? It will kill you in a few months.
The hero in the movie is enhanced by this pill and finds a solution to create this pill without side effects before the pill kills him. This is what I call a smart investment :).
If only it were that simple ...
Unfortunately it is not that easy in the real world but as well as financial investments (which take time and intelligence as well and know nothing of ;) ) there are educational investments. Things that you learn that can help you learn more things and advance you ..
I recently joined a site called ProjectEuler that is basically giving you some problems (more complicated as you go) and you get to several levels. I am at level 0 with only 8 problems solved but I find the challenges pretty interesting.
Of course you need to write code to solve those issues and I mostly use Ruby .. because it's faster. How long would it take to solve the problems without a computer ? I really don't know and I think just having the "Limitless" pill can tell. Of course you understand the algorithm but your computation skills suck.
So the "Limitless" pill is in my opinion a fast computer and a good programming language you can use to communicate to it (Ruby,Python.Java .. whichever you feel comfortable with). Learning and using A.I. techniques can help your limited algorithm knowledge.


For instance you can solve the famous NP complete problem : traveling salesman path with genetic algoritms (Here is a solution) .




So the computer can find solutions to what your mind can't effectively find.I thought that in order to solve this problem you needed discrete mathemathics knowledge, graph algorithms knowledge and of course complexity evaluation knowledge.
Well you can't actually use it because it's a NP complete problem .. that is it's not possible to actually prove it mathematically.
















Last but not least while researching some AI stuff I came across a knowledge tool I like
It's called Wolfram and it is great for finding scientific information about stuff. I really liked it and I think it would be nice to integrate with a commercial site. The applications can be amazing.
Still I want to point out something else. I tried working on difficult solutions before while working in an open space environment with eyes set on my screen from all around me. Now I work in a small office that is very quiet. I am starting to find solutions to problems I could never
find solutions before, seeing patterns , cleaning old rusty code.
Once and for all the actual office environment does matter. No great writer ever wrote with other writers in a open-space office. No great programmer/hacker did it in a bullpen 1 feet from the colleagues. Mental focus is critical to problem solving.
Of course when you are coding another J2EE application that needs to run on a 8 year old server with 2004 technology and which will probably be used just for 1 year and does just CRUD it is hard for any actual programmer to justify having his own office , a quiet environment, books or other educational investments. Been there done that.

Saturday, March 19, 2011

Finally a manager I like

As I already mentioned I am a fan of Joel Spolsky and of Peopleware.
I do believe in getting into the zone and developing quality code without interruptions. I jumped ship to a smaller company in order to actually develop code without doing 1 meeting/day.

My ex-manager used to call 2 meetings /day when things were not going as fast as required.
Then one of the members of my team asked : When are we going to work then ? Things are pretty desperate now .. it will go worse with more meetings . Sadly this guy was the first to be sent home when the time came.
Right now I am doing Scrum and I really enjoy the work from home approach to implement the caves and commons pattern .. when I really need to focus and get things done I stay at home.
The weird part is that more and more managers claim that the more you are interrupted the better the work you deliver ... my opinion is that communication time and "zone" or "flow" time must be balanced carefully and more to the zone time for knowledge workers

Jason Fried from 37 signals pretty much nails it with this video:

Sunday, March 13, 2011

Work from home ... and the laptop alternative.

It has been a long time since I have not posted. Between my busy programmer/engineer life , my fitness schedule and my time spent reading about finances/investment I do not find time to log my thoughts.
So this year I joined a new company a small startup (which will remain nameless for the time being).
One of the benefits was a very expensive state of the art Dell Precision laptop equipped with SSD and 8GB RAM .. something I could not afford to buy with my salary as a software developer and the prices in this city.
The other benefit was working from home (no limit there) . As I am obsessed with "the zone" you can imagine that I took that benefit and took a day off .
My vision on laptops was the following : Very expensive equipments that are only effective for the rich guys to check their emails and do some office work. I could buy my Core i7 computer for about 700 Euro .. a laptop would have been 2200 Euros at least.
Once I was given this laptop I found my self working on company's projects (or personal stuff ) whenever I had time. I developed a user interface while waiting for my car's 10.000 km maintenance ... I coded in restaurants and of course from home.
Well there are some drawback normally : like no dual monitor, no good keyboard mouse , no ergonomic position.
Thankfully at work I have a dual monitor setup with a docking station allowing me to plugin whichever keyboard I want.
So I had a blast working at home one friday .. 12h of uninterrupted productivity.
The only drawback : You can't stop and go home ...you're already there.
Of course Skype contacts and email helps .. and the fact that everybody gets to work from home as they please.

Wednesday, January 5, 2011

Seam Framework or the JEE answer to Ruby on Rails

After playing with Ruby on Rails for almost a month (and coding my weight management application) I can honestly say I have found my love for coding again. Mostly because of the instant feedback effect.
As I kept reading various resources on RoR I found one issue with it. It does not support XA transactions. That is if you are using an application that has to synchronize 2 databases in a transaction RoR can't help you.
Of course RoR is just a framework and Ruby standards are not as good as Java ones so there is no JTA (Java Transaction Api) equivalent in Ruby/RoR hence you are on your own. So writing enterprise stuff in Ruby will just have to wait for a while.
That did not stop me from spending the New Year's eve and 2 days after just coding a RoR application between drinking ,eating and celebrating
Now recently I have decided to study Seam Framework as the JEE answer to Java. I have received Dan Allen's "Seam in Action" book and I am trying to make sense of it.
Seam's fantastic points
1)Conversations
2)Bijection
3)Handling JSF actions on initial Request (or get)
4) Using a conversation scoped persistence manager should prevent all the LazyInitializationExceptions I kept seeing in the past 2000 days of JEE programming (not that many but you understand ..)
5)Integration with Drools , jBPM-of course best to be used in a JEE container.
A lot more small stuff that makes your life easy.
Unfortunately I can't help thinking that 2 heavy weight containers (JSF and EJB3) are integrated in a bigger container. The problem is whether Seam provides a good abstraction or a leaky one.

Of couse while reading Dan Allen's book I found that at least in the 2 initial chapters he kept trying to offset Rails .. unfortunately hot deploy is not complete in JBoss/Seam .
There are several severe limitations
  • you need to be using a war project (no EJB's)
  • you need to have a tag specifying debug =true
  • you need to configure the ide to do the explode on edit thing(or type seam explode)
Even then you would not be allowed to do Entity classes changes and changes to Session Beans without redeploying.
So it is true that it helps but even Dan specified in a Seam Framework post that incremental hot deploy in Seam is a bit of a hack .
What I did enjoy was doing integration testing with Seam , TestNG and Embedded JBoss these shoud alleviate the pain of repeated build/deploy/test cycles I mentioned. Nevertheless integration tests are always slower than basic unit tests.
I can run 54 pure unit tests on my machine in 2 seconds but just 4 integration tests take 16 seconds.
For the record my machine is now upgraded : Core i7 860 , 8GB RAM (Corsair) ,1TB HDD so I guess we are talking top of the line performance.

As a side notes I found that doing RoR development using JRuby and Webrick makes testing in the browser faster then integration testing in controllers (yap JVM start times to the rescue) so doing TDD with JRuby is not easy either.Nevertheless they take 2.8 seconds to execute + 10 seconds JVM startup time (that's why Java will never be used for OS development :) ).


Anyway if you need to stick to the JEE world or need distributed transactions go for Seam , if you are confident you won't need distributed transactions you cand certainly go for Ruby/RoR.

My objectives for the year ? Just get to 100 kg and stay there.
What I need to have this :
  1. Diet and calorie counting
  2. fitness performed regularly.
I even wrote my own RoR code to track this (not yet business ready but functional)
Oh btw : Happy new Year.