All posts by ajohnson

Scotty Cameron Studio Store: Struts, Hibernate, Quartz, Ant, Cewolf, etc..

On Monday we launched the online store I was working on this summer for ScottyCameron.com. We brought the ecommerce capabilities in-house (it was on Yahoo! Store) so that we could leverage some of the existing functionality I built for address verification, credit card fraud protection and taxation. I was able to use alot of Java related technology including Hibernate (for object persistence), Struts, Quartz (embeddable job scheduling), Ant, Cewolf (for graphing and charting), various commons projects (beanutils, httpclient, logging, etc..), Fedex API, dom4j (XML parsing all deployed successfully on Tomcat 5.0.25 across a couple webservers.

Book Review: The High Price of Materialism

A couple of weeks ago I saw a book in the semi-weekly newsletter that I get from MIT Press called “The High Price of Materialism” (buy on MIT Press, Amazon) (oops, now that I look I actually added it to my Amazon.com wishlist back in June) Anyway, I finished it tonight and wanted to note a couple tidbits.

It’s a great book on alot of different levels; it makes you think about your own life, your motivations, where you spend your time and might even influence how you make big decisions about oh, say, an election for instance. Since I’m horrible at writing summaries and because someone else already took the time to do it on the back of the book, I’ll just quote that: “Other writers have shown that once we have sufficient food, shelter and clothing, further materialistic gains do little to improve our well-being. But Kasser goes beyond these findings to investigate how people’s materialistic desires relate to their well-being. He shows that people whose values center on the accumulation of wealth or material posessions face a greater risk of unhappiness, including anxiety, depression, low self-esteem, and problems with intimacy — regardless of age, income, or culture.”

Other interesting snippets:

In regards to an experiment which “.. women who viewed the advertisements with models reported less satisfaction with their own attractiveness, but did not differ from the control group in self-ratings of how attractive they thought themselves to be. This suggests that the ads did not change the women’s assessment of their actual attractiveness, but raised their ideals about attractiveness in general… The results suggest that decreased life satisfcation could be a side effect of frequent exposure to all the different types of idealized images in the media, whether for cards, furniture, or baby powder.” (page 56) We’re in a society full of ads, one wonders what ‘frequent exposure’ is. But more importantly, remember that viewing advertisements pecks away at your soul.

The summary of chapter 5 (called ‘Fragile Self-Worth): “When people and nations make progress in their materialistic ambitions, they may experience some temporary improvement of mood, but it is likely to be short lived and superficial. Furthermore, some of the psychological dynamics related to the strong pursuit of materialistic goals (problems with self-esteem and discrepancies) keep individuals’ well-being from improving as their wealth and status increase. The sad truth is that when people feel the emptiness of either material success or failure, they often persist in thinking that more will be better, and thus continue to strive for what will never make them happier. (page 59)

“Political scientist Robert E. Lane similarly commented that people in capitalistic countries suffer ‘a kind of famine of warm interpersonal relationships, of easy-to-reach neighbors, of encircling, inclusive memberships, and of solid family life.’ What these and other thinkers note is that materialistic values ‘crowd out’ other meaningful pursuits, as the time we spend earning and consuming often means neglect of our spouses, children, friends and community.” (page 61) Purely anecdotal evidence, but since we moved into our new house, we’ve met the couple across the street and the lady next door. No one else stopped in to say ‘hi, welcome to the neighborhood!’. I’m sure suburbia has something to do that it and maybe some of the burden lies on us to the same thing.

“… when consumption, possessions, and money become our primary aims, we become less concerned with fully understanding others’ subjective experience, feelings, and desires. Instead, others become objects and thus lose their value as people. In the materialist mindset, people exist largely to reflect well on ourselves and to be used and manipulated to obtain what we want.” (page 68)

This next piece was extremely interesting and probably much more relevant to readers of this blog, the heading is “Materialism, Intrinsic Motivation, and Flow“. “If individuals place a low value on freedom and self-expression, they will be unlikely to construct their lives in a manner that enhances their chances of having autonomous and authentic experiences… values bleed over into people’s experiences, enhancing or detracting from them.

One experience from which materialistic values detract is the sort that some thinkers consider the pinnacle of autonomy and self-expression…. it occurs when an individual is doing something for no other purpose than the sheer joy, interest, and challenge involved. A great example intrinsic motivation is children’s play, but it can also be seen in any number of adult activities, such as climbing mountains, painting pictures, hiking in the woods, and even writing books. People can also feel flow or intrinsic motivation in nonleisure activities, such as their work or conversations they have with others. what is required is that people pursue activities for what the activities themselves have to offer, not for rewards or praise.” Since you’re reading this blog, I’m guessing you’ve felt the flow; it usually hits me late at night (not recently) when I’m working on a pet project that has no chance of making a dime. I think the entire open source movement can readily relate to the above paragraph and it points to why programmers on Slashdot are so passionate about freedom of speech and self-expression. In some sense, the open source movement isn’t about money and never will be. It’s about meeting a basic psychological need for self expression and autonomy… it’s about being authentic. But wait, it gets better. Tim goes on to say rewards (monetary, praise, etc..) actually decrease our intrinsic motivation. In other words, once you start to get paid to work on an open source project, it’s very possible that it won’t be as fun as it once was. (page 76-77)

So if ‘flow’ is good, how do we maximize the amount of time we spend in the flow? “Studies … have found that watching television involves very little challenge; instead it causes people to feel zoned out or apathetic… Shopping is another example of a low-flow activity encouraged by materialistic values… Working long hours and amassing debt are other activities encouraged by materialistic values that must surely involve little in the way of intrinsic satisfaction.” (page 81-82)

The cure? “Many thinkers in other fields have propounded the benefits of values such as growing as a person, knowing and accepting oneself, caring about family and friends, and helping the community and world be a better place. The importance of these values can also be recognized in a contemporary social movement called Voluntary Simplicity, a growing trend for people to abandon the high-paying, high-stress lifestyle necessary to support high levels of consumption, and focus instead on personal growth, nurturing relationships, and helping others.” (page 99)

Stop and smell the flowers today.

SQL Server Type 4 Drivers: jTDS

A couple months ago I wrote about problems I was having with Tomcat and SQL Server where I would get Connection reset by peer errors if the SQL Server was restarted. A couple people commented that instead of using the Microsoft provided JDBC SQL Server drivers, they had switched the open source jTDS driver available on sourceforge. I ignored them and went on my merry way, until yesterday when I ran into this really strange problem. I had a query written using Hibernate/HQL that would take approximately 10 seconds to run but the same query run in Query Analyzer would take less than 1 second. My code looked like this:

Query q = null;
Session session = HibernateFactory.currentSession();
String query = "select this and that from sometable";
q = session.createQuery(query);
List list = q.list();
for (int i = 0; i
Pretty simple, nothing out of the ordinary, it just took 10 seconds to go from the q.list() to the for {} block. I tried a bunch of different things: I modified the query, I tried using an Iterator rather than a List, I added named binding to the query. Nothing worked. Today I switched to the jTDS driver. Problem solved. I'll never use the Microsoft JDBC drivers again.

daily links

· Bloglines API

· Paul Graham on what the Bubble got right: “… what would be wrong would be that how one presented oneself counted more than the quality of one’s ideas. That’s the problem with formality. Dressing up is not so much bad in itself. The problem is the receptor it binds to: dressing up is inevitably a substitute for good ideas. It is no coincidence that technically inept business types are known as ‘suits.'”

· LionShare: “… an innovative effort to facilitate legitimate file-sharing among individuals and educational institutions around the world.”

· .NET Reflector: allows you to view the source code to most .NET framework classes and code written in .NET. So how does one write / compile code in such a way as to not allow someone to disassemble their code?

Java / Web Developer Job Opening: Southern Massachusetts

Don’t bother applying unless you live in or around southern Massachusetts or are willing to relocate to southern Massachusetts. I work for the largest golf company in the world and I’m looking for a partner in crime. Strong Java, Struts and Hibernate experience will get you in the door (proving that you know Java inside and out will work too); loving your work will get you a job. Email me your resume if you’re interested.

The ‘using’ keyword

Joe pointed out that the C# PGP decryption code that I wrote could be better; specifically I should be checking the xExitCode property of the Process instance and the code would also be better served if I made certain that I disposed of the Process instance by calling the Close() method when I’m done using it. The ExitCode improvement is relatively simple to add; start the process, read any lines of output and then check the ExitCode to see if everything went smoothly:

Process process = Process.Start(psi);
...
while(!process.HasExited) {
... // do stuff
}
if (process.ExitCode != 0) {
// something went wrong..
}

The second thing that Joe mentioned was the ‘using’ statement, which is a novel feature of C# that provides “… an easy way for C# code to acquire and release unmanaged or otherwise precious resources.” The code I originally wrote didn’t destroy the handle to the process; after all was said and done I should have called the Close() or Dispose() method of the process:

Process process;
try {
process = Process.Start(psi);
...
} catch {
process.Close();
}

The ‘using’ statement is syntactic sugar that’s a shortcut for the well worn try / catch idiom and shortens the above example to:

using (Process process = Process.Start(psi)) {
... // do stuff w/ the process
}

which then automatically calls the Dispose() method of the process.

Joe goes on to hijack the ‘using’ statement in some other novel ways which should you check out when you have a chance.

Conflicting mindsets of C# vs. Java: Part II

You all read the the ‘Conflicting mindsets of C# vs. Java‘ weblog post right? And you all noticed that the guys running the Lucene.NET project on sourceforge closed up shop, took all their toys and went on home right? I’m gonna go out on a limb and say that they’re related.

The way I see it, *in general* the .NET community conversation is dominated by talk about the latest and greatest that microsoft is putting out; there’s talk about MapPoint Location Server, SQL Server, Longhorn, ASP.NET 2.0 and Visual Studio; all products of Redmond. The same group of Java developers are talking about JBoss, Hibernate, Struts and Eclipse: none of which came out of the Silicon Valley.

Malcolm’s mindset #1 says that .NET developers accept the tools and services that are provided them by Microsoft and I think for the most part this is true. You don’t see .NET developers spending their cycles on persistence layers, web application frameworks or caching solutions probably because Microsoft has provided Microsoft solutions for all these problems. But if it’s just providing tools, then why aren’t JSF, JDO and NetBeans dominating the javablogs conversations? Seriously, take a look at ASP.NET and JSF. They aren’t that different and yet ASP.NET is widely used in conjunction with Visual Studio while JSF is rarely lauded and more often derided. I think he’s right, it’s really a mindset.

Which brings me back to the Lucene.NET guys. Why would they close up shop? Why not continue to donate their time and energy to an excellent cause? Maybe the Microsoft mindset has something to do with it. How about this: a search on google for ‘lucene’ within the weblogs.asp.net domain yields exactly 17 results. The same search on jroller.com yields 2570 results. Admittedly, Lucene has been around longer, but maybe one of the reasons that the Lucene.NET guys packed it up (and are now trying to sell their work) is that no one paid any attention to them because they were all too busy working with SQL Server full-text indexing, a tool given them by Microsoft (but one that costs thousands of dollars per processor). Another reason that a project like Lucene or Struts or Tomcat flourishes is because there is a certain amount of prestige working on a big open source project. If you work on open source projects for the prestige and you’re not getting the attention you think you deserve, you find another motivation. In their case money was a motivation, so they closed up project on sourceforge and they’re selling a personal edition and a business edition. They might make a couple bucks, but I bet in 1 year there won’t be many people writing about searchblackbox.com.

So what’s my point? That all .NET developers are greedy and don’t care about the community? Not really. I think it’s that the two communities have different bus drivers: .NET developers look to Microsoft to provide the tools they need to do their jobs… and if they look elsewhere or copy something else, Microsoft will eventually come in and make a product of their own that does the job, thereby negating any work the developers do in the meantime. Microsoft drives the bus. Java developers look at the products and specs that Sun puts out and then go and build their own tools or frameworks or applications to do the job. Sun will eventually put out something through the JCP that does the job…. but the developers in the Java community will only use it if they want too, witness the continued popularity of Struts and the lack of interest in JSF. In the Java camp, the developers drive the bus.

Sending your Outlook calendar using Python

At work we’re required to send an email with our personal schedules at the beginning of the month to everyone in our group so that (at least until your schedule changes) everyone knows where everyone else is. Sure, we could be using a online calendar or some kind of group collaboration software but we’re stuck using Lotus Notes, which is the worst email client I’ve ever used (don’t believe me?). I switched to MS Outlook because a) I’ve used it before and b) the Notes Connector gives me access to the Notes server. Anyway, I’ve been wanting to tinker with Python for the last couple months and this seemed like the perfect project for it. Using the excellent win32com package, I was able to get a collection of all the items in my Outlook calendar, filter those events for the current month, put a message together with the subject, start date/end date and start time/end time and then send an email to an Outlook distribution list.

