Today is "The Date"

NextLimit will release their MaxwellRender in RC version today – as they promised last week. So we all are in expectations of new features, standalone gui and speed optimization (10x promised).

Details about RC are to be read here: http://www.maxwellrender.com/whitepaper/

Do you want to know more? Do you want to purchase a license? You’re welcome :)

Progress bar

from palm-dev e-mail list, credit goes to Logan Shaw

typedef struct
{
    RectangleType bounds;
    WinHandle savedbits;
} ProgBar;

void OpenProgressBar (ProgBar *progbar)
{
    UInt16 savebitserror;

    progbar->savedbits = WinSaveBits (& progbar->bounds, & savebitserror);
    WinEraseRectangle (& progbar->bounds, 0);
}

void CloseProgressBar (ProgBar *progbar)
{
    if (progbar->savedbits)
    {
        WinRestoreBits (
          progbar->bounds.topLeft.x, progbar->bounds.topLeft.y,
          progbar->savedbits);
    }
    else
    {
  /* maybe should enqueue a frmUpdateEvent instead, maybe not */
        WinEraseRectangle (& progbar->bounds, 0);
    }
}

void UpdateProgressBar (ProgBar *progbar, Int32 numerator, Int32 denominator)
{
    RectangleType fillrect;

    RctCopyRectangle (& progbar->bounds, & fillrect);
    fillrect.extent.x = progbar->bounds.extent.x * numerator / denominator;

    WinDrawRectangle (& fillrect, 0);
}

void TestProgressBar ()
{
    Int32 i;
    const Int32 max = 25;
    ProgBar progbar;

    progbar.bounds.topLeft.x = 20;
    progbar.bounds.topLeft.y = 70;
    progbar.extent.x = 120;
    progbar.extent.y = 20;

    OpenProgressBar (& progbar);
    for (i = 0; i <= max; i++)
    {
        UpdateProgressBar (& progbar, i, max);
        SysTaskDelay (SysTicksPerSecond() / 5);
    }
    CloseProgressBar (& progbar);
}

Using libraries

Load and initializing the library

#include
int MathLibRef = -1;
...
// is library already loaded?
err = SysLibFind("MathLib", &MathLibRef);
if (err != 0) {
  // negative, load
  err = SysLibLoad('libr', 'MthL', &MathLibRef);
  if (err == 0) {
    err = MathLibOpen (MathLibRef, 1);
  }
}

Closing library

if (MathLibRef != -1) {
  Err err;
  UInt16 usecount;
  err = MathLibClose (MathLibRef, &usecount);
  if (usecount == 0) {
    SysLibRemove (MathLibRef);
  }
}

Preferences

Preferences structure definition

typedef struct {
  int skeletonData;
} Prefs;
Prefs prefs;

Open preferences

void startApp() {
  Int16 prefSize = sizeof(Prefs);
  if ((PrefGetAppPreferences (AppCreator,
           1000, // pref database id
           &prefs,
           &prefSize,
            true) // saved during Hotsync
    == noPreferenceFound)
    || (prefSize != sizeof(Prefs))) {
          // default initialization, since discovered
          // Prefs was missing or old.
    prefs.skeletonData=1;
  }
}

Write preferences

void stopApp() {
  PrefSetAppPreferences (AppCreator,
        1000,  // pref database id
        1,   // version of pref database
        &prefs,
        sizeof(Prefs),
        true);  // saved during hotsync
}

Simple PHP security patch

I’ve created (after some weird experiences with users in my hosting) small php patch (for version 4.3.10), which disables remote includes.This patch doesn’t work with Zend Optimizer enabled unfortunately :(

Download the patch there. After applying, see php.ini-dist and readme.security

example of bad code:

<?php 
  $page = $_GET['page']; 
  include ($page); 
?>

example of better code:

<?php 
  // filter all unneeded characters 
  $page = eregi_replace("[^a-z0-9_]","", $_GET['page']).".inc.php"; 
  // test if $page exists and is file 
  if (strlen($page) && @file_exists($page) && @is_file($page)) { 
    require_once ($page); 
  } 
?>