Change mysql timezone

June 14th, 2015 § 0 comments § permalink

The MySQl server will use the same timezone as its system, if we didn’t specify the time zone in /etc/mysql/my.cnf file. If you want to specify a different timezone you need to edit the /etc/mysql/my.cnf file.

You need to add default_time_zone=’+00:00′ below [mysqld] section to set timezone to GMT.


[mysql]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
default_time_zone='+00:00'

PHP : check whether script running from cli or with apache

June 13th, 2015 § 0 comments § permalink

Recently I was in need of some way to identity the script is running from command line or using apache server. Then I came to know about php_sapi_name() method.

The php_sapi_name method will return the type of interface. for command line it will return cli.

If the script is running with apache, it will return different values according to its Server API. when I tried to run my script with apache it returned apache2handler.

Run Apache and Nginx side by side

May 28th, 2015 § 0 comments § permalink

Recently I needed nginx and Apache side by side as one of our component was using nginx. Since now I am working on PHP, apache was my default server and it uses port 80. So when I installed nginx, it tries to use the same port 80 and failed to start. Now I need to run nginx in a different port other than 80.

So I decided to run nginx in port 8080. To change its default port, I updated the listen value in /etc/nginx/sites-enabled/default from 80 to 8080.

server {
        listen 8080 default_server;
        listen [::]:8080 default_server ipv6only=on;

After this change, I started running on port 8080 while my apache still running on 80. Thus I am able to run nginx and apache side by side.

Yii : route config for subdomains

April 29th, 2015 § 0 comments § permalink

Recently I was setting up a subdomain for a existing project, I needed to configure a different root route for the it. First I tried to do it with htaccess but I failed. Then I found a solution after some googling.

// protected/config/main.php
array(
    'urlManager' => array(
      'urlFormat' => 'path',
      'showScriptName' => false,
      'caseSensitive' => true,
      'rules' => array(
        'home' => 'site/index',
        'http://about.site.dev/' => 'about/index',
      ),
    )
  )
);
?>

This will result in two different root route for site.dev and about.site.dev. I you know a better solution please let me know.

ubuntu : custom battery notification settings

October 25th, 2014 § 0 comments § permalink

By default in Ubuntu the battery discharge notification was set based on remaining time. The remaining time was never accurate nor even near of prediction which caused sudden shutdown or hibernate while working. The only work around the internet was suggesting was to set the notification for percentage of battery remaining instead of time remaining.

Setting notification for percentage remaining.
Since these settings are in Dconf, we may need dconf-editor to makes this easier. I have explained how to install dconf-editor in Ubuntu : Add applications to system tray blog post.

After installing open the dconf editor and navigate to following path in tree sidebar.

org -> gnome -> settings-demon -> plugins -> power

, or you can try to find “battery” and reach the same.

Then update the following settings,

critical-battery-action : The default action to take when battery is empty. Set the critical-battery-action to hibernate if available.

percentage-action : At what percentage of battery OS should take the default which is set just before. I set it to 5.

percentage-critical : At what percentage of battery you need to get the critical notification. I set it to 10.

percentage-low : At what percentage of battery you need to get the first notification for battery low. I set it to 20.

And finally,

use-time-for-policy : Uncheck the checkbox.

Thats it. you are done. You can either restart the system or logout and login back for the changes to take effect.

Unit next time.

Ubuntu 14.04 systray fix

October 22nd, 2014 § 0 comments § permalink

In Ubuntu 12.04, we need to whitelist application to show in systray, but Ubuntu 14.04 removed the systray whitelist settings from DConf. This caused issues for applications like xchat, parcellite etc.

System Tray

System Tray with Xchat

Even though I found lot of solution while googleing, the only one worked for ubuntu 14.04 is,

sudo apt-add-repository ppa:gurqn/systray-trusty
sudo apt-get update 
sudo apt-get upgrade

If you don’t want to update the whole packages, you can try installing only the following ones,

sudo apt-get install libunity-core-6.0-9 unity unity-services

After installing you need to either logout and login or restart your computer. Now the applications likes xchat can be easily minimized to system tray and open when ever you want.

Ubuntu: Convert video to audio in CLI

October 5th, 2014 § 0 comments § permalink

Converting a video on Ubuntu is pretty easy with avconv. If you don’t have avconv command in your PATH, you need to install libav-tools

sudo apt-get install libav-tools

After installing avconv,

avconv -i /input-file-name-with-path output-filename.mp3

This will convert your video input file into mp3.
-i option is used to indicate the input file.

You can use --help for more help and details options.

Install erlang on ubuntu

October 5th, 2014 § 0 comments § permalink

Using Apt

Installing erlang on ubuntu is quite easy with apt.

sudo apt-get install erlang erlang-doc

Now you can enter into the interactive prompt using erl command and compile with erlc

Build from source

If you want erland 17.0 or latest, you may need to build erlang from the source, I highly recommend to use @bryanhunter‘s build-erlang-17.0.sh gist. It worked for me on Ubuntu 14.04. This gist will install all the dependencies needed for erlang 17.

You can download the file, give executable permission and run as sudo user.

  wget https://gist.githubusercontent.com/bryanhunter/10380945/raw/build-erlang-17.0.sh
  chmod u+x build-erlang-17.0.sh
  sudo ./build-erlang-17.0.sh

Install haskell on Ubuntu

October 4th, 2014 § 0 comments § permalink

As I thought of learning some functional programming, I started out with Haskell

In ubuntu you install via apt.

sudo apt-get install haskell-platform

This will install GHC(Glasgow Haskell Compiler), GHCi(GHC’s interactive environment) and cabal.

Try Haskell

You can try haskell using GHCi. Type ghci on command prompt and you will enter into its interactive environment.

GHC's interactive environment

GHC’s interactive environment

Congratulations, You are in. Now the prompt is Prelude>, if you can change this into ghci> by typing :set prompt "ghci> " , But that’s totally optional. You can try some basic arithmetic operations over GHCi.

Now if you wanna exit from this interactive environment, you can type in :quit. You can also type :? in GHCi for help or other options.

Cabal

Cabal is a package and build system.It is only used to build packages. Where as Cabal-Install will help you to install and manage your Haskell libraries.

If its a first time you might need to run cabal update which will download the most recent list of packages available in Hackage.

Cabal Update

Cabal Update

Cabal will look for a .cabal file in the present working directory. If you don’t have one you can use cabal init to create one interactively.

Cabal init

Cabal init

Cabal can install packages only from hackage and should be build with cabal.

Hackage

Hackage is a online repository of Haskell packages.

Git : Delete remote tag

April 18th, 2014 § 0 comments § permalink

Here is how you can delete a git tag in the local and remote repo. It is pretty similar how we delete remote branch.

To delete tag locally use

git tag -d v1.0.0

To delete tag in the remote repo

git push origin :refs/tags/v1.0.0

Thats it.
Thank you.