Thursday, January 28, 2016

echo color text in console

echo color text in console by using some escape sequences:

myecho('Hello World', 'green', 'background');

function myecho($msg, $color = 'green', $ground = 'foreground') {
  $colorArr = array();
  $colorArr['foreground'] = array(
    'black' => '0;30',
    'dark_gray' => '1;30',
    'red' => '0;31',
    'bold_red' => '1;31',
    'green' => '0;32',
    'bold_green' => '1;32',
    'brown' => '0;33',
    'yellow' => '1;33',
    'blue' => '0;34',
    'bold_blue' => '1;34',
    'purple' => '0;35',
    'bold_purple' => '1;35',
    'cyan' => '0;36',
    'bold_cyan' => '1;36',
    'white' => '1;37',
    'bold_gray' => '0;37',

  $colorArr['background'] = array(
    'black' => '40',
    'red' => '41',
    'magenta' => '45',
    'yellow' => '43',
    'green' => '42',
    'blue' => '44',
    'cyan' => '46',
    'light_gray' => '47',

  if (isset($colorArr[$ground][$color])) {
    echo "\033[" . $colorArr[$ground][$color] . "m" . $msg . "\033[0m";
  else {
    echo $msg;

Note: Google bash color for detail.


Sunday, January 24, 2016

post data to the user register form

# vim test.js

(function ($) {
  $('#edit-submit').on('click', function(event){

    var _formData = $('#user-register-form').serializeArray();

    _formData.push({name: '_drupal_ajax', value: 1});
    _formData.push({name: '_triggering_element_name', value: 'op'});
    _formData.push({name: '_triggering_element_value', value: 'Save'});

    $.ajax({method: 'POST', url: '/userregisterform?ajax_form=1&_wrapper_format=drupal_ajax', dataType: 'json', data: _formData})
      .done(function(data) {
      .fail(function(data) {

# vim TestController.php

namespace Drupal\hello_world\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;

class TestController extends ControllerBase {
  public function registeruser() {
    // register a new user
    //$values = [];
    //$values['name'] = 'robo-user';
    //$values['mail'] = '';
    //$values['pass']['pass1'] = 'password';
    //$values['pass']['pass2'] = 'password';
    //$values['op'] = t('Create new account');

    $form_state = new \Drupal\Core\Form\FormState();

    \Drupal::formBuilder()->submitForm('\Drupal\user\RegisterForm', $form_state);

    $errors = $form_state->getErrors();

    if (empty($errors)) {
      // Return new user session to client.
      $uid = \Drupal::service('user.auth')->authenticate($_POST['name'], $_POST['pass']);
      return new JsonResponse(array( 'uid' => $uid, 'name' => $_POST['name']));
    else {
      return new JsonResponse(array('errors' => $errors));


Saturday, January 23, 2016

Using Ajax Forms in Drupal 8

# vim

name: My Example Module
description: My Example Module.
package: Custom

type: module
core: 8.x

# vim myexample.routing.yml

  path: '/myexample'
    _controller: '\Drupal\myexample\Controller\MyexampleController::content'
    _title: 'Hello World'
    _permission: 'access content'

# vim src/Controller/MyexampleController.php

 * @file
 * Contains \Drupal\myexample\Controller\MyexampleController.

namespace Drupal\myexample\Controller;

use Drupal\Core\Controller\ControllerBase;

use Symfony\Component\HttpFoundation\Response;

class MyexampleController extends ControllerBase {
  public function content() {
    $contactform = \Drupal::formBuilder()->getForm('Drupal\myexample\Form\ContactForm');

    return [
      '#type' => 'markup',
      '#markup' => $this->t('Hello, World!'),
      'contactform' => $contactform,

# vim src/Form/ContactForm.php

 * @file
 * Contains \Drupal\myexample\Form\ContactForm.

namespace Drupal\myexample\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CssCommand;
use Drupal\Core\Ajax\HtmlCommand;

 * Implements an example form.
class ContactForm extends FormBase {

   * {@inheritdoc}
  public function getFormId() {
    return 'contact_form';

   * {@inheritdoc}
  public function buildForm(array $form, FormStateInterface $form_state) {
    #$form['#action'] = '/contactformsubmit';

    $form['contact_name'] = array(
      '#type' => 'textfield',
      '#title' => $this->t('Contact Name'),

    $form['email'] = array(
      '#type' => 'textfield',
      '#ajax' => array(
        'callback' => array($this, 'validateEmailAjax'),
        'event' => 'blur',
        'effect' => 'fade',

    $form['actions'] = array(
      '#type' => 'actions',
      'submit' => array(
        '#type' => 'submit',
        '#value' => $this->t('Save'),
        '#button_type' => 'primary',

    return $form;

   * Validates that the email field is correct.
  protected function validateEmail(array &$form, FormStateInterface $form_state) {
    return valid_email_address($form_state->getValue('email'));

   * Ajax callback to validate the email field.
  public function validateEmailAjax(array &$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    $valid = $this->validateEmail($form, $form_state);

    if ($valid) {
      $css = ['border' => '1px solid green'];
      $message = $this->t('Email ok.');
    else {
      $css = ['border' => '1px solid red'];
      $message = $this->t('Email not valid.');

    $response->addCommand(new CssCommand('#edit-email', $css));
    $response->addCommand(new HtmlCommand('.email-valid-message', $message));

    return $response;

   * {@inheritdoc}
  public function validateForm(array &$form, FormStateInterface $form_state) {
    #file_put_contents('/tmp/debug1', print_r($form, TRUE) . PHP_EOL, FILE_APPEND);

    if (strlen($form_state->getValue('contact_name')) < 3) {
      $form_state->setErrorByName('contact_name', $this->t('The contact name is too short.'));

   * {@inheritdoc}
  public function submitForm(array &$form, FormStateInterface $form_state) {
    drupal_set_message($this->t('Contact name @contact_name', array('@contact_name' => $form_state->getValue('contact_name'))));


To redirect both stdout output and stderr error to a file

0: stdin
1: stdout
2: stderr

Note that the order of redirections is significant. For example, the command

              ls > dirlist 2>&1

directs both standard output and standard error to the file dirlist, while the command

              ls 2>&1 > dirlist

directs only the standard output to file dirlist, because the standard error was duplicated from the standard output before the standard output was redirected to dirlist.

Redirecting Standard Output and Standard Error:

This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of word.

There are two formats for redirecting standard output and standard error:




Of the two forms, the first is preferred. This is semantically equivalent to

              >word 2>&1

To redirect both stdout output and stderr error to a file:

# find . &> /tmp/test.txt

Redirects STDOUT to log and than replaces STDERR with the redirected STDOUT:

# some_cmd > log 2>&1

Replaces STDERR with STDOUT and then redirects the original STDOUT to log:

# some_cmd 2>&1 > log

Lookup the manual and find keyword redirection for detail:

# man bash


To include the custom or external js css files

drupal_add_js and drupal_add_css have been deprecated in Drupal 8. The new way to include the Javascript or css files in Drupal 8:

# vim myexample.libraries.yml

  version: 1.x
      css/myexample.css: {}
    js/myexample.js: {}
    - core/jquery
    - core/drupalSettings

# vim myexample.module

 * Implements hook_preprocess_page().
function myexample_preprocess_page(&$variables) {
  $variables['#attached']['library'][] =  'myexample/this_is_test_lib_name';

# vim myexample/js/myexample.js

(function ($) {


(function ($, Drupal, window) {
})(jQuery, Drupal, window);

Note: underscore.js and backbone.js are in core in Drupal 8.
Note: One other change you may have noticed: Drupal.settings is now drupalSettings.


get a Drupal 8 node programmatically with console in an external script

get a Drupal 8 node programmatically with console in an external script

Install Drush by download the latest stable release using the code below or browse to

# wget

Test your Drush install:

# php drush.phar core-status

Rename to `drush` instead of `php drush.phar`. Destination can be anywhere on $PATH:

# chmod +x drush.phar
# mv drush.phar /usr/local/bin/drush

Enrich the bash startup file with completion and aliases:

# drush init

More detail:

Read Drush help:

# drush help

Run your script:

# vim test.php

use Drupal\node\Entity\Node;

$node = Node::load(6);

echo '<pre>' . print_r($node, TRUE) . '</pre>';

# drush --root=/www/drupal-8.0.1 --uri=drupal8.cent-exp.local php-script test.php

# drush --root=/www/drupal-8.0.1 --uri=drupal8.cent-exp.local --debug php-script test.php

# drush --root=/www/drupal-8.0.1 --uri=drupal8.cent-exp.local --debug --verbose php-script test.php

To create a new node:

use Drupal\node\Entity\Node;

$node = Node::create(array(
    'type' => 'page',
    'title' => 'your title',
    'langcode' => 'en',
    'uid' => '1',
    'status' => 1,
    'field_firstname' => 'My First Name',
    #'field_fields' => array(),


Friday, January 22, 2016

XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource

XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource

APIs are the threads that let you stitch together a rich web experience. But this experience has a hard time translating to the browser, where the options for cross-domain requests are limited to techniques like JSON-P (which has limited use due to security concerns) or setting up a custom proxy (which can be a pain to set up and maintain).

Cross-Origin Resource Sharing (CORS) is a W3C spec that allows cross-domain communication from the browser. By building on top of the XMLHttpRequest object, CORS allows developers to work with the same idioms as same-domain requests.

The use-case for CORS is simple. Imagine the site has some data that the site wants to access. This type of request traditionally wouldn’t be allowed under the browser’s same origin policy. However, by supporting CORS requests, can add a few special response headers that allows to access the data.

As you can see from this example, CORS support requires coordination between both the server and client. Luckily, if you are a client-side developer you are shielded from most of these details. The rest of this article shows how clients can make cross-origin requests, and how servers can configure themselves to support CORS.

Method 1:

On the remote server, add:

header('Access-Control-Allow-Origin: http://symfony.cent-dev.local');
#header('Access-Control-Allow-Headers: X-Requested-With');
#header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS');

Then, go observe the response in the browser at client side. You will see the three lines above.

Method 2:

On the remote server, edit your Apache configuration file:

<ifModule mod_headers.c>
    Header set Access-Control-Allow-Origin: http://symfony.cent-dev.local

Note: you can replace http://symfony.cent-dev.local to a wildcard *.

Note: and don't forget to load module: a2enmod headers

Method 3:

Add a proxy script on your server, ex: proxy.php then having your client side script to access the proxy.php script.

The proxy.php script then send the request to the remote server.


Thursday, January 21, 2016

simply accounting - How to connect to MySQL Server

simply accounting - How to connect to MySQL Server

Since you do not seem very familiar with ODBC and MySQL, we may be able to help you more if you describe what it is you are trying to do.

To fill the Connector/ODBC form, do the following:

1-Open Simply, go to Help > About Simply Accounting by Sage and click on Support Info... On the right side, take note of the Computer name and Port number.

2-On the ODBC form you need to fill the following fields:

Server: The Computer name from Help > About

User: Your user name (sysadmin or other with 3rd party access rights)

Password: Well, the user's password or blank if no password

Database: simply

Click on the Connect Options tab:

Port: the port number from Help > About

You'll then be able to connect. Note that Simply must be opened to connect through ODBC.

Some Files/Directories you might be interested in:
[] C:\Documents and Settings\All Users\Documents\Sage Software\ConnectionManager\ConnectionManager.ini

[] C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\dbengine.ini

[] C:\Documents and Settings\All Users\Documents\Sage Software

[] C:\Documents and Settings\All Users\Documents\Sage Software\Simply Accounting

[] C:\Documents and Settings\All Users\Documents\Simply Accounting

[] C:\Documents and Settings\danny\My Documents\Simply Accounting

Add these lines to C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\dbengine.ini
# binary log
# port number
port = 13541
# data dir
datadir = C:\\test\\asdf.SAJ
# log all the queries log (including select, insert, update, and all).

Create a file called c:\mysql-init.txt with following content:

GRANT SUPER ON *.* TO 'root'@'localhost';

Note: without granting the super privileges, you will see the following message:

Sage.Simply.DataTypes.ConnectionException: TRIGGER command denied to user 'root'@'localhost' for table 'titrec' ---> MySql.Data.MySqlClient.MySqlException: TRIGGER command denied to user 'root'@'localhost' for table 'titrec'

Run MySQL and create a new user called root on start up:
start > run > cmd.exe

C:\> "C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\mysql\mysqld-nt.exe" --defaults-file="C:\\Program Files (x86)\\winsim\\ConnectionManager\\MySqlBinary\\5.0.38\\dbengine.ini" --init-file="C:\\mysql-init.txt"

Commands you might be interested in:

Login to mysql:
cmd> mysql -u sysadmin -p --port=13541
cmd> mysql -u root -p --port=13541

Note: Simply Accounting default username: sysadmin.

Manually shutdown mysql:
cmd> mysqladmin -u root -p -P 13540 shutdown

View mysql binary log:
cmd> mysqlbinlog C:\test\asdf.SAJ\mysql-bin.000007

Simply Accounting MySQL database fine tune Tips:

Edit C:\Documents and Settings\All Users\Documents\Sage Software\ConnectionManager\ConnectionManager.ini, under the [settings] section:
# Note: Simply Accounting Connection Manager will use below setting to overwrite mysql's "innodb_buffer_pool_size".
Buffer Pool Size=1024

Edit C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\dbengine.ini, under the [mysqld] sectioin:
### Modified by Jun
# Note: do not change innodb_buffer_pool_size here, since it will have no effect because Simply Accounting Connection Manager has its own setting to overwrite it. You can either go to Simply Accounting Connection Manager and adjust the "memory buffer size",
# or edit C:\Documents and Settings\All Users\Documents\Sage Software\ConnectionManager\ConnectionManager.ini, under the settings section:
# [settings]
# Buffer Pool Size=1024
# Note: the "number of connection attempts" in Simply Accounting Connection manager is "max_connect_errors".
# Note: If you modify the innodb_log_file_size, MySQL will fail to restart and InnoDB will complain about the size of the changed log file.
# The proper way to increase the innodb_log_file_size:
# 1. shutdown mysql server.
# 2. make backup of data and log files (ibdata1 and ib_logfile*).
# 3. remove InnoDB log files (ib_logfile*).
# 4. set new value for innodb_log_file_size in my.cnf
# 5. start mysqld
# 6. check error logs to ensure everything went fine.
# Reference:
max_allowed_packet = 16M
default-storage-engine = InnoDB
# turn this on if you prefer separate inoodb file for each table.
# log all the queries log (including select, insert, update, and all).
# Port number to use for connections.
# Path to the database root.
### skip DNS domain name resolve to avoid network slow issue.

Simply Accounting Default dbengine.ini:

Use following commands to verify the settings:
mysql> SHOW VARIABLES LIKE 'innodb_buffer_%';
mysql> SHOW VARIABLES LIKE 'innodb_additional_%';
mysql> SHOW VARIABLES LIKE 'innodb_log_%';

MySQL fine tune Tips:
What is the buffer size currently set to? If it is 56 MB, try increasing to 128 and test. Here is the recommendation from the Help Menu:

Memory buffer size (in MB). The amount of system memory allocated to cache company data used to populate reports, search/lookup results, and record lists in Simply.


If a large number of records and transactions are stored in your company database, and you have sufficient RAM installed on your computer, you may be able to fine-tune Simply Accounting's performance by increasing the memory reserved for Connection Manager operations. Be careful! If you set this number too high, you may prevent other applications from running, including Simply Accounting.

We recommend that you increase the buffer size in increments of 10MB, and never exceed 60% of total physical RAM installed in your PC. If you are unable to run other applications after increasing the buffer size, click the Default button to reset the buffer to it's default size.

You can manually edit the Buffer Pool Size setting in the ConnectionManager.ini file.This setting will overwrite any existing value for innodb_log_buffer_size set in the MySQL dbengine.ini file.
I would increase to 128 as a starting place and keep it there for a while and observe. If you experience resources issues (either with Simply Accounting or another product) begin lowering the buffer.

Use bigger log files and third party database
If you want to use bigger log files setting, you have to dump the simply database and restore it to avoid "log sequence number in the future" error

- close all simply clients.

- open Simply Connection Manager, and make sure there is no connection at all.

- copy the simply db folder to Jun's machine.

- start working on jun's machine

- use the latest Simply DB

- start simply with default setting

- look at the error logs, make sure there is no error.

- close simply and restart it

- look at the error logs, make sure there is no error.

- do a mysql dump with -R option (to include routines, functions, stored procedures):

cmd> e:
cmd> mysqldump -u root -p -P 13540 -R simply > 2012-07-20_1126_simply.sql
cmd> mysqldump -u root -p -P 13540 mysql > 2012-07-20_1126_mysql.sql

Note: You don't need to backup information_schema database, since information_schema is a virtual database, rebuilt each time MySQL is restarted, so there is no point in backing it up because you can't restore it anyway.

- close simply client, and go to Simply Connection Manager to make sure there is no more connections.

- Go to Task Manager to make sure mysqld-nt.exe is not running.

- start mysql server manually:
cmd> "C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\mysql\mysqld-nt.exe" --defaults-file="C:\\Program Files (x86)\\winsim\\ConnectionManager\\MySqlBinary\\5.0.38\\dbengine.ini"

- delete simply database:
cmd> mysql -u root -p -P 13540
mysql> drop database simply;
mysql> exit

- shutdown mysql manually:
cmd> mysqladmin -u root -p -P 13540 shutdown

- Go to Task Manager to make sure mysqld-nt.exe is not running.

- Go to c:\mycompany\9901.SAJ, and backup and delete these files:

- use the custom dbengine.ini setting:
C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\dbengine.ini

- Use Simply Connection Manager to adjust the Memory Buffer size to 1024 MB.

Note: make sure you do "Stop service" and "Start Service" in Simply Connection Manager.

or you prefer to modify the file manually:

add/modify this line in C:\Documents and Settings\All Users\Documents\Sage Software\ConnectionManager\ConnectionManager.ini:
Buffer Pool Size=1024

- start mysql server manually:
cmd> "C:\Program Files (x86)\winsim\ConnectionManager\MySqlBinary\5.0.38\mysql\mysqld-nt.exe" --defaults-file="C:\\Program Files (x86)\\winsim\\ConnectionManager\\MySqlBinary\\5.0.38\\dbengine.ini" --init-file="C:\\mysql-init.txt"

- use navicat to create a new simply database.
name: simply
character set: latin1 -- cp1252 West European
collation: latin1_general_ci

- restore simply database:
cmd> e:
cmd> mysql -u root -p -P 13540 simply < 2012-07-20_1126_simply.sql

 - check log files

- close all the connections.

- shutdown mysql manually:
cmd> mysqladmin -u root -p -P 13540 shutdown

- start simply client

- make sure mysql setting is on:
mysql> SHOW VARIABLES LIKE '%pool%'
innodb_additional_mem_pool_size 16777216
innodb_buffer_pool_size 1073741824

- check log files

- create a drupal database

- restore drupal database
cmd> mysql -u root -p -P 13540 drupal < drupal.sql

- make the www user have the right to access drupal database.

 - make another backup (with -R option) after everything is done:
cmd> e:
cmd> mysqldump -u root -p -P 13540 -R simply > 2012-07-20_1818_simply.sql


Sunday, January 17, 2016

To run Red Hat KVM virtualization inside VMware workstation

On VMware, edit the virtual machine setting > Hardware tab > processor > check "Virtualize Intel VT-x/EPT or AMD-v/RVI".

To check whether the processor supports hardware virtualization:

# lscpu | grep -i virtualization

Virtualization:        VT-x

Note: VT-x for Intel processors and AMD-V for AMD processors.

The presence of this flag confirms that the processor on this host support hardware virtualization:

# grep -E 'vmx|svm' /proc/cpuinfo

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase smep

Note: vmx (for Intel processors) or svm (for AMD processors).

Look up group install:

# yum group list virtual*

Available environment groups:
   Virtualization Host

# yum group info "Virtualization Host"

Environment Group: Virtualization Host
 Environment-Id: virtualization-host-environment
 Description: Minimal virtualization host.
 Mandatory Groups:
 Optional Groups:

Install the virtualization environment group:

# yum -y group install "Virtualization Host"

Saturday, January 16, 2016

Verifying Package Attributes

To identify which package the file is associated with:

# rpm -qf /etc/passwd


# rpm -qi setup

To compare the attributes of a file on the current system with the original file in the package database:

# rpm -Vf /etc/passwd

To verify the attributes for all the files included in a package with details:

# rpm -Vv setup

Mount an ISO image file in Red Hat

If you have copied the Red Hat 7 ISO image to a directory on the system, you can mount the ISO image file by running the following command:

# mount -o loop /var/rhel7iso/rhel-server-7.0-x86_64-dvd.iso /mnt

Note: The loop option tells the mount command that what is being mounted is not a block mountable device file but a mountable image file.

# df -h | grep mnt

To mount from DVD:

# mount /dev/cdrom /mnt

做大事人的 10個特徵,很準,算算看 據說 超過5個,你註定要發達了!

做大事人的 10個特徵,很準,算算看 據說 超過5個,你註定要發達了!



































Saturday, January 9, 2016

Insert text is very slow in Vim

Read from the local file (super fast):

:read file

Try to set syntax off:

:set syntax=off

Vim tries to keep your work safe and doesn't assume you can type several thousand characters per second. Read :help swap-file for some details on the buffering. The solution to your problem is this:

Turn off vim's swapfile while you are pasting text:

:set noswapfile

Turning off swap is not safe for normal operations! Immediately after the paste:

:set swapfile

See :help swapfile for more details.

Folding could be the problem:

set foldenable              " can slow Vim down with some plugins
set foldlevelstart=99       " can slow Vim down with some plugins
set foldmethod=syntax       " can slow Vim down with some plugins

According to vim's help (:help foldmethod), the syntax setting caused vim to use syntax highlighting to determine how to automatically fold my code.

Other things to check/toggle are syntax, filetype, wrap and line length (some plugins can be slow with very long lines).

Running Vim without your current settings is a good starting point:

# vim -u NONE


Thursday, January 7, 2016

Get the first day and last day range of the current quarter

Get the first day and last day range of the current quarter:


Get the first day and last day range of the last quarter:


Get the first day and last day range of the next quarter:


Wednesday, January 6, 2016

Burn bootable ISO image to a USB drive

Burn bootable ISO image to a USB drive

Fedora LiveUSB Creator - is a cross-platform tool for easily installing live operating systems on to USB flash drives.

UNetbootin - allows you to create bootable Live USB drives for Ubuntu and other Linux distributions without burning a CD.

Monday, January 4, 2016

Disable RSS feed link and request new password link in Drupal

Disable RSS feed link and request new password link in Drupal

 * Implementation of hook_menu_alter().
function mymodule_trigger_menu_alter(&$callback) {
  ### remove the rss.xml link

  ### disable "request new password" function.
  $callback['user/password']['access callback'] = FALSE;
  $callback['user/password']['access arguments'] = array(FALSE);

Sunday, January 3, 2016

Untrack *.pyc binary files from git

git update-index should do what you want

This will tell git you want to start ignoring the changes to the file

# git update-index --assume-unchanged path/to/file

When you want to start keeping track again

# git update-index --no-assume-unchanged path/to/file

Github Documentation: update-index


# git rm -r --cached path/to/file


Saturday, January 2, 2016

Install PHP 7 Nightly Built on CentOS 7

Install PHP 7 Nightly Built on CentOS 7

Add a new repository:

# vim /etc/yum.repos.d/php7-nightly.repo

name = PHP7 nightly by Zend Technologies
baseurl =

Note: the default installation path will be: /usr/local/php7

Install PHP 7 from the PHP official development repository:

# yum install php7-nightly

Copy the configuration files:

# cd /usr/local/php7/etc
# cp php-fpm.conf.default php-fpm.conf
# cp php-fpm.d/www.conf.default php-fpm.d/www.conf

# cd ~/tmp
# wget -O php-7.0.1.tar.xz
# tar Jxvf php-7.0.1.tar.xz
# cp ~/tmp/php-7.0.1/php.ini* /usr/local/php7/etc/
# cd /usr/local/php7/etc
# cp php.ini-development php.ini

Edit www.conf:

# vim /usr/local/php7/etc/php-fpm.d/www.conf

user = apache
group = apache

Edit php.ini:

# vim /usr/local/php7/etc/php.ini

Start php-fpm in background:

# /usr/local/php7/sbin/php-fpm -D

# ps auxww|grep php

root     43345  0.0  0.1 421576  7376 ?        Ss   Jan01   0:03 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
apache   43346  0.0  1.0 429736 42760 ?        S    Jan01   0:05 php-fpm: pool www
apache   43347  0.0  1.0 429924 42276 ?        S    Jan01   0:07 php-fpm: pool www
apache   44123  0.0  0.9 429388 37168 ?        S    Jan01   0:00 php-fpm: pool www

Friday, January 1, 2016

Call an external program from MySQL trigger

Call an external program from MySQL trigger

MySQL provides a way to implement your own functions, its called User Defined Functions (UDF)

sys_eval - executes an arbitrary command, and returns it's output.
sys_exec - executes an arbitrary command, and returns it's exit code.
sys_get - gets the value of an environment variable.
sys_set - create an environment variable, or update the value of an existing environment variable.