Tutorial: Read/Write Android Emulator sdcard.img in Windows

For developers working with the Android Emulator on Windows, it can be quite tedious to interact with the “microSD card” (read:  image) from outside the Android emulator. Continue reading

Posted in Technical, Tutorial | Tagged , , , , , , , , | 23 Comments

Testing the Android Emulator…

I finally managed to figure out (and after burning through quite a lot of internet credit) how to get the Windows Android Emulator working (with Android Market). I wanted to do this so I can play around with Android before dropping a substantial amount of money on a Nexus One to replace my Nokia N78 when it dies. Installed the WordPress application just for kicks to see if it would work on my blog, and it did!

Extremely impressed.

Posted in Uncategorized | Tagged , , | Leave a comment

Quick way to generate something random

Thought I’d write a quick post to pass the time. I’m currently working on a little pet project that involves PHP, MySQL and is supposed to be a database of things that can be added dynamically. I did write it in a ‘procedural loop’ form but scrapped it due to its unmaintainability and the fact that object orientation is just so much better.
Those who know me and where I frequent online, will know what this project is; and will be released… Eventually. :)

One thing I did need was a little section of code that would generate a ‘random’ (when it comes to computers, nothing can be truely random) value to use as a primary key in a database, therefore making the entry unique across the entire database. This was required to link information across tables and the values generated by this code snippet would form primary and foreign keys. MySQL doesn’t seem to have such random generation functionality (that I could find anyway) so PHP code was the next best thing.

I found a code snippet that was based around the same thing posted below, but was designed as a session key generator (and had quite a bit more code to it. When modified, however, met my needs more than adequately.

function guid()
 {
    $id  =  md5(microtime());
    return $id;
 }

Quick explanation: I’ve enclosed this as a function so that I can re-use it where-ever I need some sort of random value. microtime() is a PHP class that returns the time in seconds since the Unix Epoch, and md5() just puts whatever value that is enclosed as an MD5 hash, making it a consistent hexadecimal 32-character value. There are probably better ways of doing this, but this works; which works for me. The return statement you see allows me to write code not dissimilar to this (if the function is in the same script):

$this->guid()

to generate the random value, which is then posted to the database under the relevant record.

Someone may find this of use, so here it is. Object orientation is difficult in PHP but once you get the hang of it, it’s quite intuitive; if a little confusing at times.

Posted in Technical | 2 Comments