Archive for September, 2008

more histarray

Friday, September 19th, 2008

I am not sure if it is even useful for anything. But I am having fun dorking on it.
New Features.
added pop() method
added splice() method
unified adding and removing for more accurate revision and length

New Home
I have been using hithub for a little now, and have put this up as my first public repo.

*Notes
There is one big, probably unresolvable issue. You have to push in new elements.

 var a = Array('one', 'two', 'three');
 a[12] = 12;
 // this would result in an array with a length of 13
 // with 3-12 undefined.

The way the getters and setters are setup, unless I where to define ervythin’ there would be nothing waiting to assign an element to the internal array.

Next Steps (if any)
Implement standard array features
Decide if push should be like an array push and create a new method for historical pushes.

Last up
I also finally got around to figuring out qunit unit testing. It is really easy to use, not sure why I have not been using it longer. I have 19(?) tests right now, and they are in /test in the repo.

histarray – An Experiment with Getters and Setters

Thursday, September 18th, 2008

While doing an experiment with Getters and Setters I whipped together a small lib for a versioning array, the histarray. So far tested only in Firefox 3, it utilizes __defineGetter__(someNumber, function(){}) to return an element from an internal array (the history). Its push method will either overwrite the current revision if it is not the last, or push a new revision into the history. A Setter is also defined, so no matter where in the time line you currently are, that element will be updated.

function histarray()
{
	for(var i = 0; i < arguments.length; i++)
		this._add(arguments[i], i);

	this.__defineSetter__('revision', function(v)
	{
		return (v > this.length) ?
			this.revision :
			this._revision = v;
	});
	this.__defineGetter__('revision', function()
	{
		return this._revision;
	});
	this.__defineGetter__('prev', function()
	{
		return (this.revision != 0) ?
			(function(self)
			{
				var a = Array();
				for(var i in self._elements)
					a.push(self._elements[i][self.revision - 1]);
				return a;
			})(this) :
			null;
	});
	this.__defineGetter__('nxt', function()
	{
		return (this.revision < this.revisions) ?
			(function(self)
			{
				var a = Array();
				for(var i in self._elements)
					a.push(self._elements[i][self.revision + 1]);
				return a;
			})(this) :
			null;
	});
};

histarray.prototype =
{
	length: 0,
	revisions: 0,
	_elements: Array(),
	_revision: 0,
	_add: function(e, i)
	{
		this._elements[i] = (function(e,self)
		{
			var a = Array();
			for(var i = 0; i < self.revisions; i++)
				a.push(null);
			a.push(e);
			return a;
		})(e,this);
		this.__defineGetter__(i, function()
		{
			return this._elements[i][this.revision];
		});

		this.__defineSetter__(i, function(v)
		{
			return this._elements[i][this.revision] = v;
		});
		this.length = i + 1;
	},
	// push csv or a single array
	push: function()
	{
		if(typeof arguments[0] == 'object')
			this.push.apply(this, arguments[0]);
		else
		{
			if(this.revision == this.revisions)
			{
				this.revision++;
				this.revisions++;
			}
			for(var i = 0; i < arguments.length; i++)
			{
				if(arguments[i] == null) continue;

				if(this._elements[i])
					this._elements[i][this.revision] = arguments[i];
				else
					this._add(arguments[i], i);
			}
		}
		return this.length;
	}
};
// creates a new histarray.
var ha = new histarray('e1', 'e2', 'e3');
// this is now just like a normal array, ha[0] == 'e1'
// now using push does not add a new element, but instead adds a new revision
ha.push('e1v2', 'e2v2', 'e3v2')
// now ha[0] == 'e1v2' and ha.revision == 1 and ha.prev[0] == 'e1'
// if we change the revision back to 0
ha.revision = 0;
// ha[0] == 'e1', ha.nxt[0] == 'e1v2'
// with the revision still at 0, we can update an old element
ha[0] = 'e1a';
// this just changes the first revision of the first element.

Not certain is will be useful for anything in particular. But I still have a couple ideas to add, and am interested in hear what people have to say about this.

jQuery Comet update (finally).

Tuesday, September 9th, 2008

Now that I am semi-settled in here in Berlin (anyone have a room for rent? (cheap)), I am trying to get caught up on stuff. I finally pushed some fixes suggested by Jörn and got the chat demo reported. Its all in the SVN at Google Code and setup an external item in the jQuery SVN. Also sent an email to Greg Wilkins today, hopefully I can get this into the Cometd SVN also.
Next release will be a total rewrite, I made a lot of mistakes in the original, and the prefer jQuery plugin style has changed. Getting back to this point will not be too difficult, and well worth it.

Euro to USD Ubiquity command

Friday, September 5th, 2008

I have been playing quite a bit with Ubiquity lately. So far, I think it is really cool. One thing that has always prevented me from really getting into Firefox extension development is the constant restarting. I am a two or three line and test type of developer and that just does not work. But Ubiquity reload all the command every time you open it. And its got jQuery. Since I am living in German now but still earning the US Dollar, I am constantly concerned with the exchange rate and find myself visiting xe.com frequently. Perfect chance to make a new command. So far it just does Euro to USD, I hope to add all their options. Here it is.

Updates in the world of Morgan

Wednesday, September 3rd, 2008

With the major exception of USPS, Deutsche Post and DHL’s combined effort to loose my laptop, things are going great. I have been in Berlin for about three weeks now, landed an exciting new programming contract, looking like I found a rather cheap room to rent.

So what have I been up to….. Since I do not have my regular laptop, the programming lad been kinda limited. I am working on my ASUS EEEpc (which I finally fixed) which has been, well, a bit of a pain in the ass. But surprisingly I have gotten used to it. But I have also gotten a new laptop (free too). So tomorrow I will be back to it, getting some really work done on a full sized screen. But I still have been working on some interesting stuff. For the new job, I have spent the last day familiarizing myself with the code already in place and doing a huge amount of cleanup. A lot of redundant code, good practices used in the wrong way, bad practices making things worse. But not too bad all in all. I have also been playing a lot with V8 which I am super excited about. While I am not the best C++ programmer, I am a terrible Java programmer. So this is a great alternative to Rhino. And that’s not entirely true, I can guess and stumble through Java as well as C++, but Java’s build environment leaves me totally befuddled. I have also been playing around with FUSE again, and decided why not combined the two? So I made JsFS (I’ll post about this again later), but basically it create a jsin and jsout file, put Javascript into jsin and it is executed by V8 and the results are in jsout. Pretty useless yeah, but it was fun to make. I figure in the end I could make a Javascript interface for FUSE.
Bike News! I rode to Copenhagen two weeks ago. Well most of the way. Weather was not very cooperative and my friend I was riding with got injured to we ended up riding about half of it while hoping on and off trains. I am putting together a better mini-touring setup and will be riding to Geneva in about two weeks to race in the Swiss Bike Messengers Championship.
Also posted some pictures. Okay, thats enough out of me.