jared@protoscript.net

Off Site

javascript
Io
pragmatic programming
my resume
ruby


programming.reddit logo User Script · 362 days ago

This one is truly awful. I hate that clicking on the programming.reddit logo on programming.reddit.com pages (especially when paginating across the results) brings you to reddit.com instead of the programming sub-site.

Here’s a horrible user script to fix it. Yes there easier/shorter code, but something just wasn’t working @ 4am when I wrote it. I am releasing it to the public because I saw a reddit thread about it:

Download the programming.reddit.com logo userscript

Comment

* * *

One line Trac userscript · 571 days ago

Because I hate using my mouse.

I present, Trac_L_ogin

Comment

* * *

MC Plus+ · 690 days ago

MC Plus + is not your run of the mill sucka MC. At least take a few minutes to listen to Syntax and Semantics. You won’t be disappointed.

Comment

* * *

javascript :: Sajax the ASP ajax toolkit · 721 days ago

Sajax is an open source tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call PHP, Perl or Python functions from your webpages via JavaScript without performing a browser refresh.

Thomas Lackner, of Sajax fame, was gracious enough to accept my JScript-in-ASP version of the Sajax toolkit. Sajax also has versions in Io, Ruby, PHP, Python, Lua, Coldfusion and Perl. The JScript port is still in beta, but I will be ironing out the oddities soon enough.

Essentially, you write server-side methods, choose which among them you’d like to be available from the client, and export them. The client-side code can then call the function and register a callback function. Sajax handles all of the client-server communication rather transparently.

Update (08/09/2006): Unfortunately, due to a misunderstanding, Thomas added my “beta” code into the release. There were some bugs and security issues* that I had not yet addressed and the ASP version was removed from the release. As I’m very busy now, I’d like to know if there is significant demand for the ASP version before I continue. If you would love an ASP Sajax toolkit, leave me a comment here.

Update (08/31/2006): I have completed a new alpha version of Sajax for ASP. If anyone is interested in testing it, please leave a comment here, or email me at jared@protoscript.net . I don’t want to release the files into the wild until I’m reasonably sure that everything is working.

Update (09/17/2006): I forgot to mention something. Sajax for ASP is written in JScript, Microsoft’s (mostly) ECMAScript compliant scripting language. Many people believe that writing ASP pages means writing only in VBScript. So why would I go against the grain and use JScript? That’s easy. It supports true closures; a powerful object model with the ability to use mutliple/dynamic inheritance; a convenient, powerful reflection mechanism; dynamically adding properties and methods to ‘classes’ and instances—at runtime; a nice, self-organizing, auto-growing native array type; a unified syntax for dealing with reference and value types (hence, no “set x = object” vs “x = 0”)—this vastly expands the expressivity derived from it being a dynamically typed language; Function.apply(); a terse, convenient syntax, especially for arrays construciton, regular expressions and, coolest of all, object and function literals… The list goes on and on. I cannot recommend highly enough the switch from vbscript to jscript. Once you get used to the new lanugage, and recognize that it is something alltogether different, you will find yourself far more productive.

Comment [6]

* * *

Dynamic Languages Love · 725 days ago

It’s really exciting to see megacorps taking a vocal interest in dynamic languages. It’s even better to see them put their money where their mouth is.

I recently mentioned Microsoft’s release of Iron Python 1.0. Now, there’s even more exciting news in the dynaming languages world.

First, for those of you who’ve never met her, I’d like to introduce you to JRuby. JRuby is a “100% pure-Java implementation of the Ruby programming language.” The mere existence of this open source project is a boon to the dynamic languages world, as it encourages the adoption of ruby. Particularly, it provides a more direct interface through which ruby can be used as an enterprise integration language for the java platform. If you’re stuck maintaining a steaming, complicated mess (e.g. a J2EE Portal), JRuby can melt off some of the fat. At the very least, you can use JRuby to write your unit tests and to script your builds.

But the real news is that “The JRuby Guys” are joining Sun as paid, fulltime employees! Sun is paying them to continue making JRuby a solid, open source environment for building and deploying ruby applications with full access to the vast multitude of java libraries. On top of that, they’ll be working on JRuby tool support and on helping to transform the Java platform into an even better platform on which to run dynamic languages.

Tim Bray announced the ‘aquisition’ in this post. As a javascript fanatic, I also took a keen interest in his mention of Phobos, about which I’ll post shortly.

