Links for Irish VIPs
Tue, Apr 30, 2013
Filed under Accessibility, Web & Internet
Tags: blind, ireland, irish, links, screen reader, visually impaired
Below is a small collection of links of interest to blind or visually impaired people in Ireland. Please come back from time to time to check for updates.
Scan Text Files for Control Characters
Tue, Apr 16, 2013
Filed under Batch
Tags: control character, scan, text file, wildcards
A large part of programming in Batch is taken up with processing text files. By “text file”, I mean a plain text file with Windows line endings. And “plain text” means no nasty control characters such as Control-Z or the infamous Null Character.
For example, the former is used by copy /a and type as the end-of-file marker, while set and echo interpret the latter as the end of input.
So it’s always a good idea to scan any text files of unknown origin for these troublesome characters before doing anything else. Which is why I wrote the ctrlscan.cmd program described below…
What Is Easter?
Mon, Apr 1, 2013
Filed under Humour
Tags: classic, easter, heaven, jesus, pearly gates, st peter, three blondes, true meaning
Happy Easter, everybody! Here’s a classic joke for you. If you haven’t read it in a while, it will make you laugh all over again. And if you haven’t read it before… well, you’re in for a treat!
I don’t normally reproduce jokes that are already all over the web like a rash, but I couldn’t find out where it originated from, and besides, it’s one of my favourites.
Irish Citizenship Test
Sun, Mar 17, 2013
Filed under Humour
Tags: 2fm, irish citizenship test, poster, rick o'shea, st patrick's day
Happy St Patrick’s Day to all my readers!
Hope you enjoy the following. Apologies if you’ve read it before. But it’s worth revisiting because it’s guaranteed to make you laugh—especially if you’ve had a few whiskeys!
Plus I added a few links and additional material you mightn’t have seen elsewhere.
Flowerpot Faux Pas
A class of schoolkids were given a project to decorate a flowerpot they could take home and show off to their parents. They wanted a plant that was easy to take care of, so it was decided to use cactuses.
Generate Any Control Character
ASCII has 33 control characters. Many of them are defunct or are used for purposes for which they were not originally intended. Most of them are unprintable and some can cause problems if not filtered out of input. All the same, a handful of these characters have proven to be indispensible when it comes to performing certain tasks in Batch.
In this post, I’ll show you commonly-used techniques for generating specific control characters, as well as two lesser-known methods for storing almost any control character in a variable. But finding uses for them is an entirely different matter. One which will be covered in an upcoming post.
DIY Code Blocks on Posterous
Thu, Jan 10, 2013
Filed under Blogging
Tags: alternative, code block, css, diy, html, posterous
The following first appeared on my old blog on Posterous in February, 2012. I moved it here because I’m afraid they’re going to pull the plug on Posterous any day now.
I realise this topic is mostly of academic interest these days, but I decided to archive an updated version of the post for posterity. And the fact that I put a lot of work into it, dammit!
Copy a Long Line from a Text File and Save It to a New File
Thu, Dec 20, 2012
Filed under Batch
Tags: copy, inefficient, long line, save, text file, ugly, workaround
This is a follow-up to my recent post on how to store the nth line of a text file in a variable. The solution given won’t work for extremely long lines because the line requested by the user is stored in a variable and variables in Batch can only hold up to 8191 characters.
If you need to select an extremely long line from a file and save it to a new file, there is a workaround. But it ain’t pretty, or efficient. It involves more, findstr, and a whole lot of temporary files.
Average Speed Over Both Journeys
Fri, Nov 30, 2012
Filed under Mathematics
Tags: average speed, counterintuitive, drive, home, puzzle, work
This question is sometimes asked on the GMAT exam, allegedly.
A woman drives to work every morning at an average speed of 30kmph. In the evening, she drives home the same distance at an average speed of 40kmph. What is her average speed over both journeys?
HINT: The answer isn't 35kmph!
Store Nth Line of a Text File in a Variable
This question crops up from time to time: “How do I save a line from a file into a variable?” It seems like a perfectly reasonable question to ask. You might think the answer is equally as straightforward. Until you try to write a Batch program to do it, that is…
Convert Newlines from Windows to Unix
16-Apr-2013: Updated source code. Rewrite of post.
Everybody knows the old trick of converting a text file with Unix newlines (LF) to Windows line-endings (CR+LF):
more unix.txt > win.txt
(Note that more will wait for a keypress after scrolling 65,534 lines, even if output is redirected to a pipe or file.) But converting from Windows to Unix is a far more complicated affair. After searching failed to find any straightforward Batch solutions—apart from this meandering thread on DosTips—I cranked out win2unix.cmd as outlined below.
Ensure Text Files End with a Newline
From time to time, you may find yourself building up a file comprised of command output and snippets from other files. On these occasions, you will no doubt be using pipes and redirection, and commands such as copy, findstr, and type.
Which is all well and good except that you could easily run into trouble if some of the bits and pieces you're cobbling together end with a newline while others don't. For instance, type will join the last line of a file that doesn't end with a newline with the first line from the next file, forming one long line. Probably not what you want.
And according to Dave Benham in his treatise on the Undocumented Features and Limitations of FindStr, findstr under XP and Win7 will hang if redirected input doesn't end with a linefeed character.
Wayback Machine Bookmarklet
Thu, Sep 27, 2012
Filed under Web & Internet
Tags: bookmarklet, favelet, internet archive, javascript, url, wayback machine
Have you ever returned to a web page you hadn't visited in a while only to discover it no longer exists, or has changed beyond all recognition? If so, one way to banish those dreaded “404 Not Found Blues” is to try your luck with the excellent Internet Archive's Wayback Machine.