Getting Started with Gulp, Browserify, and npm

I started using Gulp and Browserify lately and, quite frankly, they’re great.  However, transitioning to a new build system is not without its pain points, no matter if you’re moving from something like Grunt or if you’re adding your first build tool to an existing project.  The documentation is good and Gulp itself is easy to use, but most of the browserify examples are geared toward simpler projects where only one bundle is needed.

For example, if you’re creating a website of any significant size, there are likely to be multiple pages with varying functionality. You don’t want to create one giant bundle that contains your entire site’s JavaScript. Monoliths are bad, mmmkay?  With that in mind, here are the main points that we’ll be walking through:

That’s a lot of stuff to cover.  As the title of this article implies, I’m assuming that you’re starting from zero.  If you already know a little about npm, gulp, or browserify, you can probably safely skip ahead.  TL;DR: If you’re already decently acquainted with all of these tools, then you can just take a look at my gulpfile.js. … 


Installing PHP Couchbase extensions and libcouchbase on Mac

Following the instructions from and didn’t work for me. When using the next version, with libcouchbase installed the recommend way (the way I show you not to do it below), I got this error when using their precompiled binary:

I tried using the latest version of libcouchbase (also shown below); there were no more startup warnings, but the extension was just not showing up in the modules list. Next, I switched to using the precompiled binary from the current version. Again, no PHP startup warnings, but the extension was just not showing up. So, I poked around and found this combination that works on both OS X 10.7 and OS X 10.8.

We simply need to install the latest version of libcouchbase and then compile the Coucbase PHP extension ourselves.

First off, do not do:

This will installs the wrong version and you’ll see an error like this when you get to the ./configure step.

Instead, install the latest version of libcouchbase, and get the couchbase php extension source code and compile it:

Then, register the couchbase extension by adding the following to your Mine is /etc/php.ini.

Now, you can confirm that PHP is loading this new extension by doing:

You should see couchbase in the list of modules. If you see it there, everything has gone according to plan.  If it doesn’t show up and you see no startup warnings, you can try specifying the extensions path explicitly.

Lastly, restart Apache

and double check that the couchbase module is being shown when you do a phpinfo();


Inserting DATETIME’s with Spring’s JdbcTemplate and NamedParameterJdbcTemplate

Ran into another bit of trouble today that cost me another sizable chunk of time. When using Spring’s NamedParameterJdbcTemplate to insert into a DATETIME column, the following doesn’t work:

Your date will be happily insert, but you’ll be sad to know that the time component has been truncated to something like “2012-08-28 00:00:00.” Using Types.TIMESTAMP has the same effect.

Using Types.TIMESTAMP is actually correct, but the secret is that you have to wrap your java.util.Date in a java.sql.Date.

If you’re reaction is one of disappointment, then you’re feeling the same way I did.

For simple JdbcTemplates, there is sufficient behind the scenes magic that you don’t run into this kind of problem. The following works without any translations or other such boilerplate (making the above that much more … dissatisfying).

I leave you with a list of SQL types and their Java equivalents, which is how I finally solved my problem with NamedParameterJdbcTemplate.


Installing PHP 5.4 with MacPorts

I had a little bit of a run around trying to figure this out. So here’s the full process, all in one place for your convenience. This assumes that you have MacPorts installed, but if you don’t, there are several ways of doing so.

Before we get started, be sure to disable OS X’s default Apache install if you haven’t done so already.  This can be done by opening System Preferences, going to Sharing and disabling Web Sharing.

If you don’t care about the explanation, skip to the bottom.

Let’s get started. Open Terminal, and paste the following:

This will install Apache2 and PHP 5.4, and setup Apache to start on boot.

Next, configure Apache to use PHP 5.4. Create the file /opt/local/apache2/conf/extra/php.conf,

And paste the following into it:

This will load the PHP 5.4 module, make index.php the default directory index file and cause files with .php and .phtml extensions to be interrupted by said PHP module.

Next, tell Apache to include your new PHP config file. Open the httpd.conf,

And add this line to the bottom:

Lastly, restart Apache.

You should now have a functional PHP 5.4 environment. Also, don’t forget that you’ll need to reinstall all of your favorite PHP modules. Here’s what I normally roll with. Don’t forget to restart Apache again.

TL;DR: If you have su access, you can just copy and paste the whole thing all at once:


Configuring Remote Debugging in Jboss AS 7 and Eclipse

Configure JBoss

First, to enable JBoss to allow remote debugging, edit your <jboss install location>/bin/standalone.conf.    Now, look for # JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" and uncomment it.  It should be near the bottom.

If you are on Windows, you’ll need to edit standalone.conf.bat instead and uncomment rem set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

Start Jboss. You should now see something like this at the top of the output

Configure Eclipse

Configuring Eclipse is easy. First start by creating a new debug configuration by going to Run > Debug Configurations…  In the left side panel, select Remote Java Application, then in the toolbar up top, click on the new icon.  This will give you a new debug configuration.  On the right side, name it however you like.  Then, change the port to 8787 and the host to where ever your JBoss installation is running.  I’m running mine on the same machine that I am debugging on, so I leave it as localhost.  Hit the Debug button.

Lastly, you’ll need to switch to the debug view to see all of your tools. To do so, go to Window > Show View > Other…, type in  “debug” in the filter box and select the debug view.  You should now see a JVM with a list of a bunch threads.  If you don’t see any threads, make sure that JBoss is running and that you followed the steps above correctly.

If all went well, you can now set break points in your code and they should show up automatically in the debugger.


Change the Default Domain of a Shared IP in Plesk

Plesk is a great tool (especially compared to other domain management software), but some things aren’t as straight forward to change.  For example, if you setup a handful of domains on a shared IP, the first domain created on that IP will be it’s default.  So if you go directly to the IP in your browser (not the domain), the first domain that you setup is the one that you will see.  Fortunately, changing this is simple. … 


Generic Singleton Factory in JavaScript

I recently contributed this little tidbit to stackoverflow’s Hidden Features of JavaScript and thought it would be best to elaborate it on it fully. In a recent client project, I needed a generic method to produce singleton instances of interface widgets.  This is the method that I came up with and it works pretty well. Before we begin, these are not singleton classes in the normal sense, but a generic singleton factory. … 


Magento Onepage Checkout Template Bug

Recently, we rolled out an installation of Magento for one of our clients but ran into small a problem along the way. Being an established open source project, I initially assumed that the error was my own when I found that the onepage checkout process would stop working half way through (step 3 to be exact).  However, after digging around, I found that the problem was actually a bug in Magento’s JavaScript.  The bug has been reported and will hopefully be fixed soon, but in the meantime, here’s the fix and how I found it. … 


Semicolon insertion finally caught me

While debugging a caching class today, I realized that I had finally been caught by semicolon insertion.

Here’s the original code cut from a larger object literal

After about 10 minutes and a gratuitous amount of debug output, I realized that this function was returning undefined.  “Nonsense,” I said to myself, “it’s returning a boole…wha…wait. Dammit.”

In my effort to document and format at the same time, I dropped the expression to the next line after the return.  Being that return by itself on a line is a complete and valid expression, JavaScript’s automatic semicolon did its thing and ended the statement there and my conditional expression was never evaluated.

Wrapping the whole conditional expression in parenthesis fixed the problem by invalidating the return line as a whole statement.

Let that be a lesson to us all. I suppose it was bound to happen at some point.