opacity: 0.6; filter: alpha(opacity=60); /* For IE8 and earlier */
Category Archives: Tech
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:
- Get MacFUSE and install on OSX: http://code.google.com/p/macfuse/
- 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.
HTTP Header for JSON
To print JSON for consumption by AJAX or other web services, change the HTTP headers before output:
<?php header( 'Content-type: application/json' ); echo json_encode( $json ); ?>
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
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 );
Meta Tags for Favorites Icon
<link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
Font Squirrel
This online utility allows you to upload TTF or OTF to convert for embed with CSS3:
http://www.fontsquirrel.com/fontface/generator
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' ]; ?>
Print Object Snippet
This is a handy way to output a complex object or nested array with PHP while retaining the visual structured indentation:
echo '<pre>' . print_r ( $complexobject, true ) . '</pre>';