January 2013

Things I will do this year

  • Buy a house
  • Write a "Learn Drupal The Hard Way" book
  • Start a highcountrysomething.com website and make it work
  • Spend more time with Frank
  • Run everyday
  • Run a marathon at some point
  • Stop eating out so much and cook more of my own food
  • Blog more
  • Learn a new language
  • Visit the west coast
  • Start a few more open source projects
  • Keep OpenBlog and OpenBrewery up and awesome
  • Talk at a major conference
  • Drink more delicious beer
  • Brew more beer
Tags: 

Morning run: 2.29 miles

I ran 2.29 miles the Climbing the hill route this morning. It was cold, windy, rainy in spots and really hilly at the beginning. It was a good "getting back into things" run.

Tags: 

Useful Command-line Tools, Part 1: mktemp

This is the first part of the Useful Command-line Tools on useful command line tools. In this blog post I'm going to talk about the mktemp command.

This is a really cool command that generates unique file or directory names for temp files or directories based on a template you pass it.

Here's how you create a temp file in your /tmp directory:

$ tempfile=$(mktemp /tmp/footemp.XXXXXX) || exit 1
$ echo $tempfile
/tmp/footemp.9ZTwDS

You can also create a temp directory:

$ tempdir=$(mktemp -d /tmp/footemp.XXXXXX) || exit 1
$ ls -alh $tempdir
total 0
drwx------   2 zach  wheel    68B Jan  2 09:44 .
drwxrwxrwt  18 root  wheel   612B Jan  2 09:44 ..

You can learn more about this command by reading the man page.

Drupal 7 and paginating EntityFieldQuery queries

In Drupal 6 creating a paginated query was pretty straight forward, you would use the pager_query and go from there. With the switch to entities in Drupal 7 we have a class called EntityFieldQuery that returns an array of entities based on properties of the entity.

It's really easy to use:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->propertyCondition('type', 'thing')
  ->propertyCondition('status', 1);
$result = $query->execute();

And there you go, as long as the array in the $result variable has the 'node' key you should be good to go on to entity_load() and start using the data the class returned.

Adding pagination to this query is really simple, all you have to do this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->propertyCondition('type', 'thing')
  ->propertyCondition('status', 1)
  ->pager(10);
$result = $query->execute();

and when you're rendering the list:

theme('pager')

Which renders the pager and handles everything else. That's pretty much it.

Using grep and awk to find the ServerNames of your hosted Aegir sites

This onliner looks at your apache vhost configs (you can also change it easily to work with nginx) and figures out all of the ServerNames your apache instance is listening for.

SITES=( $(/bin/grep ServerName /var/aegir/config/server_master/apache/vhost.d/* --color=none -h | awk '{ print $2 }') )

My favorite beers of 2012

Last night it flooded, this morning snow. Hello Boone

Last night we had some epic flooding in Boone last night and this morning I woke up to snow and ice everywhere. Here's some photos from my walk to work.

Tags: