I was posed the following inquiry: “Basically I have 6 boolean variables and I need to document every possible true/false combination. I’m having difficulty finding a basic method to write all combinations out without repeating.”
It simply counts from zero to 64, prints that in binary, and I have it manually toggle 0 to ‘F’ and 1 to ‘T’ for true/false. The str_pad is called due the fact that the first few numbers will ‘not fit’ with the diagram properly, and there’s no sense to manually fill it.
The reply I was given to this was: “Brilliant, and insane – yet, it’s in PHP, so I’m beside myself.” Gee, thanks. :)
I often find myself curious as to what libraries and frameworks a program relies upon. Thanks to a recent entry by Marc Liyanage, I’ve managed to make this task rather automatic, lifting most of his little command verbatim.
Note that this is a ZSH style alias, but should be trivial to make work with the shell of your choice:
Pretty useful, huh? The way it’s written, you’ll get an error (from ls, of course) if any of the shared libraries do not exist. Thanks for this tip, Marc!
Rather than relying on the older format of cookies; Rollator’s administrative interface is now closely-knit with PHP’s session management. I’ll most likely create a bit more of an abstract layer for handling all of this.
As it stands, I’m now nearly cookie free, with everything nice and encrypted, mostly server-side. All that’s transmitted after the initial login is your cookie ID for PHP’s internal session management.
As an additional (read: useless) module to add to LiveJournal was quite easy, however WebLogs is not quite the same to parse with it’s semi-proprietary format.
The following trivial code snippit uses PHP’s (now) native XML routines to parse this format and make it human-readable. Feel free to steal, use, or adapt as you need – you’ll notice that it’s quite, ah… inelegant.
WebLogs Parsing Test
<?php
parse_webblogs();
// print_r($parsedlogs);
while (list($number, $stuff) = each ($parsedlogs)) {
echo "Entry $number: " . nicetime("$stuff[WHEN]") . " ago $stuff[NAME] [<a href='$stuff[URL]'>RSS</a>]<br />";
}
function nicetime($arg = "") {
// Boy is this ugly. I'll have to fix it later.
if ($arg < 60)
return $arg . "s";
if ($arg > 60 && $arg < 3600)
return round(($arg / 60)) . "m";
if ($arg > 3600)
return round(($arg / 3600)) . "h";
}
function parse_webblogs() {
global $parsedlogs;
$fp = @fopen('http://www.weblogs.com/rssUpdates/changes.xml', 'rB');
if (! $fp)
return false;
$data = fread($fp, 1000000);
$data = str_replace("\\r", '', $data);
$data = str_replace("\\n", '', $data);
$xp = xml_parser_create();
xml_set_element_handler($xp, '_simple_xml_startElement', '_simple_xml_endElement');
xml_parse($xp, $data, true);
xml_parser_free($xp);
return $parsedlogs;
}
function _simple_xml_startElement($xp, $element, $attr) {
global $parsedlogs;
if (strcasecmp('weblog', $element)) {
return;
}
$parsedlogs[] = $attr;
}
function _simple_xml_endElement($xp, $element) {
global $parsedlogs;
return;
}
?>