This is not a blog. So sue me!


Crikey, things are looking up!

Tuesday, November 27, 2007

Two types of programmers

iBanjo's post and Jeff's about the 80-20 rule when it comes to indifferent-excellent programmers are a bit harsh IMO. It's an exaggeration to make a point I guess. I'm sometimes in the 20%, sometimes in the 80% - depends on what applications, environment, level of expertise, and interest.

However, it brings up something very interesting, which is programmer productivity. I do strive to improve my personal productivity, and tell colleagues about useful tools. As the tools get more and more capable, people get more productive - as long as they can be arsed.

For text, computers allow people to produce more than typewriters which were more efficient than fountains pens which were better than quills. At each step the productivity mapping against the cost of a skilled worker, was to the benefit of everyone (well...perhaps that is arguable; imagine the ink well-fillers laid off when the fountain pen was introduced. :-)

With programmers, a higher degree is not necessary to be able to write a program. We no longer have to enter every character in a form for a data-entry clerk to type in. Or use a card punch. We do our own typing and the systems give us far more leverage than they used to. At the same time, we are encouraged to become lazy with things like memory allocation or cleaning up comments (yes, children, there were systems that only allowed 1000 lines of code, comments included. You have never seen such a sad girl as when I had to strip out all my lovely comments to get that darn thing to take the rest of the code :)

So we are all the more productive, in theory, and there are a lot more of us, and we're producing more...but...a heck of a lot of it is ending up being thrown away. All these startups, perhaps one in a hundred is still going after 5 years*. Perhaps one in a thousand is flourishing**. Most code that is written is being discarded without earning a real penny (I don't count IPOs and other stock market artifacts, I mean real profit for code). I think my most long-lived code was for a hydroelectric plant...embedded in the display panels representing a switch yard, it will probably live longer than I will, but the company I worked for took a big loss on the project.

I am not sure what can be done, apart from contributing to open source projects. That does seem to be a way to give the useful parts of a project to some kind of posterity.


* - unsupported assertion
** - unlikely

The first spam in the world*

This is how I got a shiv in to one of the first spammers. There's a footnote to explain why I think spam should be punishable by the death penalty. This is going to be a long post, so get comfortable.

In the late '80's and early '90's, my children, I used a discussion network called USENET
in the same way people today use on-line forums, interest groups and social networking sites. I was a contributor to a couple of groups about recreational sailing. I owned a boat, had some experience and I was able to pontificate to the grateful and less-experienced masses.

All this changed, when spam started to load up my email inbox. Every post I made started to become the subject of a couple of lame attempts to sell things to me. It wasn't even sailing-related stuff. Eventually, the volume of spam became so large that got I fed up, changed my email address and stopped participating in the groups. It had been a pleasant pasttime, and I was very unhappy that it couldn't continue, as there isn't much sailing up here when the water gets hard.

In the couple of years between the arrival of the first spam and my surrender of my right to free speech (which is how I feel about it), I encountered a particularly hapless spammer. She (for it was apparently a female) had strung together a couple of email messages each containing advertisements for about six different products. (These were the days when there were few enough spam messages that I wrote indignant responses back to senders :-)

Among the products in her messages were these:
  • Printing company in North Carolina
  • Adult videos for sale somewhere unspecified
  • A sale at a lumber store in Raleigh
  • "Wedding party favors" and wedding services (whatever they may be)
  • Pet store
You get the picture.

I leaped into action...because the spammer had given out her customers' email addresses in each of the little ads, and the email addresses were all from the same domain name, I thought that a little direct action was worth trying. Of course...the sender of the spam had blocked responses, but her customers were relying on incoming email to do their business (I presume that was her pitch to them).

I sent a dozen little emails, along the lines of "your message is unwelcome because I am paying to pick up my email" (yes we did pay per byte in those days). The best one was like this:

Dear wedding party favors vendor,
I am shocked and appalled that I have received your commercial message along with that for a pornographic film purveyor, obviously from the same service. I would not use your company because you are associated with this service provider who is promoting unsavory and possibly illegal material.
Yours etc.
Sue W....

(slight emphasis on nice female persona, presumably a target for wedding party stuff.)

The reaction was gratifying. Within the day I received a choleric email from the spammer. This was nearly a thousand words of outrage, threats, denial of wrongdoing, denial that I could possibly be upset by a suggestion that I should consider her porn-vending customer's products, how could I stop her constitutional rights to free speech, etc. and in closing, with the fact that she had blocked responses from me in future. I guess it would have been excessive to ask if I was now off her mailing list...

It was a good day. I felt much better. Obviously she (or perhaps a disguised he) had been reamed out by some or all of the targets of my messages. Revenge is a confession of hurt, but it was sweet.

Footnote: Why I think spammers should be executed:

