jquery-textrange

*sigh* This jQuery plugin was written by me a few months ago, I just hadn’t gotten around to adding a link to it on my site. If you need a jQuery plugin for messing with the location of selected text in an input field or textarea, this plugin’s for you. You can find the project on github.

DrupalCon Denver 2012

The in-US Drupal Convention this year was held in the beautiful mile-high city of Denver, Colorado. This was only my second convention, so I was by and large an observer. I listened to some excellent sessions, particularly “Tame the Burrito” by Jeff Eaton, “Using Sass & Compass in Drupal Theming” by Nathan Smith and Matt Farina, and “Drupal 8 Meets Symfony2″ by Fabien Potencier.

I got to talk with Ken Rickard of Palantir and Matt Butcher of HP. Luckily, Matt has been working on an interesting project called QueryPath that may help my University’s migration from a static HTML site (with over 90,000 pages) to Drupal. FSM, light my path!

Since we arrived earlier and departed later, I took the opportunity to take pictures around the many gorgeous locations Colorado has to offer. We went as far as Colorado Springs and Estes Park.

See my updated photostream from the trip: http://www.flickr.com/photos/dwieeb/

Pass Foreach Variables by Reference (PHP)

A recent trick I discovered while working on a Drupal module is the ability to pass the array element into a foreach loop by reference. Like so:

$array = array(1, 2, 3, 4, 5);

foreach ($array as &$element) {
  if ($element == 3)
    $element = 6;
}

print_r($array);

Your output would be:

Array
(
    [0] => 1
    [1] => 2
    [2] => 6
    [3] => 4
    [4] => 5
)

Not only does this save on memory, it also allows you to change the actual items in the array. Quite useful.

Another example:

$array = array(
  'cow' => 'moo',
  'pig' => 'oink',
  'cat' => 'meow',
);

foreach ($array as $key => &$element) {
  if ($key == 'cat')
    $element = 'bark!';
}

print_r($array);

Output:

Array
(
    [cow] => moo
    [pig] => oink
    [cat] => bark!
)

New WordPress Plugin: ScrollTo Top

Today I squeezed out a little plugin that will show a go-to-top icon in the corner of the page. When clicked, it will smoothly scroll the user’s browser to the top of the page using Ariel Flesler‘s ScrollTo jQuery plugin. The plugin comes with a few options to tweak it, like choosing or uploading your own icon, where the icon appears, etc.

I have yet to write a showcase page for it on this website, but you check out the plugin page on WordPress.org and download now: http://wordpress.org/extend/plugins/scrollto-top/