LinkShare_468x60v1

Tuesday, December 29, 2015

How to rewrite outgoing email address

When we call mail function by php on Linux , we can use postfix.

However, the sender will be always apache or www-data, since the system use default web user name as the sender name.

We can rewrite email of the sender by steps below.

Step 1

Check configuration in php.ini

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
;sendmail_from = ***@yourdomain.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =\r



Step 2

Edit main.cf for postfix

vi /etc/postfix/main.cf



Step 3

Specify the generic map file in main.cf

smtp_generic_maps = hash:/etc/postfix/generic



Step 4

Edit generic file

vi /etc/postfix/generic


Step 5

Specify the mapping address

[email protected]   [email protected]


Step 6

Create postfix db hash file

postmap /etc/postfix/generic


Step 7

Restart postfix

/etc/init.d/postfix restart



You will need use sender_canonical_maps = hash:/etc/postfix/canonical instead if your postfix is earlier version.






Wednesday, September 9, 2015

How to check array in jQuery


var dataarray = ["1", "2", "3"];

if ( $.inArray('1', dataarray) > -1 ) {

alert("checked");

}

How to clone a git branch


Create a new local branch develop and clone from remote branch origin/develop


git checkout -b develop origin/develop


How to list branches

list local branch

git branch

List remote branch

git branch -r

List all branch

git branch -a


How to switch between branch master and develop

git checkout master

git checkout develop


How to copy files/dictionaries from branch develop

git checkout develop  files/*

Monday, August 24, 2015

How to remove function from a jQuery object


The function can be removed from a previously-attached event handler.

eg. Remove submit function from a form element.

$('form[name="formname"]').unbind('submit');

Tuesday, July 28, 2015

Thursday, July 23, 2015

How to Stop Your Mac Book Pro From Freezing with Keyboard & Trackpad Unresponsive


If you can still toggle caps lock and it dones't freeze in safe mode, you can backup and remove the directory below.

/System/Library/Extenstions/AppleIntelHD5000Graphics.kext


Tuesday, March 24, 2015

How to use Replace & ReplaceAll in Java

Replace character

String newstring = str1.replace("-",",");


Replace string

String newstring = str1.replaceAll("[a-z]","0");


Replace string only for first match

String newstring = str1.replaceFirst("[a-z]","0");