The amazing adventures of Doug Hughes

Archive for the ‘Blog’ Category

Unborking VPN on OS X

For those of you using the inbuilt VPN features on OS X, you may have noticed that from time to time it will stop wanting to connect. For me, pretty much any time I disconnect from VPN, the next time I try to connect I will get an unfriendly message that looks like this:

VPN Connection An Unrecoverable error occurred. Verify your settings and try reconnecting.

This happens to me way too often. It can happen when trying to connect, it can happen after disconnecting and then reconnecting, it can happen without any apparent provocation.

In the past it seemed like the only option was to completely restart OS X. As you can imagine, this is not an acceptable solution to someone who keeps a lot of apps open, needs to use VPN frequently, and who doesn’t wish to waste time rebooting for no good reason.

Thankfully, Joe Bernard was able to track down the solution and was kind enough to share it with me.

Apparently there’s a process in OS X called “racoon”. Racoon is in charge of VPN connections. Here’s what Apple’s man pages have to say about it:

racoon is used to setup and maintain an IPSec tunnel or transport channel, between two devices, over which network traffic is conveyed securely. This security is made possible by cryptographic keys and operations on both devices. racoon relies on a standardized network protocol (IKE) to automatically negotiate and manage the cryptographic keys (e.g. security associations) that are necessary for the IPSec tunnel or transport channel to function. racoon speaks the IKE (ISAKMP/Oakley) key management protocol, to establish security associations with other hosts. The SPD (Security Policy Database) in the kernel usually triggers racoon. racoon usually sends all informational messages, warnings and error messages to syslogd(8) with the facility LOG_DAEMON and the priority LOG_INFO. Debugging messages are sent with the priority LOG_DEBUG. You should configure syslog.conf(5) appropriately to see these messages.

In a nutshell, Racoon gets borked. Sometimes this means that the racoon process needs to be restarted, but in my experience 99% of the time it means that it’s not actually running.

So, you can restart racoon from the terminal like so:

sudo /usr/sbin/racoon

I’ve also found that sometimes you need to restart the various networking interfaces you’re using. Because of this, I ended up writing a shell script I call fixnetwork.sh:

sudo ifconfig en0 down
sudo ifconfig en1 down
sudo ifconfig en0 up
sudo ifconfig en1 up
sudo /usr/sbin/racoon

I put this in my home directory, set it to be executable, and can run it like so:

~/fixnetwork.sh

Works like a charm for me. No more reboots to fix borked VPN connections! Productivity, here I come!

CoolBeans – an IOC container for Node.js

I just finished writing my first publiclyavailablemodule for Node.js. If you’re not familiar with Node.js, well, I’m just sorry to hear that. Go learn.

The module I wrote is called CoolBeans. (Thanks for the name, Mr. Chris Peterson).CoolBeans is an Inversion of Control (IOC) / Dependency Injection (DI) library for Node.js. CoolBeans is loosely basedon ColdSpring for ColdFusion and Spring IOC for Java. It’s a single js file and currently appears to be quick and easy.

To install:

npm install CoolBeans

To use CoolBeans you simply create an instance of the CoolBeans and load the configuration file like this:

var cb = require("CoolBeans");
cb = new cb("./config/dev.json");

The above code is the only require function you should need in your entire application. Once you’ve required CoolBeansyou need to create a new instance and pass in the path to its’ configuration. This is shown above.

Once you have the fully loaded CoolBeans you can use it to quickly create fully configured singleton objects based onits’ configuration. The config file for CoolBeans is a JSON file so the entire thing is wrapped in {}.

Each element in the root of the configuration file is a bean (bean = Java for object) that CoolBeans can create. Here’s anexample:

{
  "fs": {"module": "fs"}
}

This is essentially the same as:

var fs = require("fs");

However, we now only need to define this one time for an application, rather than in each file that requires it.

You can also specify paths to modules that are not node_modules. For example:

{
     "Recipient": {"module": "./entities/recipient"}
}

At the most basic, the above means that CoolBeans will call require for the module and cache the results in a variable named Recipient.

As a relative newb to Node.js, I think I’ve handled this correctly. CoolBeans is a node module which means that NPM will install into ./node_modues/CoolBeans. The actual CoolBeans script is in the lib directory. That means, that from the perspective of CoolBeans your components are three directories above it. For this reason, CoolBeans looks three directories above it for the module specified. So, the Recipient module above actually turns into ../../.././entities/recipient. This has the effect of making the paths to modules specified in the configuration file relative to the root of your module or application. So, if you make a module that depends on CoolBeans and later publish it via NPM I think it should work correctly when used in other projects.

