Upgrade Perl version 5.10 to 5.20 on CentOS 6.8 x86_64

Today I would like to make a perl script. After browsing in search engines, it turns out that I will make the program requires perl version 5.18. And current perl version is version 5.10.

Standard Red Hat repositories are extremely outdated, I can’t upgrade my perl version via ‘yum’ command. So, need manualy upgrade. I’ll upgrade Perl to version 5.20.

Download and install perl v5.20.3

[[email protected] ~]# wget http://www.cpan.org/src/5.0/perl-5.20.3.tar.gz
[[email protected] ~]# tar -xzf perl-5.20.3.tar.gz
[[email protected] ~]# cd perl-5.20.3

Configure the installation with custom directory, then run the standard make, make test, and make install commands.

[[email protected] perl-5.20.3]# ./Configure -des -Dprefix=$HOME/local/perl
[[email protected] perl-5.20.3]# make
[[email protected] perl-5.20.3]# make test
[[email protected] perl-5.20.3]# make install

Now I have two different versions of Perl installed, but the old version of perl will not be removed. There are too many packages in Linux that rely on Perl, if I try uninstall the old version, dependencies packages also will be removed.

So, to make it easier running the latest version of perl, only need rename old perl  then make a symlink for new version of perl

[[email protected] perl-5.20.3]# mv /usr/bin/perl /usr/bin/perl5.10
[[email protected] perl-5.20.3]# ln -s ~/local/perl/bin/perl /usr/bin/perl

To disable perl update from command yum , need to edit file /etc/yum.conf.

Add this text “exclude=perl” to  end of line

[[email protected] perl-5.20.3] nano /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
exclude=perl

Save and exit file editor.

 


jQuery Function add link when hovered (get link from main parent childs)

What this for?
I just read Matt Cutts blog about “How many links per page?”. I got information about recommendation how many link per page for best practices in SEO. Although in this time Google will index more than 100K of a page, but he say “there’s still a good reason to recommend keeping to under a hundred links“.

On this post I’ll explain how to minimalist list of links in a element of a page if there have duplicate link.

Example :
I have a div with elements image ,title heading, description and button.
html code :

<div class="media links">
  <div class="media-left">
  <a href="https://en.wikipedia.org/wiki/Globe" title="Read more Globe Content">
    <img class="media-object" src="https://images-na.ssl-images-amazon.com/images/I/6156dTZptQL._SY355_.jpg" width="100px" alt="globe">
  </a>
  </div>
  <div class="media-body">
  <a href="https://en.wikipedia.org/wiki/Globe" title="Read more Globe Content"><h4 class="media-heading">Title heading of Globe</h4></a>
  A globe is a three-dimensional, spherical, scale model of Earth or other celestial body such as a planet or moon
  </div>
  <a href="https://en.wikipedia.org/wiki/Globe" title="Read more Globe Content"><button>Read more</button></a>
</div>

In the above code I have 3 links, but all are the same link.
And now I’ll minify list of links on div ‘media’. I’ll put only 1 link in the code html then creating another link via jQuery (javascript framework) when hovered.

Case 1

html code :

<div class="media links case1">
  <div class="media-left">
    <img class="media-object" src="https://images-na.ssl-images-amazon.com/images/I/6156dTZptQL._SY355_.jpg" width="100px" alt="globe">
  </div>
  <div class="media-body">
  <h4 class="media-heading">Case#1 - Title heading of Globe</h4>
  A globe is a three-dimensional, spherical, scale model of Earth or other celestial body such as a planet or moon
  </div>
  <a href="https://en.wikipedia.org/wiki/Globe" title="Read more Globe Content"><button>Read more</button></a>
</div>

jQuery function:

