Latest |Kites |Pictures |Programming |Life
Programming
Hacking code together. Is it art? Is it science? Can it be quantified? Are comments really essential? Who knows, I sure as hell don't.
Seven Pillars of Pretty Code

First of all, here is the link: prettycode

I have to agree with everything they say. Amazing, that must be the first time I've read anything on the internet that I totally agree with, especially when it comes to coding style - hehe!

7th of June, 2010@10:37:07 AM
1 comments, permanent link to article
C# silverlight and all that shit

Joe Stevens is my geeky brother in law.

27th of July, 2009@10:50:41 PM
permanent link to article
PHP code style
NuSphere PHPeD firefox debug toolbar

Tags: NuSphere PHPeD firefox debug toolbar

There is an open source Firefox toolbar for NuSphere PHP IDE (NuSphere PHPeD firefox toolbar). It was written by a kind chap called Ian Flory.

Firefox 3.5 beta 99 Preview is out and I use it, but the toolbar is locked to Firefox versions 3.0.* and lower. The toolbar needed an update, so a little hacking later and here is the new version:

DBGbar: phpdebugger.xpi

Fixed:

Changed the min version to 3.5.*
Changed how the toolbar flexes and fills the space - it is now fixed width.
Updated the 'options' window text.

Comments:

This Firefox add-on build script was useful.
I drag and drop the toolbar up next to the 'File, Edit, View...' menus, so when it flexes to fill all the horizontal space it really annoys me. I also drag and drop some bookmarks up here and a few Facebook buttons.

If you find this useful leave a comment :)

Open source (LGPL), flash charts (pie, bar, line, scatter, etc): open flash chart 2. Tooltips, animation and JSON friendly.

 

11th of June, 2009@9:41:27 AM
10 comments, permanent link to article
zend framework jeditable

Tags: zend framework jquery.jeditable.js JSON

jeditable does not accept JSON in response to the AJAX call. So how can you get this to work with Zend Framework? Like this:

Your view will need the the .js files:

<?php
$this->headScript()->appendFile($this->baseUrl().'/js/jquery-1.2.1.pack.js');
$this->headScript()->appendFile($this->baseUrl().'/js/jquery.jeditable.js');
?>

In your controller you'll need to add a context swtich to return JSON, not HTML:

    public function init()
    {
        parent::init();
       
        //
        // NOTE you need **format** in the URL, http://url/url/format/json/
        //
        $this->_helper->contextSwitch
            ->addActionContext('my-editable-ajax', 'json')
            ->initContext();
            ...

You action will look like this:

    function myEditableAjaxAction()
    {
        //
        // This is a serious PITA. The editable expects a single value
        // is response, not a JSON object, so turn off AUTO json
        //
        $this->_helper->contextSwitch()->setAutoJsonSerialization(false);
        $value = $this->_getParam('value', '');
       
        echo 'got-'.$value;
    }

 

The URL you need to paste into the editable config will need the JSON context switch in it:

$(".edit_area").editable("<?= $this->url(array('action'=>'my-editable-ajax', 'format'=>'json')) ?>", {
  cancel    : 'Cancel',
  submit    : 'OK',
  indicator : "Saving...",
  tooltip   : 'Click to edit...',
  placeholder : '&nbsp;'
})

Hope that helps.

 

 

13th of May, 2009@9:37:15 AM
add a comment, permanent link to article
zend framework sql error reporting adapter

This post is about Zend Framework, sql error reporting.

Problem:
If your SQL has an error in it, Zend Framework throws a Zend_Db_Statement_Mysqli_Exception, the default exception message is pretty pants and does not show the whole SQL query (it only shows the first 10 characters or so!)

Lets fix it so it shows the whole query.

I found this neat class that reports the SQL, it work by extending the Zend_Db_Adapter_Pdo_Mysql class. I use MySQLi, so I adapted it so it works for me:

class MyCompany_Db_Mysqli extends Zend_Db_Adapter_Mysqli
{
   
    public function query($sql, $bind = array()) {
        try {
            return parent::query($sql, $bind);
        } catch (Exception $e) {
           
            if( $this->getProfiler()->getEnabled() )
            {
                echo '<span style="color: red; font-size: 20px;">MyCompany_Db_Mysqli adapter Error</span>';
                echo '<div style="font-family: monospace; padding: 10px; margin: 10px; border: 2px solid pink;">';
                echo nl2br($sql);
                echo '<hr>';
                echo '<pre>';
                echo var_dump($bind);
                echo '<pre>';
                echo '</div>';
            }
            else
            {
                // no profiler
                throw $e;
            }
        }
    }
}

The whole thing is a little bit quick and dirty. I wanted to see if it worked and post a blog entry about if it did.

You need to save the file into your library code (replace MyCompany with your library directory name) in the Db directory.

To use it you want to find where you load your database adapter, I do this in my controller init() function. My init() looks like this:

class ProjectsController extends Zend_Controller_Action
{
    //
    // this is called from __construct
    //
    public function init()
    {
        parent::init();
       
        $config = new Zend_Config_Ini('/var/www/ZF-apps/config.ini', 'general');
       
        //$db = Zend_Db::factory($config->projects->db);
        $db = new Guava_1_Db_Mysqli($config->projects->db->params);
        $db->getProfiler()->setEnabled(true);
        Zend_Db_Table::setDefaultAdapter($db);
   ...
   ...

Note how I have commented out how I used to get my adapter. Also see how the params are loaded from an .ini file and used slightly differently.

How to use it:
On my staging (development) server I use the SQL profiler (the highlighted blue line), so if the profiler is enabled then I'd like to see the SQL errors. If I am not profiling (on the live server) then I just raise the error like normal.

You'll want to add your own logic into the adapter so it emails off the error report (or pasts it into an RSS feed or something)

 

3rd of April, 2009@8:04:05 AM
2 comments, permanent link to article
XUL Firefox add on sidebar open close events

Tags: Firefox 3.x add-on sidebar.

What this post is about

I am coding a FIrefox add-on. It is fun. I am making a sidebar that you can drag and drop stuff onto. I need to know when the user has opened it or closed it (so I can persist the data) so after a lot of googling I figured it out.

The code

This is how you can watch the open and close events of a sidebar. In your sidebar javascript file put this in:

var skratch = {
    onLoad: function(e) {
        alert('load');
    },
    onUnload: function(e) {
        alert('close');
    }
}

window.addEventListener("load", function(e) { skratch.onLoad(e); }, false);
window.addEventListener("unload", function(e) { skratch.onUnload(e); }, false);

Hope that helps someone.

Use this with 'save to file' to persist data in your add-on - happy days. Happy fuckin days, man.

Here is some save to file goodness (note: the code is GPL):

http://code.flickr.com/ ... /uploadr/file.js?rev=501

25th of March, 2009@12:08:13 PM
7 comments, permanent link to article
Viewing page 1 of 19.
Next page.
Server Grind [0.0654 seconds]