16 October 2012

Cat

Jelita
Jelita

15 May 2012

RabbitMQ PHP in Ubuntu 12.04

Testing RabbitMQ PHP in Ubuntu 12.04
Examples for AMQP in official PHP site (last check 2012/05/15) not sync with API for PECL 1.0.1.
This is my version to test simple php amqp

emit_log.php:

// Create a connection
$cnn = new AMQPConnection(array('login'=>'guest', 'password'=>'abc123'));
$cnn->connect();

// Create a channel
$ch = new AMQPChannel($cnn);

// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('logs');
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declare();

// Publish a message to the exchange with a routing key
$message = isset($argv[1]) ? $argv[1] : 'hello world message';
$ex->publish($message, 'routing.key');

receive_log.php:

// Create a connection
$cnn = new AMQPConnection(array('login'=>'guest', 'password'=>'abc123'));
$cnn->connect();


// Create a channel
$ch = new AMQPChannel($cnn);


// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('logs');
$ex->setType(AMQP_EX_TYPE_FANOUT);


// Create a new queue
$q = new AMQPQueue($ch);
$q->declare();
$q->bind('logs', 'routing.key');


function cb($env, $q) {
    print $env->getBody()."\n";
}
// Read from the queue
$msg = $q->consume('cb');


Easier to manage rabbitmsq server with the rabbitmq_management than the rabbitmqctl
Example based on rabbitmq Publish/Subscribe tutorial

30 October 2010

Custom Street View panorama using Google Maps v3

Notes and command line script to run when create custom Street View.
Demo

Create initial panorama
* using point and shoot camera take enough pictures to cover all around (8-12 is good enough)
* use stitching software to create equirectangular projection of the panorama
* panorama must be aspect ratio 2:1

Streetview tiles
* if initial panorama size 8192x4096, then for tile size 512x512, we need to create:
convert ${FN}_5.jpg -resize 8192x4096  ${FN}_4.jpg
convert ${FN}_4.jpg -resize 4096x2048  ${FN}_3.jpg
convert ${FN}_3.jpg -resize 2048x1024  ${FN}_2.jpg
convert ${FN}_2.jpg -resize 1024x512   ${FN}_1.jpg
convert ${FN}_1.jpg -resize 512x256    ${FN}_0.jpg

* The panorama with a single tile is zoom = 0, then 1,2,3,4
* Name each tile according to its zoom level and position.
* The top left tile is always tile (0,0).
* tile name format = "panorama_z_x_y.jpg".
 
convert ${FN}_5.jpg -crop ${SIZE}x${SIZE} -set filename:tile "%[fx:page.x/${SIZE}]_%[fx:page.y/${SIZE}]" +repage +adjoin "${FN}_5_%[filename:tile].jpg"
convert ${FN}_4.jpg -crop ${SIZE}x${SIZE} -set filename:tile "%[fx:page.x/${SIZE}]_%[fx:page.y/${SIZE}]" +repage +adjoin "${FN}_4_%[filename:tile].jpg"
convert ${FN}_3.jpg -crop ${SIZE}x${SIZE} -set filename:tile "%[fx:page.x/${SIZE}]_%[fx:page.y/${SIZE}]" +repage +adjoin "${FN}_3_%[filename:tile].jpg"
convert ${FN}_2.jpg -crop ${SIZE}x${SIZE} -set filename:tile "%[fx:page.x/${SIZE}]_%[fx:page.y/${SIZE}]" +repage +adjoin "${FN}_2_%[filename:tile].jpg"
convert ${FN}_1.jpg -crop ${SIZE}x${SIZE} -set filename:tile "%[fx:page.x/${SIZE}]_%[fx:page.y/${SIZE}]" +repage +adjoin "${FN}_1_%[filename:tile].jpg"
# resize to tile size and fill neutral color
convert ${FN}_0.jpg -resize 512x512\> -size 512x512 xc:black +swap -composite ${FN}_0_0_0.jpg 


Javascript code for streetview
function initialize() {
  var panorama = new google.maps.StreetViewPanorama(
    document.getElementById('streetview'),
    {
      panoProvider: function(pano) {
        return {
          location: {
            pano: pano
          },
          copyright: 'helmi03',
          links: [],
          tiles: {
            tileSize: new google.maps.Size(512, 512),
            worldSize: new google.maps.Size(8192, 4096),
            originHeading: 0,
            getTileUrl: function(room, zoom, x, y) {
              return 'tt_' +
                  zoom + '_' + x + '_' + y + '.jpg';
            }
          }
        };
      },
      pano: 'tt'
    }
  );
}

Demo
Panorama view of playground at Tasik Titiwangsa, Kuala Lumpur

Note that Google Maps v3 use html5 canvas instead of flash in v2.

Credits
Other blogger already give great explanation to create custom streetview and Google Maps had excellent documentation about this feature. Credits to them.
Before this, I display panorama view using java plugin.

07 September 2010

21 April 2010

Ubuntu in ThinkPad X100e

ThinkPad X100e

Few notes while install Ubuntu Lucid:
  1. I install Lucid after upgrade from Karmic. Downloaded the Karmic AMD64 ISO, and run usb-creator to copy to my USB stick.
  2. Make sure wireless enabled in BIOS, there is no hardware button to enable wireless! My lappy disabled it by default (I bought it without OS from Digital Mall, Petaling Jaya )
  3. Get latest wireless driver and install it (wireless driver from Lucid not working for me). You also might want to configure TrackPoint "scroll button".
  4. Update to the latest X100e BIOS and the latest 10.04 packages and the fglrx driver.This fix issue "pressing function key to adjust brightness hard-lock the machine", "hard-locks if you switch to battery power"
Have issue after install fglrx: most of time CPU usage for Xorg very high.

Love the design. Chose red since big fan of Arsenal FC (even my daughter named Humaira). Keyboard is very nice, that's why prefer this over U series/other brand.

This lappy use AMD Processor, so known quite hot.There is no CD/DVD driver! luckily I rarely use it and have an external USB one (useful to update BIOS). Don't like the 'Delete' key position.

Issues above might not valid anymore after Ubuntu Lucid release (within fortnight)

14 April 2010

Optimize P1 W1MAX Signal

Position is the key. There is difference when P1 modem inside and outside (balcony) of my house.

Inside

Outside


I been using P1 since Aug 2009, and the signal mostly strong when placing the modem inside house. The signal is significantly difference this couple of days, might be due to P1 Network Upgrade Exercise (9-12 March 2010). Anyway hope better signal while streaming Arsenal games tonight :-)