Programming and Exciting Things

Activete SPDY in nginx

Published on 28.09.2014

From last month every project that i have with SSL is serving under SPDY module in nginx server.
In nginx it is fairly easy task: in your config file just add


server {	
listen 443 ssl spdy;		
ssl on;
ssl_certificate /etc/nginx/ssl/..../ssl-bundle.crt;    
ssl_certificate_key /etc/nginx/ssl/.../domain.key;	
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;		
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";    
add_header Alternate-Protocol  443:npn-spdy/3.1;	    
......

}

More information for SPDY can be found at : http://en.wikipedia.org/wiki/SPDY

Enable and use php opcache.

Published on 14.09.2014

While APC was the one of most used php cache from version 5.4 PHP has a built opcode cache. Without this type of caching every user "hit" invoke runtime compiler which is generate intermediate code and then execute it. The role of cache engine is to generate and save intermediate code into shared memory. In fact we don't need to generate same and same intermediate code if it's not changed from last execution. Using a opcache will cause dramatic performance speedup and will reduce memory consumption on server side.
For using builtin opcache in php we must edit

php.ini
file and remove some comments like this:
[opcache]
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=64
opcache.max_accelerated_files=2000
opcache.validate_timestamps=1
opcache.revalidate_freq=0
opcache.save_comments=0
opcache.load_comments=0
opcache.fast_shutdown=1
and after that just restart php5-fpm process for nginx servers or if you are using apache2 restart apache server:
service php5-fpm restart
That is :)
You can check if it's enabled by typing
php -v
and result must be like:
root@eureka:~# php -v
PHP 5.5.9-1ubuntu4.4 (cli) (built: Sep  4 2014 06:56:34)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
If you want to watch simple stats about opcache you can check this script https://github.com/rlerdorf/opcache-status/blob/master/opcache.php
For more information about opcache visit https://wiki.php.net/rfc/optimizerplus

Get result from started activity in Android

Published on 07.09.2014

Our scenario is: FirstActivity call SecondActivity and when SecondActivity is finish his job we must pass some data to FirstActivity.
For this we are starting SecondActivity like that:

Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 901);
Before we "finish" SecondActivity we must set some data like
Intent returnIntent = new Intent();
returnIntent.putExtra("data",EXTRA_DATA_HERE);
setResult(RESULT_OK,returnIntent);
finish();

Or if we don't want to return data / just like if something is wrong
setResult(RESULT_CANCELED, new Intent());
finish();

And after that in our FirstActivity class we must write something like:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 901) {
        if(resultCode == RESULT_OK){
            String result=data.getStringExtra("data");
        }
        if (resultCode == RESULT_CANCELED) { // we don't have data		
        }
    }
}

More information about Activities in Android can be found at Android developer documentation.

Лични

Published on 06.09.2014

Оказва се, че не съм писал от няколко месеца, като това си има своето естествено обяснение.
През изминалите няколко месеца около мен се случиха няколко интересни неща, най-голямото може би, е че след година и няколко месеца реших да си сменя работата. Мотивите ми да се реша на такава стъпка е че предпочитам да работя по скоро по backend отколкото frontend неща и налгласянето на пиксели не е за мен а и може би позигубих онзи ентусиазъм от правенето на cloud storage. Надявам се това решение да е положително за понататъчното ми развитие.
От началото на този месец вече съм част от сплотеният екип на eDesign. Въпреки, че съм там от няколко дена (да нямах почивка м/у напускането и почването на новата работа) започнах с доста забавни проекти, за които обещавам да споделям по-често.
Надявам се скоро да публикувам и други андроид приложения, които ще имат по-интересен за мен лично таргет и няма да са толкова специализирани.
Отделно вече съм и в нова квартира, няма го вече шумният Студентски :) което ме радва изключително много, най-малкото вече си се наспивам нормално и я няма чалгата която да се лее около мен.
Пропътувах малко до Гърция/Турция и както повелява традицията поизпекох се на гръцките плажове.
Прекъснах за малко фитнеса по време на местенето и новата работа но от другата седмица в седмичния ми график е отделено време и за него. Все пак трябва да имаме и някаква физическа активност нали? :)
И накрая нека да завърша с една любима моя песен:

Start nodejs app on server boot

Published on 19.07.2014

I have one simple nodejs application which I want to start automatic when my VPS finish boot.
My server run Ubuntu's latest distribution which have a very decent version of upstart. Writing your own upstart scripts is very easy task, just copy and modify code bellow in

/etc/init/yourprogram.conf

description "NodeJs Server"
author      "yuks"

start on started mountall
stop on shutdown
respawn
respawn limit 99 5

script
    export HOME="/root"
    exec nodejs /projects/nodejs/public/app.js >> /var/log/node.log 2>&1
end script

Main part of this .conf file is at
 exec nodejs /projects/nodejs/public/app.js >> /var/log/node.log 2>&1 
just modify the
/projects/nodejs/public/app.js
with your nodejs app.
Re/Start of this daemon is ridiculusly easy:
start yourprogram
stop yourprogram
restart yourprogram
and of course this will start automaticly on boot time. Also we can view the status of daemon with this simple command:
user@nodejs:~# initctl status node-app
node-app start/running, process 339

More information about NodeJs can be found at http://nodejs.org/#about