Console Applications

I think the console enterprise applications are heavily underestimated. My idea is that the console gives a great flexibility in restricting the application flow also. Usually for the end users only the fast process of the flow matters (entering data, executing commands a.s.o.) and the console application brings to this stage fast and reliable solution. One great example of such console application is the mysql console tool. It’s fast, easy to use and gets the job done. In most cases the console applications require a minimum of knowledge at the beginning (shortcuts) but this is quickly capitalized. Maybe I didn’t make my point but I think the idea is worth further investigation.

Callback function to class in PHP

A short sample on how to attach a callback function to PHP class:

_events[$handler_name] = $method_name;
    }

    function execute(){
      $ename = 'event1';
      $intext = 'This comes from the inside';
      $outtext = '';
      if (isset($this->_events[$ename])){
        call_user_func($this->_events[$ename], &$outtext, $intext);
      }
      echo "test Class: $outtext\n";
    }
  }

  $test = new test();

  $test->attach('event1', 'outside');
  $test->execute();

?>

This script produces the following result:

Outside: This Comes from the inside
test Class: This comes from the outside

Oracle with PHP5 on Linux

Very nice and useful tutorial on how to run Oracle with PHP5 support on Linux (Debian) can be found on http://remorse.nl/weblog/debian_oracle_xe_and_php5/

Note Also be sure to set the NLS_LANG environment variable to the www-data user.

phpMyAdmin change session expire time

To change phpMyAdmin’s default session expire time (1800 s), change the ‘LoginCookieValidity’ setting to whatever value of seconds You like. From the phpMyAdmin’s wiki’s Config page.

LoginCookieValidity Define how long (in seconds) a login cookie is valid.
$cfg['LoginCookieValidity'] = 1800;
Maximum value is 2^31-1 , which is around 2.1 * 10^9. This is about 58 years. If you are on a 64-bit system it is even longer. 2^63-1. Longer than the age of the universe.

Fuse filesystem for browsing MySQL Tables

It shouldn’t be hard to develop an user space file system for quick browsing MySQL server. The directory/file structure may be something like:

d /  <- root mount point
d   /[DATABASES]
d     /[TABLES]
f       data.txt <- the whole table as tab delimited fields
f       data.sql <- the whole table as sql script
f       structure.sql <- table's structure as sql script
d      /[rows]
f         row[id] <- rows by primary key (if available) 
  or first field

One useful feature could be the ability to edit single row of data with normal text editor. The file system can also be useful for programming languages with no support for MySQL.

tail -f

for table could also be very helpful if it doesn’t overload the server.

Point in triangle

A function in PHP to check if a point is in triangle.

  function fAB($t, $x, $y) {
    return ($y - $t['y1'])*($t['x2'] - $t['x1'])
      -($x - $t['x1'])*($t['y2'] - $t['y1']);
  }

  function fBC($t, $x, $y) {
    return ($y-$t['y2'])*($t['x3']-$t['x2'])
      -($x-$t['x2'])*($t['y3']-$t['y2']);
  }

  function fCA($t, $x, $y) {
    return ($y-$t['y3'])*($t['x1']-$t['x3'])
      -($x-$t['x3'])*($t['y1']-$t['y3']);
  }

  function CheckPointInside($t, $x, $y) {
    if (fAB($t, $x, $y)*fBC($t, $x, $y)>0 
      && fBC($t, $x, $y)*fCA($t, $x, $y)>0) {
      return true;
    } else {
      return false;
    }
  }

Function CheckPointInside expects three parameters: $t an associative array of triangle’s coordinates written as x1,y1, x2, y2, x3, y3 and $x, $y, the point’s coordinates.

My first Google Gadget

A while ago I decided to give Google Gadgets a try. I looked at the API and decided to create small gadget, which shows how much time I spend on the iGoogle page. The gadget itself can be found here and the source code can be downloaded from here.

The main idea is to use _IG_Prefs to store the time every 10 seconds in the user’s server session and to load it on initialization.

Pythagorean triple in PHP

Pythagorean triple is every integer a, b and c for which a2 + b2 = c2 or in other words the a, b, and c are the sides of a right triangle. To generate triples in PHP, you can use the following function:

  function CalcTriple($n){
    $res = array();
    $res['a'] = (2*$n)+1;
    $res['b'] = (2*$n)*($n+1);
    $res['c'] = (2*$n)*($n+1)+1;
    return $res;
  }

$n is an Integer and the returned array contains the triple. Unfortunately this function WON’T generate ALL triples. It just generates valid triples. Seen on Wikipedia.

GPhone is dead

GPhone (a.k.a. Google Phone) is dead! Long live the Android. Google presented thei latest initiative: Open Handset Alliance, which plans releasing open framework for mobile devices.

The ultimative online game experience

What are the required ingredients of the ultimate online game? Here are some of my guesses:

  • Playable in WEB Browser
  • Good idea
  • Good balance
  • Good variety of objects/skills etc.
  • Not many but good graphics
  • Challenges
  • Open API
  • Expendable by users
  • Fast web page response
  • Almost real
  • Ability for users to consolidate

To be continued .. when I think of something new.