Sunday, June 24, 2007

TortoiseSVN for Ubuntu

Update: Rabbit VCS is the answer!


I discovered Nautilus scripts just today. I was a little exasperated, because I haven't yet found a good enough TortoiseSVN for Ubuntu.

I set off to learn about Zenity, and in the end came up with two alright scripts for svn commit, and svn update.

Unfortunately after fighting awk for too long, I found nautilus-script-collection-svn (apt-get install is your friend).

Now I'm stuck: I like my svn commit script, as it's much closer to TortoiseSVN (Enter message, select files to commit), and all I can do is whinge - I can't provide a more useful thing to the world.

Sigh.

Tuesday, June 19, 2007

PHP Magic: Watch carefully as I place this DOMNode into a hat

Nab this, save it somewhere (I did it with 5.2.3). Spot my magic trick, and X_import_Y not doing what you'd assume.

<?php
$sxeA = simplexml_load_string('<nowYouSeeIt><nowYouDont /></nowYouSeeIt>');
$root = dom_import_simplexml($sxeA);
$sxeB = simplexml_import_dom($root);

print "Simplexml A\n";
print $sxeA->asXML() . "\n";

print "Simplexml B\n";
print $sxeB->asXML() . "\n";

print "I simply utter the magic xpath phrases...\n\n";

$items = $sxeA->xpath("//nowYouDont");
$node = dom_import_simplexml($items[0]);
$node->parentNode->removeChild($node);

print "ABBRA-KA-FREAKIN'-DABRA!\n";

print "Simplexml A\n";
print $sxeA->asXML() . "\n";

print "Simplexml B\n";
print $sxeB->asXML() . "\n";

Monday, June 18, 2007

No one dies on the internet...

toggg died of a heart attack

For those of you who don't know him, you may know his work.

More importantly: he was perhaps the only person who recognized me and said hello on #pear. I really appreciated that. I didn't know much about him in life, but in death I've discovered the world is a far poorer place without him.

Goodbye, toggg. You will be missed.

Saturday, June 16, 2007

Port Misery

Did you know that Port Adelaide was called Port Misery? Or that it was a mosquito infested swamp?
Port Adelaide is a very old suburb of Adelaide. It was officially proclaimed as a harbour in 1837. Its original name, Port Misery, is said to have been adopted because it was a mosquito-infested swamp when the first settlers landed at Port Adelaide. It has also been suggested the name described the unsatisfactory handling of goods at the site. In 1839, the name was changed to Port Adelaide. Today, it still maintains the port working-class feel but it is slowly becoming gentrified, especially along the Port River.

In 1853, Port Adelaide was the destination of the maiden voyage of the famous Dutch clipper California, carrying some hundred English immigrants who arrived in what was considered record time for the period[citation needed].

The suburb has many old colonial buildings, such as the Port Adelaide Uniting Church, primarily near the wharves (St Vincent Street, Lipson Street and Divett Street), that have been placed under State heritage listing.

Monday, June 04, 2007

esvn just made my day

esvn just made my ubuntu experience much, much better.

It's no tortoisesvn, but it's a damned sight better than the command line.

I wonder, is it still actively developed? Trunk shows no commits newer than 2 months old.

Sunday, June 03, 2007

php style: foreach is better

Since it seems that everyone wants to know about reading and writing csv with php, I thought I'd take a moment to push the virtues of the foreach loop.

First: It's neater. Consider that
foreach ($collection as $item) {

}
is a billion times neater than:
for ($i=0; $i<count($collection); $i++) {
$item = $collection[$i];
}

But time and time again, I see the latter used.


Second: What happens if your collection isn't neatly ordered? In this example, the size of the collection is 2, and the for loop will completely miss things. This rarely happens, but can be very frustrating when it does.
$collection = array(1,2,3); unset($collection[1]);
for ($i=0; $i<count($collection); $i++) {
$item = $collection[$i];
}

Third: I cannot think of more than one situation where I've ever had to do anything other that forward-traversal. So why waste time with a for() loop unless you really, really need it. Consider the readability of this code below, and the nightmare people can experience when trying to maintain your code.
This was some code for interacting with an open office document, extending the DOM:
if ($stylesList->length > 0) {
$styles = $stylesList->item(0)->getElementsByTagName('style');

if ($styles) {
//Load styles
for ($i = 0; $i < $styles->length; $i++) {
$style = $styles->item($i);
$name = strtolower($style->getAttribute('name'));
$this->styles[$name] = $style;
}
}
}
and this is the same code, after refactoring:
$nodeList = $this->getElementsByTagNameNS(self::XMLNS_OFFICE, 'automatic-styles');

if (!self::checkNodeList($nodeList)) {
return array();
}

$node = $nodeList->item(0);
$nodeList = $node->getElementsByTagNameNS(self::XMLNS_STYLE, 'style');

if (!self::checkNodeList($nodeList)) {
return array();
}

foreach ($nodeList as $node) {
$name = strtolower($node->getAttributeNS(self::XMLNS_STYLE, 'name'));
$this->styles[$name] = $node;
}
Notice how everything is easier to read, but the level of complexity has increased? Foreach makes life simpler...

Forth: It's faster.

Saturday, June 02, 2007

Google Gears lets me use SQLite

Google gears includes SQLite. Awesome.

At work, we have a whole bunch of tablet PCs. I've always been a little bit hesitant about the worth of them for our valuers.

We've relied on a 3rd party solution for data capture, so our valuers can draw up floor plans and capture information about the property they are at.

To get the information back is a mix of air card (for wireless connectivity), soap services, a .NET client application, a .NET server built by someone different to the client software provider, a custom XML format which has parts resembling CSV in XML, and bits of our own PHP which were hastily patched together at the last minute, then promptly shelved to do more important things.

You can perhaps see where I'm a little bit hesitant about introducing features to our tablet users. However, you can get a few different Firefox extensions to improve tablet PC usage (scrolling for instance, or enabling keyboard input on the address bar), there's the CANVAS element, SVG support, and now Google Gears providing offline support, as well as a full blown database backend and the ability to offload intensive computing processes elsewhere.

It's no longer inconceivable for us to provide the floor plan capture software over the web, or provide maps to locations for offline usage through Google maps...