I do not think that the death penalty is right. I've lived in both England and in Canada and capital punishment hasn't been allowed in either country for a long time. However, I think that spammers and those that enable spammers should be taken out and shot. Nah...something more spectacular.

These people are clogging up the arteries of the Internet, costing millions, infringing on the rights of the digital commons, if you like, to sell me stuff I don't want, can't use, can't understand. They try to take over machines for nefarious purposes, but most of all, they have cost me and many others, their right to free discourse in such as USENET groups and many other forums. The fact that many sites require registration, login, visible-only code words and other tedious impediments is due largely to these scum. They know better, but do it anyway.

Off with their heads!


* - an exaggeration, and a downright lie.

Thursday, November 15, 2007

ActionScript 2.0 function to convert milliseconds to HH:MM or MM:SS

These functions are basically the same, convert a Number in milliseconds to a displayable time string HH:MM or MM:SS:

public function convertMillisecondsToHHMM (millisecs:Number):String {
    var hour:Number;
    var min:Number;
    var hourStr:String;
    var minStr:String;

    var lenMin:Number = millisecs/1000/60;
   
    if (lenMin == undefined || lenMin <=0) {
      return "00:00";
    }
    else if(lenMin > (99*60)+59){ // greater than can be shown in 99:59
      return "99:59";
    }
    else {
      // work out how many hours and mins and concatenate them for the time
      hour = Math.floor(lenMin/60); //get the number of hours
      min = Math.round(lenMin%60); //get the remainder 0-59 mins
     
      // convert to strings
      hourStr = hour.toString();
      minStr = min.toString();
     
      // if minStr is 2 character, leave it alone, if it's 1 char, pad it, if it's more than 2 make it "99"
      if (hourStr.length == 1) {
        hourStr = "0" + hourStr;
      }
      else if (hourStr.length > 2) {
        hourStr = "99"; // this is impossible!
      }
      // if secStr is 2 digits, leave it alone, if it's 1, pad it, if it's more than 2 make it "99"
      if (minStr.length == 1) {
        minStr = "0" + minStr;
      }
      else if (minStr.length > 2) {
        minStr = "59"; // this is impossible!
      }
     
      return hourStr + ":" + minStr;
    }
  }
 
  public function convertMillisecondsToMMSS(millisecs:Number):String {
    var min:Number;
    var sec:Number;
    var minStr:String;
    var secStr:String;

    var lenSec:Number = millisecs/1000;
   
    if (lenSec == undefined || lenSec <=0) {
      return "00:00";
    }
    else if(lenSec > (99*60)+59){ // greater than can be shown in 99:59
      return "99:59";
    }
    else {
      // work out how many minutes and seconds and concatenate them for the time
      min = Math.floor(lenSec/60); //get the number of minutes
      sec = Math.round(lenSec%60); //get the remainder 0-59 secs
     
      // convert to strings
      minStr = min.toString();
      secStr = sec.toString();
     
      // if minStr is 2 character, leave it alone, if it's 1 char, pad it, if it's more than 2 make it "99"
      if (minStr.length == 1) {
        minStr = "0" + minStr;
      }
      else if (minStr.length > 2) {
        minStr = "99"; // this is impossible!
      }
      // if secStr is 2 digits, leave it alone, if it's 1, pad it, if it's more than 2 make it "99"
      if (secStr.length == 1) {
        secStr = "0" + secStr;
      }
      else if (secStr.length > 2) {
        secStr = "59"; // this is impossible!
      }
     
      return minStr + ":" + secStr;
    }
  }

getDateString: ActionScript 2.0 function to make a readable numeric date string

The getDateString returns the present date/time in the form of a readable (just) string down to milliseconds e.g. 20061231135901999. It uses the leftFill function below:

//get the current date/time and make a string
//in the form yyyymmddHHMMSSmmm
private function getDateString():String
{
var today:Date = new Date();
var dateString:String = today.getFullYear().toString()
+ leftFill((today.getMonth()+1).toString(),"0",2)
+ leftFill(today.getDate().toString(),"0",2)
+ leftFill(today.getHours().toString(),"0",2)
+ leftFill(today.getMinutes().toString(),"0",2)
+ leftFill(today.getSeconds().toString(),"0",2)
+ leftFill(today.getMilliseconds().toString(),"0",3);
return dateString;

}//getDateString

// This function will take a string (1-3 characters)
// and right justify it with fill characters padded to the left for the width required.
// Designed for use with Date/time fields 1, 2 or 3 in length
// if it is called on the wrong size inString it will return the correct size field of fill chars
private function leftFill(inString:String, fillChar:String, fieldWidth:Number):String
{
//make sure the fill character is only one character long!
var fill = fillChar.substr(0,1);
if (inString.length == fieldWidth)
{
return inString;
}
else if (inString.length == fieldWidth-1)
{
return fill + inString;
}
else if (inString.length == fieldWidth-2)
{
return fill + fill + inString;
}
else
{
return ((fill + fill + fill).substr(0,fieldWidth));
}
}//leftFill