UPDATE: Ted Leung blogged about these two events as well.

Comment

* * *

IronPython 1.0: released! · 732 days ago

Today, Microsoft released IronPython 1.0. Iron Python is the speedy Python implementation written to run atop the CLR. Incredibly, it runs the standard pystone benchmark 1.7 times faster than CPython. Of particular interest, is Microsoft’s decision to release IronPython under an open source BSD-style license.

Jim Hugunin provides a short history of the IronPython project, including this gem:

I wanted to understand how Microsoft could have screwed up so badly that the CLR was a worse platform for dynamic languages than the JVM. My plan was to take a couple of weeks to build a prototype implementation of Python on the CLR and then to use that work to write a short pithy article called, “Why the CLR is a terrible platform for dynamic languages”. My plans quickly changed as I worked on the prototype, because I found that Python could run extremely well on the CLR[...][1]

I’m excited to see Microsoft’s continued commitment to making the CLR a viable platform for dynamic languages. A language-neutral runtime—including a sizable standard library—is a boon to all who develop new programming languages.

[1] IronPython 1.0 released today!

Comment

* * *

day.licio.us - a del.icio.us greasemonkey userscript · 760 days ago

I’ve now released my second greasemonkey script for del.icio.us. day.licio.us automatically adds a string representing the current date to the “Tags” field.

This helps me find bookmarks by clicking on a tag representing the date that I’m interested in (“What was that ruby site I was looking at on Tuesday?”) to restrict my browsing to bookmarks added on that particular date.

I was manually doing this for a about a week before I wrote day.licio.us. As all good programmers know: Don’t Repeat Yourself.

Comment

* * *

Pluvo :: A Dynamic Language · 795 days ago

Pluvo is a new dynamic language. It appears to be practical, elegant and malleable.

“Pluvo is a functional and imperative programming language intended to be highly practical for scripting and CGIs, interpreted using a just-in-time compiler. Its hybrid dynamic and strict typing is flexible enough to allow duck typing. Its functions are, more specifically, closures, and it allows object orientation using prototypes.

[...]important datatype is the Table,[...]All of a program’s code is stored in Tables that may then be manipulated by the program itself. Being a data-structured language it allows self-modification à la Smalltalk and Lisp.” [1]

