Sam Wilson's Journal

Fremantle Critical MassJanuary 29th, 2010, 9PM

Walking

 

A respectable turn-out for what seems to have been a short-notice Critical Mass bike ride in Fremantle this afternoon. Hopefully next month we’ll be more.

In what other city does the mayor not only give up (by charity auction) his car parking space, but even pedals along to a Critical Mass?!!

CM happens — or can happen — at 5:30PM outside the town hall in Kings Square on the last Friday of every month, if you’re interested.

[Keywords: , , , ] [No comments] [Permanent link]

 

This morning I’m returning to work on some code that I haven’t touched for a few months, and I’ve been rather dreading getting back to it. I’ve forgotten all the details; never knew many of them anyway. I was working with someone else on this, and so have to get my head around their work too. And of course, all I’m trying to do is modify one little (well, constrained to one package) part of the program.

How to not only get over this being an annoying chore, but actually get excited again about the program? Start at the top, read through all the javadocs, read through the code, and as I go make the documentation better. Write the story of the program — the narrative of the code. Documentation, in my view, should not only be useful and readable and thoroughly explain the code, it should actually be interesting to read!

This is the essence, I feel, of Literate Programming. I know there was much more to Knuth’s idea than verbose code commentary, but the idea of being able to sit down and read a clear human-language expository of a programme is very powerful. The documentation that is produced is a hypertext, but the nodes of it should be complete, interesting, explanations of how the code works and why it was written the way it was.

[Keywords: , , , , ] [No comments] [Permanent link]

 

Someone wanted to know how to add a three-page PDF to a Word document, and then add a dozen photos after it, and then save the whole mess as a new PDF.

I suggested ImageMagick’s convert and pdftk.

  1. Combine all the images into one PDF:
    $ convert *.jpg photos.pdf
  2. Put the two PDFs together:
    $ pdftk report.pdf photos.pdf cat output report_with_photos.pdf

And that’s it.

(Of course, when one suggests this sort of thing to someone who wants to use Word, one invariable ends up doing it for them. Which is why I’ve posted this here, so in six months when I’m asked again, I’ll remember how to do it.)

External links:

Skala, M. 2008. How to concatenate PDFs without pain.

[Keywords: , , , , ] [No comments] [Permanent link]

Zend Forms are not DecorativeJanuary 27th, 2010, 9AM

Programming

 

I am trying, yet again, to make Zend_Form do what I want. It’s a tiresome process.

I am working on an application that constructs forms based on the structure of database tables. Building the actual form is fine — different types of inputs (text boxes, drop-down lists, file selection fields, pop-up foreign key selection things, etc.) are correctly produced and displayed. The problems come when I start to fiddle around with the elements’ decorators.

The idea, as far as I can see, is that one constructs a form element and then applies to it whatever decorators one wants. The element can then be added to a form, which is passed to the view for display. Something like this (in a controller action):

$this->view->form = new Zend_Form();
$element = new Zend_Form_Element_Text('element_name');
$element->setDecorators($decorators);
$this->view->form->addElement($element);

Which, on the face of it, doesn’t seem like such a bad idea to me. I have spent many hours fiddling with constructing forms, with varying levels of API assistance (from typing out the full HTML, to using HTML_QuickForm), and I’m ready to love anything that makes it easier. Zend_Form seems to do a good job. I can add validators to elements; I can set values; I can change labels and descriptions; with an extra line or two of code, I can add date choosers or sliders; the only thing that I cannot do in a normal, object-oriented, read-the-API-and-understand sort of way is make the surrounding HTML be what I want!

(Come to think of it, that’s a pretty minor quibble about Zend_Form. That it does everything that I want, but there’s just something that I can’t figure out. Operator error. Oh well.)

Anyway, here’s (roughly) what I want to see when I output the above form:

<form ... >
  <div class="element">
    <label for="element_name">Element Label</label>
    <input type="text" name="element_name" value="Value." id="element_name" />
    <span class="description">Element description here.</span>
  </div>
