Forgot your password?
typodupeerror
Perl

Journal: I love perl

Journal by tmhsiao
I love being able to write something like this:

perl -F: -ane '$hash{$F[0]}++;} for my $key (keys %hash) { print "$key: $hash{$key}\n"; } {' <file>
Programming

Journal: I hate programmers sometimes.

Journal by tmhsiao
Actual code from my company's codebase:

     $playlist{$key}[4] = $line[4];
     $playlist{$key}[5] = $line[5];
     $playlist{$key}[6] = $line[6];
     $playlist{$key}[7] = $line[7];
     $playlist{$key}[8] = $line[8];
     $playlist{$key}[9] = $line[9];
     $playlist{$key}[10] = $line[10];
     $playlist{$key}[11] = $line[11];
     $playlist{$key}[12] = $line[12];
Programming

Journal: Using XML

Journal by tmhsiao

At a couple of my old positions, various people of varying levels of education always kept coming up with the hare-brained idea of making XML the defacto format for anything, from internal data files to configuration files. Granted, there is an advantage to this--there are XML parsers either built-in or readily available to just about every programming language in common use nowadays. Not that said people ever thought about using those parsers--they were just on the whole XML bandwagon from reading hypey trade mags.

The author of Thinking in Java, Bruce Eckel, in his article "Simplifying XML Manipulation," wrote the best description of why I personally think that XML is a poor choice for internal data files and just fucking stupid for config files:

My initial strategy for XML was to recognize it for what it is -- a platform independent way to move data from one place to another -- and then, as much as possible, to ignore it and assume that I would only have to actually look at XML when I was debugging something...

Fedex and the Post Office (and UPS apparently also works this way) -- [use] something that's almost XML-RPC, but it's not, and you're expected to assemble your XML by hand and then use HTTP to send it to the server, then unbundle the XML that comes back...

The point being that here's a case where the XML should have been invisible, but you have to mess with it by hand.

User Journal

Journal: Synching time with Windows XP

Journal by tmhsiao
Apparently everything written about Windows 2000 doesn't apply to Windows XP when it comes to synchronizing time with NTP. "net time /set" does not work, even after the appropriate "net time /setsntp:server" command. Windows XP requires the following:

C:\>w32tm /resync

There is no longer a '-once' option to the w32tm program, and you shouldn't need to stop and restart the w32time service for this to take affect.

User Journal

Journal: WTF?

Journal by tmhsiao
C:\>net time /set
Could not locate a time-server.

More help is available by typing NET HELPMSG 3912.

C:\>net helpmsg 3912

Could not locate a time-server.

C:\>

Microsoft, I hate you with every fiber of my being.
User Journal

Journal: Python on Windows CE

Journal by tmhsiao
The following line of code:

for tmpfile in os.listdir('/some/empty/directory'):

Throws the following error when run on Windows CE:

Traceback (innermost last):
  File "\Program Files\Python\Lib\myscript.py", line 148, in ?
    for tmpfile in os.listdir('/some/empty/directory/'):
ValueError: Invalid path

Go figure.
PHP

Journal: null == 0...

Journal by tmhsiao

Looking at the following code:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif ($foo == 0) {
  echo "Foo is 0";
}

If $foo is not defined (as in the case of, say, an unposted $_POST variable), $foo == 0 evaluates as true.

All null values equal 0 apparently, forcing any specific zero-check to look as follows:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif (($foo == 0) && (is_numeric($foo))) {
  echo "Foo is 0";
}

Sometimes I hate this language.

PHP

Journal: Ummm.... why would you do that?

Journal by tmhsiao

count (PHP 3, PHP 4 , PHP 5)
count -- Count elements in a variable
Description
int count ( mixed var [, int mode])

Returns the number of elements in var, which is typically an array (since anything else will have one element).

If var is not an array, 1 will be returned (exception: count(NULL) equals 0).

Except, for some reason, count($var) where $var == NULL returns 1.

WTF?

User Journal

Journal: Do not do this. 1

Journal by tmhsiao
This is the kind of programming that gives Perl programmers the reputation of being sloppy and their code unmaintainable (a snippet of code from a major project at my former job):

foreach $data ( sort keys %data ) {
   push @data, $data{$data};
}
PHP

Journal: Explain this to me. Win prizes.

Journal by tmhsiao
In going over some code that I need to put up, I found the following function (names have been changed to protect the ignorant):

function my_uniq_array($myarray){
  $temparray = array_unique($myarray);
  $i=0;
  foreach ($temparray as $value) {
    $new_array[$i] = $value;
    $i++;
  }
  return $newarray;
}

Can someone explain to me why it would be necessary to do such a thing?
User Journal

Journal: Perl Win32::MsgBox quick ref.

Journal by tmhsiao
Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])

[EXT] Create a dialogbox containing MESSAGE. FLAGS specifies the
required icon and buttons according to the following table:
        0 = OK
        1 = OK and Cancel
        2 = Abort, Retry, and Ignore
        3 = Yes, No and Cancel
        4 = Yes and No
        5 = Retry and Cancel

        MB_ICONSTOP          "X" in a red circle
        MB_ICONQUESTION      question mark in a bubble
        MB_ICONEXCLAMATION   exclamation mark in a yellow triangle
        MB_ICONINFORMATION   "i" in a bubble

TITLE specifies an optional window title. The default is ``Perl''.
The function returns the menu id of the selected push button:

        0  Error
        1  OK
        2  Cancel
        3  Abort
        4  Retry
        5  Ignore
        6  Yes
        7  No
User Journal

Journal: Win2k: Internet Connection Wiz: Connection Name problem

Journal by tmhsiao

From a usenet post to alt.os.windows2000 by Gerry Kroll:

Error:

"Connection to ....." is not a valid name. The entry name must contain at least one character that is not a space and cannot begin with a period. Choose a different name

Solution:

Your problem is a corrupt RASPHONE.PBK file. It has a false end-of-file character in it. Essentially, the EOF character defines a file size that doesn't match what's recorded in the folder's directory.

Since you're going to re-create the entries anyway, simply search for all occurrences of RASPHONE.PBK and delete them.

User Journal

Journal: Python: Strip Leading Zeroes

Journal by tmhsiao
An algorithm to strip leading zeroes off of a string when you're restricted from using regexes (say, on a Windows CE machine running Python 1.2).

ii = 0
while (string[ii] == '0'):
     ii = ii + 1
string = string[ii]

A morsel of genuine history is a thing so rare as to be always valuable. -- Thomas Jefferson

Working...