BitSensei

programmer knowledge

  • Increase font size
  • Default font size
  • Decrease font size
BitSensei

Initializing a variable with an array reference

E-mail Print PDF

To initialize a variable with an array reference in PERL:

 
 
my $arrayref = [];
 
 

Remember that $arrayref is a scalar variable that acts like a pointer to an array. You can also initialize it with values like so:

 
 
my $arrayref = [ "hello", "world" ];
 
foreach my $word (@$arrayref) {
    print "$word\n";
}
 
 

Last Updated on Thursday, 28 May 2009 14:45
 

Listing the tables in a sqlite3 database

E-mail Print PDF

The following code lists the table names in a sqlite3 database.

 
    sqlite3_stmt *stmt;
 
    if (!sqlite3_prepare_v2(db, 
        "select name from sqlite_master where type='table' order by name", 
        -1, &stmt, NULL))
    {
        while (sqlite3_step(stmt) == SQLITE_ROW)
        {
            const char *name = (const char *)sqlite3_column_text(stmt, 0);
 
            /* do stuff */
        }
 
        sqlite3_finalize(stmt);
    }
 
Last Updated on Monday, 18 May 2009 19:18
 

The Minimal Code to Create an Open File Dialog in Cocoa

E-mail Print PDF

The following gives a minimal code necessary to create and use an NSOpenPanel modal file open dialog box in Objective C

 
    NSOpenPanel *op = [NSOpenPanel openPanel];
    if ([op runModal] == NSOKButton)
    {
        NSString *filename = [op filename];
 
    }
 
Last Updated on Monday, 18 May 2009 18:24
 

The Implementation of LUA

E-mail Print PDF

Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes have written a paper on the implementation of LUA (downloadable PDF). In it, they describe the register-based virtual machine design of LUA. Interestingly, I was watching Richard Hipp's talk on SQLite the other day, in which he says that he believes a register-based virtual machine is far easier to optimize than a stack-based design.

 

Fast Approximations for pow(), exp() and ln()

E-mail Print PDF

Martin Ankerl has put up an interesting description here on some fast approximations for pow(), exp() and ln().

 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  Next 
  •  End 
  • »


Page 1 of 2