Mad Props!

Omniscience is just a Google-search away.

Login

You're reading Mabsterama, the weblog of Matt Hamilton. Enjoy your stay.

Halfwit on Codeplex

There’s an age-old quote (I’m not entirely sure who first said it) that goes something like this: “It’s better to keep your mouth closed and be thought a fool than to open it and remove all doubt.”

In a lot of ways I feel like that when it comes to source code. I love to talk about programming, and I’m more than happy to offer help on others’ projects, but I haven’t “opened my mouth” and shared much of my own source code.

Well, today I’m removing all doubt. I’ve uploaded the Halfwit source to Codeplex. You can grab a copy, have a read through, spend a few minutes getting over the “anti-pattern shock”, then build it for yourself.

The project was created in Visual Studio 2010 RC, but it’s .NET 3.5 SP1, so with a bit of hacking in the .sln or .csproj file you could probably get it to build in Visual Studio 2008.

Let me know how you go – I’m very new to this open-source thing, and may have forgotten to upload some critical file.

Halfwit Build 41

Last night saw yet another update to Halfwit, with a few little extra features. Nothing major, but I thought I might as well document them here.

For starters, I’m displaying retweets slightly differently. I’m grabbing the profile picture of the person who was retweeted, and overlaying it on top of the profile picture of the “retweeter”. Here’s a screenshot:

image

So you can see funkatron’s avatar hanging off the bottom of lazycoder’s. It’s a bit of a visual clue that this is a retweet, and lets me take the next logical step: I want to remove the “RT @funkatron:” from the front of the tweet, and instead move it down into the smaller, gray text below the body. Here’s a mock-up:

image

The idea is that the link in the gray text (“retweeting @funkatron” in this case) would take you to funkatron’s profile. It’ll make native retweets feel a bit more seamless without sacrificing the functionality, and it’ll also mean that a very long tweet that was retweeted won’t get truncated (because I have access to the original text).

The other thing you might have noticed from that screenshot is that the “source” of the tweet (“API” in this example) is a link. You can click on that link to take you to the home page for the Twitter client that was used to post that update.

I still have a few feature requests on UserVoice, and a few ideas of my own. Please give Halfwit a try and let me know what you’d like to see!

Halfwit gets a Visual Refresh

I’m still actively working on Halfwit (if not its home page), and this weekend I took the time to give it a bit of a visual update.

While I like textual toolbar buttons (and judging by the current crop of software from Microsoft, so do they), I had a few users telling me I could save screen real-estate by switching to icons. They were right, of course, but I resisted until now.

So this version takes it to its logical extreme. Witness the new home page:

The Home page

So the toolbar now takes up only a few pixels at the top of the window.

When you switch to a page that can accept a bit of contextual information (like a phrase to search for on the Search page), you’ll lose a bit of vertical space:

The Search page

… and likewise when you click the “Write” button at the top-right to post an update:

Showing the update panel

All in all I’m happy with the update. Let me know what you think! Don’t forget I’m accepting feedback on our UserVoice site!

Halfwit Feedback

For those trying out Halfwit, I have decided to stop using Google Wave for feedback and go to a more tried-and-true system. To that end, I have created a UserVoice Forum for Halfwit. You can vote on any feature requests that you agree with, and suggest your own.

If you haven’t tried Halfwit yet, what are you waiting for? At least install it and have a look! :) Head on over to the Halfwit home page (which, yes, is still just a placeholder).

Halfwit Progress

My Twitter client, Halfwit (please excuse the placeholder home page), is really coming along. Already it’s up to version 0.0.0.23, and has some great new features.

The “Home” page now shows your normal timeline of followers, along with any tweets mentioning you and any direct messages sent to you. It also includes an optional search for a phrase you enter on the Options page. Here’s my Home page which incorporates tweets with the “#nocleanfeed” hashtag. You’ll notice that the “search result” tweets are highlighted in light pink rather than the standard blue:

Home Timeline with Search Results

This should prove very useful when tracking events like Code Camp Oz, coming up in a couple of months.

