Web development tips with a side of sarcasm

March 10, 2014
by Dirk Watkins

Test Your App on Slow Connections

The world is not on broadband.  A lot of people are still on dialup, or on cell phone connections.  Make sure you develop your web site and configure your servers for people on slow connections.

A great way to determine how your site behaves on slow connections is to test.  If you’re on a Mac you can do this with Apple’s Network Link Conditioner, part of Hardware IO Tools.  The download is behind a login so I’ll explain that later.

What it Does

The Network Link Conditioner will limit your bandwidth in and out of your computer.  Even to localhost. There’s a couple presets that you can play with, like wifi, Edge and 3G cell service, etc.

Network Link Conditioner

How to Get It

  1. Visit the Download section of Apple’s Developer Center
  2. Search for Network Link Conditioner  or Hardware IO Tools for Xcode
  3. Download Hardware IO Tools for Xcode (latest as of this writing was October 2013)
  4. In the DMG package is the Network Link Conditioner.
    network link conditioner install
  5. Double click the Network Link Conditioner.prefPane and it will install it into your System Preferences.

You’ll then be able to go into Apple > System Preferences and see a shortcut for the tool.

What to Do

Now that you know how your site behaves on slow connections, what should you do? Well, there’s a ton.  Here’s a shortlist:

  • Minify and bundle your javascript and css files.
  • Gzip compress the files being transferred from your web server.
  • Use sprite sheets to bundle images.
  • Load only what you need.

Oh, and Remember..

You’ll need to turn off the Network Link Conditioner when you’re done.  It’s limiting ALL traffic going in and out of your computer.

Happy programming.

Guinness has a thick head

November 23, 2013
by Dirk Watkins

How to pour Guinness from a can

Here’s the secret to pouring Guinness from a can into a pint glass.  Open the can, quickly jam it in the pint upside down, and slowly it pull out.  That’s it.

And if that isn’t clear enough, I made a little video for you.

It even “stands up” to the pencil test.


November 11, 2013
by Dirk Watkins

My Subversion Backup Script

In the name of all that’s good – backup your Subversion repository!

Your repo is the history of the code that runs your business.  Make sure you back that beast up.  You can safely back it up while developers are using it by running the dump command.

Take a dump

I like to script my dumps (backups) with a Windows batch script and then compress the output for long term storage. Here’s my batch script:


cd e:

set ts=%date:~10,4%%date:~4,2%%date:~7,2%
ECHO %ts%
set repoPath=E:\Repositories\Development
set tempPath=C:\SvnBackupStagingArea\DevRepoDump%ts%.svn
set backupPath=\\networkShareForBackup\DevRepoDump%ts%.svn.7z

ECHO Dumping SVN Repo 
svnadmin dump %repoPath% > %tempPath%

ECHO Zipping
cd "c:\Program Files\7-Zip"

set tempPathZip=%tempPath%.7z

7z a %tempPathZip% %tempPath%

ECHO Moving to network share
move %tempPathZip% %backupPath%

ECHO Cleaning up
del %tempPath%

ECHO Done.
ECHO Presented for you in it's smallest form, your backup: 
ECHO %backupPath%

The script creates a nice timestamp (ts) to append to the backup filename – it’ll end up to be something like DevRepoDemp20131111.svn.7z when it’s done. This depends on how your dates are set up in Windows so you might need to change this or remove it.

It then sets the temporary staging path and the final zipped up dump path for where you want the result to end up. The server that has the repository should be where you stage the backup file, so it can backup and zip as fast as possible. Make sure you have at least 1.5 times more free space available than the size of the repository – it’ll need to create a dump and then zip that dump.

SVNADMIN DUMP creates a hot copy of the repository. This works even if developers are using the repo while you are backing it up – Those particular changes probably won’t be in this backup though. That’s why you should run this on a schedule, preferably at least once a day that people are not using the repo, like around lunch time :)

Note: If you are using TortoiseSVN, make sure you have also installed the command line tools with it. Check your machine for svnadmin.exe – if you do not have it, re-install TortoiseSVN and include the tools.

7-Zip will compress the backup copy. And yes, this makes a big difference in the resulting file size. Our repo was 10 gig and it zipped down to 3.5g.

It’ll then move the zip to a network share, deleting the temp file.

Download the zipped batch file

Let me know if this helped you out.

September 4, 2013
by Dirk Watkins

Rangle Up Variables with JavaScript Closures

Using global variables in JavaScript is bad and can tick off other developers.  Use Closures to group your variables with proper scope and stop watching your back in JavaScript User Group meetings.

Here’s what I mean:

When you make a variable or function in JavaScript by default it’s defined on the global object and it can be accessed from anywhere.  Now we all know global objects are BAD – The names can conflict with other libraries, increase memory usage, make debugging a huge pain, etc. In JavaScript, the answer is to “enclose” your variables in a function.  The cool cats call this a “Closure.”

Here’s what I do:

var DirksApp = DirksApp || {};

(function ()
     var privateVariable = "I'm Private!";
     this.publicVariable = "I'm Public to the World!";

console.log(DirksApp.publicVariable);    //prints: I'm Public to the World!
console.log(DirksApp.privateVariable);   //prints: undefined

Instead of creating privateVariable and publicVariable in the global namespace, I’ve enclosed it in an “object” called DirksApp.  By declaring privateVariable with var it is only accessible from the inside of DirksApp.  Declaring publicVariable on this makes it publicly accessible off of DirksApp.

Just remember:

  • var for private
  • this for public

The initialization var DirksApp = DirksApp || {}; and apply(DirksApp) pieces allow the same Closure to be used in multiple files and will combine the objects. You’ll appreciate this when your application gets bigger and you want to split the code up into module files. The JavaScript apply method also sets “this” inside the closure to DirksApp, that’s why applying a new function on “this” assigns it as a public function on DirksApp.

You may have to read that last paragraph again. I was confused even writing it.  And there’s definitely more to it, but this is a quick and dirty tutorial.  Look up JavaScript Scope and IIFEs (iffys) for more info.

So, please, stop polluting the global namespace. You can start by using Closures to make your JavaScript code a bit more maintainable and you’ll make more JavaScript friends in the process.

Special thanks to Paul Sanchez, @basicdays, who presented similar content for the Milwaukee JavaScript User Group and gave me the oomph to get this article out the door.

August 30, 2013
by Dirk Watkins

Notifying DBAs of New SharePoint Databases

In our production environment, the Database Administrators like to know when a new database is created or dropped. As well they should.  They normally use a DDL trigger to send out an email when one of these events occurs.  The problem we ran into was that in Windows SharePoint Services 3 (WSS3/SharePoint 2007), the trigger broke SharePoint’s ability to create new content databases!  Perhaps the account that ran the procedure didn’t have enough rights to run sp_send_dbmail, but we don’t know for sure.  If you know why, tell everyone in the comments.

The way we fixed it was to, instead, create a nightly agent job on the SQL Server that just looked for new database records in sys.databases.

SELECT name, create_date
FROM sys.databases
order by create_date desc

Just add a WHERE clause that filters the databases based on how often you run your job. If any databases exist since the last time you ran the job, send out an email.