You can get any of the configured beans by calling cb.get(“beanName”) where beanName is the name of the bean you want to get. For example:

cb.get("Recipient");

The above will lazily create the Recipient bean, cache it as a singleton, and return it.

You can get a lot more complex with configuration too. For example, you can specify if CoolBeans should call a constructor and what arguments to pass into the constructor. For example:

"codeGenerator": {
     "module": "./util/codeGenerator",
     "constructorArgs": [
         "foo",
         123
    ]
}

What the above is saying is that when we get the codeGenerator bean, we need to load the module specified then call new on the module and pass in the values specified in the constructorArgs section to the constructor. The above means:

new codeGenerator("foo", 123);

You can also specify more complex values to pass into constructor arguments:

"codeGenerator": {
    "module": "./util/codeGenerator",
    "constructorArgs": [
        "foo",
        123,
        {"value": [1, 2, 3]},
        {"value":
            {
                "foo": "bar",
                "bar": "foo"
            }
        }
     ]
}

Note that while you can specify a string without indicating explicitly it’s a “value”, for arrays and anonymous objects you need to provide an object with a property named “value” whose value is the value you’re trying to pass in. The above could be written more explicitly as:

"codeGenerator": {
    "module": "./util/codeGenerator",
    "constructorArgs": [
         {"value": "foo"},
         {"value": 123},
         {"value": [1, 2, 3]},
         {"value":
             {
                  "foo": "bar",
                  "bar": "foo"
              }
         }
    ]
}

Strings, numbers, arrays, and anonymous objects are not the only things you can pass into constructors. You can also specify other beans that could be passed in. For example, let’s say we had a database configuration object you want to pass into any object that is used to access data you could do the following:

"mysql": {"module": "mysql"},

"dbConfig": {
    "properties": {
        "host": "server.hostname.com",
        "port": 3306,
        "user": "mysqlUser",
        "password": "password123",
        "database": "foobar"
    }
},

"recipientDao": {
    "module": "./db/recipientDao",
    "constructorArgs": [
        {"bean": "dbConfig"},
        {"bean": "mysql"}
    ]
}

The mysql bean is simply the same as saying require(“mysql”). The dbConfig is an anonymous object with properties specified (more on this in a bit). When the recipientDao (dao = data access object) is created, CoolBeans will see the “bean” property and will create and pass into the constructor the fully-constructed dbConfig object and the mysql object. Here’s what that recipientDao might look like:

module.exports = function(dbConfig, mysql){
    this.listRecipients = function(userId, callback){
        var client = mysql.createClient(dbConfig);
        client.query(
        "SELECT id, name, addressLine1, IfNull(addressLine2, '') as addressLine2, city, state, zip, taxDeductible, created, updated, 0 as netDonations " +
        "FROM recipient " +
        "WHERE userId = ? AND deleted = 0 "+
        "ORDER BY name",
        [userId],
        function(err, results, fields){
            client.end();
            callback(results);
        });
    }
}

Note that there are no require statements. The object just gets its’ dependencies when it’s instantiated and can immediately use them. These dependencies are also automatically singletons.

Also note that if you want to use a transient object you would still create an instance of it the way you always have.

I also mentioned above that CoolBeans can be used to create create and populate anonymous objects. For example:

"dbConfig": {
    "properties": {
        "host": "server.hostname.com",
        "port": 3306,
        "user": "mysqlUser",
        "password": "password123",
        "database": "foobar"
    }
}

This is a somewhat long-winded way of saying

dbConfig = {
    "host": "server.hostname.com",
    "port": 3306,
    "user": "mysqlUser",
    "password": "password123",
    "database": "foobar"
};

However, once this object is configured in CoolBeans you can easily pass it into other objects when they are created.

You can also specify properties for not-anonymous objects. You can also mix and match constructorArgs and properties.

For example:

"creditCardDao": {
    "module": "./db/creditCardDao",
    "constructorArgs": [
        {"bean": "dbConfig"},
        {"bean": "authorize"},
        {"bean": "mysql"},
        {"bean": "CreditCard"}
    ],
    "properties": {
         "service": {"bean": "service"}
    }
}

