Change DNS servers from the command line in Mac OS X

Changing DNS servers isn’t something most people need to do frequently. When you do need to change them up, though, it takes too many clicks in System Preferences. Use networksetup at the command line instead. For example, to change your DNS server to the OpenDNS servers, issue the following (if you’re using Ethernet): sudo networksetup …

Adding a link to logout of password protected posts in WordPress

I needed to add a “logout” link to a theme on which I’m working that would clear the cookie WordPress sets for password protected posts. This is what I came up with: <?php if ( $_COOKIE[‘wp-postpass_’ . COOKIEHASH] ) { ?> | <a href=”<?php echo get_template_directory_uri(); ?>/includes/logout.php”>Log Out</a> <?php } ?> COOKIEHASH is a constant …

Some snippets for password-protected pages in WordPress

I was working on a site that required protected pages in WordPress, and had a few snippets that I thought were worth capturing. By default WordPress prepends the title of a page or post with “Private:” or “Protected:” if you change the document’s visibility. This is ugly, and I can’t see the point of it. …

Validating Canadian Postal Codes with the JQuery Validation Plugin

If you’re using the JQuery Validation Plugin, you can use the following code snippet to validate a Canadian postal code: jQuery.validator.addMethod(“cdnPostal”, function(postal, element) { return this.optional(element) || postal.match(/[a-zA-Z][0-9][a-zA-Z](-| |)[0-9][a-zA-Z][0-9]/); }, “Please specify a valid postal code.”); Then use the following rule: $(“#form”).validate({ rules: { postal_code: { required: true, cdnPostal: true } } });