Howie Mandell trying to look hard.
Howie Mandell trying to look hard.

Javascript appears all over the internet. You can be pretty sure that your favorite websites use a LOT of javascript. You see it every time a website creates a pop-up advertisement, sends you an alert, lets you bookmark their page, or interacts with you in some way.

I’ve written some pretty cool (in my nerdy opinion) things in javascript:

  • A blackjack strategy simulator. You tell the program how many decks, when you want to hit, stand, double down depending on the deck count, and it will run through a given number of hands – telling you how much your strategy has won/lost overall.
  • A “Deal or No Deal” odds simulator. The program calculated the average of the remaining unopened suitcases – to compare against the Banker’s offer. It made rudimentary guesses about how much the Banker would offer. There has been some incredible and complex analysis of how these offers are created.
  • A billing program. It had separate timers for different tasks, tallied time, expenses, ability to save reports, and create invoices for different clients.
  • A simple program for tallying points for gin rummy.
  • Several small programs for solving various internet website puzzles.
  • Several small tools which allow me to write other programs or web pages more efficiently.

I’ve written innumerable other mini-programs which either had a very limited or one-time use or which I never developed into an actual program. One example was a program that would help me quickly search muliple ebay auctions and compare the various prices. Another was a Sudoku puzzle solver which I never completed.

I recently gave a brief overview of my permanent disability and workers’ compensation benefit calculators. In that post I wrote a little bit about how my online benefits calculators work. Since then I’ve posted about my use of javascript and PHP in creating these permanent disability and permanent impairment calculators.

As I’ve mentioned in those prior posts, both javascript and PHP have inherent downsides. My very first attempt at online benefits calculators using javascript and ASP actually suffered from all of the downsides of javascript and PHP. Those first calculators used tons of user’s computers’ resources, bandwidth, and server power. However, learning more about AJAX enabled me to build a set of calculators which benefited from the strengths of javascript and PHP while minimizing, if not eliminating, their weaknesses.

The acronym “AJAX” refers to “asynchronous javascript and XML” – a collection of other technologies which allow a webpage to communicate with a web server without requiring an entire page download.

Example 1: A calculator without AJAX calculating “6 x 7” would send information to be calculated to the web server. The web server would then respond by giving you an entirely new page with the answer, “42”. However, in order to download that answer you would need to download a whole new page – and all the images, text, and code associated with it. Even a normal web page could be between 30,000 and 300,000 bytes in size.1

Example 2: A calculator with AJAX calculating “6 x 7” would send information to be calculated to the web server. The web server would then respond by sending back just the answer, “42”. This would be 2 bytes.

If my calculators needed to download of 300 kilobytes for every single operation, a simple calculation could take about 30 seconds on dialup and a full 1 second on broadband. Although 1 second doesn’t seem like a long time – it is in the internet age. Most of the calculations on this site take approximately .500 seconds using a broadband connection. I would guess that about 90% of that time is due to network latency/network lag – which wouldn’t be much different for a dialup connection.

For the first few months after the launch of this website, it did not use a MySQL database. I actually went to some pretty ridiculous extremes to not have to learn a new programming language. I eventually gave in, learned how to use MySQL and am a better programmer for it.

Next up, MySQL!

  1. A download of “www.google.com” was approximately 30,000 bytes and a download of “www.yahoo.com” was approximately 300,000 bytes. []

I’ll be at the DVICA 21st Annual Golf Classic tomorrow!

Look for the guy wearing glasses and a Sebastiani cap. Unfortunately, unlike my fellow Indians, I can’t play golf. Its really quite shameful. (Sorry guys!) Fortunately I make up in enthusiasm what I lack in skill. :)

Hopefully I’ll remember to bring my digital camera so I can post a few shots here.

Be sure to track me down and say hello!

I recently gave a brief overview of my permanent disability and workers’ compensation benefit calculators. In that post I wrote a little bit about how my online benefits calculators work. My last post in this series was about how and why these permanent disability and workers’ compensation benefits calculators use javascript.

