Blog of Wonders

Author: Justin

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. … →

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:

1

brew install libcouchbase

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

1

2

3

4

5

6

configure:error:

It appears you are using libcouchbase1.x

ThisDP version of the php extension supports libcouchbase-2.0.0beta

orhigher.Either useastable1.0version of the php extension,

upgrade your libcouchbase,orspecify the location ofa

libcouchbase-2.0.0installation with--with-couchbase

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 php.in. Mine is /etc/php.ini.

1

extension=couchbase.so

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

1

php-m

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.

1

extension=/path/to/couchbase.so

Lastly, restart Apache

1

sudo apachectl restart

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

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:

1

2

3

4

5

6

7

8

9

10

publicclassExampleDao{

protectedNamedParameterJdbcTemplate jdbcTemplate;

publicvoidinsert(ExampleModel model){

jdbcTemplate.update(

"INSERT INTO `sometable` (`some_datetime_column`) VALUES(:datetime)",

newMapSqlParameterSource().addValue("datetime",newDate(),Types.DATE)

);

}

}

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.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

publicclassExampleDao{

protectedNamedParameterJdbcTemplate jdbcTemplate;

publicvoidinsert(ExampleModel model){

jdbcTemplate.update(

"INSERT INTO `sometable` (`some_datetime_column`) VALUES(:datetime)",

newMapSqlParameterSource().addValue(

"datetime",

newjava.sql.Date(newDate().getTime()),

Types.TIMESTAMP

)

);

}

}

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 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.

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,

1

sudo vi/opt/local/apache2/conf/httpd.conf

And add this line to the bottom:

1

Include conf/extra/php.conf

Lastly, restart Apache.

1

sudo/opt/local/apache2/bin/apachectl-krestart

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.

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.

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. … →

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. … →

Another discussion born from a question at stackoverflow. Today I’m laying out the differences between object literals and constructed objects, when to use which, how to get the most out of them, and a few other tricks along the way. Let’s get started. … →

Recently, we rolled out an installation of Magento 1.3.2.3 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. … →

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.