Handling NTFS Drives in OSX

Was having problems swapping an external hard drive between Windows 7 and Mac OSX. NTFS is a proprietary Microsoft format. Here’s how to solve the problem:

  1. Get MacFUSE and install on OSX: http://code.google.com/p/macfuse/
  2. Get NTFS-3G and install on OSX: http://www.tuxera.com/community/ntfs-3g-download/

There is no app to run since OSX operating system is updated directly. You will also be able to format external drives to NTFS after the install is complete in OSX Disk Utility. You can uninstall MacFUSE or NTFS-3G from System Preferences.

Javascript Slugify

Javascript function to “slugify” a string:

function slugify ( str ) {
  str   = str.toLowerCase();
  str   = str.replace( /\s/gi, "-" );
  str   = str.replace( /\//gi, "-" );
  str   = str.replace( /[^-a-zA-Z0-9,&/\\s]+/ig, '' );

  // Trim dash from beginning, end.
  while( str.substr( 0, 1 ) == '-' )  str   = str.substr( 1 );
  while( str.substr( -1 ) == '-' )    str   = str.substr( 0, str.length -1 );

  return str;
}

Windows Recursively Delete Folders

Dreamweaver creates _notes folders in each directory when you upload a file. Recently switched to Aptana and wanted to remove all of these folders that are now useless clutter in my filesystem. Here’s how to do it on Windows CLI in one fell swoop:

> cd \path\to\my\project\folder
> for /d /r . %d in (_notes) do @if exist "%d" rd /s/q "%d"

Links

Stack Overflow
Index of Windows CLI

WordPress Menu Posts

Making a Menu containing a bunch of Posts is a good way to create a Page with custom ordering/selection. The new WordPress Menus make it really easy to drag and drop and they give you the option to add Posts in the Screen Options tab.

If you want to swap out Menus in your Theme’s Menu Location frequently, it could get PITA to update your Theme every time you make a new Menu. Here’s how to get those Posts to display on your site with only knowing your Theme’s Menu Location slug instead of hard coding the Menu’s slug into your Theme:

// ---	Get the menu locations. Returns array of ( slugs => ids )
//		The menu location slugs are set in the theme's functions.php file.
//		@see http://codex.wordpress.org/Function_Reference/register_nav_menus
$menuloc 	= get_nav_menu_locations();
$menuid 	= $menuloc[ 'my-themes-menu-location-slug' ];

// ---	Get the currently assigned containing menu and associated posts.
$menuposts 	= wp_get_nav_menu_items( $menuid );

Filter Access by IP Address

This is a code snippet to keep unwanted visitors out while a site is under construction or being updated. The associative array helps to keep record of the identity of the user’s IP instead of just a collection of numbers with no semantic association. The $filter_ips value makes it easy to toggle the filtering on/off.

<?php
// ---	Filter vitsitor's IP address and bounce those not in the list.
$bounce_url 	= '/maintenance.php';
$filter_ips 	= true;
$allow_ips 	= array (
	'ORG: Firstname Lastname' 	=> '00.00.00.00'
);
if ( $filter_ips && !in_array ( $_SERVER[ 'REMOTE_ADDR' ], $allow_ips ) ) {
	header ( "location: $bounce_url" );
	exit ();
}
?>

It’s also helpful to output the user’s IP address on your bounce page so user’s trying to gain access can easily copy/paste their IP to send to you:

<?php echo $_SERVER[ 'REMOTE_ADDR' ]; ?>