Good News Everyone!

Naturally it’s been over a month since I’ve updated and rather than posting something techincal I feel I should be a little selfish and announce that:

I’M GOING TO BE SPEAKING AT ZENDCON 09!

I will be giving my talk on automated deployment techniques with Phing.

To say that I’m excited is quite an understatement. Nervous now probably tops excitement as now I have to make sure I give a damned good talk and not make Eli White look like a fool for having picked me for a slot.

Time to go bury my nose in Power Point and research!

Logitech MX Revolution revoco in Ubuntu 9.04 Jaunty: Click-to-Click even after a resume/wakeup

It’s been a LOONG time since I’ve posted eh?

Well I finally solved my issues I’ve been having with revoco in the later version of Ubuntu. For those of you who don’t know, when you buy a Logitech MX Revolution mouse (or its ilk), the middle button can alternatively work in “click-to-click” mode (where you feel “clicking” when you spin the wheel) or “free spin” mode where the wheel spins free of resistance. By default the mouse maps the middle click to alternate in between these modes (by default I mean every time it loses connection with the PC, e.g. in the event of a shut down). This has the unfortunate habit of also laying the smack down on a normal middle button event (like middle clicking a link in Firefox to open it up in a new tab) sent to the PC (plus I hate free spin).

For a while btnx solved my problems as it had the ability to send revoco signals to supported mice, but recent changes in Xorg have rendered this useless.

However an enterprising individual named Edgar Toernig wrote a command line utility called revoco that lets you set the modes.

So to get the mouse to always work in click-to-click mode (as you would expect it) you would first need to get a copy of revoco from here. Alternatively, if the site goes down you can download revoco version 0.5 from me.

Next you’ll need to compile it (just run make in the extracted directory).

Once it’s all compiled, I like to use sudo to move the file to /usr/local/bin/.

Next I create an init.d script to set the mouse to click-to-click on boot. Save the following to the text file /etc/init.d/revoco:

#!/bin/bash
/usr/local/bin/revoco click

Finally run a chmod +x /etc/init.d/revoco to allow the code to execute.

All this is well and good but you’ll notice that on a resume from hibernate/sleep, your mouse will be back to its old shenanigans. To fix this we want to create a script in /etc/pm/sleep.d/. So in this folder lets edit a text file 10revoco:

#!/bin/bash
case "$1" in
        hibernate|suspend)
                /usr/local/bin/revoco click
                ;;
        thaw|resume)
                /usr/local/bin/revoco click
                ;;
        *) exit $NA
                ;;
esac

Again lets run a chmod +x /etc/pm/sleep.d/10revoco to allow us to execute

Now if you give it a try, you’ll notice that even on wakeup/resume from hibernation/suspend your mouse will stay in click to click mode!

tamulink-wpa and Ubuntu (For my aggie linux readers)

Finally, I no longer have the pain of not being able to connect to the wireless network on campus (without having wicd installed).

I got it working using the network-manager applet in Gnome that comes installed by default (cause I like it and it makes my life easier). I’ve had people poke fun at me because I don’t feel like traversing the console and running wpa_supplicant manually, I have better things to do, like expecting things to work with the least hassle. But that’s a rant for another time.

Sadly CIS or whoever is responsible for the wireless networks has decided that Ubuntu, Fedora, or any other flavor of Linux won’t be supported. Thanks to one enterprising Maurice Rahe, I had enough information to get started. Since I was working with Ubuntu 9.10 (Jaunty Jackelope) Alpha 6, I needed to update the instructions a bit and turns out we didn’t need to do the manual wpa_supplicant.conf at all. Simply attempt to connect to tamulink-wpa and when it asks for the connection details:

Security
WPA & WPA 2 Enterprise
Authentication
Protected EAP (PEAP)
Anonymous Identity
Leave Blank
CA Certificate
/usr/share/ca-certificates/mozilla/ValiCert_Class_2_VA.crt
PEAP Version
Version 0
Inner Authentication
MSCHAPv2
User Name
NETID
Password
NETID Password

VOILA, it works! Reconnections kinda suck, but what’ll you do.

Calculating Daylight Savings Time Boundary In PHP

I had an issue recently where I needed to calculate the Unix timestamp for the daylight savings time boundaries. According to the United States Naval Observatory, daylight savings time begins the Second Sunday of March and ends on the First Sunday of November.

Awkward date calculations if you don’t have the magical strtotime() function in PHP. strtotime() is able to do relativistic time conversions from the common “+1 hours” to the more complex (and more relevant) “Second Sunday March 0″.

Why do we do the ‘March 0′ in the above string to calculate the start boundary? Doing some tests with strtotime() reveals some behavior you should be aware of.