I had tried Microsoft’s ASP (active server pages) in experimenting with a prior version of my permanent impairment calculators, and while functional, the coding was a complete mess since I didn’t fully understand what I was doing. To make matters worse, the only manuals on ASP I could find gave examples using VBScript – which is MS’s version of javascript.1

Just over a year ago a friend of mine encouraged me to try PHP. (Thanks Johnny!) Its syntax, the way in which you write code, is very similar to javascript and was fairly easy to learn.

Unlike javascript, PHP is run only on the web server. There are a lot of benefits to moving all of the calculations from being performed by a user’s computer to my web server:

  • Uniformity. All calculations will always be performed by the web server in the same exact way – irrespective of the user’s computer.
  • Speed. Since all calculations are performed on the web server, the user’s computer doesn’t need to do any number crunching.
  • Protection. All of the formulas, tables, and magical incantations used to generate the calculations are kept only on the web server.

But, PHP isn’t without its downsides:

  • PHP is being used to perform a calculation, even when javascript would be faster. Javascript takes longer to crunch the answer, but you have to “wait” for PHP to send a request to the server and wait for the answer.2
  • A pure PHP calculator would require the user to send the web server the entire page and wait for a whole new page to load. Every calculation would take a full second or more using a pure PHP calculator.3
  • When PHP is used to perform handle all calculations, there is more of a strain on the web server itself.

Using AJAX (more on this later) to create workers’ compensation benefits calculators has allowed me to take advantage of all of the strengths of javascript and PHP and minimize the negatives of these technologies.

Next up, AJAX!

  1. Can’t we all just get along? []
  2. I say “faster,” but we’re talking about the difference between 10 milliseconds for javascript to calculate the answer and waiting 400 milliseconds for the server to return the answer. []
  3. A second might not seem like a long time – but it is when you’re using a computer. I’d bet that if these calculators took 1 second for everything (such as finding an occupational code or work restriction) no one would use them. []

Mario Puzo, the famed author of The Godfather, The Sicilian, and The Last Don, also wrote a slightly lesser known book by the name of “Fools Die.” 1 Fools Die was a very cynical look at the gambling, literary, and film industries. Some of the best parts were the casino owners talking about gambling:

Percentages never lie. We built all these hotels on percentages. We stay rich on the percentage. You can lose faith in everything, religion and God, women and love, good and evil, war and peace. You name it. But the percentage will always stand fast.

Throughout the book characters say, “no percentage,” or “bad percentage,” or “I have the percentage.” This phrase refers to a (slight) mathematical advantage or disadvantage which, with the inevitability of a glacier, will guarantee a net win or loss over time.

I’ve given a little more thought to the idea of offering website calculators that can be used from a cell phone. Right now, there are precious few cell phones and cell phone web browsers that are capable of using the basic internet protocols necessary to use these workers’ compensation benefits calculators.

At this point I could redevelop the calculators to work with more phones. No one is clamoring for cell phone based permanent disability and permanent impairment calculators. Though I have a feeling that day is not far off, right now there is no percentage in that game.

However, do not despair – I’m thinking of offering something of a consolation prize. More on this later.

  1. Did you know Puzo also wrote the screenplays for Superman and Superman II? []

As the man said, “you can’t always get what you want.” Here’s what I need from a cell phone:

  • Multiple numbers per contact
  • Multiple alarms
  • Scheduling events
  • Text messaging
  • Ability to jot down notes
  • A battery with 4 hours of talk time and a few days of standby time

My current phone can do all that. The battery life is failing, reception is spotty, and its been dropped more times than I was as a baby. Here’s what I want out of a new phone:

  1. Contacts and calendar that can synch with my laptop
  2. Bluetooth support and file access (to transfer files wirelessly)
  3. A web browser that works as well as IE7 or FF2 (Namely: proper HTML rendering, CSS rendering, cookies, and javascript support)

I know the LG Dare can handle #1 and #2, but I’m dubious about its support for #3.

