LoadForCompile: Help for in-browser compilers

August 13th, 2009

As javascript engines increase in speed and efficiency, it is becoming feasible to write compilers and interpreters in javascript to allow webpages to run alternative programming languages not normally supported by browsers. See processing.js, for instance: A graphics library that runs a Java-like language in the browser.

An initial hurdle facing developers of these toolkits is the problem of loading source code. Javascript is loaded and executed natively in the browser environment, and it would be nice to load alternative language sources in a similar manner. So, today I wrote a library to do that.

The library, called LoadForCompile, is invoked with a MIME type and a callback. It searches the DOM for script elements with the given MIME type, loads their sources, and passes them to the callback. There is a very simple demo page with a "compiler" that displays whatever source code it is provided. Following is the documentation for the library.

Description

LoadForCompile will retrieve alternate-language source code and pass it (in order) to onLoad. Any sources that cannot be retrieved will be ignored by default.

If the onFinish argument is provided, it will be called when all sources have been loaded and passed.

If the onError argument is provided, it will be called with (src, k), where src is the offending URL and k is a continuation of the loading process, so the relying client may continue or entirely halt the loading process by calling k or not calling it, respectively.

Usage

  1. Place script elements in your HTML document with desired MIME type.
  2. Each script element may have a src attribute, an inline body between the opening and closing tags, or both. The body is guaranteed to be called immediately after the associated remote source, or not at all.
  3. Finally, call LoadForCompile with the MIME type and callbacks.

Specification

LoadForCompile searches the DOM for any script nodes bearing the target MIME type. For each one, it records the src attribute and the contents of the text node, if any. It is an error to have non-text elements as children of the script node, and in such a situation the behavior of this library is unspecified.

The library uses asynchronous requests to load any remote resources specified by src attributes. This loading occurs in an unspecified order. If any remote source fails to load, the library will mark that source (and any associated inline body) as invalid. If onError is provided, it will be called with a continuation function that will resume progress. (If the continuation is not called, no additional callbacks will be made.)

Note that if onError is provided and does not call the continuation, onFinish will not be called.

Metadata

The library is in version 0.2 and is licensed under the LGPL.

Tone down your system beep

August 9th, 2009

The "system beep" (or "system bell") can be quite annoying. Instead of disabling it altogether, you may be able to change it to something a little less irritating. Some operating systems will allow you to change it to a visual alert or a sound file of your choice. Today, I'll show you how to change the duration, pitch, and volume to something less grating if you're using X.Org (applies to just about all Unix or GNU/Linux systems.) [via]

I use xset, a command that can set various preferences in the current X display. One of the parameter sets is b, the properties of the system bell. It can be used to set the relative volume, pitch, and duration. Here's an example:

xset b 50 700 5

That example sets the system bell to 50% volume, a pitch of 700 hertz, and a duration of 5 milliseconds.

Experiment by entering that command, then pressing [Backspace] on the next line of your terminal (to generate a system bell.) Your hardware may not support certain combinations, in which the bell is silent.

To have this setting take effect every time you log in, add it to your session startup commands. In Ubuntu, that's System :: Preferences :: Sessions.

GWT, standard library, and IncompatibleRemoteServiceException

July 15th, 2009

The GWT is a set of programs that allows developers to write Java code and compile it down into Javascript to be run on browsers. This requires you to use the subset of Java that the toolkit can emulate, but the compile-time and runtime error messages it displays are often not very useful.

I was developing a GWT application with Eclipse and ran into a client-server communication issue that manifested at runtime. The client would request an object from the server, the object would properly serialize and deserialize (verified by JS debugger), and then GWT's glue code would throw IncompatibleRemoteServiceException (saying "This application is out of date, please click the refresh button on your browser.")

Read full entry »

Bahamas trip: Day 11

July 1st, 2009

It is my last day in the Bahamas, for now. After breakfast I have just enough time to walk out to the North Point, where I hear tell there might be some San Salvador rock iguanas, a critically endangered subspecies. It seems that some of them may have swum across the harbor from the cay where the main local population lives. (I express an interest in taking closeup photos, and am warned that they may attempt to eat my camera...)

Read full entry »

Bahamas trip: Day 10

June 30th, 2009

In the morning, my dad picks up Mr. Forbes from his house and drives him back to GRC. Just as they arrive, the power cuts out, so Mr. Forbes can't sharpen his machete. Too bad, 'cause we're gonna be in the bush again today.

Read full entry »