When CoolBeans creates the creditCardDao it will first load all the beans specified in the constructorArgs. It will then create the creditCardDao and pass in the four already-created beans to the constructor. Once the object is constructed it will set the service property on the object to the specified service bean. Note, CoolBeans will look for a setter and use that if it can find it. For example, in the service property above, ColdBooks will first look for a function named setservice (note that this is case sensitive). If it can find it, it will pass in the service bean to that function. If not, it will simply set a public property on the object.

There are a few other interesting capabilities of CoolBeans:

Beans don’t have to be lazily loaded. You can set a bean to load when the container loads. For example:

"dateFormat": {
    "module": "./util/dateFormat",
    "lazy": false
}

Also, if you have a factory that is used to construct other objects, you can specify this using the factoryBean and factoryMethod properties. For example:

"knox": {"module": "knox"},

"s3client": {
    "factoryBean": "knox",
    "factoryMethod": "createClient",
    "constructorArgs": [
        {"value":
            {
                "key": "myKey",
                "secret": "mySecret",
                "bucket": "myBucket"
            }
        }
    ]
}

The above s3client bean is configured so CoolBeans uses Knox to create it. The constructor args are passed into the factoryMethod as if it were a constructor. The above essentially boils down to:

s3client = knox.createClient({
    "key": "myKey",
    "secret": "mySecret",
    "bucket": "myBucket"
});

The really nice thing about CoolBeans is that it lets the objects in your system stay focused on what they do best. It shouldn’t be your object’s responsibility to know what they need to work. They should simply get what they need to work when they’re created. CoolBeans also helps avoid situations in complex apps where you have dozens of lines of code just getting dependencies created just to create one object that otherwise happens to have a lot of dependencies. Lastly, CoolBeans allows you to easily change how your application is configured in different environments.

If you’re a Node.js developer I’d love to hear your thoughts on CoolBeans! Heck, I’d love to hear your thoughts even if you’re not.

Soliciting Stack Suggestions

I am part owner of another web company, which shall remain unnamed. A few years ago I (and a couple others) wrote their current web application. Initially the application was sufficient, but over time weve run into some limitations of the applications architecture.

For example, this was written before I realized that writing fat controllers was a bad idea. In fact, this is such an early project that it ran on a pre-1.0 version of Model-Glue. There was no concept of ColdSpring at all. It used a stand-alone tool to generate the data access layer (which eventually inspired me to write Reactor, which is now also defunct).

Furthermore, the business requirements have changed over time. The site was initially built to satisfy one specific use case: selling a given product in one specific way.

Overtime the business team has requested new features that are difficult or impractical to implement in the existing architecture. For example, they want to be able to edit and add content on the site without involving me or any other technical staff. They also want to start selling other products in slightly different ways from their original plans.

Long story short, its time for a rewrite. I now need to choose a stack of frameworks, languages, etc, that are appropriate for this project. Im afraid that Im over complicating things and was hoping that the general Internet might have some suggestions.

So heres what I can say I think I need:

  • I need a Content Management system that allows the business and marketing team to add pages to the site, edit content, and generally manage the Information Architecture of the site. They need this because I am not as responsive to their requests as they would like. I do have Alagad to run on a day-to-day basis.
  • I need to write custom code that integrates with the CMS to support the unique business requirements of this application. This would include management of the product being sold, reporting, integration with other third party systems, and more. There really are not any off the shelf tools that I could use to replace this custom work. I really want to write this code to leverage IOC and OO. One of the biggest challenges weve had with the existing site is that it is mostly pseudo-OO, which makes changes and enhancements more difficult to implement. Hence, the rewrite we need to do!

For a content-heavy site Id typically use an off-the-shelf CMS like Mura or Farcry. For a custom-code-heavy site Id typically use Model-Glue and ColdSpring to help me structure clean maintainable code.

The problem comes in when I try to do both: Use a CMS and write clean maintainable code.

My experiences (though dated) with Farcry pretty much suggest that you have to write code Farcrys way if you want to do anything custom. I honestly just dont like Farcrys approach.

Ive also worked with Mura quite a bit over the last year on a different project. For that, we used Mura as the CMS and wrote a Mura plugin to run Model-Glue events based on how a content element is configured in Mura. Its my opinion that this was a reasonably good stack.

Ive even considered writing my own CMS that integrates nicely with Model-Glue, but thats really a non-starter.