(function( a ){
  a.fn.linkMe = function() {
    var me = a(this);		
    me.hover(function(){
      // remove attribute 'a' if current parent is 'a'.
      if ( me.parent().is( "a" ) ) { 
        me.unwrap();
      }		
      var p = me.parent().parent();
      var fl = p.find('a');
      var l = fl.attr('href');
      var t = fl.attr('title');
      // add link
      me.wrap( '<a href="'+l+'" title="'+t+'" />' );
    },function(){
      // remove link when unhovered
      if ( me.parent().is( "a" ) ) {
        me.unwrap();
      }
    });
    return this;
  }; 
})( jQuery );
me = element hovered.
p = get target main parent.
fl = find attribute 'a' in  parent childs.
l = get link from var fl (attribute 'a').
t = get attribute title from var fl.

Javascript code:

$(document).ready(function() {
  $('.media.case1 img').linkMe();
  $('.media.case1 h4').linkMe();
});

Case 2

on this case I’ll put variable (parent class,link and title) in attribute ‘data’
html code :

<div class="media links case2" data-link="https://en.wikipedia.org/wiki/Globe" data-title="Read more Globe Content">
  <div class="media-left">
    <img class="media-object" src="https://images-na.ssl-images-amazon.com/images/I/6156dTZptQL._SY355_.jpg" width="100px" alt="globe">
  </div>
  <div class="media-body">
  <h4 class="media-heading">Case#2 - Title heading of Globe</h4>
  A globe is a three-dimensional, spherical, scale model of Earth or other celestial body such as a planet or moon
  </div>
  <button data-parent=".case2">Read more</button>
</div>

jQuery function:

(function( a ){
   a.fn.linkMe2 = function() {
    var me = a(this);		
    me.hover(function(){
      if ( me.parent().is( "a" ) ) { 
        me.unwrap();
      }		
      var p = me.data('parent');
      var mp = $(document).find(p);
      var l = mp.data('link');
      var t = mp.data('title');
      me.wrap( '<a href="'+l+'" title="'+t+'" />' );
    },function(){
      if ( me.parent().is( "a" ) ) {
        me.unwrap();
      }
    });
      return this;
   }; 
})( jQuery );

Javascript code:

$(document).ready(function() {
  $('.media.case2 img').linkMe2();
  $('.media.case2 h4').linkMe2();
  $('.media.case2 button').linkMe2();
});

 


How to auto backup private server with dropbox

Make sure you’ve dropbox already intalled in your server. You can read my previous post how to install dropbox if not already installing dropbox.

This note is only for backup a directory website with small space, because dropbox only give you 2GB free space for free account.

After dropbox installed on your server. You can create a symbolic link in Dropbox directory that points to public directory your website.

Example I have a directory website in “/var/www/html”. In my public directory I have a fews directories and files, but I don’t want sync all of them. This my steps how to setting my dropbox.

1. Stop your dropbox service

[[email protected] ~]# dropbox stop

Note: I’ve already shortcut for running dropbox application. Read my previous post how to create shortcut dropbox.

2. Enter directory Dropbox

[[email protected] ~]# cd ~/Dropbox

3. Create a symbolic link

[[email protected] ~]# mkdir -p /root/Dropbox/www
[[email protected] ~]# for d in /var/www/html/*; do ln -s "$d" '/root/Dropbox/www/'; done
[[email protected] ~]# ls -la /root/Dropbox/www

lrwxrwxrwx 1 root root   11 Sep 14 04:28 css -> /var/www/html/css
lrwxrwxrwx 1 root root   11 Sep 14 04:28 fonts -> /var/www/html/fonts
lrwxrwxrwx 1 root root   11 Sep 13 01:36 images -> /var/www/html/images
lrwxrwxrwx 1 root root   11 Sep 13 07:16 js -> /var/www/html/js
lrwxrwxrwx 1 root root   11 Sep 15 04:03 index.php -> /var/www/html/index.php
lrwxrwxrwx 1 root root   11 Sep 15 04:03 robots.txt -> /robots.txt
lrwxrwxrwx 1 root root   16 Oct 19 07:46 TMP -> /var/www/html/TMP

 There are lists of my directory “/var/www/html”. Now I’ll remove dir “TMP” from symlink Dropbox, because I don’t need them to sync to my dropbox.

[[email protected] ~]# rm /root/Dropbox/www/TMP

4. Start your dropbox service

[[email protected] ~]# dropbox start

