How to center text within a DIV element

This is one of those things I’m blogging about strictly so I can search it later and find the answer. Below, we use a DIV contained within a DIV to center text/images/anything on a page, which we’ve arbitrarily decided is 1024px in width.

<div style="width: 1024px;">
	<div style="width: 50%; margin: 0 auto;">
		Everything within this DIV element will be centered within the 1024px outer DIV element!
	</div>
</div>

Reference: StackOverflow – How to center DIV in DIV?

Referring to a PHP object property using a variable

This is one of those really simple things that I use infrequently enough that I tend to forget: If you’ve tried using $object->$field_name to address a property of a PHP object, you’ll know that PHP isn’t happy with that syntax. Instead, use:

return $object->{$field_name};

Outputting MySQL results to a CSV file without OUTFILE access

The MySQL client’s -e (or –execute=) flag allows you to specify a query to be run at the command line, which can then be output back to a local file:

$ mysql -h server.com -u username -p -D database -e "SELECT user_id FROM users ORDER BY user_id" > output.tsv

Note that by default this will output a tab-separated value file (TSV), not a comma-separated value (CSV) file.

Creating a patch file for a single commit using Git

One important workflow to attempt to standardize is the method in which an organization rolls out updates to its production webservers. If you’re making heavy use of Git (and GitHub) in your development environment, it only makes sense to bundle your updates into patch files that can safely be applied and rolled back by someone with no working knowledge of the source code.

To create a patch file out of a Git commit, you’ll first want to retrieve the commit ID that your patch will retrieve data from. The git log command below retrieves information regarding the last 3 commits made:

$ git log -3
commit b29d8f2a0e6ad5595330f62f60b978fbc5696bcb
Author: Sully Syed <[email protected]>
Date:   Fri May 13 15:41:05 2011 -0400

    The Feed Importer module will hook into Drupal's cron scheduler script and retrieve new 
    featured articles automatically.

commit 65abfeeea27311effb21a547af99b3427126601f
Author: Sully Syed <[email protected]>
Date:   Fri May 13 15:36:01 2011 -0400

    Add the Google logo image to the footer directory.

commit 33764e5d9ccd0222ad3d38cc1e77eb8242fb120d
Author: Sully Syed <[email protected]>
Date:   Wed May 11 15:45:41 2011 -0400

    Fixed the typo that would have made Skynet sentient.
$ git format-patch --help

The git format-patch command allows us to select a range of commit IDs to bundle into a patch. For our example, the range will consist of begin and end with the same commit ID to limit the patch to the one commit:

$ git format-patch -M -C b29d8f2a0e6ad5595330f62f60b978fbc5696bcb~1..b29d8f2a0e6ad5595330f62f60b978fbc5696bcb
0001-The-Feed-Importer-module-will-hook-into-Drupal-s-cron-.patch

The patch file created takes the name 0001-The-Feed-Importer-module-will-hook-into-the-Drupal-s-cron-.patch, which can then be e-mailed or sent by other means to the production staff who will apply it.

Reference: Blogging the Monkey: git format-patch for specific commit-ids