Posts

Showing posts with the label unix

PHPUnit: Basics of Unit Testing

Image
What is Unit Testing ? Unit Testing is a software testing method by which individual units of code are tested to determine if they are fit to use. Benefits of Unit Testing - find problems early - facilitates changes - simplifies integration - documentation - design interface What is PHPUnit? - xUnit-style library by Sebastian Bergmann - Installable via Composer, PEAR and Phar - well integrated and well documented reference: http://phpunit.de/manual/current/en/index.html Installation (globally via Phar) wget https://phar.phpunit.de/phpunit.phar chmod +x phpunit.phar mv phpunit.phar /usr/bin/phpunit source: http://phpunit.de/manual/current/en/installation.html Installation (as vendor via Composer) Create a composer.json file in the root directory then add the ff.: { "require-dev" : { "phpunit/phpunit" : "4.8.0" }, "autoload" : { "psr-4" : { "Project\\" : "app...

Python: Install ansible with pip

Note that ansible can only be run on a machine with Python 2.6 or 2.7 Install ansible package using pip module: sudo pip install ansible Install required packages: sudo pip install paramiko PyYAML Jinja2 httplib2 six To install the latest development version: sudo pip install git+git://github.com/ansible/ansible.git@devel

Python: Install pip on Mac OS X

Download get-pip.py Run the following command: sudo python get-pip.py Upgrading pip: pip install -U pip

Bash: Caret Substitution

Sample command: echo "dev" && echo "my dev" Replace "dev" with "prod": ^dev^prod Previous command will now be this: echo "prod" && echo "my dev" To replace all occurences of "dev": ^dev^prod^:& Previous command will now be this: echo "prod" && echo "my prod"

Bash: Copy files by extension from sub-directories to another directory

Goal: Copy all image (*.png) files from all sub-directories of dir1 into single directory, dir2. Source: bash_examples/ dir1 - dir3 - f1.png - f2.png - f5.jpg - dir4 - f3.png - f4.png Destination: bash_examples/ dir2 - f1.png - f2.png - f3.png - f4.png 1. Change the directory to dir1 cd ~/Desktop/bash_examples/dir1/ 2. Find all files with .png extension then apply cp command to copy each file from dir1 to dir2 find . -name \*.png -exec cp -v '{}' "/Users/mac0611/Desktop/bash_examples/dir2" ";" ./dir3/f1.png -> /Users/mac0611/Desktop/bash_examples/dir2/f1.png ./dir3/f2.png -> /Users/mac0611/Desktop/bash_examples/dir2/f2.png ./dir4/f3.png -> /Users/mac0611/Desktop/bash_examples/dir2/f3.png ./dir4/f4.png -> /Users/mac0611/Desktop/bash_examples/dir2/f4.png cd ..; ls dir2/ f1.png f2.png f3.png f4.png

Bash: Calculate Date in Ubuntu and Mac OS

Display current date date +'%Y-%m-%d %H:%M' 2015-08-07 17:06 Add 3 mins, 5 days, 2 months, 4 years to current date (Mac OS) date -v +3M -v +5d -v +2m -v +4y +'%Y-%m-%d %H:%M' 2019-10-12 17:09 Add 3 mins, 5 days, 2 months, 4 years to current date (Ubuntu) date -d "3 minutes 5 days 2 months 4 years" +'%Y-%m-%d %H:%M' 2019-10-12 17:09

Enable OPCache on Ubuntu: Alternative to APC Cache

If you are using PHP 5.5, it is not supported by APC Cache. For reference, see PHP Bug #65731 PHP 5.5 comes with it's own opcode cache which can be enabled with the following steps: 1. Enable opcache in php.ini sudo nano /etc/php5/apache2/php.ini Look for the line: ;opcache.enable=0 And replace with: opcache.enable=1 2. Enable the php mod sudo php5enmod opcache sudo service apache2 restart If you are using PHP lower than 5.5, then you can still use APC. Just run this line in the terminal to install APC. sudo apt-get install php-apc

Install MONACO Font in Ubuntu

To download MONACO font in Ubuntu, follow the steps below: #1: Install directly: 1. Download http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf 2. In ~/Downloads, click Monaco_Linux.ttf 3. Click the Install button. #2: Using terminal: 1. If you have cURL installed, run the following in the terminal: curl -kL https://raw.github.com/cstrap/monaco-font/master/install-font-ubuntu.sh | bash #3: Manual installation: sudo mkdir -p /usr/share/fonts/truetype/ttf-monaco; cd /usr/share/fonts/truetype/ttf-monaco/ sudo wget http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf sudo mkfontdir cd /usr/share/fonts/truetype/ fc-cache

MySQL Without The Login Prompt

There may be times when you want to use MySQL without the login prompt like when running cron jobs. For that MySQL has something called Option Files wherein you can specify commonly used options so you do not need to enter them in the command line. To use MySQL without the login prompt, create a file in your home directory: touch ~/.my.cnf Modify the file and paste the following configuration: [mysql] user=your_mysql_user password=your_mysql_password You may also specify your configuration for mysqldump so that you can backup files with cron periodically :) [mysqldump] user=my_user password=my_password