Since I’m new to Python, I’m going to walk through the code, narrating what I *think* is happening as I go along. A link to the finished product is available at the end, please let me know what, if anything, I’m doing wrong…

First things first, I import the appropriate modules (or packages?):

import win32com.client
import time
import datetime

After that I dive headfirst into Outlook getting an Outlook Application object, log on to the MAPI namespace, and retrieve all the items in the Outlook Calendar. Most examples I saw using ‘olCalendar’ as the argument to the GetDefaultFolder() method, but got the impression that ‘olCalendar’ is some sort of intrinsic constant that I didn’t have access too. This page that listed all the Outlook constants was where I got the number nine.

outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
appointments = namespace.GetDefaultFolder(9).Items

Next I sort the events by Start Date (right?) and flip the ‘include recurring events’ flag to true:

appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"

After that I do a bit of date munging to get the starting month/year and the last day of the month/year, use the Restrict() method to filter out only events in the current month and sort the events again:

# start date
monthNow = now.month
yearNow = now.year
begin = datetime.date(now.year, now.month, 1)
# end date
nextMonth = begin + datetime.timedelta(days=35)
end = datetime.date(nextMonth.year, nextMonth.month, 1)
appointments = appointments.Restrict(
  "[Start] >= '" + begin.strftime("%m/%d/%Y") +
  "' AND [End]
Now I'm left with a filtered and sorted collection of Outlook calendar items so the next step is to loop over the results, adding the subject, start time and end time to a message string:

appointment = appointments.GetFirst()
message = begin.strftime("%B, %Y") + " Meetings & Events for Aaron Johnson\n"
message += "