strtotime("March"); doesn’t actually give you the first of March, it gives you the current day in the month specified (date('D, F j, Y, g:i a', strtotime("March")); returns Tue, March 10, 2009, 12:00 am at the time of this post). Doing a similar test but substituting April for March results in the 10th of April (at 12 am).

Now in most cases doing a strtotime("March 1") will suffice (date('D, F j, Y, g:i a', strtotime("March 1")); results in Sun, March 1, 2009, 12:00 am). However, as you can tell, this month is going to be awkward because the first day of the month is a Sunday. strtotime(), when calculating the fuzzy “Second Sunday,” doesn’t include the current day. So calculating date('D, F j, Y, g:i a', strtotime("Second Sunday March 1")); will actually return the 3rd Sunday (Sun, March 15, 2009, 12:00 am).

So our solution is actually to take a step back and return the PREVIOUS day to the first day of March and then calculate the Second Sunday from there (since we know that starting from the next day will account for the first). Normally, dealing with the last day in February is a headache, BUT again thanks to PHP magic we don’t have to figure out if it’s February 28th or 29th, we merely do a “March 0″ which steps us back a month (date('D, F j, Y, g:i a', strtotime("March 0")); returns Sat, February 28, 2009, 12:00 am). From there we can calculate the Second Sunday with ease and eventually determine that the second sunday is March 8th, which is confirmed by the above USNO website.

Applying these lessons to calculating the first Sunday in November we come up with the following snippit:

<?php
$remove_hour = strtotime("Second Sunday March 0");
$add_hour = strtotime("First Sunday November 0");

$time  = time();

if( $time >= $remove_hour && $time < $add_hour )
{
    var_dump("Lost an hour");
}
else
{
    var_dump("Gained an hour");
}

Cheers!

PHP File Uploads And Background Conversion: Oopsie

So I spent an inordinate amount of time tracking down a bug recently for a former employer in a system that accepts media file uploads and converts them on the fly.

The system spawns off a small script that manages mplayer/ffmpeg/lame into the background and holds on to the PID to track the conversion process. HOWEVER, there was a problem in the system where large files were being ignored and no error messages were popping up.

What ended up happening was I forgot to take into account PHP’s file upload behavior in the conversion process.

When PHP accepts a file upload it creates a temporary file (usually in /tmp/). The caveat is PHP frees (read: deletes) the temporary uploaded file at the end of script execution.

So, while the converters could convert a small file in the same encoding as the desired output, a large file (say, a 10mb MPEG) that needed to be converted to a different format (say, a FLV), the converter would begin working in the background but when the PHP script finished executing, PHP would delete the file right out from under the converter’s feet.

So, a tip to anyone doing anything similar, go ahead and at least rename/move the file (I created a unique MD5 hash from the current time plus a few other things and use that as the new file name) and pass that to any background processing functions so PHP won’t delete the file at the end of processing.

It will save a WHOLE lot of headaches for you in the future.

Also, if anyone is interested, I will probably write up a tutorial on how to write a PHP script that will convert your MP3’s in the background.

PHP, Mumbles (Growl), and DBus: Sweeet

So, after reading Mark Shuttlework’s blog on ideas for notifications in Ubuntu (basically mimicking Growl notifications for the Mac), I decided I wanted that kind of functionality, but… you know, NOW!

There are a multitude of options available but currently I’m liking Mumbles. Unlike, say, Specto, which does the monitoring itself, Mumbles provides a DBus interface, a command-line app named mumbles-send, and (I’m not sure if it’s implemented in the current stable download) libnotify support. Woutc, from the Specto project, commented below explaining that Specto is not intended to be a Mumbles competitor, but a package to easily monitor system internals (I quote “…the purposes from mumbles and specto are different…specto is monitoring what happens outside your desktop, mumbles monitors what happens on your desktop (or in your network)…”) Apparently he has plans to build a Mumbles plugin so that one can optionally have Specto send its messages to Mumbles for display.

I decided the best easiest route is to access the internal DBus API, however the forums and other resources on the Mumbles site… well… just plain suck. And by suck I mean tell you that something exists and… thaaats about it.

D-Feet browsing Mumble's Growl interface

D-Feet browsing Mumble's Growl interface

Well in my Google quest I discovered the existence of D-Feet, a DBus debugging tool (on Ars of all places). Thanks to a quick sudo apt-get install d-feet I found the existence of a public interface in info.growl.Growl that allows for a Notify(title, message) signal to be passed.

Well, with a place to access all I needed was DBus integration with PHP (because I want to start sending debug notification via Growl/Mumbles like this idea on the Zend Framework incubator).

Luckily, GREE Labs provides a DBus C extension for PHP that was easily downloaded and installed. Once installed I read the documentation to get an idea on how to use the API (which is a 1:1 mapping to the DBus API).

After a bit of hacking I finally came up with an alpha product:

