ALTER TABLE table_name ADD UNIQUE INDEX(column1, column2);
Take apache for example:
Disable - update-rc.d -f apache2 remove
Enable - update-rc.d apache2 defaults
If you use Amazon RDS, especially micro plan,
remember to set $config['pconnect'] = FALSE in application/config/database.php.
Because RDS has Max_connection limits.
If you use RDS, remeber that the system timezone in RDS is +0 timezone.
In your application, you should care about this thing.
If you will use loadbalancer, remember to ….(???)
將 query 出來的多筆記錄結合成一個欄位
例如原本的 query 結果為:
SELECT 'fruits' FROM 'fruits_table'
apple
banana
kiwi
SELECT group_concat('fruits' separator ',') FROM 'fruits_table'
result: apple,banana,kiwi
改變 datetime 欄位的顯示結果
SELECT DATE_FORMAT( 'created_at', '%Y/%m/%d %H:%i') AS 'created_at' FROM 'message_table'
result: 2014/05/06 18:20
若某個欄位的值為空,則給予預設值
SELECT ifnull('is_success', 0) AS 'is_success' FROM ....
Easy way:
Below the single command line to compiling and install the last openssl version. $ curl https://www.openssl.org/source/openssl-1.0.1h.tar.gz | tar xz && cd openssl-1.0.1h && sudo ./config && sudo make && sudo make install Replace old openssl binary file by the new one via a symlink. $ sudo ln -sf /usr/local/ssl/bin/openssl `which openssl` how to check version:
$ openssl version -b built on: Mon Apr 7 20:33:29 UTC 2014 $ openssl version -a OpenSSL 1.
Normal json string:
{"Hey":"There"} Error json string got from $_POST variable:
{\"Hey\":\"There\"} This may causes by magic_quotes in php.ini Magic is never good in development.
Ruby:
~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Ruby/Ruby.sublime-build
{ "env":{ "PATH":"${HOME}/.rvm/bin:${PATH}" }, "cmd": ["rvm-auto-ruby", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.ruby" } http://rubenlaguna.com/wp/2012/12/07/sublime-text-2-rvm-rspec-take-2/
According to rails convention,
PUT is used for updating an existing resource
POST is used for creating a new resource
In rails 4, PUT has been changed to PATCH to avoid confusion.
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"} POST /posts(.:format) {:action=>"create", :controller=>"posts"} new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"} edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"} post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"} PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"} DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"} 延伸閱讀:ihower - HTTP Verbs: 談 POST, PUT 和 PATCH 的應用
Add swap for an instance
$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 $ sudo /sbin/mkswap /var/swap.1 $ sudo /sbin/swapon /var/swap.1 $ echo "/var/swap.1 swap swap defaults 0 0" >> /etc/fstab #將 swap 加入 開機啟動 在 Amazon EC2 micro plan,加入 swap 很容易 I/O 過量, 因此最好是需要時才開啟 swap,不用時關閉 swap 以免被收錢~
swap usage
$ swapon -s $ free -k --- $ swapoff -a $ swapon -a