I’m going to list some of the features that appeal to me:

  1. Runs on Windows. Unfortunately, for now, this is a must for me.
  2. Easy to Install. As long as you have Cygwin (with programming tools like make) and python, you’re set. This is a dream compared to my experiences with the most beautiful language with which I have any experience, Io (http://www.iolanguage.com).
  3. Prototype-based. With simplicity comes elegance. Not differentiating between classes and objects really simplifies metaprogramming and reasoning about object hierarchies in general.
  4. Dynamically Typed with optional static typing. We’ll have to see whether the community embraces duck typing as a default. If the community makes static typing the de facto standard, I might lose some of my interest (particularly if type inference does not quickly follow). Fortunately, all of the examples I remember seeing used dynamic typing, with the exception of the static typing example, of course.
  5. Infix and Prefix Syntax. You can choose between infix and prefix syntax, at the caller. This is an innovation the author refers to as coordination. While some of the practical implications remain to be seen, I was excited to see somthing very similar to one of my many ideas for protoscript (originally, the name was conceived to be a dynamic, prototype-based scripting language) implemented in a real, living language.
  6. Code as Data. Pluvo’s programs are Table objects filled with Block objects. This appears to provide rich reflection and metaprogramming facilities.
  7. Everything is a Table/Block. And I do mean everything. The dot ”.” ‘operator’ is a function that provides access to functions defined within a prototype using the method function. Even comments are generated by calling one of a series of functions.

I’m definitely going to be playing with Pluvo. I hope you will too.

[1] http://inamidst.com/pluvo/

Comment

* * *

def.oc.us - a del.icio.us greasemonkey userscript · 809 days ago

I created a del.icio.us GreaseMonkey userscript to set focus to the “Tags” textbox when I am tagging a site. I was getting annoyed having to take my hand off of the keyboard (and without pressing tab a ‘bunch’) every time I wanted to tag a site. Now, using the handy-dandy del.icio.us firefox extension, tagging a site is as simple as:

  1. Ctrl+Shift+/ “Tag this page” keyboard shortcut
  2. Type the necessary tags (this is where def.oc.us jumps in)
  3. Press Enter

Ah, sweet tagging bliss!

Well, not really. If I could find a tagging service that let me use spaces in my tags and that had a popup tagger, I’d be a happy man. Sadly, Ma.gnolia.com (and some others that allow spaces in tags) redirect me away from the page I am trying to view when I activate the bookmarklet. This drives me insane. Maybe I’ll create a Ma.gnolia.com bookmarklet that allows inline site tagging. Do you know of one?

Install all 6 fabulous lines of def.oc.us!

Update: I made the script a little more robust. It can now be used for any page on the delicious site. If there isn’t a text field with the id “tags”, the del.foc.us will gracefully terminate.

Comment

* * *

C# 3.0 - Shock and Awe · 1084 days ago

I haven’t spent a lot of time reviewing C# 3.0, but to say that it has left me pleasantly surprised would be an understatement. A better descriptor might be: “Shock and Awe”.

It looks like C# will some day include:

Believe me; I am aware that MS often fails to provide promised features in many of their products. Regardless, I am excited that Microsoft has apparently recognized the usefulness of these features. Even if all of these features make it into C# 3.0, it will still be lacking in flexibility and power compared to languages that have been available for decades. But when compared to C# 1.0, these features are truly shocking.

[See The LINQ Project Overview (.DOC format) for more information.]

Comment [3]

* * *

javascript :: extending the language · 1235 days ago

Todd Ditchendorf, of ditchnet.org, shared a technique to extend javascript’s standard Array type. This technique highlights the expressive power that prototype-based languages provide to developers.

 Extensibility

Let us assume that we want to add a method, last, to our Array type. In most* class-based languages, one would be forced to subclass the Array class and add the last method to their new class (which is why you sometimes see classes in static languages with names like BetterArray or even ArrayWithLast). The intent of the programmer is to add functionality to the Array type, not to create a new, separate type that happens to provide the two sets of functionality.

In javascript, you can achieve this by adding a property to the prototype property of the type (or object) you are trying to extend:

Array.prototype.last = function()
{
     return this[this.length-1];
}

The first line adds the last method as a property of the prototype object of Array. Whenever javascript attempts to access a method meth (or any property, for that matter) of object Obj, the interpreter first checks to see if Obj.meth exists. If the method cannot be found, javascript searches the object’s prototype chain. This chain consists of all of the properties of the object’s prototype, as well as it’s prototype’s prototype, and so on (Fortunately, this chain is finite; Object’s prototype property is set to null). So, to check the prototype chain for the method, the interpreter looks for Obj.prototype.meth, then Obj.prototype.prototype.meth, and so on.**

From this point forward, we can access the {font-family:lucida console}last% method of any array we create. A slightly more subtle effect of this is that all arrays, even those created before this code was executed, can access this new method.

The benefits of using this technique are probably rather clear, but I’ll enumerate just a few of them anyways:

 An Example

I’d like to proceed to an example, specifically the contains method that Todd added to Array.

First we will need some sample arrays to use for testing purposes:

unlucky = [7,13,99];
num = 1;
nums = [new String(num),"2","3","4"];

And here is Todd’s implementation of contains:

Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
            if (this[i]==element) {
                return true;
            }
    }        
            return false
};

Now, we can test the membership of an array for a specific element like this:

if(unlucky.contains(13)){document.write("13 is unlucky!")}

Let’s try a—very contrived—example with our other array:

if(nums.contains(new String(num))){document.write("We found "+num)}

If you run this code, you’ll find that, even though you are storing num in the array and passing that same variable to contains, the message never prints! This is due to the strange manner in which javascript handles the comparison of String objects, especially those allocated with the String constructor. I only mention this problem because it has brought me hours of suffering while working on a large project. My colleagues and I were in the habit of new String()-ing things to ensure that we were dealing with the string representation of objects before concatenating to them or comparing them. I’m not sure whether this problem occurs in any other context, but it’s a good idea to reduce the potentiality for error as much as we can.

I realized that the problem vanished if toString was called on either of the objects being compared. It seems like the interpreter is checking the equality of the identities of the objects when both are created with an explicit call to the constructor; otherwise, it tests the value of the objects. My first idea was to change the body of the for loop to this:

        if(typeof(element)=="string")
        {
            if (this[i].toString()==element) {
                return true;
            }
        }
        else
        {
            if (this[i]==element) {
                return true;
            }
        }

