Sleep mode in Mac

MacOS X 的3種睡眠模式

    Sleep – 保持 RAM 的內容不變
    Safe Sleep – 保持 RAM 的內容不變,同時會將 RAM 的內容備份至硬碟
    Deep Sleep – 將 RAM 的內容儲存至硬碟

首先,要確定一下現在設定的是哪個睡眠模式,到 Terminal 輸入以下指令:
pmset -g | grep hibernatemode
它會給你一個像 “hibernatemode X” 的回應。而 X 會有幾個可能性:
0 (數字零,不是英文字母 o) – Sleep
1 – Deep Sleep
3 – Safe Sleep
如果需要變更的話,就到 Terminal 輸入以下指令:
sudo pmset -a hibernatemode X
X 則跟上面的一樣,0是 Sleep,1是 Deep Sleep,3是 Safe Sleep。更改後,下一次睡眠就會以剛設定的模式進行。


Setup multi version PHP on same server

LoadModule fastcgi_module /usr/local/Cellar/mod_fastcgi/2.4.6/libexec/

SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1

FastCgiExternalServer /Work/domains/cgi-bin/php54-fcgi -idle-timeout 60 -host -pass-header Authorization
AddHandler php54-fcgi .php
Action php54-fcgi /php54-fcgi
Alias /php54-fcgi /Work/domains/cgi-bin/php54-fcgi

FastCgiExternalServer /Work/domains/cgi-bin/php55-fcgi -idle-timeout 60 -host -pass-header Authorization
# AddHandler php55-fcgi .php
Action php55-fcgi /php55-fcgi
Alias /php55-fcgi /Work/domains/cgi-bin/php55-fcgi

FastCgiExternalServer /Work/domains/cgi-bin/php53-fcgi -idle-timeout 60 -host -pass-header Authorization
# AddHandler php53-fcgi .php
Action php53-fcgi /php53-fcgi
Alias /php53-fcgi /Work/domains/cgi-bin/php53-fcgi

RHEL 6/ CentOS 6: Slow SSH logins with DNS timeouts

If you’re experiencing slow logins via SSH on a Red Hat Enterprise 6 or CentOS 6 system, it’s probably caused by DNS that is taking too long to respond. Even with correct nameservers in /etc/resolv.conf, you may still find yourself stuck with slow logins.

The solution is to add the following line to your /etc/resolv.conf. Just add it all the way at the bottom, as the last line.

options single-request-reopen

That should fix your slow SSH logins, given you have valid and fast-responding nameservers in your /etc/resolv.conf.

SSH tunneling for proxy

ssh -f -L -N

The -f tells ssh to go into the background just before it executes the command. This is followed by the username and server you are logging into. The -L is in the form of -L local-port:host:remote-port. Finally the -N instructs OpenSSH to not execute a command on the remote system.

This essentially forwards the local port 2000 to port 25 on over, with nice benefit of being encrypted. I then simply point my E-mail client to use localhost:2000 as the SMTP server and we’re off to the races.

Self Sign Multiple Domain Cert

1. create the CA cert

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt

2. create client req csr

openssl genrsa -des3 -out server.key 2048

*edit the openssl.conf

uncomment “req_extensions = v3_req”

in [ v3_req ] add

subjectAltName = @alt_names

add the end of the file

[ alt_names ]
DNS.1 =
DNS.2 =

openssl req -new -key server.key -out server.csr

*create a config file “server.conf”

subjectAltName = @alt_names

[ alt_names ]

DNS.1 =
DNS.2 =
openssl x509 -req -days 365 -in server.csr -CA ca.crt  -CAkey ca.key -set_serial 01 -extfile server.conf -out server.crt

Symfony 2 can’t not write cache files

1. Using ACL on a system that supports chmod +a

Many systems allow you to use the “chmod +a” command. Try this first, and if you get an error – try the next method:

rm -rf app/cache/*
rm -rf app/logs/*

sudo chmod +a “www-data allow delete,write,append,file_inherit,directory_inherit” app/cache app/logs
sudo chmod +a “yourname allow delete,write,append,file_inherit,directory_inherit” app/cache app/logs

2. Using Acl on a system that does not support chmod +a

Some systems don’t support “chmod +a”, but do support another utility called “setfacl”. You may need to enable ACL support on your partition and install “setfacl “before using it (as is the case with Ubuntu), like so:

sudo setfacl -R -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:yourname:rwx app/cache app/logs

Git notes

delete branch remotely

to delete local/remote branch "newfeature":

git branch -d newfeature

git push origin :newfeature

export changed file of last commit to tar:
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD | xargs tar czvf last_commit.tar.gz

export changed file between two commit
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT tag1 tag2 | xargs tar czvf last_commit.tar.gz 

last commit deleted files
git diff-tree -r --no-commit-id --name-only --diff-filter=D HEAD