removeString: ActionScript 2.0 function to remove delimited strings

This function is quite useful.
It will remove strings that are delimited by known characters, any number of times from a target string. For example to remove all the markups in an XML node and just leave the text, call it with this snippet:
tempString = pNode.toString();
while (tempString.indexOf("<") != -1) {
tempString = removeString(tempString,"<",">");
}

function removeString(input:String, sDelim:String, 
eDelim:String):String {
var startIndex:Number = 0;
var sDelimIndex:Number = input.indexOf(sDelim);
var eDelimIndex:Number = input.indexOf(eDelim);
var endIndex:Number = input.length-1;

var output:String = "";

if (input == undefined ||
input == "" ||
sDelimIndex != -1) {
//get the substring before the delimiter, if any
if (startIndex < sDelimIndex) {
output += input.substring(startIndex,sDelimIndex);
}
if (eDelimIndex != -1) { // if any end delim
// get the substring after the delimiter, if any
if (eDelimIndex < endIndex) {
output += input.substring(eDelimIndex+1,endIndex+1);
}
}
}
else {
//nothing to be done
output = input;
}
return output;
}

Wednesday, November 7, 2007

Spam going down

Is it me, or has the level of spam gone down?

Gmail has a good spam filter (I've only had to mark 3-4 spam messages in the last few months). But I do scan the list of spam in case there are any false positives (only one, years ago). In doing so I had noticed that the level of spam was going up and up and the subject was largely what is delicately called "enlarging one's manhood".

As an aside, I have never, ever, had trouble enlarging a man's penis at will, by at least four inches (10 cm). And it only takes a minute or so, not four weeks...ahem.

Anyhoo, I was reading in the Economist that a second Russian spammer within a year or so had been assassinated (hooray!*). Guy was making a couple of mil a year spamming on behalf of dodgy on-line pharma-product outlets.

However, in the last couple of days, I have noticed the torrent of spam is less...perhaps it's just me, but in 3 days I have only 18 messages, and the profile is this:

Watches: 2
Penis enlargement: 7
Pharmacy: 6
Make money/loans: 3

So penis enlargement is definitely going down.



* I have never been, nor ever will be, an advocate for the death penalty, except for spammers. They are the worst kind of parasites and should be put down. More in another post.

Flash: You're _so_ modal!

It's interesting to pick up and try to use a technology after it's been around for a while. Back in the '90's I had the experience with Microsoft tools, but since then I have been working in Java web technologies starting from when they were fairly new.

I have spent the last few months digging into Flash development, learning the IDE (CS3) and ActionScript. The IDE is fairly strange and rather old-fashioned feeling. Perhaps it's just a different way of thinking from the "Dreaming in code" text-based world of conventional programming.

Flash is extraordinarily powerful in some respects but, in my opinion, lends itself to poor design decisions, less than easily supportable code and lots of maintenance headaches. All the more work for developers in the future, I think!

Some areas of the IDE have been neglected, the ActionScript editor and the debugger most prominently. Modal search boxes that have to be dismissed...grrr!

I have been guided by our new Flash designer, Derek. He can really do amazing things using Flash to create visual components and interactive demos etc. He's been working in this tool since the advent of Flash, focussed on the visual aspects, less on the programming ones. However, I would not have easily discovered some of the more esoteric things without him.

The most irritating thing about the whole experience, and this might seem petty, is that Flash is so...modal...everything that is does (publish, test movie, debug movie) takes control of the entire computer. It's all about you, isn't it, Flash? An incoming IM which takes focus in the middle of a Flash publish (compile/build movie) can crash the IDE! You cannot start publishing a big movie and switch to another window...Flash doesn't play well with others.

I'm told that until recently one couldn't run anything else on a development workstation except Flash. Resource hog...however we have an OS that can do multitasking windows and why should Flash be the one to say "Wait up everyone, I'm about to Publish a Movie! Stand back!!" Sounds like poor fundamental tool design to me. Very 1980's.

It's a clipper-ship technology. Huge, useful, really impressive, very elaborate and so on, but labour intensive, accident prone and inefficient. I hope there is a steamship coming up somewhere.

Derek's predecessor, Chris, who moved on to a better life in another place, tells me he is using some newer Adobe tool chains: Flex and ActionScript 3. More stuff to look into!

I have loaded ASDT into Eclipse and this helps a lot when editing ActionScript. However for the price that Adobe charges for their tools, am I wrong to expect more?

Contributors

St Lawrence Rowing

Test content from SLRC