KBD

Keith Devens .com

Thursday, January 8, 2009 Flag waving
whether or not it is clear to you, no doubt the universe is unfolding as it should.... – Max Ehrmann (Desiderata)

Archive: March 29, 2003

← March 28, 2003March 30, 2003 →

Daily link icon Saturday, March 29, 2003

RSS 2.0

Sometime soon I'm going to convert my RSS feed to version 2.0. I want to know what the right tags to put my content in are, so I'm keeping track of this bit on XHTML in RSS 2.0 from Sam Ruby.

Caching data in RAM with PHP

Anyone know if it's possible to cache data in RAM in PHP? I have a configuration file for my CMS that's growing rapidly as I put more and more metadata into it. I'd like to cache the resulting data structure in RAM and only reload the config file if the date of the file changes or if the system is rebooted and the data doesn't exist in RAM anymore.

Ok, well there's this, but I certainly don't have that compiled in... what else...

techInterview is awesome

techInterview is awesome! Try to solve the problem of the two switches.

A great quote from Einstein

which I never heard before:

"The release of atomic energy has not created a new problem. It has merely made more urgent the necessity of solving an existing one."

http://www.quotationspage.com/quotes.php3?author=Albert+Einstein

Chandler 0.1

Mitch Kapor: Chandler at O'Reilly Emerging Technology Conference

Andy Hertzfeld and I will be making a presentation on Chandler on Thursday, April 24, at 3:45 P.M., at the upcoming O'Reilly Emerging Technology Conference in Santa Clara. This will be the first public demo of what the OSAF team has been working on. I expect that the conference will be heavy weblogged, so you should be able to get a sense of the goings on wherever you are.

What we'll be showing is the 0.1 release of Chandler. Our internal 0.03 release of this past week has virtually the entire (limited) feature set of 0.1 with the exception of a couple of cool features we are trying to get ready for the demo.

Since we are all mortified at the prospect of embarrassing ourselves in public, we are trying to make sure that what is out there is real code we can be proud of.

I've been referring to Chandler 0.1 as our "ultrasound" release: the fetus won't be viable outside the womb, but if you look closely you can see tiny arms and legs waving around and you can believe it's going to turn into a real baby eventually. With 0.1, we will also open up our bugzilla database and accept bug reports and submissions of patches per guidelines which will come with the release.

Very cool. The page for Chandler 0.1 is an interesting read:

In the spirit of getting the community on board as soon as possible, we want to make source code available as soon as we have something we don't intend to throw away, but that will likely be a foundation for the real application. This means issuing a release that will lack most key features, have a very limited and primitive user interface, and won't be usable for real work.

A good 80 percent of our effort to date has been evaluating the open source projects we're building Chandler on, and learning how to use them (i.e., getting them to build!). These projects include Python, ZODB, wxWindows, wxPython, and in the future, Mozilla. This has taken a lot longer than expected because many of these projects are either incomplete or in a state of change. So a major goal of our first public release is to include precompiled versions of Chandler and its underlying technologies on all three major platforms, as well as source code you can easily build yourself using the latest compilers for each platform.

Chandler stores data in an RDF-compatible format using ZODB4, which is a persistent object database. The advantage of persistence is that data is accessed in native Python data structures. This eliminates the need to write code that translates data back and forth between native data structures and a foreign format, and it also eliminates code for housekeeping tasks like garbage collection, saving and storing to disk, and so on. To store data in Chandler, we specify the format of each data type in an RDF schema that's stored in a persistent Python data structure (see the diagram). Instances of the RDF data type can be created and used directly from the schema.

Analysis of the war

Steven Den Beste relays a great analysis of the war so far, and adds a little of his own.

So what's the plan? While claiming no inside knowledge, there are only so many ways of skinning this cat, and strategically it's a fairly simple problem. Any workable plan must have a minimum of 4 elements:

1. Road march: advance on Baghdad and establish attack positions while shoring up supply lines.
2. Whoop ass: destroy the Republican Guard units around Baghdad.
3. Vise Grip: complete the encirclement of Baghdad and cut off all supplies to the city.
4. Mop up: defeat remaining Iraqi forces while awaiting Baghdad's surrender.

Coalition forces are currently somewhere between 1 and 2. A sure sign the road march is complete is that the units stop moving and wait for orders to attack. That appears to have happened. The next step is to attack the Republican Guard forces, which must be destroyed before any credible attack on Baghdad can begin. The aerial softening up phase is in progress, and a ground assault is imminent.

SmartPHP.net

Simon points to SmartPHP.net, which looks like it has some neat stuff on it, like SmartTemplate and SmartCache.

Do RSS readers support HTTP redirects?

I just set it so my RSS feed at the old location:

http://www.keithdevens.com/weblog/?rss

redirects to its new location at

http://www.keithdevens.com/weblog/rss

Syndirella had no problem, but does anyone know if any RSS readers don't support HTTP redirects?

Trials of developing with error_reporting(E_ALL) in PHP

If you use PHP, and are familiar with PHP's error handling system, you know that by default, there's an entire class of errors, E_NOTICE, that you don't see (PHP's default error handling settings are equivalent to error_reporting(E_ALL & ~E_NOTICE)). But, you're really supposed to at least develop, if not deploy, with notice errors on.

Notice-level errors come up most often when you index into an array that doesn't have that index defined.

So if I were to say:

<?php
$arr 
= array();
$foo $arr['bar'];
?>

that would give me a notice error. So, you have to have things like:

<?php
$foo 
= (isset($arr['bar']) ? $arr['bar'] : NULL);
?>

all over the place. Very irritating. Perl (or maybe just Perl 6) has a special operator for this very reason. I think the operator is '\=', but I'd have to check. Oops, got it backwards (look for the heading 'binary //'). The operator is //=. I don't know if that exists in Perl 5.