I know the iPhone can handle #3 fairly well, but am dubious about its support for #1 and #2.

So, it looks like the only phone thus far that can use these calculators is… the iPhone. Don’t blame me – blame every other cell phone maker out there. I played with an LG Dare again a few days ago and was disappointed with its web browser this time.

I’m sure its a great phone. But, let’s be real, that’s not good enough any more.

Pros:

  • Touch screen
  • Virtual QWERTY keyboard
  • A screen that rotates when you tilt the camera
  • MP3 player
  • Digital camera, video camera
  • Removable memory chip
  • 500 contact with up to 5 phone numbers each
  • A web browser that will support AJAX and XMLHttpRequest
  • Decent support of cascading stylesheets

Cons:

  • Imperfect support of javascript
  • No support of cookies/sessions

What does this mean for you? You can go to my site, but you can’t log in. If you can’t log in, you can’t use the calculators. :/

As a side note, just about every Verizon rep I’ve talked to pushes this phone’s 500 person contact list. My question, “How much memory does the phone have?” Their response: “It has 5 phone numbers per contact? Wow. That’s a lot. I didn’t know that.” Riiight – you didn’t know? Why have I heard that exact line from three separate reps? I don’t have 500 contacts. I don’t even know 500 people.

Verdict: It may be a good phone, but you won’t be able to use my calculators from it.

I recently gave a brief overview of my permanent disability and workers’ compensation benefit calculators. In that post I wrote a little bit about how my website calculators work.

In late 2004 I spent some of my free time working on a calculator for the 1997 Permanent Disability Rating Schedule 100% pure javascript (the only programming language I knew at the time). I had several reasons for never publicly releasing this calculator:

  • Uniformity. Not all computers and browsers perform all javascript functions the same way.
  • Speed. A pure javascript calculator would require the user to download all of the code – not just the parts they needed.
  • Protection. Anyone with a modicum of technical knowledge could simply downloaded the calculators, and then post it as their own.
  • Obsolete. With SB 899 and the 2005 Permanent Disability Rating Schedule, my calculator became nearly obsolete. I scrapped it rather than building a second calculator.

The current workers’ compensation benefits calculators use very very little javascript. Doing so has meant that I don’t have to worry about different computers/browsers, users only need to download the code they need to run a single calculation, and my calculators don’t work without my server.

Next up, PHP!

This jet
This jet

Mostly because its so flipping cool.

I’m one of those kinds of people who likes to customize their things to suit them better. My junky cell phone has a custom ringtone I created, custom welcome/power-on message, my e-mail and word processing programs have tons of little shortcuts to make my life a little easier in a multitude of ways. My dictaphone has a sticker on it.1

The great thing about WordPress is that the entire program is SO customizable. You can change how it looks with “Themes” and how it acts with “Plugins.” I’ve been using it since March or so, even though it wasn’t publicly launched until July. I’m still finding all of these cool little features.

My current favorite feature: The ability to schedule a post. I can draft a quick post and then schedule it to appear on a particular day or time. Brilliant!

Its the little things in life, you know?

  1. A sticker of a jet. []

Here’s a (simplified) overview of how my permanent disability/impairment and workers’ compensation benefits calculators work. As I’ve mentioned elsewhere, I wrote these website calculators using javascript, PHP, MySQL, and AJAX.

In a recent post, I created a really simple test for cell phones using the above languages. Here’s what was happening:

  • The user clicks the button “Cell Test.”
  • The javascript embedded in the button detects the “click.”
  • The javascript embedded in the button then tells an AJAX program that the button was clicked.
  • AJAX sends a little bit of information to the web server – saying that the user clicked that button.
  • The PHP program on the server is notified that the button was clicked.
  • The PHP program checks a MySQL table to see what it should happen when that button is clicked.
  • The MySQL table returns the answer, what should happen when a button is clicked, to the PHP program.
  • The PHP program takes the answer from the MySQL table and sends it back to the AJAX program.
  • The AJAX program takes that information and, using a little bit of javascript, displays the answer in your web browser.

Easy!