<?php
function null_callback()
{
        var_dump(func_get_args());
}

$dbus = dbus_bus_get(DBUS_BUS_SESSION);

$m = new DBusMessage(DBUS_MESSAGE_TYPE_SIGNAL);

$m->setPath('/info/growl/Growl');
$m->setInterface('info.growl.Growl');
$m->setMember('Notify');
$m->appendArgs('Hello World!');
$m->appendArgs('Lorem Ipsum Dolor Sit Amet. (' . time() . ')');

$r= $dbus->send($m);

After running the script in the console, did I see success?

Mumbles and PHP Test: Success!

Mumbles and PHP Test: Success!

Damn right I did!

Though with a caveat:

Warning: dbusconnection::sendwithreplyandblock(): dbus_connection_send_with_reply_and_block() failed (Traceback (most recent call last):
File "/var/lib/python-support/python2.5/dbus/service.py", line 643, in _message_cb
(candidate_method, parent_method) = _method_lookup(self, method_name, interface_name)
File "/var/lib/python-support/python2.5/dbus/service.py", line 244, in _method_lookup
raise UnknownMethodException('%s is not a valid method of interface %s' % (method_name, dbus_interface))
UnknownMethodException: org.freedesktop.DBus.Error.UnknownMethod: Unknown method: Notify is not a valid method of interface info.growl.Growl
) in /home/daniel/test.php on line 21

Call Stack:
0.0002 64496 1. {main}() /home/daniel/test.php:0
0.0024 66372 2. dbusconnection->sendwithreplyandblock() /home/daniel/test.php:21

Apparently Mumbles seems to be throwing an Exception that it’s failing to to find the Notify signal (though everything works correctly). I guess I could ignore this, use the error suppressor (@), or even yell at GREE Labs to have the objects throw exceptions so I can catch them… I guess I’ll hack on it some more and report back. I should probably spend more time learning the DBus specs since this is my first project playing with DBus…

Update: Though it’s not listed on the API page for PHP DBus’s API, there is a method send() that takes only a single argument (the message object).

Edit:

I saw a question on Reddit asking what is the use of this technique if it’s limited to the desktop it was called on and PHP is primarily a server side language. Why not do this in Python or Perl?

Well, Mumbles was written in Python so there’s no point in me doing this in Python: it’s already been done.

However, the primary use case of a technique like this is having a web app post notifications and errors for the developer. When I work on a site I have a local copy running on my desktop and/or laptop, so when it posts Growl/Mumbles notifications, I get them on my desktop. It’s great for situations where, say, I have a page in my PHP app that never displays its contents because it processes data then redirects to another page. If a warning or other non-fatal error that I should really fix occurs, then I would normally have to dig through the system wide PHP error log (if you even have error logging enabled). However, if I wrote a custom error handler that posts errors to Growl/Mumbles as they happen, when I visit a transitory page like I described I get little Growl/Mumbles notifications showing that I screwed up!

On Looking For A Job And Online Reputation

As many of you know I am finishing up my last semester at school and at the same time on the lookout for jobs (For those interested, you can look at my résumé).

As a part of the last few classes I have to finish, I am taking a CPSC Seminar course which so far has consisted of talks from the Texas A&M Career Center. A lot of talk has been on managing your personal on line reputation. Besides the obvious “don’t post pictures of you on Facebook doing keg stands” or “don’t post embarrassing, topless photos of yourself”.

Me (without my shirt) at Fish Camp

A lot of these tips are based on the idea that you don’t want potential employers that read your blog (Hi prospective employers!) and research your internet famousness to screen you based on what they gather from their research. From not hiring you because all of your Facebook pictures involve you being trashed at a party to an extreme scenario of a Baptist corporate recruiter seeing that post you did on how much you hate Baptists. The theme is the same: don’t let the company screen you unnecessarily. Usually the safe bet is to TIGHTLY titrate the amount of information you post on the internet.

However if one does a cursory Google search of my name, one will find that I have not shied away from associating my content with myself. Granted the first page of Google results is mayhaps even sexy to recruiters (hey look, a couple of my technical blog posts linked on PHPDeveloper.org, my LinkedIn account), if one can see or gets access to my Facebook profile or read the rest of my blog, one will notice that I do not hesitate in expressing myself.

Why would I put myself out there like that? Because while companies are out shopping for employees, I am out shopping for companies. And such shopping extends beyond basic research on a company and visiting their work environment.

How many of you found the above photo offensive? uncouth? unprofessional? ridiculous? How many people would put that person lower on a hiring list because of the information you’ve gathered so far in seeing that photo? If you were, I would bid you adieu (yes, that picture is of me) because a company that would penalize me without investigating as to why a picture is ridiculous. Would the backstory that this picture was taken of me performing a skit as a Fish Camp counselor in front of 150 freshmen, trying to provide a little humor as we spent a little over 3 days preparing them for their time at Texas A&M, change your opinions?

