Cross-Domain Requests and Prototype

Ever since 3.5, cross-domain HTTP requests have been supported in Firefox. Getting this to work may seem easier and saner than piggy-backing Flash ("simply request a URL of different origin in your XMLHttpRequest!"), but unless you use jQuery, you'll realize that for some reason, cross-domain requests mysteriously fail in your JavaScript framework despite the fact that the server is correctly responding with an appropriate Access-Control-Allow-Origin header.

JavaScript Quiz and Explanations of its Answers

Update: Comments are now enabled.

In the field of linguistics, rules can be either descriptive or prescriptive. Simply put, descriptive rules tell you what can be done and prescriptive rules tell you what you shouldn't do. Many articles about JavaScript give you prescriptions: they tell you what you shouldn't do in JavaScript because it's bad practice. After learning to stay away from certain styles and patterns, though, sometimes a simple typo or brain fart can avalanche into a disaster in your code and still leave you puzzled even after attempting, descriptively, to explain what exactly happened.

kangax's JavaScript quiz, geared towards web developers, helps exactly that: finding descriptions that clarify perplexing situations. It does not test your knowledge of any DOM behavior and is focused on the ECMAScript language itself. Since this quiz targets web developers, SpiderMonkey gurus can likely even point to where a given quirk (the term is being used very loosely here) is manifested in the implementation. As always, please point out any possible error in the answer explanations about to follow. Those who are interested but still haven't taken it: halt! Go and take it. I'll wait. After that, read on.

Why Mac?

I have again been asked recently by those around me: "Why a Mac?" Despite that it was not so much of a shocking revelation when I realized that the general argument that it makes web development easier is no longer convincing anymore, I was still quite perplexed. After thinking for a few days straight, I finally nailed down the subconscious reasons why I chose a Mac in the absurd age where Apple hardware, in terms of specs, is no different than any other PC.

  1. It just works.
    This seems to go without saying, but it really is true that when I plug in the devices I bought to a Mac, it almost always works immediately. This is sometimes true for Windows, but half of the time I have to install the drivers that are included. Linux. It's getting there, but not quite. Ubuntu is doing an alarmingly good job at supporting various devices and in certain scenarios, outdoing Windows by a margin.
  2. Eye candy software and pretty hardware.
    I will not lie to myself and claim that eye candy is useless. When used sparingly, eye candy increases productivity by providing useful, intuitive visual cues and just pleasing the users in general. Linux needs lots of manual configuration to get there. The furthest Windows can get is either Aero on Windows Vista (which, I admit, is the prettiest version of Windows yet) and GDI++ on Windows XP. Customization is cool, but it does bring awkwardness when certain apps that break because they weren't written with Windows theming in mind.
  3. Sweet blend of proprietary and free software.
    Linux has a huge repertoire of free software, but there is a lack of commercial software support. Wine can alleviate this a bit, but there is a limit for Wine as to how native a Windows app can behave on Linux. Windows has the hugest amount of software available, be it commercial software, freeware, or free software, but even Cygwin can't make up its unfriendliness to various open source tools. Mac OS X, on the other hand, has lots of commercial software offerings (e.g. Adobe) and, along with its Unix / BSD heritage, makes messing with open source tools way easier in general.
  4. Viruses are out of the picture.
    Because Mac OS X does not have a huge market share, it is not an attractive platform for malware authors. This means I don't have to deal with security software and other similar headaches on a daily basis.

The fact that I have less time to reinstall Windows every now and then, lower tolerance for ugly UIs, more chances to muck around with Photoshop, and more lines in my ~/.bash_profile than your average user shows that Mac OS X is currently my ideal platform.

LOLFeed for Ruby

Flickr's recent introduction of the LOLFeed format was highly amusing. Following Mark Christian's footsteps, I decided to write a Ruby version of the LOLFeed parser. At first it was merely a port, but I then found the state machine to be too cumbersome, so I went all out with regular expressions. Read on for the code.

Ubiquity commands for Drupal

Ubiquity is a dynamic command and quasi-natural language add-on for Firefox, recently released by Mozilla Labs. It sure is getting ever so popular, so I decided to write two Drupal-related Ubiquity commands in one shot: drupal and drupal-api.

Building and compiling V8 on Mac OS X

Now that Google Chrome is released, the project page and repository of the V8 JavaScript engine is revealed and available for public hacking. This guide shows how to get the source of V8 and build a V8 JavaScript shell on Mac OS X Leopard.

Google Chrome SunSpider benchmark results

I promised to post the SunSpider benchmarks for Google Chrome, and boy, V8 surely blew away other browsers in many aspects! For the visual learners, here's a pretty chart to show just how monstrous Chrome is when it comes to JS perfs (as Intchanter noted, smaller is better):

Here are some nicely formatted raw numbers:

What Google Chrome means to web developers

With the release of Google Chrome just coming up tomorrow, by now the blogosphere should be on fire with all the screenshots and juicy details. Even though I see Google Chrome as something that means more to the user than to the developer, there are certain goodies in Google Chrome that aim to provide a better platform for developers. What's the implication for web developers here?

Mini-DVI, DVI-D, DVI-I, and frustration

It has been a while ever since I have been so pissed off. By Apple.

Apple sells these Mini-DVI to DVI adapters that work with MacBooks and whatever other kinds of Apple hardware that sport Mini-DVI ports, and, thinking that now I have a DVI to VGA adapter, I bought one of those Mini-DVI to DVI adapters at Fry's in hopes of finally being able to connect my MacBook to a VGA LCD monitor.

My dazzling happiness was abruptly halted when I realized that the Mini-DVI to DVI adapter does not work with my typical DVI to VGA adapter. It didn't fit. Then I realized that it's a Mini-DVI to DVI-D adapter, and my DVI to VGA adapter is a DVI-I to VGA adapter.

Even the packaging on the adapter showed a female DVI-I connector. Misleading enough, huh? Now I have to return the damn thing and buy an Apple Mini-DVI to VGA adapter, something Fry's doesn't have in stock.

Prototype Essentials: just the essence

One of my recent efforts is Prototype Essentials. It is, pardon my pun, essentially Prototype stripped of its browser-specific parts such as Ajax, DOM stuff, selectors, form helpers, and an event system. Why would anyone want a stripped down version of Prototype?

The big idea is that sometimes your preferred JavaScript library or your JavaScript environment has an underpowered API when it comes to pure programming. I'll draw two of my personal examples. I find jQuery to be awesome for intuitive DOM traversal and manipulation, but when it comes to non-DOM objects, what jQuery can do is limited (and also, in my own opinion, not as intuitive). Drupal is a great platform to build web apps on, but its simplicity (bundling jQuery) comes with a cost, and I find myself constrained because of this. Not anymore.

My second example is when I'd like to throw together a quick and dirty shell script using JavaScript on Rhino. I frequently find myself in need of an intuitive way to get the last element of an array (Array.last in Prototype), interpolate strings (String.interpolate in Prototype), or construct ranges ($R or ObjectRange in Prototype). Now all I need to do now is load Prototype Essentials and I'd have a much richer set of utilities.

So please check out the website I set up for Prototype Essentials. I also plan to wrap this into a Drupal module so I can ease my pains (and hopefully those of others) in JavaScripting in Drupal.

Syndicate content