Drupal Behaviors: A Quick Introduction & How-to

I’m fairly new to Drupal myself and came across something called Drupal Behaviors when I was working over at BioWare Austin. A fellow Drupal developer whom was part of the team, Ivan Fuyivara, gave a presentation on what they were and how to use them. Being a complete greenhorn at Drupal then, I was a little foggy on the concept and didn’t really understand. Now with a year of Drupal dev under my belt, a better understanding on how to do things the ‘Drupal way’, and an opportunity to work on a re-theme project at Stratfor Global Intelligence, I had the opportunity to put this feature into practice.

Here’s a quick introduction on what Drupal Behaviors are and how to use them. Feel free to critique or tell me I’m completely wrong here… in no way am I claiming to be a Drupal expert. You can also read more (though not too much info) on Drupal.org.

Continue reading “Drupal Behaviors: A Quick Introduction & How-to”

Useful Git Delete Branch Commands

Want to delete a branch in GitHub? It’s a simple operation.

Need to delete a branch in GitHub? It’s a simple operation and keeping your repo clean & tidy is incredibly important in any project. In this post, I’ll show you how to:

Delete a Local GitHub Branch

$ git branch -d yourbranch
Deleted branch yourbranch (was 2a4ef7)

Depending if you already have unmerged commits in the branch you’re trying to delete, you may see this error:

error: The branch 'my-branch' is not fully merged.
If you are sure you want to delete it, run 'git branch -D my-branch'.

This protects you from losing your reference to those commits, which means you would effectively lose access to that entire line of development. If you really want to delete the branch (e.g., it’s a failed experiment), you can use the capital -D flag:

$ git branch -D yourbranch
Deleted branch yourbranch (was 2a4ef7)

This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development.

Delete a Remote GitHub Branch

As of Git v1.7.0, you can delete a remote branch using:

$ git push origin --delete yourbranch

Previous to Git v1.7.0, you can use:

$ git push origin :yourbranch

Delete Merged Branches

Through time as you create and merge branches, you’ll want to delete the one’s no longer needed. In order to delete local branches which have already been merged, run:

$ git branch --merged master | grep -v "\*master" | xargs -n 1 git branch -d

You can omit the master branch argument to remove local branches which have already been merged into the current HEAD:

$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

For more information, see Git Clean: Delete Already-Merged Branches.

Delete All Branches Except Master

If you’re like me, you leave branches laying around, even after they’ve been merged into master. The sad part is GitHub even provides a button to do the cleanup, but I can’t be bothered. So when you’re ready to do some real cleanup on a repository, run this command to delete every branch in your local except for the master branch.

git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -d /' | bash

Recover a Deleted GitHub Branch

What if you accidentally deleted a branch or just need to recover one that’s been deleted? Not a problem. Use the following to find the HEAD commit of the deleted branch to get it back:

$ git fsck --full --no-reflogs | grep commit
dangling commit 609bb956bc9ef1b43c0w6af60fa009e37be0566d
dangling commit 608bb956bc9ef1b43c0g4af60fa0e9e34be0566d
dangling commit 708bb956bc9ef1b43c0wdaf60fa000e99be0566d
dangling commit 402bb956bc9ef1b43c0d4af60fa001e87be0566d

Then do a git show to find the commit you want to recover:

git show 609bb956bc9ef1b43c0w6af60fa009e37be0566d

Once you found the commit you want, do a git branch to recover the branch:

git branch 609bb956bc9ef1b43c0w6af60fa009e37be0566d

Simple stuff!

Mozscape API PHP Class

Mozscape’s API is a little daunting to use with the amount of valuable information it can offer. Here’s a simple PHP class that allows you to easily access your site’s SEO metrics using the Mozscape API. A major benefit to the Mozscape API PHP Class is the ability to return detailed information on the response fields Mozscape provides.


Download Now (Version 1.1) Fork on GitHub


It’s pretty simple to use this class. Currently it’s pretty limited to the data it can provide in relation to what’s available through Mozscape’s API, but I do have plans on adding the rest of the available APIs later on.

That’s it, pretty simple huh?


Here’s more detailed information on how to use the class. If you have any questions or suggestions, I’d love to hear them.

Mozscape URL Metrics API

urlMetrics($site_url, $sum_of_bit_flags)

To access the Mozscape URL Metrics API, you just need to provide the URL you want to retrieve data for and the type of data you want (the total sum of Bit Flags).

Mozscape Response Fields

responseFields($field, $return_value = '')

This is a great helper to get information on the various response fields that the Mozscape API provides, including the bit flag values, user-friendly names, slugs, and descriptions! See more information on Mozscape’s Response Fields here: http://apiwiki.seomoz.org/response-fields.

Mozscape Top Pages API

topPages($url, $offset = 0, $limit = 1000, $bits = 4)

This paid call returns the metrics about many URLs on a given subdomain. The top pages call can be accessed by the API call top-pages. A set of metrics can be requested by indicating them as bit flags in the $bits parameter. A page of urls with associated metrics is returned. The start record of the page can be specified using the $offset parameter. The size of the page can by specified using the $limit parameter. URLs are currently sorted by number of linking root domains.

A maximum of 1000 records can be retrieved per call. Limits over this value will result in a 400 Bad Request or 500 Internal Error response.

Currently only 10,000 pages may be retrieved using top-pages calls, in at least 10 calls.

See more on Mozscape’s Top Pages API here: http://apiwiki.seomoz.org/top-pages-api

Mozscape Required Attribution Link

attributionLink($type, $size, $img_dir = 'img/mozscape/')

This is good to use to stay compliant with the required Mozscape API’s attribution links. Provides easy output using their approved logo or icon with the required link.

Change Log

Version 1.1

  • Created a changelog file
  • Added an error message if the Curl request to the Mozscape API failed
  • Added the Mozscape Metadata API Calls
  • Added the Mozscape Top Pages API

Quit Blaming Browsers & Users: We don’t all have to be the same!

I recently watched a talk given by Kyle Simpson at the HTML5.tx conference on February 2nd, 2013: Browser Versions Are Dead. It’s a little less than an hour long, but I think well worth the time. Basically, he explains why developers need to quit blaming browsers for their problems. An idea that I completely agree with and hope other developers take to heart.

Continue reading “Quit Blaming Browsers & Users: We don’t all have to be the same!”

Interaction Points jQuery Plugin

Trying to come up with a fun way to keep user’s on your site? Try the Interaction Points jQuery plugin. It’s a simple script that enables a point system for your site’s users. It’s fully customizable and is easily integrated into existing point systems. There’s nothing like a little competition to keep people engaged and coming back to your site.

This is also great from and SEO perspective to boost your site’s CTR and decrease its bounce rate. It will keep your users active while they surf and is perfect for gaming sites and other user interactive sites.


  • Allows you to customize your own script to handle storing and processing user points
  • Users only occur points when their actually doing something
  • Set how many points the user earns each second while being active on the site
  • Allows additional data to be passed to your script
  • Includes a debugging feature to help you track down problems
  • Control how often the script get’s pinged to update user points

Download Now (Version 1.0) Fork on GitHub


It’s simple to integrate. Just include the JS and modify the script that handles the post information to suit your site’s needs.

Here’s a sample PHP script you can use as a template to create your own:

I haven’t had a chance to throughly test it in all browsers, but don’t foresee any problems. If you run into any, let me know and I’ll get it fixed and updated. Let me know what you think!