Sunday, March 6, 2011

Mandelbrot Set












I just finished a trivial but entertaining programming project: rendering a Mandelbrot set using Java.

Mandelbrot sets are named after Benoit Mandelbrot, the recently deceased mathematician that "discovered" them. He took a simple recursive relationship and mapped it onto the complex plane by counting how many iterations were required to observe the magnitude diverge when repeatedly squaring the value at each point:



I've known about Mandelbrot sets for more than twenty years. Chaos theory was all the rage in the late 80s; James Glieck wrote a terrific, accessible book entitled "Chaos: Making A New Science" that summarizes the history beautifully.

Knowing about Mandelbrot sets and having successfully coded them for oneself are two very different things. I saw a question about an implementation on Stack Overflow. Having not gone through it for myself I had nothing to contribute, so I decided to tackle it.

It took me a little while. It all starts with a good Complex class. I implemented the basic arithmetic operators using a fluent style, because it seemed cleaner to me. I wrote a nice JUnit test and asked IntelliJ to tell me about code coverage.

I haven't done any Swing programming in a very long time. I had the set in black and white displaying quickly, but then I had to get a nice color map. It was a happy moment when I saw the picture that accompanies this posting.

That wasn't enough; I had to be able to use the mouse to select a sub-region and zoom in. Once that was working I wanted to be able to save the lovely images to a file. Adding a "save" button would be nice, but my first try just writes the image to an output file when the window closes:



I checked all my code into my local Subversion. I have 100% code coverage for my two model classes (Complex and Mandelbrot, which implements an IterativeFunction iterface) and two view classes (MandelbrotPanel and PixelMapper).

It's not much more than a nice undergraduate problem, but it made me happy to get through it and get such a satisfying result.

I've created an open source project on SourceForge.net and uploaded the code to their Subversion repository. Anyone with a Subversion client can download the code and give it a look:

svn co https://mandelbrotset.svn.sourceforge.net/svnroot/mandelbrotset mandelbrotset


profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Monday, January 31, 2011

Password Card













It seems like every day we see articles about personal information being compromised. Authorities like Bruce Schneier have recommendations on how often to change passwords.

I'm trying something different when it comes to computer security.

I found a site called PasswordCard.org that has a solution that flies in the face of the "don't write your passwords down" admonition.

The site is based on a simple assumption: We all know how to protect our wallets. The site provides a printable card that can be laminated and kept in a wallet. There are randomly generated strong passwords of varying length showing. The idea is to pick a password starting from any row and column, of sufficient length, and use that for a site. Go left to right, right to left, up or down, diagonally - it doesn't matter. Keep the site associated with a password safe and you're in good shape. Even if the card fell into someone else's hands, they'd have a herculean task to figure out the combination and site it applied to.

I want to be sure that Facebook, e-mail, financial accounts, etc. are safe. I won't be using a common password everywhere anymore, thanks to PasswordCard.org.





profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Wednesday, January 26, 2011

Pro-crastination















My character flaws are like grains of sand at the beach - too numerous to count. Like my sweet tooth. Pepperidge Farm's double chocolate Milano is a special weakness. Do they lace those things with crack cocaine? I think they must have hired the chemists from the tobacco companies who specialize in keeping users addicted. They probably got a sweet rate for their trouble, too.

Did I mention my awful sense of humor?

But one of my very worst traits is my procrastination and laziness.

I had a sad reminder of that this morning. The Taking Care Center where I swim is in the basement of a building across the street from where I work, two floors below street level. I had a very nice swim, during which time I played "stroke golf" to measure my efficiency and speed, did a set of 5x100 IM, and finished with a 1x200 kick with board set that left my poor hips tired and sore. I showered, dressed, and put my stuff back in my locker before trudging up four flights of stairs to get back to street level.

For some reason a memory popped into my head while I was walking. I found myself back in the insurance industry after I left Kaman Aerospace for The Hartford in Jan 2005. Soon after I arrived I had a good idea. The engineering education that I received left me with a wealth of mathematical knowledge that was lying fallow since I left engineering back in 1995. But actuaries are the lifeblood of the insurance industry. Why not leverage something that I already had in this new field? At worst, it would improve my industry knowledge and make me a better developer. At best, it could become a new career path in case I needed one.

I contacted the head of the actuarial program at The Hartford and went so far as to order study guides for the first two actuarial exams. I found out right away that my knowledge was long on calculus of continuous functions and physics, but short on discrete math, statistics, and probability. I had a lot of work ahead of me to refresh my memory of the things I used to know and to fill in the gaps in my background by learning the new material.

As I trudged up those stairs this morning, I realized that six years have passed and I've made no progress whatsoever towards achieving this goal.

The thought depressed me terribly.

Six whole years gone by. It seemed daunting at the time, but if I'd been able to summon the energy and dedication to make a little progress every day I would have been able to get through it in spades. A long, steady accumulation of small steps does the trick every time.

How do you make something like this happen? There are lots of technical topics that I want to master (Python, Android, jQuery) and books to get through ("The Algorithm Design Manual", John C. Hull's derivatives and options text, etc.), but my efforts are too scattered, diffuse, and sporadic.

I could take the Nike approach - "Just Do It" - but that hasn't worked so far.

I've had great success in my fitness life with tracking. Just the act of writing it down and seeing progress helps. But what to write? Problems completed? Chapters read? What's the metric that I should track? My new One Hundred Push-ups regimen not only has the counting metric going for it, but it also mandates a Mon-Wed-Fri weekly schedule.

What's standing in my way besides my natural laziness?

The Internet isn't helping me. StackOverflow, Facebook, StumbleUpon - all are time sinks. I need to kill my television. It's like the hearth in my house - it's always on. It's too easy for me to surf over to a Celtics game and become an anti-athlete. I love the game, and know it well from a youth misspent trying to master it, but it's been years since I played myself. When did watching others do things become a worthy use of my precious time?

Seneca's "On The Shortness Of Life" says it best:

It’s not that we have a short time to live, but that we waste a lot of it.


I'm desperate for a plan. How can I fix this?




profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Saturday, January 15, 2011

One Hundred Pushups













I'm already obsessively tracking my swim progress each and every year. While my yardage totals and performance in the water would not be impressive for a trained swimmer, I've been pleased enough with my old guy efforts.

One of the joys of swimming is also a problem: buoyancy. The water holds me up when I'm swimming. It's gentle on joints - knees, ankles, and hips don't take the pounding that something like running or basketball would dish out. But you don't get the benefit of a weight-bearing activity.

We all lose muscle mass as we age. I've been thinking for a while that I need to mix some strength training into my routine. I've never been a machine or weight lifting kind of guy. The place where I swim today offers a lot of interesting alternatives besides swimming, but I'm not sure that they fit into my day as nicely as the early morning, before work swim does.

So what's my solution? I'm trying a regimen that I Stumbled Upon: One Hundred Pushups. The idea is to build strength by working your way up to 100 good push-ups per day over a six week period.

I like it, because it can fit into any day, it doesn't use machines, and I don't have to go to a special place in order to do it. I can also work it in with yoga, so I'd have all three legs of the fitness stool: aerobics, strength, and flexibility.

Today was my first day. I know, the web site says to work on Mon-Wed-Fri with weekends off, but I swam last night and wasn't up to doing pushups when I returned home. I did the test on Wed and found that I was average for a guy my age. So I'm starting at the beginning at Week 1.

I'm hoping that having a routine laid out will help me stay with it. I'll be tracking it in my Excel spreadsheet. I'll report back on my progress in six weeks.

profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Wednesday, January 12, 2011

A Record Snow Event













We had a record snow event here today.

The forecast was bad enough where people were planning to work from home before leaving the office last night. I was one of them. I made sure that I had my laptop and power cord before I left. As long as the electricity and Internet stayed up I'd be able to work.

It wasn't snowing when I went to bed last night.

I slept in a little bit this morning, since I didn't have to catch the early bus. I got up at 6:30 when the dog started flapping his ears and whimpering to let me know that he needed to go outside. We both had a shock waiting for us when I opened the back door to let him out: 18" of snow had fallen overnight, and it was still snowing hard! Somebody had a cold, wet tummy when he came back inside.

I made some tea, ate a quick breakfast, and headed outside to start clearing off the driveway. I didn't have plans to leave, but I knew that I'd need a couple of passes on the driveway to keep it clear.

A year ago I finally broke down and bought a Honda snow thrower. I had cleared my modest driveway and sidewalks with a shovel all my life, but a December nor'easter convinced me that I should spare my back and get some help. I was happy with my purchase right away, but today it was a life saver. The snow spilled over the top of my 18" tall snow thrower when I started. It was still a chore to push it through all that snow, but it kept up nicely.

A modest snowfall would usually require 45-60 minutes of effort with a shovel to clear off the driveway. Today it took me two hours, even with the help of the thrower. The stuff that was packed into the end of the driveway by the snow plows was truly heart attack snow. I don't know that I could have gotten through it without mechanical assistance.

The snow was falling so fast that there were 2" on the part where I started by the time I was done. I had to do a second pass right away! But the worst was over.

I went inside, fired up the laptop, and drove revenue for my employer all day. I went out again at dusk to take another shot at it. A fresh 6" had fallen since morning, bringing our total for the day into the neighborhood of two feet of snow.

Yes, it's a record for this area.

If winter ended tomorrow, and we didn't get another flake of snow until next winter, we'd already be over the average snowfall for the year.

The last memorable years for snowfall were 1995-1996. They were two record totals in a row. We seemed to get a fresh storm every week, usually in the middle of the work week to maximize the inconvenience. Our kids had to attend makeup days almost until the Fourth of July.

It looks like 2011 is poised to challenge them.


profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Thursday, December 30, 2010

The End Of 2010









Another year has come and gone. Time to write another retrospective on the year. Turn back now if this is too self-serving or boring!

Any year in which you maintain your health, family, and economic base is a good one, so 2010 was a good year.

My mother is ensconced in her new home. I thought we'd be doing well if she was transitioned by spring, but she's well ahead of that deadline. She sounds happy in the new place whenever I talk to her. What a relief! She's a marvel of good humor and optimism. I hope I can follow her example through my life changes to come.

My youngest sister had her second child, a boy. What a happy occasion! My oldest sister's son announced that he and his wife are expecting their first child in the spring of 2011. It'll be my mother's first great-grandchild. We're all happy to see the first of another generation arrive.

I was lucky enough to change groups at my current employer. The new gang is doing work that I enjoy a great deal more and the people are terrific. It's such a pleasure to work with folks that actually smile and laugh once in a while. There's a lot to be done, but I'm grateful for the chance to do something good with people I like.

My oldest daughter has moved to New York City to work and go to grad school. She's doing a great job of figuring out how to manage herself as an adult. My youngest daughter continues to make progress towards her undergraduate degree. We're still on track to get both of them through school without debt.

This fall was the first time my wife and I have been alone in the house for an extended period since our eldest was born. I was concerned at first: would I be enough? Would my wife be happy with the children gone? I was relieved to find that everything was great. My wife still has the capacity to surprise and delight me, even after 29 years of marriage.

As usual, my athletic and technical goals were the most measurable things I did all year.

I had my best swimming yardage total ever in 2010, topping my "unbeatable" record set in 2008. I started the year off with a bang: I had "best month" totals in seven of the first eight months of the year. My attendance was stellar. I had resolved to make 2500 yards my new daily standard, and I kept to it. "90% of success is showing up" rings true in this case.

I was on a pace to exceed 600,000 yards for the year back in June, but I tailed off in the last third of the year. The last four months weren't nearly as good as the first eight. Work pressures start to get in the way.

I expect that the trend will continue in 2011, but that's not a bad thing. Rather than pushing myself to greater heights, I'm planning to take another direction. A yardage total exceeding 400,000 yards would still be in my top five totals ever, so that's what I'll be shooting for.

Instead of merely piling up yards, I'd like to change the way I swim. One thing that I did this year was train myself to breathe every other stroke. I've always been comfortable with breathing to either side, but now I can do waltz time over long distances. I think it makes my stroke more balanced and efficient.

I tried an experiment before the holidays: if breathing every three strokes is good, would every five strokes be better? It takes greater lung capacity and discipline. I did a set of 20x50 on 1:00 one morning, breathing every fifth stroke. It was hard, but I was able to do it. I counted strokes per length the whole time. I found that my stroke count ranged between 16-19; my three breath stroke usually takes 19-21 strokes per length. Making five strokes per breath my new standard will be a goal for 2011.

I'd still love to work my way up to 200 yard butterfly. That's a stretch goal.

Mostly I'd like to weave more cross-training into my life. I've maintained my yoga practice all year. It's making my flexibility, balance, and core strength better. I think I need to work in some strength training. Muscle mass is something that declines with age. I need to start fighting the good fight on that front.

My cycling fell off a long way when compared to 2009. I still rode to work with my friend Michael, but not nearly as much as I had the previous year. My cycling mileage dropped by almost 50% in 2010, and it was a small fraction of the 2,500 miles that Michael logged for the year. I'll try to improve on that next year.

I had a pretty good technical year. I made a lot of progress in learning Python. I have a new IDE in PyCharm to help. I've been poring over some good books. I wrote a lot of code on my own. Now I need a focused effort at an application to pound it into my head. I've got some ideas that are worth pursuing. I'll see if I can bring that home in 2011. In the meantime, I'm glad to have more of a development role during my core hours. It helps to not have to do all my saw sharpening on my time.

I had a fine year with Toastmasters. I achieved "Competent Communicator" status by completing ten speeches, entered and won a competition, and was elected an officer of my club. I'm actually a mentor for two newer members of our club. I hope to complete my "Advanced Communicator Bronze" and "Competent Leader" designations for 2011.

The economic debacle that I feared back in 2008 didn't happen, but I'm concerned that nothing significant has been done to prevent it. We're in a holding pattern, convinced that our past behavior can continue without change. The alterations to come could be neither orderly nor our choice. I don't want to find out how deadly hyperinflation can be. I fear the rise of the political and religious right in our country. 2011 will bring a new Congress to power in the United States. I hope they don't accelerate our slide in the coming year.


profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers

Sunday, December 12, 2010

Keeping Faith, Keeping Contact








It's a cold, rainy Sunday morning here. Icing conditions were predicted, because the jet stream has dipped down and brought arctic Canadian air all week. I heard a sanding truck drive down the street early this morning.

I was concerned about driving conditions because I had agreed to have breakfast with two friends, one of whom had left the company about eight months ago. We've sent messages back and forth on Facebook, but there's been no face to face contact since he departed. I was looking forward to the meeting. I hoped the weather wouldn't interfere.

I was relieved to find warm conditions and rain when I went out to get the paper. The ice line was north of us.

Breakfast was great fun for me. The two young men aren't too far in age from my oldest daughter. It's more likely that they'd come by to chat her up and ask for a date than to spend time with her father. I'm flattered that they'd want to.

We fell into a little work talk to catch up, but not too much. We talked about working life, women, car problems, and strength training. I've had a great swimming year - my best ever; more about that in a later entry - but I've neglected strength training all my life. My flexibility problems are less critical now that I've made yoga a regular feature of my week. I'm thinking that a good objective for 2011 would be to work something into my routine to help improve strength and retain muscle mass. These two guys are perfect sources of information. I was glad to be able to ask questions and soak in their knowledge.

I've accumulated a long list of people that I like very much after hopping between jobs as often as I have over the last fifteen years. The problem is that they leave my life once we lose the shared context of work.

It seems to me that regular, face to face contact is the only anecdote there is for this malady. Technology won't do: all the cell phones, e-mail, instant messaging, chat, and Facebook applications you can think of can never fill the void.

Breakfast is the perfect way to sort this out.

It's a meal that's unobtrusive: early in the day is transparent to my wife. It takes at least an hour to order and consume, so you have time to sit and chat. It's inexpensive - we met at a diner and had simple breakfast food with coffee. I met the man who is the best friend I have early in my engineering career. Since I've switched to software development we've made it a point to get together for breakfast once a month before work. We get to catch up, discuss our favorite topics, and make it to work without a hitch. I wouldn't miss these get-togethers.

I enjoyed the conversation so much. This morning's meal was a reminder that I should expand its reach. I need to make sure that all these terrific folks I've met don't diffuse out of my life.




profile for duffymo at Stack Overflow, Q&A for professional and enthusiast programmers