For this rewrite I have been planning to use the following stack:

  • Mura for content Management.
  • ColdSpring, Model-Glue and Hibernate for custom code that will be run within Mura via a Mura plugin.
  • JQuery
  • This would be run on Railo, which would run in Tomcat.
  • Eventually this would be deployed as a WAR to Amazon Elastic Beanstalk or another Java Platform-As-A-Service provider.

And while that seems like a reasonable stack to me, I have a few concerns:

  • Overall performance: The Mura + Model-Glue project I mentioned earlier has been suffering general performance woes. Many of these could be attributed to the sheer volume of custom code and the fact that it is not running the latest updates to Mura and Model-Glue. These have mostly been ironed out, but its still an area of concern to me.
  • I might be crazy: To me, the stack above makes sense. However, every other developer who has worked with me on this stack doesnt like it. At all. Some developers dislike Mura. Some developers dislike the Model-Glue integration. Some developers think the stack is too deep. Some dislike using unfamiliar platforms like Tomcat and Amazon EBS. Lastly, very few developers have experience with the complete stack (even when you ignore Tomcat and Amazon).

I know I could build this system using the stack Ive outlined above and Im reasonably sure I can get it to perform well. However, I feel like Im not seeing something that everyone else sees. Ive even had three contract developers quit in the early phases of this project.

Im not sure if my stack should change. Thinking pragmatically, can you think of an alternative approach to this problem? One that lets the business and marketing teams have the flexibility they need and also allows developers to write clean, well structured code, using the latest best practices?

Im open to all suggestions. Ive been considering other languages and platforms. However, I also need to keep in mind my learning curve on any other tools or languages that might be used as well as unique business requirements that may make some choices impractical.

Id greatly appreciate your suggestions. What are your thoughts?

Remember to Contribute to OSS (or Tweet) to Get an Alagad Backpack

Alagad BackpackPardon the shortness of this post, I simply wanted to remind those out there who follow this blog that I’m holding a contest to give away a very nice Alagad Swiss Gear laptop backback. To quote Vicky Rider of CodeBass fame, they’re “legendary”. All you need to do is make a first time contribution to an open source project and comment on it on this entry. The best first time contribution will be picked and that lucky person will get the backpack! The contest is open through the end of the year and, as of now, I’ve receivedpreciselyzero submissions.

So, go forth and contribute. Then report back! It’s that simple. You’ll be helping support the community of OSS developers and you just might get a really, really, nice backpack out of the deal!

Also, to try to drive a little interest in this contest, I’m holding a side contest for yet another Alagad bag. Simply tweet the following to enter and I’ll pick a random tweet the same day that this OSS contest ends. Here what you tweet:

Now I wish I’d never contributed to open source! #AlagadBag http://bit.ly/eJvDfi

Also – you may want to note that CodeBass is holding a contest to give away some swag to commemorate their MediaSlurp collaboration. I’ve donated an Alagad bag to their swag set. Get more info and learn how to enter their contest here.

Contest: Best First Time Open Source Contribution (Updated)

A couple of days ago I asked for suggestions for contests so that I could give away a bunch of extra Swiss Gear Alagad laptop backpacks that are taking up my precious garage space. I received a number of good suggestions and, for my first contest, I’m going to go with Kurt Wiersma’s suggestion: Best First Time Open Source Contribution! (Congrat’s Kurt – Send me your address and I’ll send you a backpack.)

The contest title is pretty self descriptive. I want to encourage those of you who haven’t contributed to an open source project in the past to contribute. So, go out, choose a project you deem worthy and contribute. It doesn’t matter how you contribute. Obviously you could contribute code or bug fixes. You could also write documentation. There are probably other things you could do as well. For example, maybe you could start a fundraising or publicity campaign for your designated project. The choice is yours – be creative!

As you make your contribution please put a summary into the comments on this blog entry. Be sure to make a good sales pitch on why your contribution should be the winner. When the contest ends I’ll post a survey and the community can choose which contribution is their favorite. The winner will get a really nice laptop backpack. Everyone else will get the glowing sense of well being and pride in knowing you’ve done a good deed.

The contest starts now and runs through the end of 2010.

Alagad BackpackI’ve given away several of these backpacks in the past, but, if you’ve never seen them in person, trust me, they’re very nice! I’ve been using mine for about two years and it still looks brand new. It’s very well constructed from very nice materials. It’s well padded and won’t hurt your shoulders, no matter what you load into it. There are about a bazillion pockets on this beast – more than enough to securely store and organize just about anything you might want to cary with you. Heck, it’s even gotventilationchannels to keep your back cool!

