Forcing New Relic into Kiosk Mode

New Relic Ring

New Relic is a great bit of kit - nobody can deny that. I recently needed to configure it on a standalone box so it could be open on a large screen so my colleagues and I could see the current status of our sites. New Relic has a Kiosk Mode which strips out some of the navigation from the page an optimises it for "viewing only". Very handy.

Exporting a Git Repository

Druplicon Git Logo

Have you ever needed or wanted to pull a remote Git Repository on Drupal.org down as a zip or tarball? You know, the way Github does? Most project releases have fairly recently built tarballs which is awesome - but Sandboxes do not (so it seems - please correct me if I'm wrong!).

The following snippet lets you "archive" a remote repository, pull it down as a tarball, and extract it in-place:

git archive --format=tar --prefix=PROJECT/ --remote=USERNAME@git.drupal.org:sandbox/USERNAME/123456789.git BRACH | tar -xf -

Quick Tip: Drupal Hook Commenting Using Vim

Vim

According to the Drupal Coding Standards for Documenting Hook Implementations, its considered a good practice to quickly chuck a comment before any function which implements a Drupal hook (eg, hook_menu). This helps someone reading your code quickly see that the function is actually linked with a hook in Drupal and isn't just a function in your module to be called directly.

Export a single row from a database as MySQL

MySQL

Nathan Rambeck has a great simple snippet of how to export a single row from a table however it didn't QUITE do what I needed it to. I needed to export a variable from {variable} as I was working on an update script which pulled data from a variable and into a database schema. I got fed up of re-populating the variable data each time.

How to get Load AVG for remote server on loop

Baby Tux

This handy script will allow you to get the current Load Average (loadavg) for a remote server over SSH. It will stream the result set back to you, which you can then pipe into a file if you need to.

This would be handy for monitoring the load of a server while stress testing, for example.

Nice Dates - A How To

Thingy Ma Jig Date

I've had several people ask me recently how I managed to get the nice date effect on my blog headers. It's quite simple really. All you need is:

  • An Image - A background image (a CSS Sprite) which contains the days, months and years.
  • Some HTML - A VERY basic HTML template.
  • Some CSS - To align the image sections.
  • A PHP Snippet - A Drupal preprocess function.

Batch Revert Views

Druplicon Logo

Isn't it a pain when you have dozens of Views setup and they are all marked as "overridden" because you just pulled in an updated feature file from somewhere. Features doesn't always notice when the Views on your site aren't up to date.

The following snippet (which you should use with caution) will batch "delete" (or Revert, once the view is in code) all Views which are marked as Overridden. This took a few seconds to run on our development machine.

Entity Encode Text Using PHP

PHP Logo

Ever needed to Entity Encode a block of text (maybe to partially protect it from spam bots or just hide/obfuscate the content?). I did. It's pretty easy.

If it's just based Entity Encoding, you can always use htmlentities - however this only does the "important" characters such as quotes, ampersands and angle brackets.

Thingy Ma Jig - Now brought to you by Drupal 7

Drupal 7 Logo

So, Drupal 7 is out. Have you heard? It was a bit of a quiet launch really. ;-)

When it came to upgrading by blog, I decided (eventually) that I needed to do a cleanup as the Database had been upgraded from 4.7, to 5 and then to 6 - with many modules added and removed in between. New year, new drupal, new blog (kinda)!

It's also a good excuse to test out that some of the modules I maintain actually work in Drupal 7 (such as Page Title and GlobalRedirect). It's also a kick up the arse to get Relevant Content ported to Drupal 7!

New Drupal Site: Rate My Christmas Tree

Christmas Tree

Ever wondered if your Christmas Tree is really any good? Well last weekend I decided to make a website for this purpose. It's just a bit of fun really! You login using your Facebook credentials (using Facebook Connect) and can create Chrismas Tree posts by linking to Flickr or Facebook photo's. You can then vote on your favourite tree's in an "A vs B" type match. If you like the sound of this and fancy something a bit festive, please give it a go and let me know if you have any thoughts! Head over to Rate My Christmas Tree :-)

Fixing Dos Line Endings

Linux Tux

Sometimes, when you're running coder on a module, you'll get a lot of errors complaining about Windows line endings. This is because you should set your editor to use Unix Line endings to be consistent with all developers. See the Drupal Coding Standards for more details.

Below is a handy bash script which will help you batch convert many files from DOS to Unix line endings.

MySQL: How to upper-case words

MySQL Logo

 I recently needed to clean up a MySQL Table which contained people's names. Upon searching the MySQL commands, I was surprised to find there was no equivalent of PHP's ucfirst or ucwords. There were commands to convert entire strings into upper or lower case, but not just the first letter.

How to setup reminders on OS X

Quicksilver

I just wanted to quickly setup a reminder on my mac (in this case that Star Trek was on in ten minutes - I know, I'm a geek!). It dawned on me that I didn't know a way to do this off the top of my head.

After a little Googling and trial and error, I found that the awesome Quicksilver could execute timed events!

It's a little convoluted, however here is the process...

Drush Cron & XCache can cause var_size errors

Drupal & Drush Errors

I use a cron script on this server which fires up Drush to run Cron (rather than the standard wget method). There is nothing wrong with using wget, however it does tie up an apache or lighttpd process while cron is running. It also means it's harder to control process priority. Drush, on the other hand, runs in CLI mode, so controlling process priority is easier (using nice). But then I started seeing odd errors…

MySQL: Count occurrences of string

Drupal and MySQL

Today I needed to quickly find out a list of node's which did not contain a certain token (one we use on PPOnline to insert adverts into articles). There were meant to be 2 of these tokens per article but we had noticed some only had one. Some didn't have any at all!

Now, this might already exist as a neat function somewhere, but I couldn't find it. So I wrote this little query to find the number of occurrences of a substring in a larger block of text.

I did look into using the SUBSTRING() and SUBSTRING_INDEX() commands, however I couldn't see a way of efficiently using them to find any number of occurrences. So I settled on the following…

Pages

Subscribe to Thingy Ma jig RSS