21 Jul

javascript compression tip

I was just reading through the latest article in A List Apart, and there was a little bit of discussion on the following snippet of code:

function getValueFor(data){

  var value;

  if (firstCondition(data)){
      value = 1;
  } else if (secondCondition(data)){
      value = 2;
  } else if (thirdCondition(data)){
      value = 3;
  } else {
      value = 4;
  }

  return value;

}

When compressed with YUI Compressor, that’s reduced to 140 bytes.

By changing it slightly, you can reduce it further:

function getValueFor(data){

  var value = 4;

  if (firstCondition(data)){
      value = 1;
  } else if (secondCondition(data)){
      value = 2;
  } else if (thirdCondition(data)){
      value = 3;
  }

  return value;

}

That’s reduced it to 133 bytes.

I think Nicholas missed a trick, though – by removing all the “else if”s and replacing them with ternary operators, he could reduce it even further:

function getValueFor(data){
  return firstCondition(data)
    ?1
    :secondCondition(data)
      ?2
      :thirdCondition(data)
        ?3
        :4;
}

The above will reduce to 95 bytes. That’s 95, where the previous record was 133.

18 Jul

more music scams…

last year, I wrote about some scams where people claimed to be looking for music lessons for their son or daughter.

So far, I have not had one single student for guitar come to me through email or the Internet. Every single request has been a scam.

Here is an example email I received today from andrewbarton67@yahoo.com (Andrew Barton):

Hello,

I’m Andrea Barton during my search for a Music Instrument Lessons teacher that would always take my Daughter (Gwyn) and I found your advert.Your advert looks great and it is very okay to me since you specialize in the area I am seeking for her. My daughter will be coming to your Country before the middle of July for 2 Months. She is just 15yrs Old, a beginner, I want you to help me teach her music during her stay in the Country because i will not want her to less busy, i want her to engage in something to keep her busy during her stay.

So, kindly let me know your charges cost per week in order for me to arrange for the payment before she travels down to your country.I would also like to know if there is any Text Book you will recommend for her as a beginner so that she will be reading privately at home after the lesson during her stay.

Please Advise back on;

(1) Your charges per 1 hour twice a week for 2 Months?

(2) The Day and time you will be available to teach her During the week?

(3) Tuition address?

I will be looking forward to read from you soonest.

Best Regards.

There are a few things about this which should immediately strike anyone:

  • People don’t usually mis-spell their own name. Is it Andrea (in the text) or Andrew (in the email address)?
  • There is no mention of what instrument the girl is supposed to be learning. Guitar? Piano? Didgeridoo?
  • The weird capitalisation says to me that translation software has been used, and only for some specific words. I can imagine a template that goes something like this: “I’m ________ during my search for a ________________ teacher that would always take my ________ (____) and I found your advert”. Every one of the blanked out words was inserted with capital letters.
  • There’s a lot of talk about countries – “your Country”, “the Country”, “down to your country”. This person obviously does not know what country I am in, yet knows that his/her daughter will be coming to it?
  • As for that, “My daughter will be coming to your Country before the middle of July for 2 Months.” The email arrived at 2 in the morning today. It’s the 18th of July. A real request for upcoming lessons would surely arrive weeks or months before the trip had already started?

There is a quirky little urge in me to take this as far as I can. However, I’m also not made of time, so I won’t bother.

So here’s the warning: NEVER trust an email from anyone you don’t know.

Here’s how this would pan out if I took it seriously:

  1. We agree price and dates.
  2. They send a cheque and urge me to cash it. I go to the bank and do so.
  3. I suddenly receive an urgent email saying there’s been an error and they sent me too much, and to please send back the extra money.
  4. Of course, that involves me writing and sending a cheque of my own.
  5. They then cash my cheque.
  6. Their cheque then bounces….
  7. The student never turns up.

So don’t be an idiot. Either throw these email in the spam directory (or delete it), or have fun trying to get the guy to do ridiculous things, but never take it seriously.

Btw: here’s an example of this same exact person being a bit over enthusiastic with the attempts – 9 copy/paste messages, with two separate daughters, Rita and Marsha – this guy should probably have got the kids lessons when they were younger…