But when a string is allocated using the String constructor, passing it to the typeof method returns “object”. So, I decided to check for the String constructor directly:

       if (this[i]==element || element.constructor==String &&
                               this[i]==element.toString() ) {

Finally, we’re getting the results we expect! Fortunately, the factors that cause this odd behavior are only found rarely. It is a small price to pay for the dynamic power that javascript provides!


*Ruby is one exception. I’m still researching, but I often get the impression that, internally, Ruby is closer to a prototype-based language than to a traditional, static, class-based language. Of course, one could employ containment to accomplish a similar effect, but the solution is still an extra step away from the problem domain.

**This is accurate conceptually; under the hood, the details may differ slightly.

NB: I use the word “type” to refer to the concepts behind javascript’s constructor functions. Of course, these “types” are just regular objects with a few special responsibilities, but it’s helpful to be able to differentiate between an instance of Array and Array itself.

UPDATE: The ECMAScript specification states that the proper way to convert a String object to a string value is to call String as a function. Using this technique, the example would look like:

       if (this[i]==element || element.constructor==String &&
                               this[i]==String(element) ) {

Comment [1]

* * *

javascript :: generic favelet · 1246 days ago

Lately, I’ve been burned by the size restriction that IE enforces on favelets. I exported a bunch of them to my flash drive, and happily imported them when I got to my home PC. Then, I went back to work and imported them again. Well, IE silently trimmed them down to 259 characters. Since the corrupt versions were imported over both of the locations I keep my favelets, I lost quite a bit of code—some with details that I don’t remember well enough to bother re-writing completely from scratch.

But recently I realized that the size limit need not be a problem. After all, we are talking about a dynamic language! Here is what I came up with:

(function()
{
     var s,f;

     //put your favelets url here
     f="http://www.protoscript.net/favlets/site_search.js";

     s=document.createElement("SCRIPT");
     s.setAttribute("src",f);
     s.setAttribute("type","text/javascript");
     document.getElementsByTagName("HEAD")[0].appendChild(s);
})()

The base script, without the URL defined, weighs in at 196 characters. With 63 characters left to define my URL, I shouldn’t need to worry about losing my favelets ever again. If you want the one-line version, email me and I will send it to you.

NB: I know, I know, I should be using firefox. Greasemonkey just might be the proverbial straw. But I have quite an emotional investment in IE, and I need to code specifically for it at work. Soon, perhaps…

Comment

* * *

Ruby on Rails :: Two New Articles · 1255 days ago

While most of you (you know, all two of my readers) have probably seen these, I wouldn’t want anyone who’s wasting their time looking at my site to miss out on useful Rails content.

So, I present:

You got your Ajax in my Ruby (oh my!)

...and…

Exploring Ruby on Rails

Hey, at least your not leaving empty handed today. My apologies for not having written anything in over a week. Moving into a new condo and planning a wedding, while learning ruby and spending extra hours at work each nite, really manages to keep me from my blog for longer than I’d like…

I promise: more content soon!

Comment

* * *

pragmatism :: dynamic languages · 1263 days ago

In the The State of the Scripting Universe, DevEdge’s Lynn Greiner interviews Dave Thomas for Ruby, Guido van Rossum for Python and other highly respected icons of the PHP, Python and Perl communities.

I am a strong proponent of referring to so-called ‘scripting’ languages as Dynamic (or Agile) Languages. Sadly, ‘scripting languages’ are often considered poor substitutes for their heavy-weight counterparts like Java and C++. Saying farewell to that term (at least as the primary manner in which we categorize our favorite languages) may be a good first step in broadening IT Management’s all too myopic vision.

For more on this topic, you might also be interested in ActiveState’s Dynamic Languages whitepaper.

Comment

* * *

Ruby on Rails :: Rails 0.11.0 released · 1264 days ago

This blog is about dynamic programming generally, but most often Ruby and Javascript specifically. So, it would be a crime against protoscript’s nature to not announce the announcement of Ruby on Rails Ajax support!

Ajax helpers in this most recent release remove the need to handle ajax-style requests manually. While I am quite sick of hearing about how “ugly” javascript is, it is true that manually dealing with XMLHTTPRequest gets old quickly.

Have fun with Rails!

Comment

* * *

© Jared Nuzzolillo