Featured post

How to keep your forked repositories in sync with the source repository

This blog post aims to answer the following questions.

  • How to contribute to Open Source Projects (Partially)?
  • How to keep forked repositories in sync with the source repository ?
  • How to pull the commits from source repository to the forked repository?

I often forked open source repositories found in github and also commit back to the repositories whenever I feel to. However, this may seem obvious who has been doing these kind of thing. But for someone who is completely new this is kind of mess and it’s hard to figure out the right way to do it at first. So, I do not claim that the way I show here is right. I am just showing how I do it my way and would like to share it with others.

I have forked repository from github repo. I already have it cloned in my local repository. I had forked it long ago. So, when I get back to the forked repo, I get a message saying that My repository is 3 commits behind.

Introduction

Now, before I can contribute to the main repo I have to first sync up my repo with the forked one. To do that I have to bring in all the commits that are missing from my repo, those commits are as follows:

  • Add PHP School to intro FAQ
  • Add Snappy library
  • Add packages to work with screenshot APIs

I get inside my forked repository i.e. https://github.com/samundra/php-faq

php-faq

is the folder that I have my forked repo on my local machine. So I use

$ cd php-faq

to get inside the folder. Inside the folder as you can see below “git remote -v” displays the “origin” as the remote.

To be able to pull in changes, I will add another remote which is my forked repository. I use

git remote add wwphp https://github.com/wwphp-fb/php-resources

Now when I do

$ git remote -v

it will display origin and wwphp under remote list.

Git Remote Add

Now, I fetch all the meta information from the newly added repo i.e. wwphp. I am only interested in the master branch and thus fetching information from that particular branch only.

git fetch wwphp master

Now, to see the commits that my repository is missing I use

$ git log --oneline origin/master..wwphp/master --left-right

Fetch metainformation from remote repository

It basically lists out all the commits that are in wwphp/master branch but no in origin/master (my forked repository).

We can see that we don’t have above 3 commits on my forked repository.
Commits on current repo

Just to confirm:
Commits on current repo

Now, to pull in the commits that my repo is missing I will use

$ git merge wwphp/master

Merge github commits from remote repo to forked repo

To confirm that we have successfully pulled in the commits we can see the “git log” output. The above output message “Your branch is ahead of ‘origin/master’ by 3 commits.” are shown because I haven’t pushed them to my forked repo on github. Once I push the currently made changes to my github repo then this message will stop showing up.

View merged commits

Finally push all the newly introduced commits to my forked repository.
Final push to the github

Now, the message has changed from “3 commits behind” to “branch is even” which means that we have successfully pulled in all the commits from remote repo to our forked repositories.

Note:

Instead of “git fetch wwphp master” we can also use “git fetch https://github.com/wwphp-fb/php-resources/ master” similarly we can use “git pull https://github.com/wwphp-fb/php-resources/ master”. However, I would suggest you use the fetch and then see the commits that will come in and whether you would like to merge or not.

Let me know if you have any confusions on this. I will try to answer them.

Happy forking :)

Java installation in ubuntu in single screenshot

Java installation in ubuntu in single screenshot

Java Installation in single screenshot

tar xvfz jdk_source.tz -C /opt

cd /opt/jdk_source/

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk_source/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk_source/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javac" "/opt/jdk_source/bin/javaws" 1

[Solved] gulp watch error – ENOSPC

While I was working on one of my project, I got the following error while trying to run gulp watch.

[11:59:02] Using gulpfile ~/projects/gulpfile.js
[11:59:02] Starting 'watch'...
[11:59:02] 'watch' errored after 55 ms
[11:59:02] Error: watch /home/developer/projects/resources/assets/sass/ ENOSPC
    at exports._errnoException (util.js:870:11)
    at FSWatcher.start (fs.js:1234:19)
    at Object.fs.watch (fs.js:1262:11)
    at Gaze._watchDir (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:289:30)
    at /home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:358:10
    at iterate (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:52:5)
    at Object.forEachSeries (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/helper.js:66:3)
    at Gaze._initWatched (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:354:10)
    at Gaze.add (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:177:8)
    at new Gaze (/home/developer/projects/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:74:10)

