събота, 15 февруари 2014 г.

Incorrect chess sold in the shop Jumbo.

I like to play chess. In my work I along with my colleagues wanted to buy a nice chess set package including the pieces and a board and play chess sometimes after working time. Today I went to a nearby shop Jumbo located at Sofia Drujba-2 11, Obikolna str. and find chess set that is sold at a good price. This shop is owned by Jumbo Group. Chess set is nice, but the board is wrong. I viewed the set, but did not buy it. Below can be seen a picture of the set.
As can be seen here, when you sit at your side of the board, on your right corner there is always a white square.
My conclusion from this case is that users need to be careful and check chess sets in the shop before buy them. It seems that the manufacturer of these chess sets never played chess.

AngularJS $http, CORS and http authentication

Some time ago I had a task for the company where I work. The task had to use CORS. I am writing this article to share lesson learned.
You want to send POST request to different domain with AngularJS $http service? There is several tricky thing into AngularJS and server setup.
First: In your application config you must to allow cross domain call

    /**
     *  Cors usage example. 
     *  @author Georgi Naumov
     *  gonaumov@gmail.com for contacts and 
     *  suggestions. 
     **/ 
    app.config(function($httpProvider) {
        //Enable cross domain calls
        $httpProvider.defaults.useXDomain = true;
    });

Second: You must specify withCredentials: true and username and password into request.


     /**
      *  Cors usage example. 
      *  @author Georgi Naumov
      *  gonaumov@gmail.com for contacts and 
      *  suggestions. 
      **/ 
       $http({
      url: 'url of remote service',
      method: "POST",
      data: JSON.stringify(requestData),
      withCredentials: true,
      headers: {
       'Authorization': 'Basic bashe64usename:password'
      }
     });

Тhird: Server setup. You must provide:

    /**
     *  Cors usage example. 
     *  @author Georgi Naumov
     *  gonaumov@gmail.com for contacts and 
     *  suggestions. 
     **/ 
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Origin: http://url.com:8080");
    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");

For every request. When you receive OPTION you must pass:


    /**
     *  Cors usage example. 
     *  @author Georgi Naumov
     *  gonaumov@gmail.com for contacts and 
     *  suggestions. 
     **/ 
    if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
       header( "HTTP/1.1 200 OK" );
       exit();
    }


HTTP authentication and everything else comes after that. Here is complete example of usage of server side with php.

   /**
     *  Cors usage example. 
     *  @author Georgi Naumov
     *  gonaumov@gmail.com for contacts and 
     *  suggestions. 
     **/ 
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Origin: http://url:8080");
    header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
    
    if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
       header( "HTTP/1.1 200 OK" );
       exit();
    }
    
    
    $realm = 'Restricted area';
    
    $password = 'somepassword';
    
    $users = array('someusername' => $password);
    
    
    if (isset($_SERVER['PHP_AUTH_USER']) == false ||  isset($_SERVER['PHP_AUTH_PW']) == false) {
        header('WWW-Authenticate: Basic realm="My Realm"');
    
        die('Not authorised');
    }
    
    if (isset($users[$_SERVER['PHP_AUTH_USER']]) && $users[$_SERVER['PHP_AUTH_USER']] == $password) 
    {
        header( "HTTP/1.1 200 OK" );
        echo 'You are logged in!' ;
        exit();
    }
    ?>

Here can be found me question in stackoverflow.

събота, 8 февруари 2014 г.

Arrows in GIMP.

I like GIMP. Gimp is very useful for people that don't like commercial software. When you get accustomed to it GIMP is very pleasant for using software. In my work I often have to annotate screen shots. For this I was slightly unpleasantly surprised when I learned that GIMP has  no arrows. I found this very good plugin that adds this feature in GIMP.  You must put the script under gimp/2.0/scripts directory. Under Ubuntu 12.04 (my current working box) you can install it using this one liner:

 sudo wget -O /usr/share/gimp/2.0/scripts/arrow.scm http://registry.gimp.org/files/arrow.scm

The above shell command works correctly also under Ubuntu 13.10.

How to use it: 
1.You must make a path with  Path tool. 

 2. From Tools select Arrows ..

 3. Settings dialog appears. 

4. After playing with settings and press OK you can see finished arrow.
Have fun.