skip to content

Detecting iPhone/iPod version

In some cases it is required to change application behaviour depending on iPhone or iPod Touch device version.

#import <sys/utsname.h>;
...
struct utsname u;
uname(&u);

After calling uname() function, u.machine will be “iPod1,1″, “iPod2,1″ for iPod Touch and “iPhone1,1″, “iPhone1,2″, “iPhone2,1″ for iPhone (or similar depending on current device).

Source:

SQLite Sorcerer – great application for editing SQLite

Last few days I spent a lot of time looking for clean and simple tool for viewing and editing SQLite databases. As a user of Windows and Mac computers, I wanted it to be multiplatform so I could use it on both machines. And finally I found it – SQLite Sorcerer.

sqlite-sorcerer

It’s written using Adobe Flex and AIR so it runs as standalone application on all supported operating systems. There are no fancy features available in many commercial applications, but I am sure that there is everything that most users need during day-to-day usage of SQLite.

Download SQLite Sorcerer 1.5

RegExhibit

RegExhibit is great Mac OS X tool for testing regular expressions.

Python – testing regular expressions

Very nice and simple online Python regular expressions tester: Python Regular Expression Testing Tool.

RIA Data Loading Benchmarks

I just found great application for testing performance of various data exchange protocols for client-server communication using Flex - Census.

Random permutation of array

Here is the code snippet for generating random permutation of array:

var a:Array = new Array( 1, 2, 3, 4, 5, 6, 7, 8, 9 );

trace( "Array: " + a );

for ( var i:uint = 0; i < a.length; ++i )
{
    var j:int = Math.random()*i;
    var j:int = Math.random()*( i + 1 );

    // Swap a[i] and a[j]
    var temp:* = a[j];
    a[j] = a[i];
    a[i] = temp;
}

trace( "Permutation: " + a );

Update: fixed bug with finding index of item to swap – thanks for pointing that out Kevin!

Flex Explorers

Four most useful explorers for every Flex developer:

TODO/FIXME extension for Flex Builder

Great little tool for Flex Builder users. It parser all ActionScript and MXML files and searches comments for FIXME and TODO tokens. Complete list of them will be available in Window > Other views > General > Tasks panel. It was designed for Flex Builder 2 but works like a charm with version 3.

Download extension

Seeded random number generator in ActionScript 3

Recently I needed seeded pseudo-random number generator for my Flex project. After searching I found three good articles with solution of that problem. Grant Skinner proposed use of BitmapData.noise() method. He also provides Parker-Miller psuedo-random number generator based on implementation by Michael Baczynski.

Useful links:

WordPress plugin: Code Markup

The best plugin for displaying code in WP. Without any fancy coloring but supports HTML tags and preserves code formatting. You can find it at semicolon blog.