Setting up an Airport Express on Mountain Lion

The old style Airport Expresses are amazing and have been around a long time, they are great for extending your home network and also great for setting up impromptu networks when travelling.

However, as of Mountain Lion the Airport Utility (which is now pretty dumbed down) doesn’t support them which is kind of lame – I guess when the devices once had an expected life of 18 months that isn’t much of a surprise.

There is however still a solution, AirPort Utility 5.6 for Mac OS X Lion, which of course you can’t install on Mountain Lion until you find these excellent instructions.

From frustrated to happy in the space of 5 minutes, now I can get this Tiger running Mac Mini from 2006 back online alongside the new Mac Book Air that replaces it.

Now I just need to see if I can set the second one up for my in-laws too so they can get iPlayer on the TV :)

Finding “popular” IP addresses in access_log files

Every now and then I find myself needing to quickly analyse a set of access_log files to see who the most common visitors are so that I can decide if there are any abusers I should be blocking or poorly configured services running somewhere that I can try to get fixed.  I can never remember the quickest was to do this so I decided to write down the “one liner” that I cobbled together this time so I can hopefully find it next time and not have to reinvent the wheel again.

Here is the one-liner I used to find the top IPs this time:


sed -e 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*$/\1/' -e t -e d access.log | sort | uniq -c | egrep -v "\s([0-9]|[0-9][0-9]|[0-9][0-9][0-9]) "

Splitting this out we have:

  1. A call to <code>sed</code> to extract all the IP Addresses from the access_log file
  2. A call to <code>sort</code> to sort the list of IPs
  3. A call to <code>uniq</code> to create a list of unique IPs with counts
  4. A call to egrep to filter the unique list down to IPs we at least 1000 appearances – this will need tuning depending on the volume of requests / time period the file covers.

Always show admin bar

I like the admin bar that we are adding in the soon to be released WordPress 3.1 so much that I wanted it to always show on my site.  This way you get an easy to use search box on every page even when logged out.

I wrote a quick plugin file which I dropped into the wp-content/mu-plugins folder on this site. Here is the code I used in case you want to do the same:


<?php
function pjw_login_adminbar( $wp_admin_bar) {
 if ( !is_user_logged_in() )
 $wp_admin_bar->add_menu( array( 'title' => __( 'Log In' ), 'href' => wp_login_url() ) );
}
add_action( 'admin_bar_menu', 'pjw_login_adminbar' );
add_filter( 'show_admin_bar', '__return_true' , 1000 );

As you can see to make it even more useful I’ve added a Log In link so I can use it to log in to the site.

As with anything else to do with the Admin bar this code requires WordPress 3.1 to work.

Mangling strings for fun and profit

As a WordPress lead developer, every time I see someone recommending editing a core WordPress file, a little bit of me dies.

You should always avoid editing the core files and put your modifications into a plugin so as to ensure you have a smooth upgrade experience to a future WordPress version.

Therefore inspired by the following forum post here is how to change one of the translatable strings in WordPress without hacking a core file using the filters available in the translation functions:

<?php
/*
 Plugin Name: PJW Translation Mangler
 Plugin URI: http://blog.ftwr.co.uk/#
 Description: Example of how to mangle translated strings.
 Author: Peter Westwood
 Version: 0.01
 Author URI: http://blog.ftwr.co.uk/
 */

class PJW_Translation_Mangler {
 /**
 * Filter the translation string before it is displayed.
 *
 * @param $translation The current translation
 * @param $text The text being translated
 * @param $context The context for the translation
 * @param $domain The domain for the translation
 * @return string The translated / filtered text.
 */
 function filter_gettext($translation, $text, $domain) {
  $translations = &get_translations_for_domain( $domain );
  if ( $text == 'View all posts filed under %s' ) {
   return $translations->translate( 'See all articles filed under %s' );
  }
  return $translation;
 }
}
add_filter('gettext', array('PJW_Translation_Mangler', 'filter_gettext'), 10, 4);
?>

The filter used in this example gettext is one of a set of filters in the translation functions in wp-includes/l10n.php which also include gettext_with_context, ngettext, and ngettext_with_context.



d
go to dashboard
l
go to login
h
show/hide help
e
edit post/page
r
comment on post/page
m
go to moderate comments
esc
cancel