KBD

Keith Devens .com

Saturday, August 30, 2008 Flag waving
Would that which we have achieved have been possible if Providence had not helped us? – Adolf Hitler (in a speech at Regensburg on June 6th, 1937)

Archive: July 15, 2004

← July 14, 2004July 17, 2004 →

Daily link icon Thursday, July 15, 2004

Quote of the day: Charles on Astrology

Charles:

If you honestly think that a human being’s personality or destiny is shaped by the fact that some guy looked up at a pattern of dots in the sky a few thousand years ago and thought “Ooh! Horsey!”, then I’m sorry, you’re an idiot.

Gloating over the collapse of Joe Wilson's credibility

Glenn Reynolds is gloating, and rightly so, over the discrediting of Joe Wilson.

Roger Simon helps to put the man and his actions in perspective:

... Wilson is no ordinary rat, the likes of which have abounded in virtually every political party since time immemorial. He is a deeply evil human being willing to lie and obfuscate for temporary political gain about a homicidal dictator's search for weapon's grade uranium. Think about that when you walk into your dining room tonight and sit down to dinner with your family. And think about this -- John Kerry, The New York Times, even some bloggers are willing to soft-pedal this. And they call themselves "liberals." Puh-leeze!

What's probably most frustrating about all of this is that the media that trumpeted Joe Wilson's lies at the time are now almost completely silent in trumpeting their own gullibility in being duped. By not announcing their failing as widely as they covered the original "story" the media is complicit in Joe Wilson's lies. Both the original coverage, as well as what now amounts to the cover-UP, are transparently political.

It shouldn't be surprising, I suppose. We know their agenda already (they've told us as much). But the fact that it's not surprising makes it ever more infuriating. The old saying goes "never ascribe to malice what you can ascribe to incompetence". Unfortunately, we know that this is malice. While incompetence can be forgiven if corrections are made, malice is unforgivable (and the corrections aren't being made).

Update: Scott at Wunderkinder has stuff to say. And more that should scare the crap out of anybody, that should remind us of just how important all of this really is. This isn't just politics, this is life and death.

Powerpuff girls e-mail address?

I just got an e-mail from what's probably a little girl asking me for the Powerpuff Girl's e-mail address. She found this page from this search and chose to e-mail me.

And I quote: "i really would like to talk to them online especially bubbles .I llike her the most please tell me how I can get in touch with them..." What do I tell her? I mean, it's not like Big Bird or Santa Claus, where maybe it's a real person you can talk to. It's a cartoon! But, I don't want to shatter her dreams by saying "What the bejeezus are you talking about little girl!?"

Update: Jinkies!

Storing times in MySQL

Starting principle: Because MySQL doesn't support time-zones in its time formats, you should never only store time/date data in a timezone other than GMT (UTC). If you do, you actually lose information about what time it really was.

There are a few options for storing dates and times in MySQL while respecting time zones:

  1. You can store the GMT time and an offset from it in seconds to represent the time zone.
    1. The date/time being MySQL's "datetime" type, and the timezone offset in "seconds from GMT". This takes 8 bytes for the datetime type and 3 bytes for the mediumint you'll need to be able to store all possible timezone offsets. Unfortunately, it just misses being able to be stored in a smallint (smallint range is -32768 to 32767, but time offsets from GMT can be ±43200 (there are 86400 seconds in a day)). (11 bytes total per row)
    2. You can store the date/time using normal unix timestamps. This should be fine for most things, and takes 4 bytes for the int to represent the time and 3 bytes for the mediumint timezone offset. (7 bytes total per row)
  2. You can store both the localtime and GMT time:
    1. Each one being a MySQL datetime (16 bytes total per row) (WordPress does this, incidentally)
    2. Each one being a unix timestamp (8 bytes total per row)

I mentioned the total size requirements not because that's a very important issue but just because it's something worth keeping track of. What's most significant in the choice is what type of burden you put on your application by what you choose.

If you need to store "normal" dates (where "normal" means "in between 1901 and 2038") I think my preferred solution is option 1B. By storing the date in GMT and storing the offset in seconds you're going to need to do some date math anyway, so it's better to just have everything in the DB be in the same "units". Your application will then have to take care of all your date logic, but that seems better than having some in your DB and some in your code and having to constantly convert between timestamps and MySQL's datetime format.

However, I'm honestly not sure if that's feasible. For instance, I use some of MySQL's date math in my code, and it's not immediately obvious to me how I'd replace it. For instance, if you want to get rows grouped by the day, how would you do this in MySQL if you were using unix timestamps? Ultimately, what WordPress goes for might be the simplest and best, though it feels like duplication of data to me.

Update (Jul 28, '04): See this update for my conclusions and recommendations.

'Show' function for debugging in PHP

I'm surprised I've never blogged this. Here's my "show" function I've used in PHP for a long time for debugging data structures. I have it right in my main file (dispatcher.php) so that it's always available.

<?php
function show($data$func "print_r"$return_str false){
    
ob_start();
    
$func($data);
    
$output '<pre>'.htmlspecialchars(ob_get_contents()).'</pre>';
    
ob_end_clean();
    if(
$return_str) return $output; else echo $output;
}
?>

This way, I don't have to do things like:

<?php
echo '<pre>';
var_dump($data);
echo 
'</pre>';
?>

all the time, and can just say show($data, 'var_dump') instead. Moreover, the code example I just gave doesn't escape the output of var_dump(), so if you may have stuff that needs to be escaped for HTML you'll essentially have to type out the contents of my show() function above to correctly display it Smiley winking.

The reason I'm blogging this now is because someone asked if he could see the source to my XML to PHP translator. I'm giving him an excerpt of it, and that excerpt contains show() (that's what actually prints everything if you run the translator). Here's a piece of that code:

<h2 id="xml">The original XML:</h2>
<?php show($f);?>
<h2 id="php">Resulting PHP data structure:</h2>
<?php show(XML_unserialize($f),$form->get('style'));?>

And, of course, that $form->get('style') bit is using my PHP form-processing library, Formation.

← July 14, 2004July 17, 2004 →
August 2008
SunMonTueWedThuFriSat
 12
3456789
10111213141516
17181920212223
24252627282930
31 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

new⇒Johnny Walker Blue Label

Wow, thanks for the scotch review​:D

Lagavulin and Laphroaig are​some of...

Keith: Aug 29, 3:35pm

Girls, please don't get breast implants

Wow, After all this time, the​comments on this page continue to​grow. It wa...

Ajeet: Aug 25, 2:36am

Generated in about 0.054s.

(Used 7 db queries)

mobile phone