I looked into PEAR today. It’s simple, and it’s good. It’s puts a lot of “best practices” into practice. Everything is open source, which is good. Everything is easy to use, and documented, which is good. And you don’t have to reinvent the wheel. All these PHP classes have already been written to do whatever it is you’re trying to do. So you save a ton of time. So, just to get the hang of it I took HTML_Table and rewrote my stats page with it. Twice. It was really easy to do what I wanted to do, which was dump the contents of this array out in a nice table. So, that’s nice. In this particular case, the code I wrote to dump the data was just as short and sweet as either of the versions that I wrote with HTML_Table. So using the PEAR class didn’t help me anything. And worse, the HTML_Table class wants to make the first column an index value, which I could not turn off. I’m sorry. None of that made much sense. It’s hard to concentrate when the people around me are playing Mr. Roger’s clips really loud and laughing at them because I guess there are gay jokes in them.
Monthly Archive for October, 2006
I just had a neat idea. Everybody should be storing their resumes in XML. There should be a “standardized” XML resume format, like there is for xHTML and CSS. XML is meant to be sent around, and you want your resume to do that. Then each company can have their own XSL, so that every resume they look at is formatted the way they want it. If Company A only wants to look at the last position this person had, they can write an XSL for that. If Company B likes everything to be in bulletted lists, they can do that. It’s all the same data, all the same resume, but people would be able to choose how they see it. XML is easier to search than a Word document. XML files are smaller than Word documents. XML is more platform independent than Word documents. Conceptually, a person could write up one resume and then write multiple XSLs to display the resume for different skills/positions/etc. I wonder if this already exists…
I cobbled together a “yell” program for linux. It’s a perl script that takes advantage of “write” to send a giant message to another user. You type something like “yell ethan you rule!” and ethan gets a giant message telling him he rules. Rather than post the entire thing here, you can check out the source code here.
A long time ago there was a joke about a sorting algorithm called “monkeysort.” Monkeysort says that in order to sort an array, you keep randomizing the order of the elements in the array until it is sorted. Obviously, terribly inefficient but that was the point. For some reason, PHP has a shuffle() function which does the bulk of “monkeysort” for us. Here’s some code.
function isSorted($a) { $sorted = true; for ($i = 0; $i < count($a) - 1; $i++) { if ($a[$i] > $a[$i+1]) { $sorted = false; break; } } return $sorted; } function monkeySort($a, $limit = 0) { ### given an array ### randomizes the order of the elements ### until it's in sorted order ### set $limit if you want to put a limit on it if (!is_array($a)) { return $a; } if (count($a) == 0) { return $a; } echo "Monkeysorting...n"; $counter = 0; while (!isSorted($a) && (($counter < $limit) || ($limit == 0))) { shuffle($a); $counter++; } return array($counter, isSorted($a), $a); } $test = array("a", "x", "c"); # this will tell you how long it took to sort # whether or not it actually sorted # and return the sorted (?) array list($count, $isSorted, $sorted) = monkeySort($test);