Archive for the ‘Uncategorized’ Category

Ruby, Java, Monkeys, and Bananas

Wednesday, December 21st, 2005

This whole Ruby v. Java, humane v. minimalist monkey knife fight reminds me of the debate over the correct way to peel a banana.

For the uninitiated: you can peel from the end with the stem (this is the traditional way to do it), or you can peel from the end without the stem (this is the way most monkeys do it).

The stem end is appealing (pun not intended, but I’ll take it anyway), because there is a convenient handle/lever to use. Just bend it down to break the “seal” and peel away. This works pretty well for a ripe banana, but not so well for a green one (you end up with banana mash).

Peeling from the non-stem end is probably the faster way to do it, on average (in case you’re ever in a banana-peeling contest). I haven’t tested it, but I’m more inclined to think that monkeys have come up with the more efficient approach.

There are problems with peeling from the non-stem end: that’s the end that typically gets “bruised”. So what do you do with the yucky brown part of the banana? If you had only peeled from the other end, you could have just aborted consumption and disposed of the unappetizing remnant with the peel.

So… what is the correct way to peel a banana? Maybe it depends on the individual banana. Maybe green bananas should be peeled from the non-stem end (do green bananas have fewer bruises?) and ripe bananas using the stem.

I’m accustomed to using the stem, but I’m not opposed to experimenting with new technologies :-).

I don’t want to draw too many parallels between banana peeling methods and humane v. minimalist programming languages. I will say that knowing that there is more than one way to peel a banana and that each method can provide a useful banana experience has enriched my life immensely.

I wonder if there is yet another undiscovered banana-peeling method…

UPDATE 29-Dec-2005: and once you’ve decided how to peel your banana look here.

French v. American School Lunches

Wednesday, December 7th, 2005

A somewhat old post at Idle Words that speaks volumes about American values.

I checked the American school menu for this month and little has changed. The American ultra-processed food industry has it’s brands (and its greasy fingerprints) all over the thing…

The menu for the French school remains just as interesting (though one could argue that “Steak haché pur bœuf et ketchup” will always be more interesting than “Ground beef and ketchup”… meatloaf, anyone?)

Americans tend to view food as a means to an end: satisfy hunger, regardless of nutritional value.

I wonder what the children would think if the menus were suddenly reversed. Would the French students revolt? Or would American students actually learn about moderation and a balanced diet?

AJAX in Pocket IE?

Wednesday, November 30th, 2005

According to the IEMobile Team Weblog, the answer is Yes! [Thanks Ajaxian Ben & Dion]

They have some sample code and an example page. Also, they point out:

  1. On Smartphone/PocketPC 2003
    • innerText and innerHTML Properties are only supported on div and span elements
    • Form elements are scriptable as well
  2. On Windows Mobile 5
    • innerText and innerHTML Properties are supported on all elements
    • In addition there is support for document.all and the style object

I had noted some limitations of Pocket IE DOM manipulation in a previous post.

How Should We Then Live?

Tuesday, November 29th, 2005

Steve Pavlina:

By their words I hear that most Americans are Christian. By their actions I see that most aren’t.

Why [Not] Ruby?

Monday, November 28th, 2005

I’ve recently been playing around with Ruby (yes, and Rails).

Though there are still some language issues that need to be sorted out (like variable scoping), Ruby seems to be a very elegant language, with an intuitive syntax (and by intuitive I don’t mean to imply similarity to C/C++/Java). I particularly enjoy it’s poetic terseness: Ruby code is actually readable (for the most part, anyway).

FWIW: I don’t think Ruby will ever be a 100% replacement for Java — and I hope the priests of the Java cathedral are extremely circumspect when it comes to attempts to push Ruby-like features into the language (we could end up with something even more disastrous than Generics!).

The Truth about Multitasking

Wednesday, November 23rd, 2005

JavaScript Dynamic Content Templates

Wednesday, November 23rd, 2005

For a recent project, we had to do some dynamic content replacement on a web page. We had to support a primitive version of IE (viz., Pocket IE for Windows Mobile 2003), so fancy DOM element creation and manipulation were out of the question — we were stuck with simply changing the value of the exposed innerHTML JavaScript attribute of <div>s, <span>s, etc.
Some of the dynamic content was relatively long (using tables, etc for layout), so rather than creating it using a long series of JavaScript string concatenations (with all necessary character escapes), we created <span>s that contained template HTML. For example:

<span id="template" style="display:none;">
<table>
 <tr><th>Name</th><th>Value</th></tr>
 <tr><td>{propertyName}</td><td>{propertyValue}</td></tr>
</table>
</span>

Then, we can get the template string:

var templateStr = template.innerHTML;

Notice that the template has a couple strings enclosed in curly braces. These are tokens that will be replaced by values from a JavaScript object. A simple JavaScript method takes care of this:

<script language="JavaScript">
function doTemplateReplacements (template, tokensObj)
{
var output = template;
for (var prop in tokensObj)
{
  var re = new RegExp ("\{" + prop + "\}", "g");
  output = output.replace (re, tokensObj[prop].toString());
}
return output;
}
</script>

Usage is pretty straightforward. Simply pass the template string and an object with properties matching the tokens in the template. Then, set the innerHTML of your “target” container to the dynamicContent string.

<span id="target"></span>

<script language="JavaScript">
var dynamicContent =
   doTemplateReplacements (templateStr,
                           { propertyName: "Cost",
                             propertyValue: "$100.00" });
target.innerHTML = dynamicContent;
</script>

The target <span>’s content becomes

<table>
<tr><th>Name</th><th>Value</th></tr>
<tr><td>Cost</td><td>$100.00</td></tr>
</table>

A while after devising this approach, I ran across the TrimPath JavaScript Templates library. This library supports this simple templating and a *lot* more. I haven’t actually used this library, but it’s interesting in that it implements a micro expression language for use in the templates. Might have been useful in the project, but I’m not sure if it would be 100% functional in Pocket IE.

UniqueProperties.java

Friday, August 19th, 2005

We had a properties file that had massive numbers of duplicate property definitions. Since the Java convention is that the last definition of a property is the one that will be used, I created a simple utility that outputs a properties file with non-final definitions skipped:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;

/*
 * File UniqueProperties.java
 * Created on Aug 19, 2005 by jstell
 *
 */

/**
 * Simple utility to remove the non-final
* occurrences of a property in a
 * properties file. The unique content is
* written to Standard Out.
 */
public class UniqueProperties
{
  public static void main(String[] args)
    throws Exception
  {
    if (args.length != 1)
      System.err.
       println("USAGE:n java " +
               UniqueProperties.class.getName() +
               " [props file]");

    String in = args[0];
    BufferedReader frIn =
      new BufferedReader(new FileReader(in));

    int lineNum = 0;
    ArrayList linesToSkip = new ArrayList();
    HashMap propLines = new HashMap();
    String line = null;
    // figure out what lines to skip
    while ((line = frIn.readLine()) != null)
    {
      lineNum ++;
      if (line.indexOf('=') > 0 &&
       !line.startsWith("#"))
      {
          String pName =
          line.substring(0,
                         line.indexOf('=')).trim();
          Object prevLine =
          propLines.put(pName,
                        new Integer(lineNum));
          if (prevLine != null)
          linesToSkip.add(prevLine);
      }
    }
    // start over, output skipped lines
    frIn.close();
    frIn = new BufferedReader(new FileReader(in));
    lineNum = 0;
    while ((line = frIn.readLine()) != null)
    {
      lineNum ++;
      if (!linesToSkip.
           contains(new Integer(lineNum)))
        System.out.println(line);
      }
    }
} // UniqueProperties

del.icio.us linkroll

Friday, August 5th, 2005

del.icio.us has (at long last) added JavaScript link roll functionality. Just add a JavaScript include to the page, and your del.icio.us links appear. A good set of options, including filtering by tag, in case you only want to show links tagged ‘website’ or ‘public’.

Right now, del.icio.us still seems to be predominantly tech, GTD/productivity, web stuff (take a look at the most popular tags)– much of which I find interesting. The signal to noise ratio (for me) is tolerable. I wonder what will happen when the masses jump on the bandwagon and the most popular tags become more general interest… I suppose at that point I’ll need to start filtering/ignoring out some of those tags.

It would be interesting if del.icio.us started suggesting items bookmarked by users with similar tags and bookmarks. Actually, I’d be surprised if they haven’t already started looking into this.

I wonder when a big player (Google, M$, Y!, Fox, etc.) is going to make a move to acquire del.icio.us?

Update: I suppose I could’ve poked around a bit more. Here is a blog post listing all kinds of del.icio.us tools. For instance, Outfoxed is a tool that lets you specify trusted "informers" to help make decisions about interesting/safe links.

New favorite phrase: “Impenetrable Gobbledygook”

Wednesday, June 29th, 2005

Ahhh… impenetrable gobbledygook.
Doesn’t it just roll off the tongue?
Sometimes it’s prefixed with “pretentious”, and sometimes “academic”, “legal”, or “marketing” is thrown in.

“Gobbledygook” is fun by itself, but with “impenetrable” tossed in, it’s pure music.

According to The Word Detective, the word “gobbledygook”…

   …all started with a 19th century Texas cattleman named Samuel Maverick who became famous for not branding his cattle. His cattle, left unidentified and free to roam, were often “adopted” by other ranchers who termed them “mavericks,” and by the end of the century “maverick” had come to mean any sort of rootless wanderer or rebel.

   About 100 years later, Sam Maverick’s grandson, Maury Maverick, was serving in the U.S. House of Representatives during World War II. Charged with overseeing factory production for the war effort, Rep. Maverick coined the term “gobbledygook” to describe the impenetrable bureaucratic jargon and doubletalk he encountered. He later explained that he based the word on the behavior of turkeys back in Texas, who were “… always gobbledygobbling and strutting with ludicrous pomposity. At the end of this gobble there was a sort of gook.” Rep. Maverick went on to issue a memorable edict stating that “Anyone using the words ‘activation’ or ‘implementation’ will be shot.” Sadly, no bureaucrat was ever actually shot, and unfortunately “governmentese” is still going strong, but it certainly seems fitting that Sam Maverick’s grandson would be the “maverick” who fired the first shot against “gobbledygook.”

… as only a Texan could have put it.

In the course of my extensive etymological research ;-), I ran across a fun little tool to generate some gobbledygook, whenever you might need it.