</form>

But the best I can get at is to have the input and description elements in their own wrapper element, and the label a level above them. This is jolly annoying!

Later: I give up. I’m going back to the table layout that we were using before. It’s ugly, and really not style-able, but it’ll do for now. I’ll come back to this.

[Keywords: , , , , ] [No comments] [Permanent link]

Mapping Cantonment HillJanuary 26th, 2010, 4PM

Open content

 

Further to this morning’s geeking with Cantonment Hill photos, I’ve (discovered NearMap; how have I missed this?!… and) been tracing what I can of the hill and surroundings. Here’s what it’s looking like now:

You can see the current state of this bit of the map at openstreetmap.org.

I don’t know what’s going on with that ocean background. It seems that the entire coastline of Perth has been moved inland in a big box sort of a thing, but I can’t see it in Potlatch. I’ll leave that up to the proper OSMers to sort out I think.

[Keywords: , , , , ] [No comments] [Permanent link]

 

The news that Flickr Commons is full prompted me, yesterday afternoon, to cycle down to Cantonment Hill to get some photos to add to the hill’s Wikipedia article. Why? Because I added a short note to Wikinews the other day about the imminent return of the hill to the FCC; and because I was reminded that Commons is a place — the place, perhaps, now — to put photos that might be of use or interest to other people, and I like that ‘collective archive’ idea.

I have always felt that Commons only wants files that are of direct use in another project — mainly Wikipedia — and that unless one can think of a good reason to upload a file, that file should be posted elsewhere. Such as Flickr Commons, or the Internet Archive; I can’t think of anywhere else. Perhaps I’m wrong. Is Commons more like the IA than one might first think? Is it acceptable to add material that is highly unlikely to ever make it in to a ‘proper’ article on one of the projects? Unless there is a need to illustrate, for example, the various types of steel handrails used on stairs in the 1950s, then there are some photos that will never make it out of Commons. That’s okay though. Someone might want to write that article in fifty years’ time.

So I am going to keep working on Wikimedia projects, in my own way, in the hope that it is a worthwhile use of my time. I think it is.

[Keywords: , , , , , , ] [No comments] [Permanent link]

Trying to understand MySQLJuly 21st, 2009, 2PM

Uncategorised

 

I’ve been asking around about how to execute dynamic SQL, that contains a cursor variable, in a stored procedure.

I’m steadily getting closer to chucking it in and writing a PHP script to do the same thing…

(For my future reference, here’s the SQL:)

DELIMITER //
DROP PROCEDURE IF EXISTS generate_district_files //
CREATE PROCEDURE generate_district_files()
BEGIN
 
    -- Declare variables
    DECLARE district_val VARCHAR(50); -- The name of the cufrent district
    DECLARE no_more_rows BOOLEAN; -- Loop exit condition; set by NOT FOUND handler 
 
    -- Declare the cursor
    DECLARE districts_cur CURSOR FOR SELECT district FROM staking_jobs GROUP BY district;
 
    -- Declare handler to set loop exit condition
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;
 
    -- Get the districts
    OPEN districts_cur;
 
    -- Loop through each district, creating a DFIS file for each
    the_loop: LOOP
 
        -- Get the district name
        FETCH districts_cur INTO district_val;
 
        -- exit the loop if there were no records, or we've processed them all
        IF no_more_rows THEN
            CLOSE districts_cur;
            LEAVE the_loop;
        END IF;
 
        -- Output the CSV file for this district
        SELECT CONCAT('Exporting data for ', district_val, '.');
 
        -- Set up the statement for exporting (required because of dynamic filename)
        SET @export_sql_stmt = CONCAT('SELECT district, \'s\', pick_id',
            ' FROM staking_jobs WHERE district = \'', district_val, '\'',
            ' INTO OUTFILE \'/tmp/to_be_staked_', district_val, '.csv\'',
            ' FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\'');
 
        -- SELECT @export_sql_stmt;
 
        PREPARE stmt1 FROM @export_sql_stmt;
        EXECUTE stmt1;
        DEALLOCATE PREPARE stmt1;
 
    END LOOP the_loop;
 
