Blank MySQL Graphs in Munin

August 13, 2010 – 4:33 pm

From the Munin FAQ

Q: Why are the graphs for the MySQL plugin blank?

This is due to a bug in a Perl library Munin uses which causes $PATH to be lost. This again causes the plugin to not find the mysqladmin program which it needs to retrive the numbers the needed in the graphs. The solution is to hardcode the path of the program.

First locate the mysqladmin program. On most systems, the command which mysqladmin, type mysqladmin or locate mysqladmin will help you. When you find the path, enter that path in /etc/munin/plugin-conf.d/munin-node.

This is how it might look:

darkstar:~# which mysqladmin
/usr/bin/mysqladmin
Then, under the [mysql*] section identifier in /etc/munin/plugin-conf.d/munin-node, add the following line:

env.mysqladmin /usr/bin/mysqladmin

Found in the Munin Docs

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Git – What Changed Between Pushes?

August 12, 2010 – 2:53 pm

There’s an overwhelming amount of git tools, and if you’re coming from SVN you might expect that the tools w/ the same names work the same way. You’d be wrong.

Because of Git’s distributed nature, you can (and frequently do) have commits in your repo that you might not have pushed up. You might also have forgotten what they were. Good thing there’s a tool to check that.

Lets assume you’re on your master branch, and you’re comparing against the origin remote repo.

git whatchanged -p origin/master..HEAD

That’ll give you a nice text diff of everything you’re about to push. Awesome, right?

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

UIS PHP53, DOM Parsing, PHPUnit, Puppet Config Solution

July 21, 2010 – 1:42 pm

I’m using PHP53 package from the IUS Community repository. I’ve been trying to get phpunit to install, but it gives an error that it needs DOM install. It took me a little bit to figure this out, but I finally got it working. What you need is the php53-xml package. You can install it using

yum install php53-xml

or if you’re using puppet

package { ["php53-xml"]:
          ensure => present
        }

And finally, to get it to install, I used the below. I had to make it go to multiple lines to fit on the page but I have it all on 1 line in my puppet script:

exec { "pear channel-discover pear.phpunit.de;
pear channel-discover pear.symfony-project.com;
pear install --alldeps phpunit/PHPUnit  ":
          creates => "/usr/bin/phpunit"
 }
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Debugging with Erlang

July 15, 2010 – 4:58 pm

First, make sure you have the compile flag (+debug_info) set when compiling your source, then fire up the debugger:

1> i:im(). 

My Erlang Makefile:

EBIN_DIR := ebin
SRC_DIR := src
EXAMPLES_DIR := examples
INCLUDE_DIR := include
ERLC := erlc
ERLC_FLAGS := +debug_info +native -W -I $(INCLUDE_DIR) -o $(EBIN_DIR)

all:
	@mkdir -p $(EBIN_DIR)
	$(ERLC) $(ERLC_FLAGS) $(SRC_DIR)/*.erl

clean:
	@rm -rf $(EBIN_DIR)/*
	@rm -f erl_crash.dump

Read up on the Erlang docs.

The debugger can be a bit weird in that it doesn’t always find your ebin directory (if you’re compiling to a separate ebin dir)… it took me a bit to figure out. Also on the Mac it seems to either crash or not launch timetimes.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Headless Virtual Box

July 15, 2010 – 4:07 pm

I like running VirtualBox headless on my Mac. It doesn’t show up in the Dock, and feels like it’s a remote server.

First, figure out which VMs you have on your machine.

haddad-work:~ jhaddad$ VBoxManage list vms
Oracle VM VirtualBox Command Line Management Interface Version 3.2.6
(C) 2005-2010 Oracle Corporation
All rights reserved.

"WebServer" {2c61a180-e098-4926-b09a-27e431791c88}

Then start it using VBoxHeadless

nohup VBoxHeadless -s WebServer -vrdp on  &

I’m using Cord for RDP.

Open up Cord. If you’re using the default settings, you can just go to quick connect and type “localhost”. You’ll see your VM booting.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Running Erlang Code from the Command Line

July 9, 2010 – 11:31 am

This was really useful for me in scripting TextEdit to run my unit tests, as Erlide has been crashing every time I use it.

erl -run mymodule myfunc -run init stop -noshell

http://www.trapexit.org/Running_Erlang_Code_From_The_Command_Line

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Working with DOM in PHP – Looking at a PHP HTML Parser

June 6, 2010 – 12:25 pm

So, lets assume you’ve got a PHP project where you’re scraping pages and trying parse fields out of the DOM.  Up till now, I’ve just used regular expressions because they’re easy.  I avoided trying to parse html as xml using SimpleXML because there’s just to many cases where it would fail due to invalid tags.

Well, I feel like an idiot.  It turns out there’s a great extension built into PHP to do just that, and it’s the DOM extension.  Using this, parsing HTML with PHP is just as easy as accessing the DOM using JQuery. (hint: very easy).

Lets say we’ve got a page our drive already.  For this example, I’ll use the homepage of this blog.  We’re going to parse out all the links.  I’ve saved the page as index.html and in the same directory I’ve created the parser script.

<?
$dom = new DomDocument;
// you can use loadHTML if you already have your string in memory
$dom->loadHTMLFile( "index.html" );
$dom->preserveWhiteSpace = false;

// grab all the A tags
// returns a domnodelist
$tags = $dom->getElementsByTagName( 'a' );

// you can actually iterate over the tags returned - 
// I'm not sure why they don't say that more explicitly
echo "Total length:"  . count($tags->length) . "\n";

foreach($tags as $t)
{
	// each of these is a DOMElement object
	// the value is what's inside the tag
	// the attributes can also be accessed
	printf( "%-50s%s   \n", $t->nodeValue, $t->getAttribute('href') );

}

Here’s a glimpse of the output:

vim                 http://www.rustyrazorblade.com/category/vim/  
virtual box         http://www.rustyrazorblade.com/category/virtual-box/   
vmware              http://www.rustyrazorblade.com/category/vmware/
weird               http://www.rustyrazorblade.com/category/weird/   
wikipedia           http://www.rustyrazorblade.com/category/wikipedia/
windows             http://www.rustyrazorblade.com/category/windows/  
xcode               http://www.rustyrazorblade.com/category/xcode/ 


Here’s another great reference I originally used to get started:

You can take this a bit further if you want to use the php curl extension.  Additionally, if you’re interested in using the advanced curl_multi_exec functionality, check out my previous post.

Edit: cynope on reddit suggested phpquery. I haven’t used it yet but it looks pretty cool. If I get a chance to try it I’ll post a followup.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Print all Puppet Config Variables

May 7, 2010 – 2:44 pm

For some reason, I haven’t found this anywhere in the docs.

puppet --configprint all

It’ll print all your puppet configuration variables.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

VirtualBox Guest Additions – Redhat / CentOS

April 30, 2010 – 2:49 pm

Mount VirtualBox Additions disk through the VirtualBox UI.

yum install -y gcc kernel-devel-`uname -r`
mkdir /mnt/cdrom
mount -o ro -t iso9660 /dev/cdrom /mnt/cdrom
sh /mnt/cdrom/VBoxLinuxAdditions-amd64.run

Info found on tuxtraining.com

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Remove File From Git History

April 30, 2010 – 1:55 pm

Useful stuff.

git filter-branch -f --index-filter 'git update-index --remove filename' HEAD
git push --force --verbose --dry-run
git push --force

Slight better version. Only rewrites history from the first commit the file existed.

git filter-branch -f --index-filter 'git update-index --remove filename' ..HEAD
git push --force --verbose --dry-run
git push --force

Found on github.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit