Adam Gotterer

Find the secrets to infinite income, and automate it!

Archive for February, 2008

Using Prototype XUL

The examples here are taken from Function page of the Prototype JS api documentation. They have been re-written to reflect the Prototype XUL changes. Hope they help!

argumentNames

var fn = function(foo, bar) {
   return foo + bar;
};
 
argumentNames(fn); //-> ['foo', 'bar']

bind

var fn = function(foo, bar) {
   return foo + bar;
};
 
argumentNames(fn); //-> ['foo', 'bar']

bindAsEventListener

var obj = { name: 'A nice demo' };
 
function handler(e) {
  var tag = Event.element(e).tagName.toLowerCase();
  var data = $A(arguments);
  data.shift();
  alert(this.name + '\nClick on a ' + tag + '\nOther args: ' + data.join(', '));
}
 
Event.observe(document, 'click', bindAsEventListener(obj, handler, 1, 2, 3));

curry

String.prototype.splitOnSpaces = curry(String.prototype.split, " ");
"foo bar baz thud".splitOnSpaces(); //-> ["foo", "bar", "baz", "thud"]

defer

function hideNewElement() {
  $('inserted').hide();
};
 
function insertThenHide(markup) {
  $('container').insert(markup);
 
  // Prototype XUL
  defer(hideNewElement);
}
 
insertThenHide("
<p id="inserted">Lorem ipsum
 
");

delay

// before:
window.setTimeout(function() {
Element.addClassName('foo', 'bar'); }, 1000);
 
// after:
delay(Element.addClassName, 1, 'foo', 'bar');
 
// clearing a timeout
var id = delay(Element.hide, 5, 'foo');
window.clearTimeout(id);

delay

// start off with a simple function that does an operation
// on the target object:
var fn = function(target, foo) {
  target.value = foo;
};
 
var object = {};
 
// use the original function
fn(object, 'bar');
object.value //-> 'bar'
 
// if we methodize it and copy over to the object, it becomes
// a method of the object and takes 1 argument less:
 
object.fnMethodized = methodize(fn);
 
object.fnMethodized('boom!');
object.value //-> 'boom!'

wrap

String.prototype.capitalize = wrap(String.prototype.capitalize, 
  function(proceed, eachWord) {
    if (eachWord && this.include(" ")) {
      // capitalize each word in the string
      return this.split(" ").invoke("capitalize").join(" ");
    } else {
      // proceed using the original function
      return proceed();
    }
  }); 
 
"hello world".capitalize()     // "Hello world"
"hello world".capitalize(true) // "Hello World"

Prototype XUL Documentation

For the most part the functionality of Prototype XUL works the same as normal prototype. The prototype documentation can be found here. The underlying changes are in the methods that extend Prototype.function. The functions that have been re-written are: argumentNames, bind, bindAsEventListener, curry, delay, defer, wrap and methodize. The core difference in use, is that these functions can not be extended from objects anymore and must be explicitly called.

argumentNames

argumentNames(someFunction) //-> Array

bind

bind(thisObj, someFunction) //-> Function

bindAsEventListener

bindAsEventListener(thisObj, someFunction) //-> Function

curry

curry(someFunction, [args...]) //-> Function

defer

curry(someFunction, [args...]) //-> Number

delay

delay(someFunction, seconds, [args...]) //-> Number

methodize

delay(someFunction, [args...]) //-> Function

wrap

delay(wrapperFunction, someFunction, [args...]) //-> Function

Prototype XUL Update

While writing out the Prototype XUL documention I came across a nasty little bug that took me a few hours to fix. I will wrap up the documentation tomorrow. If you downloaded the Prototype XUL 1.6.0.2 file anytime before today, please upgrade (the version number has not change).

Drum roll please… After three attempts/failures, I present to you the newest version of the Prototype XUL library! The previous released version technically never worked. It was something I threw together for a Firefox project that only required the basic of functionality (Ajax.Request, utility functions, etc.). I was under the impression that converting the functions that failed due to the known XUL function bug would solve all the problems. Unfortunately this was not the case and under these assumptions more complex functionality ceased to work correctly. This version has gone through a finer examination, conversion and code update to (hopefully) be a fully functional representation of prototype. Hopefully Firefox 3 will have this bug corrected and I wont have to release many future updates. Please post any bug reports, questions or feedback in the comments section, this will help reduce duplication and make my life easier :). Enjoy!

WARNING: I have not fully tested this library!

Disclaimer: This modified version of the Prototye JavaScript framework is in no way affiliated, distributed or supported by Sam Stephenson or the Prototype library project. This library has been modified from its original intended version/use and I take no responsibility for any bugs, damages or problems this library may cause.

Download Prototype XUL

* Most up to date version as of 2/22/08
* Documentation
* Examples

Facebook Application Invites

Facebook Logo

Let preface this by saying I actually do love facebook and check it a few times a day. I have followed them as a company from the moment my school was listed, several years ago. There were even thoughts in the past of applying for a job there.

Now to my little rant… These applications are getting out of hand. Mainly the invites and notifications, but most of the applications them self suck as well. This isn’t facebook’s fault, I blame the developers. I get all excited when I login and have a bunch of new notifications. Maybe I got tagged in a new picture? Maybe a new wall post? 9 out of 10 times it was a notification from an application about some nonsense. I have since removed every application except one.

For weeks I have been collecting invite requests. Only recently facebook added a clear all button, but I want to see how many I can rack up. At the time of writing I have 106 application invites. Most of these invites come from people I never speak to or most likely ever will again (not because of the invites). The whole invite process leads me to believe that they are sent out automaticly or are simply part of a “click here to get to the damn application”, in which case they have automatically selected a few people and by the user clicking, it sends to the first 10 or so selected people. My name starts with an “A”. I most likely appear near the top of all of my friend’s lists. I am a prime candidate for application invite hell.

I wont even get into how pointless most of these applications are right now. The only application that I am running is SnowTick, which gives me updates on how much snow the mountains I ride at have gotten. Theres a great development mantra that facebook application developers refuse to follow. MAKE THINGS PEOPLE WANT!

Click the invite thumbnail to see the full list!
Facebook Invite Thumb

  • 0 Comments
  • Filed under: General
  • My First Schwag Bag

    Startupschwag Logo

    I received my first schwag bag from startupschwag.com last week. Startup Schwag has picked up where Valley Schwag failed and left off. It’s basically a t-shirt of the month club for web 2.0 companies. The first bag I recieved had a mashable t-shirt and a ton of great stickers. The other past shirts have been techcrunch, digg and reddit. The shirt is awesome, it’s printed on American Apparel, it’s comfy as can be and the ink is high quality. Whats really interesting is this shirt is comprised of 12 different colors, which is really high for a tee. If you are as much of a internet geek as I am, every month you will look forward to your schwag bag!

    Startupschwag - Masbale T-shirt

  • 0 Comments
  • Filed under: General
  • Month In Review

    I have spent the last few minutes trying to come up with a good excuse to why I haven’t posted in the past few weeks. Early January was excusable. I was snowboarding in Lake Tahoe from Jan 2nd to the 9th. Just before I left my hard drive crashed. I didn’t have time for diagnosis during the holiday season,so I didn’t get around to getting a replacement from Dell until after my trip. After the new hard drive arrived my memory went corrupt. It took several days to figure that out and get replacements. That covers early January,the rest is inexcusable. I made a promise to myself today to get back on track and post more. So here is my triumphant return!

  • 0 Comments
  • Filed under: General