END //
DELIMITER ;

[Keywords: , , ] [No comments] [Permanent link]

phpMyAdmin AnnoyancesJuly 21st, 2009, 12PM

Uncategorised

 

It seems that my hassles this morning with getting building a stored procedure that generates DFIS lists were not, in fact, rooted in my ignorance.

I haven’t looked into it—I’ve got too many other things to worry about—but it seems that SQL that works fine when executed on the command line, does not cope when uploaded into phpMyAdmin.

And thus, I learn.

[Keywords: , ] [No comments] [Permanent link]

Poorly, and a Return to WordPressJuly 18th, 2009, 7PM

Memory

 

I think I rather like WP after all, and intend now to use it again. I hope to get back to writing here. Perhaps I will … tomorrow.

Right now, I’m sick, and intend to while away the few hours until bedtime in reading Mr Waugh’s Put Out More Flags.

[Keywords: , ] [No comments] [Permanent link]

CarsJuly 18th, 2009, 7PM

Reason

 

The words below I move here from their own page, because…

I now seem to be going in cars again. Ah well. It was the move to Perth that did it, and the hanging out with Bec, and the general lightening of my mood towards idealism (or what some would call stubbornness). It’s time to relax.

* * *

In July 2004 I made the decision to completely stop travelling in all cars.

Since then, I have refused to get in any car whatsoever (even if it’s “going there anyway” or an electric vehicle!), and although my life has become more geographically limited, I have never felt such personal feedom. I am, every day, more committed to this endeavour.

Connection to Place

Being limited in where I can go is part of why I do this; being forced to properly consider how I relate to place and speed. It is a contrived limitation that I place upon myself, but it’s been so long that I usually forget about it, and walking has become my naturnal way of going from place to place — I never feel like I’m going slowly or am being prevented from doing what I want.

I’ve offended some people, and missed out on some nice trips to the bush, but I feel so exceptionally fortunate to — almost every day — be given opportunities to appreciate, in a real and deep level, the places that I walk through. I mean anywhere, be it suburban pavement or inner-city park taking in a place slowly and on foot is truly amazing.

And some random other points:

  • Speed, and the taking-in of where one is and where one is going.
  • Devotional attachment to place.
  • Lots of places that I can’t go and lots of things I can’t do, but these limitations are positive.
  • Forces a real (human, environmental) relationship with place.

Environment

There’s also the macro-environmental thing: cars, and fossil-fueled transport generally, are killing the planet. That used to be a motivating reason for me to reduce my car usage (and my food-miles and all that); it isn’t really any more. I don’t mean that I’ve changed my mind about the environmental impacts of cars, but just that their impacts upon the urban landscape, and upon my personal experiences, are far greater than what I see of their impacts upon the arctic ice-shelf (for example). Of course, the local-environment things (streetscape, noise, etc.) are also environmental, but I don’t think revving engines or ugly streets ever brought about large-scale species destruction. And, finally (and possibly most importantly!), I really cannot be bothered with keeping up to date with all the latest scientific imformation about climate change etc. that are central to the ‘cars are environmentally bad’ argument.

People’s Reactions

What I said to my IBM colleagues in August 2007: “It’s about cars’ influence on society, urban design, the environment, and a bunch of other stuff… that I can go into if anyone cares.” They replied with silence, mostly, and “what about motorbikes?”. Other people, sympathetic people, asked “what if it were a biofueled car?” (I don’t care about the fuel source; I don’t know anything about fuel). But they were all, absolutely, respectful.

Random Other Stuff

  • H2G2 Fit the 7th: “People going from A to B, B to A, not C. Decide where to be!”.

[Keywords: , ] [No comments] [Permanent link]