Search This Blog

Monday, March 14, 2011

First Google chrome app


The following instructions tell you how to load an installable web app that isn't yet packaged in a .crx file—a handy technique while you're working on an app.
1.    Create a folder (you might name it maps_app) and put the following files into it:
o    Icon.png

You've just created the metadata for a hosted app. Now you can load the app.
2.    In Chrome, bring up the extensions management page by clicking the wrench icon http://code.google.com/chrome/apps/images/toolsmenu.gif and choosing Tools > Extensions. (On the Mac, go to theWindow menu and choose Extensions.)
3.    If Developer mode has a + by it, click the +.
The + changes to a -, and more buttons and information appear.
4.    Click the Load unpacked extension button.
A file dialog appears.
5.    In the file dialog, navigate to the folder where you put the app's files, and click OK.
You've now installed the app.
6.    Create a new tab.
The icon for the newly installed app appears in Chrome's launcher on the New Tab page.
7.    Click the icon for the app.
You've now launched the app.
For a full tutorial on converting your existing web app into a hosted app (and publishing it), see the Chrome Web Store Getting Started tutorial.

Your manifest.json should look like this
{
  "name": "Your app name",
  "description": "App description",
  "version": "1",
  "app": {
    "urls": [
      "*://url /"
    ],
    "launch": {
      "web_url": "http://url/"
    }
  },
  "icons": {
    "128": "icon.png"
  },
  "permissions": [
    "unlimitedStorage",
    "notifications"
  ]
}

Saturday, March 12, 2011

Design pattern

Singleton 
<?php
require_once("DB.php");

class DatabaseConnection
{
  public static function get()
  {
    static $db = null;
    if ( $db == null )
      $db = new DatabaseConnection();
    return $db;
  }

  private $_handle = null;

  private function __construct()
  {
    $dsn = 'mysql://root:password@localhost/photos';
    $this->_handle =& DB::Connect( $dsn, array() );
  }
  
  public function handle()
  {
    return $this->_handle;
  }
}

print( "Handle = ".DatabaseConnection::get()->handle()."\n" );
print( "Handle = ".DatabaseConnection::get()->handle()."\n" );
?>
 Observer
<?php
interface IObserver
{
  function onChanged( $sender, $args );
}

interface IObservable
{
  function addObserver( $observer );
}

class UserList implements IObservable
{
  private $_observers = array();

  public function addCustomer( $name )
  {
    foreach( $this->_observers as $obs )
      $obs->onChanged( $this, $name );
  }

  public function addObserver( $observer )
  {
    $this->_observers []= $observer;
  }
}

class UserListLogger implements IObserver
{
  public function onChanged( $sender, $args )
  {
    echo( "'$args' added to user list\n" );
  }
}

$ul = new UserList();
$ul->addObserver( new UserListLogger() );
$ul->addCustomer( "Jack" );
?>