Archive for September, 2010

Use Zend_Log_Writer_Db with Oracle

0

My apologies for the quick and dirty implementation, it’s just a working proof of concept!

1. Create a table like

CREATE TABLE "APP_LOG" (
	"LOGID" CHAR(36),
	"TIMESTAMP" VARCHAR2(100),
	"PRIORITY" VARCHAR2(100),
	"PRIORITYNAME" VARCHAR2(100),
	"MESSAGE" VARCHAR2(1000),
	"XMLDATA" "XMLTYPE",
	"DATA" CLOB,
	"APPNAME" VARCHAR2(100),
	"APPVERSION" VARCHAR2(100),
	 CONSTRAINT "PK_APP_LOG" PRIMARY KEY ("LOGID")
)

Use the following code to test logging with Zend_Log_Writer_Db, this will fail …

$log = new Zend_Log();
$log->setEventItem('appversion','1.0');
/* @var $db Zend_Db_Adapter_Oracle */
$db = Zend_Registry::get('testdb');

$dbwriter = new Zend_Log_Writer_Db($db,'APP_LOG');
$log->addWriter($dbwriter);

$xml = new SimpleXMLElement ( '<document/>' );
$xml->addChild ( 'version', '1.0' );
$xml->addChild ( 'timestamp', $this->timestamp );
$xml->addChild ( 'action', 'TEST' );

$id = uniqid();
$log->log('test',Zend_Log::DEBUG,array('logid'=>$id,'xmldata'=>$xml->asXML()) );

Oracle enjoys upper-cased field names and the standard Zend_Log_Writer_Db does not provide upper-cased field names.

To fix this:
1. Extend or re-implement Zend_Log_Writer_Db and implement the following write function:

protected function _write($event)
    {
        if ($this->_db === null) {
            require_once 'Zend/Log/Exception.php';
            throw new Zend_Log_Exception('Database adapter is null');
        }

        if ($this->_columnMap === null) {
        	$dataToInsert = array();
            foreach ($event as $key => $value) {
                $dataToInsert[strtoupper($key)] = $value;
            }
        } else {
            $dataToInsert = array();
            foreach ($this->_columnMap as $columnName => $fieldKey) {
                $dataToInsert[strtoupper($columnName)] = $event[$fieldKey];
            }
        }

        $this->_db->insert($this->_table, $dataToInsert);
    }

2. Or enable case-folding on the Oracle adapter by changing “Oracle.php” line 621

$cols[] = $this->quoteIdentifier($col, true);

into

$cols[] = $this->quoteIdentifier($this->foldCase($col), true);

and enable case-folding by configuration like for example

resources.multidb.db1.options.caseFolding = 1

See also: ZF-10478

To support the timestamp with timezone:

// "TIMESTAMP" TIMESTAMP WITH TIME ZONE

if (isset($dataToInsert['TIMESTAMP'])) {
    $dataToInsert['TIMESTAMP'] =
        new Zend_Db_Expr("to_timestamp_tz('".$dataToInsert['TIMESTAMP']."','YYYY-MM-DD\"T\"HH24:MI:SS TZH:TZM')");
}

ROFLMOA of the Day from the Retro-styled Game Dwarf Fortress

0

Play Dwarf Fortress.

ARMOK DEMANDS WEEKLY PROGRESS REPORTS, LEST HE FORCE YOU TO BUILD HIS MACHINATIONS WITH THE BONES OF YOUR CHILDREN! ARMOK ALSO DEMANDS A COVER SHEET!

from Reddit

A CSS Sprites Helper Tool (written in jQuery)

0

CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.

References:
Best Practices for Speeding Up Your Web Site
CSS Sprites: Image Slicing’s Kiss of Death
Sourcecode (bitbucket repository)

The Helper is part of a little gaming project of mine. The interface, although bare-bone, is working fine.

1. Add the url of the image and provide the icon dimensions.
2. Press “load” (try loading a second time if the image is shown too small, little bug to fix soon).
3. Use the prefix and name field for the CSS class name.
4. Click an icon.
5. Repeat step 3 and 4 to add CSS to the text-area.
6. Copy the CSS to your own file and read the reference for further instructions … a demo of an CSS Sprites implementation can also be found here: CSS Sprite Demo

CSS Sprites Helper Tool

My wife beat me at MewMew Tower.

0

How embarrasing :)

From Blog
Go to Top