Halfwit also has a feature that I’m calling “dynamic column layout”. Essentially, you set an “optimum width” for your tweets on the Options page, and as you widen the window, Halfwit will detect whether there’s room for another column of tweets. Here’s the same view as before, widened:

Two-column Layout

As you can see, I’m getting nearly twice as many tweets on the screen at once. There was a trade-off in introducing this feature: The use of WPF’s WrapPanel as the underlying panel for the ListBox means that the ListBox isn’t “virtualized” anymore. It has to render every item whether or not it’s visible on screen. This has increased the memory usage a bit but doesn’t seem to have impacted on performance much, so I think it was worth it.

There are still a few little glitches to work out. I’m keeping a To-Do list in Google Wave, so if you’re interested in being added to that, add me to your Wave contact list and let me know. I’m mabsterama –at- googlewave.com.

More Halfwit posts to come – I’m keen to talk about the architectural decisions I’ve made and see if I can get some advice around memory usage.

Halfwit

The preview build of my new Twitter client, Halfwit, is now available.

Halfwit was designed to have as few features as possible, to keep the user interface clean and tight. The only feature I truly need is font scaling so I can read the tweets on my notebook monitor. Here’s a screenshot of the main window as it looks right now (click to embiggen):

Halfwit Screenshot

I haven’t yet gotten a proper “home page” up for Halfwit here at Mad Props, so for now just jump straight to its placeholder install page to grab a copy. Leave me a comment (or a tweet) with any feedback!

A New Hobby Project

A few weeks ago I picked up my new netbook, an HP Mini 311. I almost hesitate to call it a netbook, because it has an 11.6” screen, 2GB of RAM, and runs Windows Home Premium. So it’s more like an ultraportable notebook. Still, it rocks and is a big step up from my five year old Dell D400!

The screen on the HP Mini has a resolution of 1366x768. That means it’s great for watching 720p videos or for running applications that take a lot of screen real-estate, but it also means that the default font size is rather small. Windows has never been very good at scaling font sizes, and while Windows 7 is an improvement, I still don’t like switching to “large fonts”. Something about having the larger fonts in the Window chrome as well as the content just doesn’t gel with me.

So anyway, I’ve been looking at the various Twitter clients that are out there, trying to find one that was simple (not too many features that I won’t use) and supported custom font sizes. The one I like best so far is Sobees Lite (formerly known as bDule), but its user interface is rather “busy”.

So in the spirit of flooding the market, I’ve decided to write my own Twitter client.

The idea is that I’ll steal the layout and some UI from Witty (my favourite Twitter client) but change the feature set. I’ll strip back most of Witty’s features, and add one or two new ones (like custom font scaling, and support for native retweets). Like Witty, this will be a .NET 3.5 WPF project, using Visual C# Express 2010 and TweetSharp. Since it’s a scaled-down version of Witty, I’ve decided to call it Halfwit.

I’ve made good progress on it so far, and hope to have a version I can publish for people to try on the weekend. Stay tuned!

My Week Offline

Friends and colleagues have noticed that I’ve not been online at all this entire week, and I thought I’d share the story behind that in a post.

Last Sunday afternoon I was sitting in the cinema about to watch The Lovely Bones, and all was well. About half an hour into the movie, though, I began to feel cold. Since Sal wasn’t cold, we figured I must’ve been sitting in line with the air conditioner. The theatre was busy enough that we couldn’t really change seats, so I put up with it. As the movie went on, I got colder and colder, and by its end I was physically shivering, teeth chattering, lungs sore from breathing in cold air. It was literally the coldest I had ever felt.

Well, it turns out that it had nothing to do with the cinema. When I got home I was no better. I didn’t stop feeling cold until an hour or two later when the fever kicked in.

Sunday night was sleepless as I wrestled with spikes in body temperature and general pain throughout my body, and of course I resolved not to go to work on Monday, figuring that this was some sort of 24-hour bug and that I’d be good by the next day.

Monday brought new surprises, and I’m sure you’ll forgive me for not going into any more detail than the following two words: Explosive Diarrhea.

