GoogleAppEngine

Tuesday, 28 July 2009

BadUUID

Tuesday, 17 February 2009

Don't try this at home, kids.

int i;
char uuid[16];

for( i = 0; i < sizeof( uuid ); i += sizeof( int ) ) {
    *( ( int * ) ( ( ( char * ) uuid ) + i ) ) = rand();
}
printf( "generated random id, %llu.%llu\n", *( ( ( uint64_t * ) &uuid; ) + 1 ), *( ( uint64_t * ) &uuid; ) );

A quick call to some CF (on a Mac) functions solved this right up.

UITableViewCell thoughts

Sunday, 15 February 2009

In iPhone development, the class UITableViewCell is king. You use it to customise any of the table views you might create. The thing is, table views are used not only for tabular data, but also menus, form interfaces, and so on. However, despite being king, there are a woeful number of examples or sample cells you can use.

One of the smaller problems that I've just overcome is the fact that you can use an unchanged cell structure to display plain black text. This looks quite nice and works quite well. However, as soon as you customise a cell, you have to recreate this original black text if you want it. I have discovered, through Science!, that this text can be reproduced through a rectangle with a left and right margin of 10 pixels, and a font size of 20 points.

// assuming title is a property of some UITableViewCell subclass
title = [[UILabel alloc] initWithFrame: CGRectInset( self.contentView.bounds, 10, 0 )];
title.textColor = [UIColor blackColor];
title.font = [UIFont boldSystemFontOfSize: 20.0];
title.backgroundColor = [UIColor clearColor];
[self.contentView addSubview: title];

And there you have it. For your, and indeed my own, future reference.

JenIsCool

Thursday, 29 January 2009

So she is! Mwuhaha.

awesome italics

ArduinoScheduler

Wednesday, 21 January 2009

I wrote a small-scale interface to schedule intermittent tasks for the Arduino environment. Well, any environment, really, but this doesn't use much memory. And... doesn't handle an overflow of the current time value.

/* usage:
 *   fnregister( target_function );
 *     nb. where target_function returns a uint16_t that indicates the next time it should be invoked
 *   fndelay( ticks );
 *     used the same way as delay(), except will invoke registered functions when their time is up.
 *
 */

#define FNBITS 3                /* bits to use for number of FN's */
#define MAX_FNS (1<<FNBITS)

static struct {
    uint16_t (*fn)(); /* actual fn pointer */
    uint32_t nextat; /* when to next run */
} fns[MAX_FNS];
static int fncount = 0;

int fnregister( uint16_t (*fn)() ) {

    if( fncount == MAX_FNS ) {
        return -1;
    }

    fns[fncount].fn = fn;
    fns[fncount].nextat = 0;

    ++fncount;

    return 0;
}

int fndelay( int ticks ) {

    int best, waitfor, i;
    long now, returnat;

    now = millis();
    returnat = now + ticks;

    for( ;; ) {
        best = -1;
        waitfor = -1;
        for( i = 0; i < fncount; ++i ) {

            /* fall out, taking too long */
            if( now > returnat ) {
                return 0;
            }

            /* if we don't have a best, or this is a good idea */
            if( ( best == -1 && fns[i].nextat < now ) || ( best > -1 && fns[i].nextat < fns[best].nextat ) ) {
                best = i;
            }

            /* otherwise work out how long to waitfor */
            else {
                int _waitfor = fns[i].nextat - now;
                if( waitfor == -1 || _waitfor < waitfor ) {
                    waitfor = _waitfor;
                }
            }

        }

        /* if we didn't find a best fn */
        if( best == -1 ) {

            /* if we don't know how long to wait for, or waiting will go too long */
            if( waitfor == -1 || now + waitfor > returnat ) {
                delay( returnat - now );
                return 0;
            }
            delay( waitfor );
            now = millis();
        }
        else {
            now = millis();
            fns[best].nextat = now + fns[best].fn();
        }
    }

}

moofwiki

Saturday, 17 January 2009

Software designed to run on GoogleAppEngine allowing Sam to blog, and make wiki articles and the like. Some current work-in-progress ideas are listed below.

mooflog

Saturday, 17 January 2009

mooflog is Sam's blog, hosted on GoogleAppEngine.

Welcome

Saturday, 17 January 2009

This is a test of moofwiki, a tiny wiki system for mooflog, Sam's minimalist blog where he attempts to remain anonymous.