Monthly Archives:

April 2008

Posted on April 28, 2008 by Chris LoSacco

Need to cite this article?

Online science magazine ScienceDaily has a great little feature at the bottom of its articles: a simple, straightforward display of how to cite the article in APA or MLA format. Brilliant. This is one of those little things that goes a long way; I would have killed for this in college!

ScienceDaily Article

| Comments (1) | Technorati Tags :

Posted on April 24, 2008 by Ben Sgro

Gaining Insight into Your Zend Queries

Zend Framework is great. However, there is a limitation when using the database abstraction layer: You are unable to see the SQL query Zend is generating. Below is a patch that can be applied to the Pdo.php class. It will log all SQL queries to a file. It requires that your development directory structure includes a log/directory and a sql.log file, with the correct permissions. Of course, you can change this to fit your development environment.
-- Pdo.php.bak 2008-04-21 11:04:26.000000000 -0400
+++ Pdo.php     2008-04-21 13:35:54.000000000 -0400
@@ -227,6 +227,15 @@ class Zend_Db_Statement_Pdo extends Zend
   */
  public function _execute(array $params = null)
  {
+        /**
+         * This does not go into production code.
+         * To use:
+         *
+         * # touch sql.log
+         * # chmod 777 sql.log
+         */
+        file_put_contents("../log/sql.log", date("D M j G:i:s T Y") . ':' . $this->_stmt->queryString . "\n", FILE_APPEND);
+
      try {
          if ($params !== null) {
              return $this->_stmt->execute($params);

To install the patch, move to the Pdo.php directory and execute:

patch -p0 < PdoPatch.txt

Once the patch is installed, you can conveniently tail the sql.log file and watch each query.

# tail -f sql.log

It's not the most elegant hack, but it works fine for development. This is not recommended for production environments.

| Comments (3) | Technorati Tags :

Posted on April 21, 2008 by Matt Williams

Preventing Accidental File Deletion in Unix

Every seasoned command-line user has at least one horror story involving an accidental file deletion.

Unfortunately, experience won't prevent this from happening again as fingers will still occasionally outrun (or outmaneuver) the preoccupied brain.

One way to defend against this is to use the -i flag with potentially destructive commands such as cp or rm. Even if it were possible, however, to train yourself into this habit 100% of the time, that's 3 extra characters to type with every file manipulation command - not exactly efficient.

The best line of defense is to modify the .bashrc (or .bash_profile) file in your home directory to alias these commands.

alias rm="rm -i"
alias cp="cp -i"

Great, but...

...deleting a directory containing many files can become a huge annoyance, since the -i flag will prompt you about deleting each file. This is what the less popular -I (uppercase i) flag is for. Unfortunately, this isn't available with every implementation of rm (looking at you OS X!), but if your *nix supports the flag (man rm and look for the flag if you're unsure), you'll get a single prompt when you try to delete a directory using the -r flag asking if you want to recursively delete. If you prefer this (I do) and if your *nix allows it (Debian does), just modify the alias that you just created.

| Comments (0) | Technorati Tags :

Posted on April 21, 2008 by Chris LoSacco

Updated : SVN Notifier 1.0.1

Thomas Roessler sent us a note that we had a pretty major security hole in our lab widget, SVN Notifier, that allowed unrestricted system access (yikes!) to nefarious commit messages. We spent some time in the code today and plugged up that hole, and made a few other fixes and tweaks as well. This latest release, 1.0.1, is recommended for all users (you can get it from the lab).

Thanks very much for the heads up, Thomas!

| Comments (2) | Technorati Tags :

Posted on April 21, 2008 by Javier Julio

Adding A ContextMenu To A Flex Tree

I've been working on an AIR application for managing SQLite databases where I've been using the Flex Tree component to list out all databases. I've been having a hard time finding good resources on working with a ContextMenu (right click menu) on a Tree component.

I tried my luck on adding a ContextMenu to the Tree component itself and managing it there. But that idea went sour because I couldn't find a way to get the current Tree item selected since right-clicking doesn't actually select it. After checking out what others have done, this wasn't getting any easier because I wasn't convinced by the solutions provided. They seemed more like hacks when I knew this should be pretty simple.

It never occurred to me to try adding the ContextMenu on a Tree ItemRenderer, so when I originally thought of it, I figured eureka, that's it! Ultimately, though, I didn't think it through that well since adding a renderer would also remove the folding arrows and folder/leaf icons. Ouch! Although now I know what was needed, I realized that adding a TreeItemRenderer is not the same as another List-based renderer such as one for a DataGrid or List component.

After following the solution on the Flex Cookbook, I dropped in that demo item renderer and was able to attach a ContextMenu object to it in the renderer constructor. So something like this:

public function DatabaseListRenderer()
{
super();

var contextMenu:ContextMenu = new ContextMenu();
var menuItems:Array = [];
var edit:ContextMenuItem = new ContextMenuItem("Edit Name");
edit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, databases_menuItemSelectHandler);

menuItems.push(edit);

contextMenu.customItems = menuItems;
this.contextMenu = contextMenu;
}

private function databases_menuItemSelectHandler(event:ContextMenuEvent):void {
trace("menu item selected: " + data);
}

Now when I right-click on a particular item and select a menu option, the event handler fires and I see my trace message. Notice I dump out the data to see what's there (debugger is a better place for this) and I see the data for that specific Tree item as if it were selected. Problem solved!

| Comments (8) | Technorati Tags :

Posted on April 18, 2008 by Avi Flax

Patrick & Avi's Java Tips #2: Graceful JVM Shutdown in Eclipse

If your Java application has any Shutdown Hooks, you probably want them to run every single time you stop your app - even when it's running within Eclipse. Unfortunately, when you click the red "Terminate" button in Eclipse, it kills the JVM process abruptly; Shutdown Hooks don't have a chance to run.

<p>Here's my approach to this problem:

  1. Add an environment variable to your run configuration, in the Environment tab. I call it RUNNING_IN_ECLIPSE, I like to be super-explicit. Set its value to TRUE.
  2. Add this block to the bottom of main():
    /* a hack to make sure that our shutdown hooks get called from within eclipse */
    if (Boolean.parseBoolean(System.getenv("RUNNING_IN_ECLIPSE")) == true)
    {
           System.out.println("You're using Eclipse; click in this console and
    press ENTER to call System.exit() and run the shutdown routine.");
           System.in.read();
           System.exit(0);
    }
    

As the code says: from now on, any time you run your app using this run configuration, the console will listen for input, blocking. As soon as you click in the console to give it focus and press enter, the next line will call System.exit(0), which will tell the JVM to gracefully shut down, which includes calling your shutdown hook.

| Comments (0) | Technorati Tags :

Posted on April 16, 2008 by Michael Helmuth

Resizing Your Windows XP Boot Partition in Parallels

After many hours installing the various things required for .NET development on my Parallels instance of Windows XP, the last service pack was finally installing.  I really thought 14 gigs would be enough for my XP Parallels install.  Apparently, I was wrong.  Disk full.

Once I began looking at my options, I realized it was not as simple as using the Parallels Image Tool to expand the disk and boot partition.  The Parallels Image Tool allows you to resize the virtual disk but not your boot partition, or any partition for that matter.  Further, when you resize the image and then look in the XP disk manager, you find that you can partition and format your newly created space, but you can't actually resize the boot partition into it. Apparently Vista allows this from the Win disk manager but XP does not.

I did a little research and came up with a really cool little application called GParted (http://gparted.sourceforge.net/download.php).  This app offers a bootable disk image that allows you to manipulate the partitions of a Windows disk--which includes the boot partition. It turns out to be a brilliant solution to this problem.

In practice, there really are quite a number of steps involved, but nothing particularly difficult.  In my hunting I also turned up a helpful tutorial with screenshots to guide you every step of the way: (http://uneasysilence.com/archive/2007/01/9404/).  I followed that carefully and everything is working great.

Problem solved.

| Comments (0) | Technorati Tags :

Posted on April 16, 2008 by Avi Flax

Trying Out Blog It

Blog It is Six Apart's new Facebook app for blogging. I'm writing this post in it right now. Above this box for the post content, there are four checkboxes; one for each blog I've set up with the app. Simply by checking the desired blogs, I can send this post to any combination of them, with a single action. Pretty nice.

But there are already plenty of blogging apps - I'm currently using MarsEdit - so the big question is: what's special about Blog It?

A few things come to mind:


  • Most obviously: it's a Facebook app. That means it gets the advantages of a web app: nothing to download, easy upgrades, big potential user base, cross-platform; and one of the big advantages of a desktop app: no need to sign up, create an account, keep track of yet another password, or understand OpenID. Also, being a Facebook app, it gets the possibility of quick "viral" adoption, integration with an experience people are already using every day, and the ability to update the user's Facebook status.

  • Adding blogs is really, really easy. And a wide variety of platforms are supported.

  • Finally, a unique twist: it's not just for blogging. It's also for updating your "Status", on Facebook itself but also external services such as Twitter. I don't really use these services, but I do have accounts with some of them, which I opened just to try them out. It's pretty cool: a single text box and pressing enter can post an update to Facebook, Twitter, and a bunch of other services, all at once. I have four accounts set up, and it works very smoothly. Also notable is that apparently blog posts are also sent to these services as well - although I'm not quite sure how, or in what form. What gets posted? A link? An excerpt? Well, I'm about to find out.

A few drawbacks:

  • like most web-based blogging interfaces, the post body is typed into a large text area - with no auto-save. So if your browser crashes, or the post doesn't work, there's a good chance that any time spent typing could be lost. I know plenty of people - myself included - who've been bitten by this case. At this point I tell people to never spend more than five minutes typing in a web page. It's one reason that I use a desktop blogging app. (WordPress's built-in blogging interface does auto-save; one of it's best little-known features.)
  • The entry body is just a simple text area: no rich editing, no support for other media, such as images, music, video, etc. It's a bit of a throwback. Six Apart says this'll be enhanced soon, so this initial release can be thought of as almost a proof-of-concept.
  • The app is for posting only; once a post is up, it can't be edited within Blog-It; you'd have to use a different tool.
  • No ability to add tags or choose categories.

Here's what it looks like:
Screenshot of Blog It

It'll be interesting to see how Blog It grows and matures, and how it fares in the market, given its unique set of features and its identity as a Facebook app.

| Comments (0) | Technorati Tags :

Posted on April 15, 2008 by Joel Potischman

Parameterized XPath Expressions in .NET

Escaping parameters in an XPath expression in .NET is hard. Quick, which of the following is right?

Beats the hell out of me. Maybe one works, but I'm guessing not, and I'd assume a weird search term like Hello >:-< "How're you?" would blow me up. Fortunately, I found the wonderful Mvp.Xml .NET library, which will handle the tough work of escaping for me by letting me parameterize my XPath expressions, thereby protecting me from blowups and XPath injection attacks, like a search for '|@superuser='true. I can rewrite that search as follows:

How nice is that?

| Comments (0) | Technorati Tags :

Posted on April 9, 2008 by Javier Julio

JQuery Plugins: Callbacks and Now Triggers

Recently, I helped a developer with the JQuery TableSorter plugin where he needed to run some code whenever the TableSorter finished sorting. The plugin didn't provide any callbacks in its configuration which seemed odd, as this is normal practice with any JQuery plugin.

After digging through the plugin source code, I noticed it was using JQuery's "trigger" method which dispatched a built-in or custom event. From there, the solution was simple. When initializing theTableSorter plugin, we used the "bind" method to listen for any event bubbled up from within the plugin. In this case, we listened for the "SortEnd" event. An example can be seen below:

$("table.sortable")
	.tablesorter()
	.bind("sortEnd", function(){
		// fired when sorting has finished
	});

I had used the "trigger" method in an earlier project but never seen it used before with a JQuery plugin. We can expect to see two standards now on how to tap into a plugin event-- one using callbacks, and the other using events. If you run into a plugin that doesn't give the option to pass in a callback, be on the look out for a custom event trigger!

| Comments (0) | Technorati Tags :

Posted on April 5, 2008 by Javier Julio

ColdFusion 8.0.1 Released With New Features!



What's new you say? Well for starters we now have 64-bit support! AJAX libraries have been updated such as Ext to 1.1.1, Spry to 1.6 and YUI to 2.3. The <cftextarea> tag's rich text editor (using FCKEditor) now upgraded to 2.5. Not to mention some of the features that the CF team couldn't get into the initial release but we finally have.

1. Support for nested inline array and struct creation. You can now do the following:

<cfset myNestedArray = [ {version = "8.0.1"}, [1,2,3], [4,5,6], [7,8,9] ]>

2. Support for mixing attributeCollection and individual tag attributes with the latter replacing any occurrences in the former. So we can now do the following:

<cfquery attributeCollection="#queryProperties#" result="resultStatus">
...
</cfquery>

I definitely suggest checking out the release notes as the updater includes several bug fixes and a lot more specifics on what tags and other areas have been touched up. They also cover known issues with the updater that may affect you. A great release by the CF team with much appreciated features!

| Comments (0) | Technorati Tags :

Posted on April 4, 2008 by Javier Julio

Using ColdFusion Components (CFCs) in AIR Powered Flex Applications

Recently, I took one of my Flex/CF projects here at work to see how much effort and time it would take to deploy it on AIR without any of the desktop enhancements. I had no prior experience with AIR so I wasn’t sure what was involved.

The application uses the RemoteObject component in Flex to connect to CFCs to pass data and typed objects back and forth. Since it's deployed as a web application, Flex can figure out the “endpoint” automatically but since we are now on AIR, we need to provide that. An example if you were doing local development would be something like:

All I had to do was to add the "endpoint" property to all of my RemoteObject definitions. Since I used the PureMVC framework I had that nicely abstracted out as delegates within a business folder so it was even easier to find and get too. No other changes at all were required because my application now functioned on AIR as it would if it were in a browser.

| Comments (0) | Technorati Tags :

Posted on April 2, 2008 by Andy Lewisohn

Start RESTing on your laurels

There's a new ActionScript 3 library available over in the Arc90 Lab called RESTService. Now developers can make fully aware HTTP calls from Flex/AIR applications. There are some caveats for use on the web, but the desktop is fair game.

Take a look and let us know what you think.

| Comments (1) | Technorati Tags :

Posted on April 2, 2008 by Chris LoSacco

Introducing our first Apple Dashboard widget : SVN Notifier

It's widget time in the Arc90 lab. For all of you Mac developers who are a fan of the Dashboard and use Subversion for version control, take a glance at SVN Notifier. Growl support comes along, too!

Check it out and let us know what you think.

| Comments (25) | Technorati Tags :

Posted on April 1, 2008 by Joel Potischman

Exception-Based Programming : A Primer

One of the hallmarks of modern programming languages is structured exception handling. Put simply, exception handling is a way for programs to handle "exceptions" to expected behavior. An error occurs, and it rockets up the call stack until code that knows what to do with it "catches" it. If it's left uncaught, the program shows a big ugly error message to the user and exits. This reduces cross-cutting concerns by allowing application logic to separate cleanly from exception-handling logic.

Continue reading "Exception-Based Programming : A Primer" »

| Comments (1) | Technorati Tags :

March 2008 | Main | May 2008