Monday night saw me bouncing between the bed and the toilet every 40 minutes or so, so it looked like it was going to be two days off, and a visit to the doctor. The doctor immediately diagnosed it as an infection of campylobacter, which is a common cause of food poisoning. The third case he’d seen that week. He said it takes about five days to pass, and suggested two things in the meantime:

  1. Codeine
  2. Sports drinks

Weird, huh? The codeine was for the stomach cramps (which, by this stage, were brutal) and (his words) to “bundle me up” a bit inside. The sports drinks were for rehydration and electrolyte replenishment.

We got straight into the codeine, which worked pretty well, but unfortunately it was not until late Wednesday that I remembered about the sports drinks. I’d been trying, until then, to sip at glasses of water, but by Wednesday arvo I was dangerously dehydrated. I could barely move, and my skin (particularly my lips) was dry and flaky. They say you can last three days without water. I’d been drinking, but not nearly enough. Let me say that when Sal brought home a bottle of Gatorade, it was a revelation. It was like I’d been waiting for that drink since Sunday night.

By Thursday I was starting to come round. I hit the pain killers every four hours, and kept up with the sports drinks.

The doctor had given me a medical certificate through ‘til Thursday, but luckily my boss has given me the ok to work from home on Friday. I’m definitely still in no shape to drive for an hour to get to work, much less sit at a desk for a day.

The big news came last night on the local news on TV: It turns out that It’s not just food poisoning, it’s a salmonella outbreak that has struck the border region! So I’ve just gone through a week with salmonellosis. I can tell you that I lost about 7 kg in three days, and it’s without a doubt the sickest I’ve been since I contracted chicken pox back when I was 21.

The moral of the story: don’t get salmonella poisoning. Apparently local authorities have traced the source back to a retail outlet in town that we ate at on Saturday (Sal was lucky not to pick it up herself). My brother-in-law ended up in hospital on a drip, and I’m sure I could’ve been next to him if we’d gone there rather than to the doctor. What a week!

I Want a “while” Linq Keyword

The other day when I was playing with the coin change code kata, I thought I’d try doing it in the keyword-based “sql” style of linq coding. The hurdle I struck (well, not the only hurdle, but a major one) is that not all of the linq extension methods have keyword equivalents. Case in point, the TakeWhile() extension method.

What I’d like to see in a future version of C# is for the team to hijack the existing “while” keyword and let us use that. So the code would become:

var solution = from c in coins
           orderby c descending
           while amount > 0
           select new { Coin = c, Number = amount / c, Remainder = (amount %= c) };

Now, this is missing the final “Where” clause from the previous posts (which filters out any coins that don’t apply), but that’s no big deal.

I’m not sure why the C# team didn’t include the “while” keyword in their longhand linq syntax from the get-go. Perhaps it was difficult to parse, or maybe they were concerned about making a query that “looks” set based use an iterative keyword like that. I think it fits right in! How about you?

Code Kata – Coin Change Problem

Remember the old problem you had to tackle when you were first learning to program, where you had to output how many of each coin denomination made up a given value? I thought I’d tackle it using Linq to see how it might look in modern C#.

Here’s my first attempt:

var coins = new[] { 1, 2, 5, 10, 20, 50, 100 };
var amount = 3347;

var solution = coins
    .OrderByDescending(c => c)
    .TakeWhile(_ => amount > 0)
    .Select(c => new { Coin = c, Number = amount / c, Remainder = (amount %= c) })
    .Where(i => i.Number > 0);

foreach (var i in solution)
{
    Console.WriteLine("{0} x {1}c", i.Number, i.Coin);
}

This uses OrderByDescending so that the coins don’t need to be defined in any particular order, and reduces the “amount” each time inside the assignment to the “Remainder” property.

What do you think? It’s interesting, tackling these age-old problems with fresh approaches. If you search for “code kata” you’ll find many people writing modern code to do things like finding prime numbers etc. I haven’t seen this particular problem being attacked (perhaps because it’s so simple). If you have a better way to do it, let me know in a comment or a post of your own.