The Daily Parker

Politics, Weather, Photography, and the Dog

New Scientist: Smart soldiers die faster

A British government study found that smarter Scottish soldiers were more likely to die than dumber ones in WWII:

The 491 Scots who died and had taken IQ tests at age 11 achieved an average IQ score of 100.8. Several thousand survivors who had taken the same test - which was administered to all Scottish children born in 1921 – averaged 97.4.

A previous study found a fall in intelligence among Scottish men after the war, and at the time Deary's team theorised that less intelligent men were more likely to be rejected for military service. The new study appears to refute that suggestion. Men who didn't serve were more intelligent than surviving veterans, and of equal intelligence to those who died.

In related news, our governor, who still hasn't resigned, has announced a press conference today at 2pm.

Turning Japanese

I've given up for the evening attempting to configure a recalcitrant firewall. To cheer up, I turn to Paul Krugman, who reminds us that a 0% Fed rate means we're in trouble:

ZIRP!

That's zero interest rate policy. And it has arrived. America has turned Japanese.

This is the thing I’ve been afraid of ever since I realized that Japan really was in the dreaded, possibly mythical liquidity trap. ...

Seriously, we are in very deep trouble. Getting out of this will require a lot of creativity, and maybe some luck too.

At least I think I've figured out where I mis-configured the firewall....

More good news

From my dad, yet another New York Times article to make you all warm and fuzzy inside:

Thieves Winning Online War, Maybe in Your PC

Despite the efforts of the computer security industry and a half-decade struggle by Microsoft to protect its Windows operating system, malicious software is spreading faster than ever. The so-called malware surreptitiously takes over a PC and then uses that computer to spread more malware to other machines exponentially. Computer scientists and security researchers acknowledge they cannot get ahead of the onslaught.

As more business and social life has moved onto the Web, criminals thriving on an underground economy of credit card thefts, bank fraud and other scams rob computer users of an estimated $100 billion a year, according to a conservative estimate by the Organization for Security and Cooperation in Europe. A Russian company that sells fake antivirus software that actually takes over a computer pays its illicit distributors as much as $5 million a year.

Sigh.

Lost passwords

I spent part of this afternoon rooting around in my email correspondance from 1999 and 2000. Forgetting the wherefores and whatnots of the emails themselves, just getting into the Outlook files proved difficult. How many passwords does anyone remember from nine years ago? I actually remember a few, but not, unfortunately, the ones I needed.

Sure, I found them eventually, but heavens. That's half an hour of my life I'll never get back, and it was my own fault.

LINQ to FogBugz fun

Most Daily Parker readers can skip this (long) post about software. But if you're interested in C# 3.0, LINQ, or FogBugz, read on.

I use FogBugz's time tracking tool to provide tracability in my billing. If I bill a client 2.75 hours for work on a bug, I want the client to see the exact times and dates I worked on the bug along with all the other details. And because I track non-billable time as well, and I often work in coffee shops or places like the Duke of Perth, I wind up with lots of tiny time intervals that I have to aggregate to produce a bill.

My time sheet today, for example, looks like this:

Start End Case Title
7:11 AM 7:23 AM 901 Walking the dog (November)
8:18 AM 9:32 AM 950 FogBugz to LINQ project
9:32 AM Stop Work 902 Blogging (November)

But what I need for QuickBooks looks like this:

Case Hours
901: Walking the dog (November) 0.20
950: FogBugz to LINQ project 1.23
902: Blogging (November)  

