Category Archives: Code

WordPress Most comments

Here’s the SQL to find which of your WordPress posts have the most comments:

SELECT wp_comments.comment_post_id, count(*) as commentcount, wp_posts.post_title, wp_posts.post_date FROM wp_comments, wp_posts
where wp_comments.comment_post_id = wp_posts.ID
group by wp_comments.comment_post_id, wp_posts.post_title, wp_posts.post_date
order by commentcount desc

Making programmers productive

Oh God, yes! Joel Spolsky on what makes a programmer the most productive:

A programmer is most productive with a quiet private office, a great computer, unlimited beverages, an ambient temperature between 68 and 72 degrees (F), no glare on the screen, a chair that’s so comfortable you don’t feel it, an administrator that brings them their mail and orders manuals and books, a system administrator who makes the Internet as available as oxygen, a tester to find the bugs they just can’t see, a graphic designer to make their screens beautiful, a team of marketing people to make the masses want their products, a team of sales people to make sure the masses can get these products, some patient tech support saints who help customers get the product working and help the programmers understand what problems are generating the tech support calls, and about a dozen other support and administrative functions which, in a typical company, add up to about 80% of the payroll. It is not a coincidence that the Roman army had a ratio of four servants for every soldier. This was not decadence. Modern armies probably run 7:1. (Here’s something Pradeep Singh taught me today: if only 20% of your staff is programmers, and you can save 50% on salary by outsourcing programmers to India, well, how much of a competitive advantage are you really going to get out of that 10% savings?)

For myself, it’s silence that’s missing from my workplace. Ringing phones, the printer, the guy with the loud sneezes… all of these conspire to slow down my day, with music via headphones helping to minimise it.

Hassles with background-image and font sizes

The other day I was working on upgrading the eVision web site to the new look (as well as the latest WordPress 2.02). While I’ve been using HTML for more than a decade, I have to admit, my grasp on CSS is patchy. I’m still picking it up. So it took a bit of wrestling to get it to (more or less) match the design provided by the graphic designer. The big graphic still isn’t in quite the right spot, but no matter, it’s still a vast improvement over the old one.

I did learn a couple of (possibly) valuable tips:

  • In Firefox, the background-image of a div doesn’t display in the portion of the div that has nothing in it. In my case, I had a UL (which forms the dropdown menu) in there, right justified. The background only appeared in the left hand bit in IE, not Firefox. I had to add a   to it to get it to appear… and then I had to specify a height, so the background image would go to the right height, instead of just the nominal height of the non-existent text.
  • Font sizes… after complaints from a colleague who is keen on big text, I had to remove all the references to pt sizes in text, in favour of em, so that IE would resize the text when asked. Firefox handles this even if you’ve got all pt sizes.
  • I also learnt I need to study CSS a bit more. The next projects will be doing some more upgrades and new WordPress themes, I think. I’ve got a few that need doing.

Friday quickies

What if Microsoft was marketing the iPod? (Article about the origins of the video here.)

In case you’ve been living in a virtual cave, VMWare’s basic VMServer product is now free.

Google is beta trialling GMail from your own domain, primarily aimed at organisations to start with. (via Patrick)

Found an old quote of mine:
To me, reading Perl is a little like trying to understand Norwegian. A minority of things – essentials like “Help!” or “Hello” – I can probably understand. The rest is just gobbledygook. (Quoted here, originally posted here.)

Migrating .Net 1.x to 2.x

Having got Visual Studio 2005 into my hot little hands, I’ve upgraded one of my projects from VS 2003 to 2005, and .Net Framework 1 to 2. Just loading it into VS2005 seemed to do most of the work for me.

I did find the new VS gives out a few very informative warnings in the code editor, such as unused variables. Good stuff (and shame on me for being so sloppy during repeated revisions of code).

The other thing I found was a few things had changed in the Web.Config file format. After much fiddling I found it easier to create a fresh one and copy my custom settings into it, than try and convert the old one over.

The only catch is that after copying it all over to the test server, it didn’t work. Turns out apart from installing the .Net 2.X Framework on your server, you’ll also need to get into the IIS setup and make sure it knows it’s now a 2.X application.

Other than that, pretty smooth. The one gotcha on my actual code was a custom button click routine that took the form QueryString and stripped out all the ASP.Net guff I didn’t want needed a bit of tweaking, as in .Net 2.0 there’s an extra __EVENTVALIDATION value. (My version is adapted from a 15seconds.com article, and is used to produce tidy QueryStrings that can be bookmarked.)

