Checking my paper mail, I noticed that Australia Post is peddling a new stamp. Except it looked like two stamps. Now usually stamps are tiny postcard of cultural history – endangered species, famous people/places and the like, but one day you run out of ideas, and that’s how we get this– the Meta-stamp – a stamp depicting… errrm… a stamp!
I guess it’s kind of similar to when Hollywood remakes classic movies.
Can’t wait for the next one – the stamp of a stamp of a stamp. A bit like the infinite cat project.
This was forwarded to me a little while ago, by now making the rounds through the “tubes”. Not sure if it’s a group of factory workers with too much time on their hands (a spectacular breach of Occupational Health & Safety, surely), or an equally unsafe attraction where you actually pay for the privilege of experiencing your face being millimetres away from being ground into the pavement by a giant robot arm. Step right up.
I like to read developer articles. Some of the best dev articles (in my opinion) for the .NET space are published in the MSDN magazine, available online for free. Sometimes it’s convenient to print them, to read on the train, or to make notes in the margins. But Microsoft wants to make that difficult for you.
They do this in two ways:
1.Refusal to remove a print redirection tag in the header of the articles. The print redirection tag exists to suggest to browsers where they should go in order to get a more printer friendly version of the page. For example, say you look at this article. If you are in IE7 or IE8, when you go to File->Print Preview, you’ll see a version of the page that’s entirely unlike what the original page looked like. That was achieved via this directive in the header: <link rel="alternate" media="print" href="/en-us/magazine/dd569757(printer).aspx" />. The browser sees this, takes you to the “print version”, and prints it. Note that Firefox seems to ignore this, and stubbornly refuses acknowledge that the creator of the page went to the effort of providing an optimised print page.
But ignoring that… so far so good – but then the web designers did something weird. The print version of the page (to which you can get by clicking the “Print View” button on the page) has a printing header link… back to itself. This has the effect of cancelling any changes you performed on the page, like expanding code regions etc – the page reloads just before printing.
Now recently, MS seems to have realized this, but their fix was nothing short of bizarre – add a script to automatically expand all the collapsed regions on load. Why does the print view redirect to the print view at all?? Anyhow, the bizarre fix kind of works, in the past you couldn’t actually expand the collapsed regions, as they’d collapse as soon as you tried to print (because the page reloads). Now they’re open by default. But this doesn’t work for Firefox - when you print in Firefox, the regions are collapsed, the script for some reason doesn’t execute, and you’re off trying to expand all the regions by hand.
2.Somebody forgot their stylesheets. The generated page is full of class attributes, but the stylesheet definitions for a lot of them are missing:
There is no differentiation between headings and text. The class attributes are there.
So what to do? Greasemonkey, that’s what. Greasemonkey is an add-on for Firefox, that allows you to execute custom scripts after the page loads. You can do funky things like tweaking the specific HTML elements, adjust styles etc. There is a handy online reference, that gets you started using it in no time. So now every time I visit an MSDN print page, the styles are magically fixed.
The resulting script I present here improves on the page in more ways than the above features – I’ve changed the code font to Courier, as that’s a far more common programmer font family, and removed items that “float”, upsetting printing, as well as removing the Copy Code link.
Here is are some snapshots of the results, side by side (“before” on the left, “after” on the right):
Header and “Sidebar” entries (I’ve moved the “Sidebar” element to appear inline, for better printing):
Section headings and code snippets (no need for the grey background in my opinion, or the “Copy Code “link):
The entire script is below, enjoy (feel free to comment on any styles that I might have missed):
The obvious barrier of entry is that you have to know how to actually add a script to Greasemonkey. An exercise left to the reader.
The MIX 09 conference is well over in the US, and all the content is now available online, all the presentations were recorded. You can even get them all on the one page, instead of search the presentations for each day:
The iPod Nano is a beautiful thing. That is unless you want to do something custom. So it is with the lap timer in it. There is no obvious way of synchronising the timer logs with the computer. Even if there is a way in ITunes (I’m pretty sure there isn’t), the point is moot, as I don’t use ITunes (instead I’m using the wonderful ml_ipod plugin for Winamp). This is “suboptimal” if you want to, for example, use the lap timer to chart your jogging progress over the course of a year. You want to crunch those stats in Excel or some such, you certainly aren’t going to copy them from the screen.
The information on the web is a little sparse on this matter, but there are a number of applications that will let you do this. The one that caught my eye was http://wafflesoftware.net/ipodtimer/ which luckily provided source code (Mac OS X only – aren’t we feeling exclusive). A relatively trivial exercise in parsing. The timer format was loosely described in the TimerFormat.txt in the zipped source. At least detailed enough for me to whip up an implementation in C#. Hence this post.
The underlying format is a binary file. Time to dust off .NET’s BinaryReader. The below method ReadTimerEntries(string filepath) will read in an iPod timer file (on my Nano it’s /IPod_Control/device/timer) and produce a list containing the date of the recording, and the associated laps. From there you have all the info you need. Anyway, it works for me, on an iPod Nano (3rd gen). I don’t imagine that the file structure changes much though.
Ahh, the Terminator movie that we’ve always wanted – entirely set in the future, focusing on the war between man and machine. I’ve always wondered when they would show the future they hinted at, a void slightly filled by the Terminator TV series (Sarah Connor Chronicles). Another point of note is that this coming instalment is but the beginning of a Terminator revival – part of a new trilogy apparently. And you can’t go wrong with Christian Bale as John Connor.
Firstly, a correction. Last time I posted about Powershell, I came up with something that did the job, but was, well, a tat long winded. Kind of like building a skyscraper so that you can store garden tools in the basement. Basically I didn’t realise that the Sort cmdlet already had a –Unique switch. Thanks to Stephen Mills for pointing it out:
Now to the business at hand – reading database tables. Consider a situation where you’re asked to read in the data in a database table into some readable form, for reference, printing or whatnot. Rather than using SQL Management Studio to query the results, selecting the entire results grid, copying it, pasting into Excel (if available on the same machine), or into a text file, then getting it into Excel – you could just use Powershell to connect to the DB and dump out the results into a HTML table. Behold:
# Parse Database tables
# This will connect to a database, do a "select *" on a table or view, and produce a html file with the data in a table.
# Note: don't forget to loosen up your execution policy "Set-ExecutionPolicy Unrestricted"
# and the connection string is ADO style : "Data Source=database;Initial Catalog=oesc_offerman;User Id =username;Password=password;Trusted_Connection=False;"