The way I see it is the company that would weigh so heavily on the superficial and not on the content (leeway given to the fact that not every company will have the time to do full background research on me) is not a company I wish to work for. If they do this while they’re in the process of hiring me, what do I have to look forward to in my future with that company? Apparently not much.

Maybe this is just an excuse to myself for having a lot of information about me out in the wild, however I feel like I have carefully filtered information about me onto the internet to aid in my job search, and to help potential recruiters understand my personality a bit better. Because as cantankerous as I sound above, the “not being hired by X firm” works both ways. I don’t want to work at a firm where I will not be a good fit. I’ll cause friction, drop morale, and generally be ineffective.

Plus this post has been a great chance to explain that picture.

My brother’s actually blogging!

Hey everyone, my brother is actually blogging! Check out Eric Cousineau’s blog. Right now it’s looking like the focus of his posting will be about Digital Mars D programming language. Everyone go give him some traffic and encourage him to keep posting!

Blog Updates

Just made a few changes to the blog. I added a recaptcha to the comment system as well as subscribing to the comments via email. I also updated the code highlighter so we get the pretty boxes and line numbering (and the code will look much nicer on skinnier browsers).

I also added my résumé for those interested in me. If you have any suggestions for improvements on the résumé feel free to let me know.

The code highlighter was a big enough change that I think sometime in the future I’ll be updating the blog design in the future. However for now I’m just going to try to come up with stuff to post!

OSS Bugs Are Features

I’ve been thinking a lot lately about a presentation given by whurley at a refreshBCS meeting a long time ago. He gave his presentation on Open Source Software, only SLIGHTLY an era of his expertise (just in case you can’t tell, that was sarcasm) and raise an interesting point.

He talked about how when BMC Software picked him up to head up their open source efforts, he battled a little bit the developers. They wanted to make sure the code was perfected, polished, and at its best whenever they started dumping it on the public. Of course they’d want to do this, releasing code as OSS is almost equivalent to deciding to present yourself to the work naked and without makeup. They wanted their friends who could see the code to be in awe, and their code base to be a shining example of a project done right.

Whurley wanted them just to release it. Not because he wanted it now, not because of impatience or deadlines or anything else. He wanted them to just release it because, and I’m paraphrasing him, releasing open source thats a little buggy will actually help grow and foster the project. Granted, you do not introduce bugs, you just open and display the code and start making releases even though there are still tickets in your bug tracking system.

He gave the hypothetical example of the stereotypical arrogant OSS developer finding a bug in BMC’s FooBar software, calling the BMC devs dumbasses, fixing it (because it was a small and easy bug), and now being invested in the software. You don’t really lose much reputation, but you gain an invested and loyal following.

While this sounds good and true, and it makes a lot of sense (if there’s nothing to do, OSS developers will never get involved), it never really clicked for me until I associated another story with whurley’s principle.

I meet Elizabeth Marie Smith (aka auroraeosrose) at ZendCon08 and had good times talking with her and many of the other #phpc members. At one point in the conference, at an opening for one of her talks (a brief overview of PECL extensions), she told the audience how she got into programming PHP and PHP C extensions. She wasn’t a computer science major, she only started in the early 2000’s (prior to that not much computer science experience).

What had happened was, to the best of my recollection and her seven things post, in the early days of 2001-ish she was really big into Anime and wanted to start a fan site. Her dad helped her install a forum (written in PHP) on a server he was running out of his house on a cable connection.

Well, as with many of the forum projects, there were bugs to be had in the software. Elizabeth was dedicated to the idea of her site and decided to break open the forum and dig around to fix the bugs. Fix them she did but everything kinda snowballed from there. In fact it was bugs in the PHP-GTK extension that caused her to learn C (not an easy feat) and become the maintainer of PHP-GTK as well as the Windows port of PHP maintainer.

It was bugs and problems in the software that caused her to be where she is now, it was bugs in the OSS world that caused her to latch on to PHP-GTK and the Windows PHP port and get them to where they are today. Though she told this story a long time ago, and whurley’s presentation was even further back yet, it only just now clicked that I had seen a real life example of whurley’s principle of “just publish it, flaws and all.”

The lesson from all this can even be applied outside of OSS development. It’s a lesson on perfectionism and can be applied towards my personal development practices. I know that agile teaches to publish early and publish often, fixing bugs and adding features on the way, but perfectionism still plagues me. I have maybe 10 drafts on this blog on small little PHP and Python topics I could publish that I never do because I feel it’s not good enough, or too simple. I have had code at work that I could have released a week ago but instead I obsess over making sure its “perfect” when a simple staging deployment will keep everyone happy, keep my moral up, and show me where the REAL bugs are.