CityLink eTags to be used for a reverse-toll

There’s a proposal to have Melbournians use their CityLink eTags for a reverse-toll on public transport by a economist-type guy from Melbourne Uni. I can just see homeless guys making a living by taking sackfuls of eTags around the city on trams while their owners are at work, to make the day’s commute in to work and back again net-free.

It’s an attempt to address the free rider problem of vehicular road use; he’s also proposed that the charging should be demand driven – so road tolls are higher in peak hour, and might be free in the middle of the night. But we have a crude version of this proposed roaduse charge already – it’s called fuel excise. Cars idling in traffic jams keep burning petrol, and thus their owners paying tax, as an added bonus, SUVs/4WDs burn a whole lot more of it. If you want to hike the charges up, I’m all in favour of, say, tripling the excise on fuel. That should make public transport more attractive – especially as there won’t be homeless guys with sacks!

Dr Watson bites arse

I had a program that was crashing at the customer site, but not in any way I could reproduce back at the office. I wasn’t able to load up a dev environment on the affected box, but someone had the bright suggestion of running Dr Watson (DrWtsn32.exe), and checking out the stack trace. As we all know, if you know your codebase well enough, you can almost explain a crash just by where it happened.

So I created an exe with debug symbols and optimizations removed, and waited for the crash. The DrWtsn32.log contained, amongst other things, the dump of the thread that caused the program crash:


*----> Stack Back Trace < ----*

FramePtr ReturnAd Param#1  Param#2  Param#3  Param#4  Function Name
0100F9E8 00438172 01010460 0100FBE0 0100FB00 00D85698 !<nosymbols> 
0100FAF4 0048DD45 01010460 0100FC54 0100FBFC 00D85698 !<nosymbols> 
0100FBEC 004C3DBE 0106D028 00000114 0100FC60 0100FC64 !<nosymbols> 
0100FC54 004C3C17 00D8AFC0 00000114 0100FD60 0100FD70 !<nosymbols> 
0100FCDC 004CBDE9 010101F0 00000110 0100FDE0 0100FD70 !<nosymbols> 
0100FD60 004C6FC5 010101F0 00000110 0100FE44 0100FDF0 !<nosymbols> 
0100FDE0 004B63BD 010101F0 00000110 0100FEEC 0100FF00 !<nosymbols> 
0100FE50 004B61B6 010101F0 00000110 0100FF7C 0100FF00 !<nosymbols> 
0100FEEC 004B5C9C 010101F0 00000110 00000001 000001FB !<nosymbols> 
0100FF7C 1020BFD2 00D84058 000001FB 00130178 00D85698 !<nosymbols> 
0100FFB4 77E8B2D8 00D85698 000001FB 00130178 00D85698 !beginthreadex 
0100FFEC 00000000 1020BF20 00D85698 00000000 00000008 kernel32!lstrcmpiW 

Which added nothing to my understanding of what went wrong, beyond it happened at some point after the thread started. Great. Did I mention I’d done a debug build – the kind with all the symbols compiled in? Anyway, I figured switching to the binary output (which I understand is like a unix core file) may provide further explaination.

The format of the binary output from Dr Watson is lost in the mists of time. I had to go to an NT4 server install CD (you have to love the pack-rats who keep the German Server version of NT4 ©1999!) to locate the two necessary files for working with the user.dmp file it generates. The files are DUMPCHK.EXE and DUMPEXAM.EXE.

Running DUMPCHK.EXE gives a little output

C:\...\RetailGateway>dumpchk user.dmp

Filename . . . . . . .user.dmp
Signature. . . . . . .USER
ValidDump. . . . . . .DUMP
MajorVersion . . . . .5
MinorVersion . . . . .0
DirectoryTableBase . .0x0000014c
PfnDataBase. . . . . .0x00000004
PsLoadedModuleList . .0x00000018
PsActiveProcessHead. .0x0000009a
MachineImageType . . .NumberProcessors . . .7528
BugCheckCode . . . . .0x00001f65
BugCheckParameter1 . .0x000000a0
BugCheckParameter2 . .0x00000040
BugCheckParameter3 . .0x00001ca8
BugCheckParameter4 . .0x00d6df65