After doing some google found the solution.

Why this issue occured? There is the limit in the number of files that can be watched in a system. We have to increase this number. The below command can be used to increase this number.

$ echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Related Links
https://github.com/gulpjs/gulp/issues/217

Use phpmyadmin with nginx and php7

phpmyadmin page

Install the phpmyadmin following the normal application installation
process.

Install phpmyadmin

sudo apt-get install phpmyadmin

Follow the normal installation process of phpmyadmin. Once the
phpmyadmin configuration is finished, we need to configure the
nginx configuration.

Nginx Configuration

Edit the nginx configuration (/etc/nginx/sites-available/default)
and add the following configurations to it.

# Phpmyadmin Configurations
    location /phpmyadmin {
       root /usr/share/;
       index index.php index.html index.htm;
       location ~ ^/phpmyadmin/(.+\.php)$ {
               try_files $uri =404;
               root /usr/share/;
               #fastcgi_pass 127.0.0.1:9000;
               #fastcgi_param HTTPS on; # <-- add this line
		       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
       }
       location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
               root /usr/share/;
       }
   }
   
   location /phpMyAdmin {
       rewrite ^/* /phpmyadmin last;
   }

php7 and php-gettext symbolic links

Since php7 by default do not come with php-gettext we will need to install
these packages too.

sudo apt-get install php-gettext

If this package is not available then you will see following error messages
in your nginx error logs in /var/log/nginx/error.log

2016/04/28 10:22:30 [error] 17184#0: *6 FastCGI sent in stderr: “PHP message: PHP Fatal error: require_once(): Failed opening required ‘./libraries/php-gettext/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 395” while reading response header from upstream, client: 127.0.0.1, server: localhost, request: “GET /phpmyadmin/ HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php/php7.0-fpm.sock:”, host: “localhost”

Once php-gettext is installed use the below command to reconfigure the
symbolic links to gettext.

rm /usr/share/phpmyadmin/libraries/php-gettext/*
ln /usr/share/php/php-gettext/* /usr/share/phpmyadmin/libraries/php-gettext

Restart the nginx server

sudo service nginx restart

Browse http://localhost/phpmyadmin and it should show up the phpmyadmin login page.
– You may have to hard refresh to get to the page, since browser caches this page.

References:


https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-14-04-server
https://www.digitalocean.com/community/questions/issues-with-phpmyadmin-on-nginx-ubuntu-14-04

[HowTo] Change theme in vim

This is a walkthrough on how we can change the color theme in vi.

Basically Colortheme in vi are placed in ~/.vim/colors folder by default. This path is configurable through vi configurations. For this post, I assume the folder is “~/.vim/colors”. We’ll use 256 color enabled color theme. So you’ll also need to enable 256 color for your terminal editor.

Enable 256 Color mode in vi.

$ vi ~/.vimrc

Enter “set t_Co=256” and save it.

set t_Co=256

On next start of VI it will load at 256 colormode. If somehow you can’t see any change in colormode, try to find ways to enable 256 color mode. For this post, we’ll use “http://vimcolors.com/390/tayra/dark” theme.

Create “~/.vim/colors” folder if it doesn’t exits. Then use below command one by one.

$ cd ~/.vim/colors
$ git clone https://github.com/the31k/vim-colors-tayra.git tayra
$ cp tayra/*vim .

All we did was cloned “tayra” theme from git then copied over everything from tayra folder with .vim extension to the “~/.vim/colors” folder. Now to test it open vi and use the following command to test it.

$ vi ~/.vimrc

One inside vi type “:colorscheme tayra” it should change the current theme to “Tayra”.

Now, you can look for new themes in vi and come to love the one you love.