You can watch the sync processing with command below:

[[email protected] ~]# dropbox status

Well, now your server auto backup to your dropbox account.

Note: be careful deleting your files from dropbox dashboard, because all your files and folders on dropbox are already syncing with your server.

If you want to get 500 MB of bonus space dropbox, this my refferal link https://db.tt/yhtSrsQa for create new dropbox account.


How to Install Dropbox On CentOS 6 (as root user) via CLI

Before instaling dropbox you need to check your centos version.

[[email protected] ~]# uname -m
x86_64

my current server is Centos 64-bit

Download and install dropbox 

Follow the steps below to install dropbox on centos 32-bit:

[[email protected] ~]# cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -

And for centos 64-bit, follow the steps below to install dropbox:

[[email protected] ~]# cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

 Run Dropbox application & Verification your Dropbox Account

Note:
If you have current user dropbox and want to get free 500MB space, try install dropbox on your new server with new user dropbox as refferal current user.
You can change later with your current user dropbox if needed.

1. Star dropbox application

[[email protected] ~]# ~/.dropbox-dist/dropboxd

2. Verification your Dropbox
It will return response like this:

"This computer isn't linked to any Dropbox account...
Please visit https://www.dropbox.com/cli_link?host_id=(some code)" to link this device.

Copy the link, then open it in your brwoser ( Doesn’t matter if it’s the same computer, can be your Windows PC. ).
Login to your dropbox account.

If you are using refferal, you need to verification first.
After done logging in, click popup warning "Verify Email". 
Check your email address, then verification.

To stop dropboxd installation, use ctrl+c. A new directory will appear on current user directory called “Dropbox”

Downloading the python CLI interface from Dropbox

– Create new directory for save your file dropbox CLI interface if needed.

[[email protected] ~]# mkdir -p ~/bin

– Download file dropbox CLI interface

[[email protected] ~]# wget "https://www.dropbox.com/download?dl=packages/dropbox.py" -O ~/bin/dropbox.py

– set permission dropbox CLI interface

[[email protected] ~]# chmod +x ~/bin/dropbox.py

or you can run with following command:

[[email protected] ~]# mkdir -p ~/bin && wget "https://www.dropbox.com/download?dl=packages/dropbox.py" -O ~/bin/dropbox.py && chmod +x ~/bin/dropbox.py

Start your dropbox application

[[email protected] ~]# ~/bin/dropbox.py start

Dropbox command-line interface:

1. Help

[[email protected] ~]# ~/bin/dropbox.py help

Provide help Dropbox command-line interface

2. Check status

[[email protected] ~]# ~/bin/dropbox.py status

Prints out the current status of the Dropbox daemon.

3. Set bandwidth limits (throttle)

[[email protected] ~]# ~/bin/dropbox.py throttle

Set bandwidth limits for file sync.

DOWNLOAD – either “unlimited” or a manual limit in KB/s
UPLOAD – one of “unlimited”, “auto”, or a manual limit in KB/s

4. Get public url

[[email protected] ~]# ~/bin/dropbox.py puburl <file>

Prints out a public url for FILE (which must be in your public folder).

5. Stop Dropbox daemon

[[email protected] ~]# ~/bin/dropbox.py stop

6. Check is Dropbox running or not

[[email protected] ~]# ~/bin/dropbox.py running

Returns 1 if running 0 if not running.

7. Start Dropbox daemon

[[email protected] ~]# ~/bin/dropbox.py start

Starts the dropbox daemon, dropboxd. If dropboxd is already running, this will do nothing.

options:
-i –install auto install dropboxd if not available on the system

8. Check file status sync

[[email protected] ~]# ~/bin/dropbox.py filestatus <file>

Prints the current status of each FILE.

options:
-l –list prints out information in a format similar to ls. works best when your console supports color 🙂
-a –all do not ignore entries starting with .

Aliases: stat

9. Get list files and folders

[[email protected] ~]# ~/bin/dropbox.py ls

10. Set Dropbox auto start ( for Ubuntu distributions)

[[email protected] ~]# ~/bin/dropbox.py autostart [y/n]