ExceptionCode. . . . .0xc0000005
ExceptionFlags . . . .0x00000000
ExceptionAddress . . .0x0045b4a9
ExceptionParam#0 . .0x00000000
ExceptionParam#0 . .0x00000000

At which point I got this dialog: DUMPCHK barfs reading the user.dmp file from Dr Watson
“Oh well,” I thought, “I’ll just head on straight to examining the dump, rather that checking it.” Unfortunately, DUMPEXAM.EXE wasn’t on my side. All I got was:

C:\...\RetailGateway>dumpexam user.dmp
unsupported processor type

Which is useless. Which is the sum value of the binary dump from Dr Watson. And, in this case, all of the output from Dr Watson.

Browser vs Website

Am I the only person who uses Alt-D to get to the address bar in Firefox? I suppose I could also use Ctrl-L, or F6, but I’ve settled for Alt-D, probably because it can be easily done with one hand — my left hand — and is close to the bottom of the keyboard, making it easy to find.

Problem is some web sites implement access keys that conflict with this. The default setup for MediaWiki sites uses Alt-D as a shortcut for deleting pages! Thankfully it goes to an Are You Sure confirmation before actually doing it. They seem to have disabled it on Wikipedia, but others still have it.

Likewise, Horde (web mail) uses Alt-B to Blacklist mail senders, conflicting with Firefox’s Bookmarks menu.

Firefox doesn’t appear to have an about:config tweak for turning all such keys off, though altering accessibility.accesskeycausesactivation to False will merely put focus on the link with the access key, not “click” on it.

This article discusses access keys in detail, including listing the requirements for access keys on UK government sites. Alt-5 for FAQ… hmmm.

Binary Output

Last night Owen started experiencing the symptoms of his first cold, which prompts me to talk about communications with babies. Newborn babies have only one output mode: screaming. Communicating with the world is a somewhat limited experience when joy, fear and hunger are all exhibited using the same mode of operation. From observation, crying may mean:

  1. Please feed me.
  2. I need to burp.
  3. I’m cold.
  4. I’m tired, please put me to sleep.
  5. I wish my nappy to be changed.
  6. The { toy | valuable object | fragile object } that I can’t reach – give it to me. Now.
  7. No, not that one, the other one.
  8. I’m bored. Amuse me.
  9. Ow, that really hurts.
  10. Carry me / lift me up.
  11. Holy crap! Don’t let that happen again! Are you listening?

Often, context will allow distiction between these options. It’s like a computer system saying “Something went wrong.” I’ve seen computer systems, particularly embedded ones, behave in a similar way. Often through design. Like, if they give you one red / green LED, then you’ve got green – all is good, red – not so good. You might get away with blinking them, and maybe even combining them to form orange, but there’s only so far you can take that (“Hmm, 600ms blink rate – that must mean that ethernet port two has a receive failure – because a 650ms blink rate would mean RAM failure”). That BIOSes doing their Power On Self Test use the PC speaker to report error codes prior to the video system coming online, I think the maximum number of beeps you’d get out of that was eleven… better pay attention and count them out. And a lot of Common Object Model errors are along the lines of “COM didn’t work because something failed”.

Interestingly, often babies don’t care too much that you understand them. They’ll keep on with the output, secure in the knowledge that you’re doing everything you can to determine what it is that they’re trying to say. And servicing one system fault may merely unmask another – a wet nappy may be followed by the need for a feed.

Screeching may also mean:

  1. This is great fun.
  2. Ha! You found me!
  3. Look at that guy, he’s funny.
  4. Hello, toy. You’re red.

The point being, the obviously inferior nature of binary output means it’s replaced as soon as possible by something else. Talking, outputing to screen, COM+, whatever. Oh, except COM+.

Cathy and I want to increase the output vocabulary of our son by using Baby Sign Language, mainly as a way of avoiding the expected trantrums: apparently, kids can sign much earlier than they can talk – like, children of deaf parents are signing from six weeks of age. Most excellently, I got given a book on the subject for Christmas, and joy-of-joys it was Australian made, so rather than American Sign Language, it was filled with AUSLAN, meaning it will have some use as a language outside on family communication (6500 Aussies – my perceived use rate is higher, because I work on St Kilda Road – home of the Victorian College for the Deaf). I’m seeing some comprehension from him, but I’m yet to see him generate any signs. Having re-read the Wikipedia article on the subject, I’m going to try to sign with Cathy when he can see us. I’ll let you know how this little experiment turns out.