Ubuntu un-tar/extract tar ball/file to another directory

January 4, 2015

To extract an archive to a directory different from the current, use the -C, or –directory, tar option, as in: tar -xf archive.tar -C /target/directory

PHP get first day of current month, datepicker friendly

December 22, 2014

The simplest and readable way to do it is using this clean solution. All you need is a string represent the date. First day of the month: Last day of the month:

Magento checkout Paypal change “What is PayPal text

December 14, 2014

The Magento checkout “What is PayPal” text is code in this file, as well as paypal logo /app/design/frontend/base/default/template/paypal/payment/mark.phtml Ideal way to make changes is copy this file with same path in your theme and modify this file according to requirements. Example your theme is: yourtheme /app/design/frontend/default/yourtheme Then in template folder create same path as “paypal/payment” […]

MySql find all tables with specific column/field name

December 8, 2014

How to look up in the entire DB and list out all tables which have specific column name or field name? Example belows looks for field `currency` from all database: To add specific database to the query, use:

PHP script execution time tracking wallclock time

December 1, 2014

A simple way to find out execution time of php script without lots of calculation is tracks the wallclock time. Compare to tracking CPU time, it also include time that PHP is sat waiting for external resources such as disks or databases, which is not used for max_execution_time. Output: Execution time get user: 0.00023317337036133

Linux Ubuntu move file from one directory to another directory command

November 26, 2014

In Linux, type: To move file mv somefile /anotherfolder/ To move all folder content: mv /somefolder/* /anotherfolder/* In Ubuntu, type: To move file sudo mv somefile /anotherfolder/ To move all folder content: sudo mv /somefolder/* /anotherfolder/* There’s almost always more than way to do something in Linux. And more importantly, there are almost always caveats. […]

PHP fgetcsv count lines end of file, eof

November 17, 2014

Due to fgetcsv read only a line from open file, or line by line if looping. As decribe below, it doesn’t able to return number of line from specific file. The fgetcsv() function parses a line from an open file, checking for CSV fields. The fgetcsv() function stops returning on a new line, at the […]

PHP check string exist in string

November 17, 2014

The correct way to write the statement to check if string contains specific words is use strpos function. Strpos is used to find the occurrence of one string inside other. Note that the use of !== false is deliberate; strpos returns either the offset at which the needle string begins in the haystack string, or […]

Ubuntu user management command line

November 14, 2014

Change user password To change self password #passwd To change other user password #passwd username Removes the user’s home directory as well as deleting the user #sudo userdel -r [username] Add new user: #sudo adduser <username> Add user to admin #sudo adduser <username> admin Add user to sudoer #visudo Switch user sudo <username>

PHP dealing with commas in CSV data

November 12, 2014

Look carefully the data, there are multiple commas ‘,’ inside the address field. When transform the data to array, the output will be each commas separated in one array value. Example: (wrong way) Don’t attempt to do this with a regular expression. Just use str_getcsv()! The third parameter informs str_getcsv() to look for quote-enclosed fields. […]