Anyway, PHP doesn't have that, so typing the line above all the time gets a little tedious. But what I discovered today is more sinister.

I have a function called getPath() that will take a string expression that looks like "foo|bar|baz" and index into an array. So if you make the following getPath() call:

<?php
$foo 
= &getPath($data'foo|bar|baz');
?>

that would be equivalent to saying:

<?php
$foo 
= &$data['foo']['bar']['baz'];
?>

Don't ask me why I have this function, I can't tell you. It's part of a secret larger project. Just believe me that it makes a lot of sense for me to have it.

Now, the important thing to notice is that I'm taking a reference in the code up there. First of all, if the expression I give getPath() results in a large array, I'd rather take a reference to it than copy the whole thing and waste space. More significantly, I want to be able to get a reference to a piece of a data structure, and then assign to that. So, for instance, I have something like the following setPath() function that I want to behave like this:

<?php
function setPath(&$data$path$value){
    
$foo = &getPath($data$path);
    
$foo $value;
}
?>

The actual specifics (function names, details, etc.) are different than that, but that gives you the idea. So now you understand the second reason why I wanted to be able to get a reference out of getPath().

Now we're going to get to the sinister part. Smiley Take a look at the previous version of my getPath() function:

 1: <?php
 2
: function & getPath(&$data$path){
 
3:     if(is_array($data)){
 
4:         $path_parts explode('|'trim($path'|'));
 
5:         $c count($path_parts);
 
6:         $temp = &$data;
 
7:         for($n=0;$n<$c;$n++){
 
8:             if(isset($temp[$path_parts[$n]])){
 
9:                 $temp = &$temp[$path_parts[$n]];
10:             }else{
11:                 return NULL;
12:             }
13:         }
14:         return $temp;
15:     }else{
16:         return NULL;
17:     }
18: }
19?>

You can see I'm being really careful to make sure that the piece of $temp I'm taking a reference to in line 8 is set with the isset() function, so that I don't get NOTICE errors if the $path I give points to somewhere that's undefined. The problem is twofold. First, isset() returns false if the value is NULL, even if you actually set it to NULL. So if I try to index into a piece of the array that's NULL, get the reference to it, and assign to that reference, instead of replacing the actual NULL value in the array, because I was being careful and returning a "new" NULL in line 11, I wouldn't be changing anything in the old data structure anymore.

At that point I thought I was stuck. But I made sure error_reporting(E_ALL) was on and did some testing. It turns out that this code gives a NOTICE error:

<?php
$arr 
= array();
$foo $arr['bar'];
?>

But this code doesn't!

<?php
$bar 
= &$blah['bazooooooo']['foo']['roar'];
?>

even if the array doesn't even exist yet (yes, that last bit was actual code I used to test it). It turns out that if I then assign to $bar the following array is created:

array(1) {
 ["bazooooooo"]=>
 array(1) {
   ["foo"]=>
   array(1) {
     ["roar"]=>
     &string(3) "foo"
   }
 }
}

So the point is that trying to take the value of a non-existent array index is a NOTICE error, but taking a reference to something that doesn't exist is just fine Smiley So that's great! I was able to change my getPath() function into this, and it worked fine:

 1: <?php
 2
: function & getPath(&$data$path){
 
3:     if(!is_array($data)){
 
4:         return NULL;
 
5:     }else{
 
6:         $path_parts explode('|'trim($path'|'));
 
7:         $c count($path_parts);
 
8:         $temp = &$data;
 
9:         for($n=0;$n<$c;$n++){
10:             $temp = &$temp[$path_parts[$n]];
11:         }
12:         return $temp;
13:     }
14: }
15?>

Problem solved. Note that I changed a little bit stylistically as well. If you have a condition in which one branch corresponds to a check for an error condition that is only a few lines long, and the other branch has many more lines, it's typically better to put the quick error clause closer to the condition, which is what I did above.

So, hopefully we all learned a little bit about PHP we didn't know before through my little exercise.

I want a better aggregator!

Not to be disparaging, but it seems like Dmitry has slowed development on Syndirella. As I add more feeds, it's getting harder and harder to find things... I could really use some categories Smiley

War crimes

A great post by Steven Den Beste on the double standards everyone has regarding war crimes.

...even with this kind of care, it seems like everyone out there who can possibly find a reason to do so is tossing around accusations of war crime.

But they're only flinging those accusations at us. In response to absolutely clear and blatant war crimes by Iraq, there has been a notable silence.

In some of the fighting in the last couple of days, members of the Fedayeen have been herding civilians in front of them as they move towards our troops, to use them as "human shields". That's a blatant violation of the Geneva Convention, but I sure as hell haven't heard any massive international outrage about it, or denunciations and condemnations of Iraq.

So where is all the outrage?

Update: Here's a follow up by Steven.

← March 28, 2003March 30, 2003 →
January 2009
SunMonTueWedThuFriSat
 123
45678910
11121314151617
18192021222324
25262728293031



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

Recent comments XML

new⇒The Elegant Universe

Well I have finally found the crazy​guy that preaches useless nonsence​in A...

Joseph Baxter: Jan 7, 11:07pm

I hate Norton Antivirus


SYMANTEC is very​cunning..
Symantec now have a​redeemable cash back offe...

CAN: Jan 4, 6:25pm

Spider solitaire

Hi everyone!

Glad to have found​this site.  I have enjoyed reading​the c...

flwrchld53: Jan 4, 5:30pm

The Escaped Prisoner: When God Is a Monster

if islam is afraid of one woman, it​is sad. it is sad that a lot of​muslim ...

alex: Jan 2, 1:56pm

Generated in about 0.081s.

(Used 7 db queries)

mobile phone