« June 2009 | Main | August 2009 »

July 28, 2009

What are the odds ...?

From the latest BBC Magazine ...

Imagine you've invented a machine to detect terrorists. It's good, about 90% accurate. You sit back with pride and think of the terrorists trembling.

You're in the Houses of Parliament demonstrating the device to MPs when you receive urgent information from MI5 that a potential attacker is in the building. Security teams seal every exit and all 3,000 people inside are rounded up to be tested.

The first 30 pass. Then, dramatically, a man in a mac fails. Police pounce, guns point.

How sure are you that this person is a terrorist?
A. 90%
B. 10%
C. 0.3%

What's your answer ...?


July 24, 2009

Hidden Linux : Games penguins play


Linux games don't get much press but that doesn't mean there aren't any about. In fact there are numerous websites dedicated to the subject (like this one, this one and this one), and even a Wikipedia link list. I've even mentioned the occasional one here in the past. But if you want more than a tiny screen shot and a one-paragraph review, you can't go past Dedoimedo.

Amongst (many) other things Dedoimedo keeps track of Linux games with detailed reviews, plenty of decent-sized screenshots and summaries of quality and playability. He recently posted the seventh part of this on-going series -- you'll find the other parts here -- and it's well worth a look.


<--Previous Hidden Linux      Next Hidden Linux -->

July 14, 2009

Hidden Linux: Regular expressions, by example


Most Linux users avoid regular expressions (or "regex"), and unless you're a programmer you don't really need to know much about them. But a little knowledge can be useful as regular expressions are often presented as an option to enhance searches. You'll find them under More Options in OpenOffice.org's Find & Replace, for example.

Think of regular expressions as a kind of mini-programming language. Rather than go into details -- you'll find a great resource here -- I'll just list some examples you might find useful in your searches.


Metacharacters

Regex will find any character you enter except for the following:

   .   ?   |   ^   $   *   +   [   ]   (   )   \

They're known as "metacharacters" and are part of the regex "language".

The fullstop (".") will match any character except for line breaks:
  Searching on c.t will find catcotcutc2tc#t, etc.
 

A question mark ("?") makes the preceding character in the search optional:
   Searching on colou?r will match colour and color.


The vertical bar ("|") separates alternatives:
   Searching on gray|grey will match both gray and grey.
   Searching on abc|def|xyz will match abc, def or xyz.

 
The caret ("^") matches the start of a string -- which is to say, after any line break:
   Searching on ^blah will only match the first blah in a new line beginning blah, blah, blah

 
The dollar sign ("$") matches the end of a string -- which is to say, before any line break:
   Searching on blah$ will only match the last blah in a line ending in blah, blah, blah

 
The asterisk ("*") matches the preceding character zero or more times:
   Searching on ab*c will match acabcabbcabbbc, etc.

 
The plus sign ("+") matches the preceding character once or more times:
   Searching on ab+c will match abcabbcabbbc, etc. but not ac.

  
Square brackets ("[" and "]") find single character matches:
   Searching on gr[ae]y will match gray or grey but not graey or gry.
   Searching on in[du] will match the ind in Windows and the inu in Linux.

   To find multiple characters, repeat the square brackets:
     Searching on [1-9][0-9] will match all double-digit numbers from 10 to 99.

   Add a hyphen to indicate a range:
     Searching on z[1-3] will match z1z2 and z3 but not z4.

   Multiple ranges are allowed:
     Searching on z[1-3a-c] will match z1z2z3zazb and zc but not z4zd or zA.
     Searching on z[1-3a-cA-C] will match all of the above plus zAzB and zC.

   A caret ("^") inside square brackets reverses the sense of the search:
     Searching on z[^1-3] will match z4z0 and zB but not z1z2 or z3.

 
Brackets ("(" and ")") group a series of pattern elements into a single element:
   Searching on (.pet) will find carpet, parapet and petal.
   Searching on (g..)|(m..) in the string program name will find matches in gram n and me .