So, please, go do a good deed and help out an open source project and report back!

Update: I’ve added a side contest to this contest. More information can be found here. In short, all you need to do is tweet the following to enter:

Now I wish Id never contributed to open source! #AlagadBag http://bit.ly/eJvDfi

Contest: Help Alagad Give Away Swiss Gear Backpacks

Alagad BackpackI have a bunch of promotional laptop backpacks I purchased for Alagad taking up precious space in my garage. These are very nice swiss gear backpacks with the Alagad logo tastefully embroidered on the back pocket. They’ve got, I’d guess, a zillion pockets, lots of storage space, can fit a 17″ laptop, and are tough as heck. I’ve been using mine for a couple years and it still looks like new! I really want to give them away to good homes, but I’ve been struggling on how to best do this. Maybe you can help?

A few weeks ago I posted a contest where entrants would make a word search generator in an unfamiliar language. And, well, honestly, that went over like a lead balloon. I hadpreciselyzero entrants. Maybe I made it a bit too complex?

I’d like to turn this into a game or a contest or something of the sort and have a little fun with it! Furthermore, a little promotional activity can’t hurt since it looks like Alagad will be winding up their current contract in April. (It’s never too early to be looking for the next gig.) If possible, it’d be really nice to be able to help people learn something new or, perhaps, help out those who are less fortunate, especially durring this time of year. Winners of these contests would get an Alagad backpack.

So, this time I’m having a contest to come up with ideas for contests, games, or whatever. If you have an idea on what I should do to give away these backpacks post it in the comments below. I’ll pick one or more of the ideas and run with them. If your idea is picked, you’ll get a very nice backpack for your troubles!

So, how should I give away these backpacks?

Make a Word Search Puzzle Generator and Win an Alagad Backpack

Alagad Backpack

My family is in the midst of downsizing a bit and moving to a new house. While digging around in our attic I discovered a set of Alagad promotional backpacks. Personally, I love mine. It has about a bazillion pockets, is very well made, and can easily hold a 17 laptop. Over the last few years Ive given a number of these away and everyone who has one raves about them.

I dont plan to sponsor any conferences any time soon and so I thought I should come up with a way to give these backpacks away. (Ive only got so many backs, myself.) What better way to do this than to have a contest?

Example Word Search My son loves word search puzzles. He loves them enough that Ive often considered writing a simple application to generate word search puzzles for him. In my minds eye I see an application where I can provide various options I can choose from such as:

  • How many letters wide and tall a puzzle should be.
  • A maximum length for and number of words to choose randomly from a dictionary.
  • An option to provide your own words and title.
  • Directionality settings. Such as forward, down, down at an angle, backwards, backwards at an angle, up, etc. These would control how words would be hidden in the puzzle.

Clicking a button would spit out a word search that I could print out and do with a pen. Im sure you could come up with many of your own ideas for how a simple word search generator might work.

Of course there are already a wide number of word search puzzle generators on the web, but as a programmer I was interested in the challenge. And so, here is my challenge to the community in general: Create a word search generating application.

And heres the twist: Create the word search genrator in any language (or technology) you dont already know. If I were to write this right now Id probably choose NodeJS since Im interested in its capabilities and itd be fun to do something more than just a hello world application in it.

Your application can be as complex or simple as you want. Complexity doesnt guarantee a win and neither does simplicity. What Im going to be looking for is the uniqueness of the language you choose and how well written the application is from my personal perspective. For example, Ill be more interested in a well-written Clojure application than a poorly written one in Ruby or C. Yes, its entirely subjective, but Im less familiar with Clojure (and bet most of my readers are too) and therefore would be more interested in seeing what can be learned.

Submissions are due a week from now. Ill start reviewing them on Tuesday the 26th. Depending on how loudly people complain I may push this deadline back.

Once Ive had a chance to review the entries Ill pick three winners, each of whom will get one Alagad backpack. Ill then write a blog entry (or three) about the entries, the languages used, and the approaches taken in building the applications. Assuming its practical, Ill also host the applications so the whole world can play around with them. Furthermore, Ill publish a SVN or GIT repository where people can download the source code.

Every time I do one of these contests I forget something important. So, if you have any questions or concerns please add them in the comments. Ill reply and clarify.

Good luck!

Tag Cloud