Programming and Exciting Things

Use rsync on non standart port

Published on 21.01.2015

I want to get out from my current hosting provider - Superhosting servers but I'm super lazy and instead of making tar.gz / zip archives and moving them via wget for example I prefer to use rsync. Everything is good until I realize that Superhosting is using non standard SSH port, fortunately I can still using rsync with setting "-e" parameter

rsync -avz -e "ssh -p 1022" user@server.net:~/www/ /tmp/copy
This will copy all content from account www directory to /tmp/copy on new machine.

Install php 5.3.12 on ubuntu 14.04

Published on 20.11.2014

Installation from source code is not difficult but I want to share how to do it with older php version on Ubuntu 14.04
First of all we need to get php source code and extract it into some directory

mkdir -p ~/Downloads/php-5.3.12
cd ~/Downloads/php-5.3.12
wget http://museum.php.net/php5/php-5.3.12.tar.gz
tar zxf php-5.3.12.tar.gz
cd php-5.3.12

After that we must install some libraries:
apt-get install libxml2-dev
apt-get install libpcre3-dev
apt-get install libbz2-dev
apt-get install libdb4.8-dev
apt-get install libjpeg-dev
apt-get install libpng12-dev
apt-get install libxpm-dev
apt-get install libfreetype6-dev
apt-get install libt1-dev
apt-get install libgd2-xpm-dev
apt-get install libgmp-dev
apt-get install libmysqlclient-dev
apt-get install libmhash-dev
apt-get install unixodbc-dev
apt-get install freetds-dev
apt-get install libpspell-dev
apt-get install libsnmp-dev
apt-get install libtidy-dev
apt-get install libxslt1-dev
apt-get install libmcrypt-dev
And of course
apt-get install make
After that we create Makefile. In this case we will install php in
/usr/share/php5.3.12
./configure \
  --prefix=/usr/share/php5.3.12 \
  --datadir=/usr/share/php5.3.12 \
  --mandir=/usr/share/man \
  --bindir=/usr/bin/php5.3.12 \
  --with-libdir=lib64 \
  --includedir=/usr/include \
  --sysconfdir=/etc/php5.3.12/ \
  --with-config-file-path=/etc/php5.3.12/cli \
  --with-config-file-scan-dir=/etc/php5.3.12/conf.d \
  --localstatedir=/var \
  --disable-debug \
  --with-regex=php \
  --disable-rpath \
  --disable-static \
  --disable-posix \
  --with-pic \
  --with-layout=GNU \
  --with-pear=/usr/share/php \
  --enable-calendar \
  --enable-sysvsem \
  --enable-sysvshm \
  --enable-sysvmsg \
  --enable-bcmath \
  --with-bz2 \
  --enable-ctype \
  --with-db4 \
  --without-gdbm \
  --with-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-cli \
  --with-gettext \
  --enable-mbstring \
  --with-pcre-regex=/usr \
  --enable-shmop \
  --enable-sockets \
  --enable-wddx \
  --with-libxml-dir=/usr \
  --with-zlib \
  --with-kerberos=/usr \
  --with-openssl=/usr \
  --enable-soap \
  --enable-zip \
  --with-mhash \
  --with-exec-dir=/usr/lib/php5/libexec \
  --without-mm \
  --with-curl=shared,/usr \
  --with-zlib-dir=/usr \
  --with-gd=shared,/usr \
  --enable-gd-native-ttf \
  --with-gmp=shared,/usr \
  --with-jpeg-dir=shared,/usr \
  --with-xpm-dir=shared,/usr/X11R6 \
  --with-png-dir=shared,/usr \
  --with-freetype-dir=shared,/usr \
  --with-ttf=shared,/usr \
  --with-t1lib=shared,/usr \
  --with-ldap=shared,/usr \
  --with-mysql=shared,/usr \
  --with-mysqli=shared,/usr/bin/mysql_config \
  --with-pspell=shared,/usr \
  --with-unixODBC=shared,/usr \
  --with-xsl=shared,/usr \
  --with-snmp=shared,/usr \
  --with-sqlite=shared,/usr \
  --with-tidy=shared,/usr \
  --with-xmlrpc=shared \
  --enable-pdo=shared \
  --without-pdo-dblib \
  --with-pdo-mysql=shared,/usr \
  --with-pdo-odbc=shared,unixODBC,/usr \
  --with-pdo-dblib=shared,/usr \
  --enable-force-cgi-redirect  --enable-fastcgi \
  --with-libdir=/lib/x86_64-linux-gnu \
  --with-pdo-sqlite=shared \
  --with-sqlite=shared \
  --with-libdir=/lib/x86_64-linux-gnu \
  --enable-ipv6 \
  --enable-fpm \
  --with-mcrypt \
  --with-imap-ssl
After that
make && make install
Result must be this: result 1
result 2

Stop tracking file on git

Published on 03.11.2014

I have one config file on remote server which I won't be tracked on git repo. Usualy hiding/ignoring files with git is super easy. For this problem we can just use:

git update-index --assume-unchanged filename
Example:
#git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add file..." to update what will be committed)
  (use "git checkout -- file..." to discard changes in working directory)

        modified:   app/Config/database.php

no changes added to commit (use "git add" and/or "git commit -a")

# git update-index --assume-unchanged app/Config/database.php

# git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Simple and effective :)

More information about git-update-index can be found here https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html

Convert png and gif file to jpg in bash script

Published on 29.10.2014

Very quick script for converting all png and gif files in directory to jpeg with image magick.

set -e
 
dir=/var/www/default/public_images
 
for ext in png gif; do 
	for i in `find "$dir"  -type f -regex '.*'$ext `; do
		( filename=${i%.*} 
		convert "$i" -quality 90 -strip "$filename.jpg"
		echo "$filename" )
	done
done

Simple way for casting array of values to int

Published on 06.10.2014

Here is a simple way to cast all elements in array to integeres in php

$array = array('1', '24', 'da','fa24');
$array = array_map('intval', $array);
And yes it have overhead but for small arrays it is ideal solution instead of writing a classical foreach loop
$array = array('1', '24', 'da','fa24');
foreach($array as $k =>$v) {
	$array[$k] = (int)$v;
}