The backslash ("\") allows you to search for any of the metacharacters:
   Searching on $2 in the string $2.50 will find nothing because $ is a metacharacter.
   Searching on \$2 in the string $2.50 will find $2.

   Searching on \\ in the string C:\filename will find \.
   Searching on \\\\ in the string C:\\filename will find \\.

   Searching on 1\+ in the string 1+2=3 will find 1+.



Character Classes

The backslash ("\") is also associated with special characters:
     \d matches any digit. Equivalent to [0-9].
     \D matches any non-digit. Equivalent to [^0-9].

     \w matches any alphanumeric character plus the underscore ("_").  Equivalent to [A-Za-z0-9_].
     \W matches any non-alphanumeric character excluding underscore. Equivalent to [^A-Za-z0-9_].

     \s matches whitespace characters -- including tabs and line breaks.  Equivalent to [\f\n\r\t\v].
     \S matches any non-white space character. Equivalent to [^\f\n\r\t\v].

     \t matches tab characters.

     \r matches carriage returns.
     \n matches line feeds.
         Note that Windows uses \r\n to terminate lines. Linux just uses \n.

    \f matches form feeds.
    \v matches vertical tabs.

    \b matches a word boundary:
        er\b will only match the last er in "observer ".
        \bword\b will find "word" in " word ", " word," and "-word." but not crossword or wordy.

    \B matches a non-word boundary:
        er\B will only match the first er in "observer ".

    \A matches the start of a string.
       \A. will match the a in abc.

     \Z matches the end of the string.
       .\Z matches f in abcdef



Quantifiers

Curly braces ("{" and "}") specify the number of times the preceeding character is to be searched:
   Searching on o{2} will match the oo's in good, food and Wooooooo! but not oboe.



Conclusion
By now you'll probably appreciate how powerful regex's can be. By combining metacharacters, you can perform some pretty sophisticated matches. Searching for:

\b[1-9][0-9]{3}\b
will find all numbers between 1000 and 9999.

\b[1-9][0-9]{2,4}\b will find all numbers between 100 and 99999.

(\<(/?[^\>]+)\>) will find all HTML tags.

(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}) will find all email addresses.

((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}) will find all 8-15 character strings with at least one upper case letter, one lower case letter, and one digit. In short, it'll identify all potential passwords!


<--Previous Hidden Linux      Next Hidden Linux -->




July 9, 2009

Sign away your privacy with NZ Post!

New Zealand Post are attempting an outrageous invasion of privacy under the guise of a competition. This week, letters addressed to every household in the country went out offering "An opportunity to win!" a total of $50,000 in prizes. All you have to do to enter is surrender your privacy.

The document, far more detailed than any census form, contains six-and-a-half pages of questions. In addition to your name, address and full contact details they want to know ...

  • About your interests
  • What sports you play
  • What vehicles you own
  • Whether you rent or own your own home
  • How long you've been there
  • How much it's worth
  • Your mortgage rate and when you took it out
  • How big the house is
  • How many people live there
  • Whether you intend to move, build, buy or renovate in the next 12 months
  • Whether you intend to marry in the next 12 months

... and that only takes you to the bottom of the second page! Subsequent sections enquire about your finances, your shopping habits, your travel habits, and then a little "general information" such as:

  • You and your partner's dates of birth
  • Your ethnicity
  • Marital status
  • Ages and sexes of your children
  • Your occupation
  • The postcode of your place of work(!)
  • Your annual income
  • Your sources of income
  • Even what charities you support

In the quarter-page of Guidance Notes they do acknowledge that participation is voluntary and that you can skip particular questions, but how many people -- fooled by the document's semi-official look -- will fill out the whole thing?

This piece of fine print is particularly revealing:
"By undertaking the New Zealand Post survey, you and your partner's name, address and other information you supply ... may be provided to companies and other organisations from New Zealand and overseas to enable them to provide you and/or your partner, with information about products and services relevant to your responses to this survey."
In short, they're going to spam you!

If you're even considering filling out this piece of trash, remember;
  • This is a commercial transaction. I'm guessing that NZ Post won't be giving away your information. They'll sell it, and/or sell services that utilise it. Offering $50,000 worth of prizes to obtain it is chickenfeed.
  • While I acknowledge you'll be able to "check, correct and remove your survey responses", what happens to the information they have already "provided to companies and other organisations from New Zealand and overseas"? Will that be checkable, correctable and removable? I doubt it.
Offering the remote chance of a prize in exchange for personal information is morally dodgy in my book, especially in the middle of a recession. If a stranger knocked on your door and asked about your personal investments, how much you earned and the ages of your kids, you'd tell 'em to bugger off. So why supply such information (and more!) to a bunch of corporate strangers?


July 6, 2009

Is XT over-hyped?

Reports are emerging that Telecom's new XT mobile network has been over-hyped. Surely not! Not Telecom, the company that "unleashed broadband" with their Go Large plan of 2006? The plan I reported on and charted on this very blog? The one that resulted in a complaint to the Commerce Commission and an eventual prosecution? No way! Not possible ...

(Have you tried XT? What's been your experience? Answers below ...)


July 2, 2009

Make way for open source!



Rick Hodgin has an interesting opinion piece on geek.com. In spite of its clumsy title -- "Death knell heard for Microsoft and really all proprietary efforts" -- its a well written piece on why you should start getting comfortable with open source.


... consumers don’t really care whether or not they have Windows-powered devices or something else. It is the vendors themselves, the manufacturers and carriers who are saying ”No„ to Microsoft ... opting instead for the platform which will get the job done (perhaps even with better graphics, speed, less bugs, faster update times, etc.) while making them more money. You see, a lot of the expense in Windows-powered devices does not come from the device itself, but from the Windows license paid to Microsoft, which for netbooks is reportedly up to $50 per machine, a fee the OEMs must collect by passing along that expense to end consumers.


He reckons corporate use is creating a snowball effect ...

As more and more companies walk away from Windows ... their developers are forced to tweak and enhance existing libraries. And, since these are all open source efforts, the enhancements made by company Z are filtered into the products available for companies A-Y as well.   

And amongst other things he cites the maturity of Linux and its responsiveness to incorporating new hardware developments or even simply patching bugs.

Linux has become mature, open-source has proven it can be a viable solution for businesses, and that the expenses involved in applying their own personal paid developer staff toward efforts which ultimately are given away for free, in the long haul are actually far more cost effective than paying continuously for proprietary access to systems, such as those provided for by Microsoft and Windows-based products.

The French police reckon they saved €50 million switching to Linux, the New York Stock Exchange did it a couple of years ago and Amazon have been using it for almost a decade. If you're a user of Firefox, Thunderbird, Gimp, Blender, Audacity, NVU, OpenOffice.org, Apache or MySQL you're already part of the movement. And if you're not, it really is worth a look!