Colon In XML/RSS Messing Up PHP’s SimpleXML

Recently used PHP’s simpleXML to parse through a blogs RSS feed. The parsing worked great and it was simple and clean. Only problem was that the XML nodes that contained colons in the name were being discarded by simpleXML. Example:

<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>

Not sure if this is a bug, error, or what but it was causing me grief. I haven’t been able to find others on the web complaining of this but my own solution was to remove the colons and traverse accordingly. I wrote a function that takes the feed as a string and returns the string with all colons inside tag names removed.

function removeColonsFromRSS($feed) {
    // pull out colons from start tags
    // (<\w+):(\w+>)
    $pattern = '/(<\w+):(\w+>)/i';
    $replacement = '$1$2';
    $feed = preg_replace($pattern, $replacement, $feed);
    // pull out colons from end tags
    // (<\/\w+):(\w+>)
    $pattern = '/(<\/\w+):(\w+>)/i';
    $replacement = '$1$2';
    $feed = preg_replace($pattern, $replacement, $feed);
    return $feed;
}

Print Ubuntu Server IP or EC2 Public IP with Bash Script

How to get EC2 public IP from command line or bash script

Recently, while helping out with the OpenPhoto project, I created a bash script that would print out the Ubuntu server’s IP address if it was not installed on Amazon’s EC2. If it is installed on EC2 it would get the publicly accessible IP address of the machine and print that out instead.

#!/bin/bash
# finding IP address and compensating for possible EC2 installation
EC2=`curl --silent --connect-timeout 1 http://169.254.169.254/latest/meta-data/public-hostname`
if [[ $EC2 != "" ]]; 
then
    IP=`echo $EC2 | sed -rn 's/ec2-(.*?)\.compute.*/\1/p' | sed 's/-/./g'`
else
    IP=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
fi

Disable Google Chrome Cache

Tired of Google Chrome cacheing resources while you are trying to build a web app or site?

Here is how you can disable the Google Chrome cache:

  • open developer console
  • click settings gear in bottom right
  • check “Disable cache” under Network heading

How to disable Google Chrome cache

This is as of version 14

Delete Data From Graphite

If you have set up a Graphite server and played with it like I have, you have some data in there cluttering up your interface.

graphite resource tree

You can get rid of any of the data or folders by deleting them from the server. The data is stored in files found starting at

/opt/graphite/storage/whisper/

Happy deleting!