(The last bit has no time because I'm still working on it.)

This is the perfect kind of thing to waste a few hours on while learning some new programming tricks. (Code here.)

First: the entity

To use LINQ to SQL in its pure form, you first have to create entity classes that pretty much exactly mirror the tables you're interested in. My target, the FogBugz timeintervals table, yields an entity that looks like this:

[Table(Name="timeinterval")]
class TimeInterval
{
	[Column(Name="ixInterval",IsPrimaryKey=true)]
	public int Identity;

	[Column(Name = "ixPerson")]
	public int PersonId;

	[Column(Name = "ixBug")]
	public int CaseId;

	[Column(Name = "dtStart")]
	public DateTime StartDate;

	[Column(Name = "dtEnd")]
	public DateTime EndDate;
}

Because I'm interested in the aggregate time spent on each case, I also created a simple structure to hold that info:

struct AggregateInterval
{
	public int CaseId;
	public double TotalHours;
}

Second: the console app

To use LINQ to SQL, you need to include a reference to the System.Data.Linq assembly, and import the appropriate namespaces:

#region Copyright ©2008 Inner Drive Technology

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;

#endregion

namespace InnerDrive.Research.FogBugz
{
	class Program
	{
		static void Main(string[] args)
		{

Next, set up the data context:

DataContext context = new DataContext(" (your connection string) ");
context.ObjectTrackingEnabled = false;
Table<TimeInterval> table = context.GetTable<TimeInterval>();

(I turned off object tracking because this is a read-only application. Setting ObjectTrackingEnabled to false improves performance, but the data context will throw an exception if you call DataContext.SubmitChanges().)

I actually need two queries, one to get the table rows and another to aggregate them. The reason for this is that my aggregation depends on getting the total hours each interval represents; LINQ to SQL won't do that. Here's the first query:

// FogBugz stores time as UTC; I want the time for today in Chicago, not London
DateTime startDate = DateTime.Today.ToUniversalTime();

var intervals =
	from interval in table
	where interval.EndDate <= startDate.AddDays(1) &
		interval.StartDate >= startDate
	group interval by interval.CaseId
	into grouping
	select grouping;

The second query does the aggregation, transforming the first query into an IEnumerable<T> and returning AggregateInterval structs:

IEnumerable<AggregateInterval> aggregation =
	from grouping in intervals.AsEnumerable()
	select new AggregateInterval
	{
		CaseId = grouping.First().CaseId,
		TotalHours = grouping.Sum(t => t.EndDate.Subtract(t.StartDate).TotalHours)
	};

Neither query has fired yet, by the way. That's another cool thing about LINQ. Both queries fire when I output the data, which is trivially simple:

foreach(var item in aggregation)
{
	Console.WriteLine(string.Format("Case {0} = {1:0.00}", item.CaseId, item.TotalHours));
}
Console.ReadLine();

That's it. Share and enjoy.

Efail?

Via Jeff Atwood, San Francisco-based programmer Tantek Çelik's definition of Email as "Efail:"

All forms of communication where you have to expend time and energy on communicating with a specific person (anything that has a notion of "To" in the interface that you have to fill in) are doomed to fail at some limit. If you are really good you might be able to respond to dozens (some claim hundreds) of individual emails a day but at some point you will simply be spending all your time writing email rather than actually "working" on any thing in particular (next-actions or projects, e.g. coding, authoring, drawing, enjoying your life etc.) and will thus experience a productivity failure. The obvious solution is to push as much 1:1 communication into 1:many or 1:all forms such as public blogs and wikis. ...

think two specific reasons in combination account for most of the problem. [First,] point to point communications do not scale. ...

The second reason that I think email is becoming a worse and worse problem is directly due to its higher usability barrier, that is: Emails tend to be bloated with too many details and different topics.

Paean to Lolcats

Salon has a sublime ode to the "I can haz cheezburger" crowd:

By now, even the most casual observers of the Internet are aware that lolcats have become a certifiable Internet phenomenon. Their flagship site, Icanhascheezburger.com, is one of Web 2.0's big success stories -- on track to top a billion page views this year -- and its content is entirely user-generated. Readers upload over 5,000 homegrown submissions every day, of which six or eight are posted on the site. And in October, the lolcats got their very own coffee table book, "I Can Has Cheezburger," published by Gotham Books.

What makes lolcats different from the cat porn of the past -- the motivational posters of the '70s and '80s featuring furry kittens hanging from tree limbs, covered in toilet paper or in some other kind of adorable predicament -- is that lolcats aren't trying to be cute. In the cat-based imagery of ages past, cats retain their iconic traits: curiosity, skittishness, the tendency to curl up in a ball and just lie there. Even the YouTube cats of today perform characteristically catlike actions, repeatedly flushing toilets, dragging their paws along piano keys or getting flung off the ends of treadmills.

Lolcats are different in that the characters they portray -- and yes, they are portraying characters -- don't represent cats at all. They're a completely different kind of beast, mischievous (if incompetent) rascals, scheming for cheeseburgers and stopping at nothing to get them.

Take the lolcat that started it all, created by a Hawaiian blogger named Eric Nakagawa, who posted it in January 2007. The image features a cat with a crazed look of pure animal hunger, its eyes maniacal with desire, asking, "I can has cheezburger?" Underneath is the comment: "The Internet's piece de resistance, the website's raison d'etre."

This ur-lolcat created such a sensation that Nakagawa turned it into a blog, spawning not only the eponymous Web site but also a whole mythology. The cheezburger has become the Philosopher's Stone of the lolcats mythos -- the most prized, cherished and elusive object in their universe. It is for this reason that, when a tiny kitten being sniffed by a Great Dane 20 times its size needs a quick escape, it says, "I iz not cheezburger, kthxbai." It is for this reason that when a user finds a photo of a cat sitting by the window with its paws in its lap, the caption reads, "I iz waitin for cheezburger man. Does you have a money?"

The Web is now spawning a wave of next-generation lolcats sites that take the lolcats concept and run with it. There's lolpresident, loldogs, and even lolhan, a site devoted to Lindsay Lohan that includes such classics as "I layded you an egg but I'z hidin it."

On that note, I turn in to see y'all in the morning.

Missed my own anniversary!

Last Thursday, The Daily Parker turned three.

Actually, yesterday, the dog turned 2 years, 5 months; but the blog is three years old.

And in honor of this august day in November, I hit "Post" three times before correcting all the typos.