options:
n dropbox will not start automatically at login
y dropbox will start automatically at login (default)

11. Excluding files or folders
check list all files and folders currently excluded from syncing

[[email protected] ~]# ~/bin/dropbox.py exclude list

exclude files or folders

[[email protected] ~]# ~/bin/dropbox.py exclude <path> <path> ....

remove files or folders from currently excluded

[[email protected] ~]# ~/bin/dropbox.py exclude remove <path> <path> ....

“list” prints a list of directories currently excluded from syncing.
“add” adds one or more directories to the exclusion list, then resynchronizes Dropbox.
“remove” removes one or more directories from the exclusion list, then resynchronizes Dropbox.
With no arguments, executes “list”.
Any specified path must be within Dropbox.

12. Enables or Disables LAN sync

[[email protected] ~]# ~/bin/dropbox.py lansync [y/n]

options:
y dropbox will use LAN sync (default)
n dropbox will not use LAN sync

12. Get a shared link for a file in your dropbox

[[email protected] ~]# ~/bin/dropbox.py sharelink <file>

13. Set proxy settings for Dropbox.

[[email protected] ~]# ~/bin/dropbox.py proxy MODE [TYPE] [HOST] [PORT] [USERNAME] [PASSWORD]

MODE – one of “none”, “auto”, “manual”
TYPE – one of “http”, “socks4”, “socks5” (only valid with “manual” mode)
HOST – proxy hostname (only valid with “manual” mode)
PORT – proxy port (only valid with “manual” mode)
USERNAME – (optional) proxy username (only valid with “manual” mode)
PASSWORD – (optional) proxy password (only valid with “manual” mode)

Create Shortcut Dropbox

If you wanna create a shortcut for dropbox cli interface ex:(~/bin/dropbox.py). Edit file .bashrc on current user directory.

[[email protected] ~]# nano ~/.bashrc

 

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# add the line below
alias dropbox='~/bin/dropbox.py'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

save file, then relog.

Now you can run dropbox application via command “dropbox”

[[email protected] ~]# dropbox status
[[email protected] ~]# dropbox start
[[email protected] ~]# dropbox stop

Congrulations !! your dropbox already installed and ready to use.

If you want to get 500 MB of bonus space dropbox, this my refferal link https://db.tt/yhtSrsQa for create new dropbox account.


Query for mysql with order by multiple items

If you want to sorted your mysql query with multiple items (order by), but at the same time. You can run mysql query as follows as:

SELECT *
FROM (TABLE)
WHERE  (condition)
ORDER BY (COLUMN1) (ASC/DESC), (COLUMN1) (ASC/DESC);

Example :

SELECT *
FROM `table_master`
WHERE  `external_link` !='' or external_link !=null
ORDER BY `title` ASC, `last_update` DESC limit 0,20;

 


How to add MULTIPLE columns AFTER existing column in Mysql

If you want to add single column after specific field, then the mysql query is:

ALTER TABLE `your_table` ADD COLUMN `year` SMALLINT(4) DEFAULT NULL AFTER `title`;

If you want to add multiple columns, then you need to use ‘ADD’ command each time for a column. The mysql query as follows as:

ALTER TABLE `your_table`
ADD COLUMN `year` SMALLINT(4) NOT NULL AFTER `title`,
ADD COLUMN `last_update` DATE NOT NULL AFTER `year`,
ADD COLUMN `custom_field` VARCHAR(100) DEFAULT NULL AFTER `last_update`;


How install module python from full packages Github

Make sure you have already installed pip. if you’re using Python 2 >=2.7.9 or Python 3>=3.4 pip is already installed.

pip install -e git+https://github.com/facebook/python-sdk.git #egg=FacebookSDK
git clone http://github.com/facebook/python-sdk.git
pip install https://github.com/facebook/python-sdk/zipball/master
pip install https://github.com/facebook/python-sdk/tarball/master

for windows users:

1) I first download and unpack the file.

2) Then in the python directory going to \Scripts

3) Starting here the command prompt

pip install C:\pgoapi-master

# pgoapi-master is example library