1. cd /tmp
2. vi backupday.sh
內容如下:


#!/bin/bash
basedir=/tmp/backup/
PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH
export LANG=C
basefile1=$basedir/[檔案名稱].sql.gz
[ ! -d "$basedir" ] && mkdir $basedir
mysqldump -u[資料庫使用者名稱] -p[資料庫使用者密碼] [資料庫名稱] | gzip > $basefile1

3. 設定crontab

sudo vi /etc/crontab

4. 內容如下(假設每日的晚上23時59分進行備份):

59 23 * * * root /tmp/backupday.sh

資料庫備份匯出成.sql.gz
mysqldump -uroot -p [databasename] | gzip > [databasename].sql.gz

資料庫匯入 (Linux)
gunzip < [databasename].sql.gz | mysql -uroot -p [databasename]

資料庫匯入 (Mac)
gunzip < [databasename].sql.gz | /usr/local/mysql/bin/mysql -uroot -p [databasename]

從本機上傳資料到遠端主機
scp -P [port] [yourfilename].tar.gz username@foo.com:/path/to/

從遠端主機下載資料到本機
scp username@foo.com:/path/to/[yourfilename].sql.gz /yourlocal/path/to/

資料打包壓縮
tar -zcvf [yourfilename].tar.gz [yourfoldername]

資料解壓縮
tar -zxvf [yourfilename].tar.gz

install PHP DLL first:

https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx

CodeIgnitor: 2.2
SQL SERVER: SQL SERVER 2008 R2
PHP: 5.4
Web Server: Apache


/application/config/database.php
$db['default']['hostname'] = '.\SQLEXPRESS';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'XXXXXXX';
$db['default']['database'] = 'YYYYYYY';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

//system/database/drivers/sqlsrv/sqlsrv_driver.php
LINE 121 – 124

function db_select()
{
return $this->_execute('USE [' . $this->database.']');
}

//application/models/brand_model.php (testing model)

class Brand_model extends CI_Model {
private $table_name = "";

public function __construct() {
$this->load->database();
$this->table_name = "[Brand]";
}

public function get(){

$query = $this->db->get($this->table_name);
return $query->result_array();

}

}

As a newbie of Rails, we might need to try this web application on AWS server, especially AWS providing Free tier Server for us. I use t2.micro as a testing server in this scenario.

Step One—Install Ruby
1. sudo yum install ruby (in my server, ruby is already installed, you may check by using this command)

Install necessary packages and libraries
2. sudo yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel

3. sudo yum install ruby-rdoc ruby-devel

Step Two—Install Ruby Gems
4. sudo yum install rubygems

Step Three—Install Rails
5. sudo gem update

6. sudo gem update –system

7. sudo gem install rails

Step 8 lacking repositories
8. gem install io-console
9. gem install json
10. sudo yum install nodejs npm –enablerepo=epel

Step 9 remember to open port 3000 from AWS security Group

Step 10 Try to create a blog web application
11. cd /home/ec2-user
12. rails new blog
13. cd blog

Step 11 Start the server!
14. rails server

Step 12 Open your browser and take a look
15 http://x.x.x.x:3000

 

15. cd /home/ec2-user/blog

16. vi Gemfile

17. add "gem ‘io-console’" at the top of the file, so that you can execute "rails generate controller welcome index"

Offical Website: http://www.shadowbox-js.com/index.html

sometimes we might need to decide what images need to be played instead of using

<a href="..." rel="shadowbox[Vacation]"><img src="..."/></a>

This is how we can do to create an Array to store all the object

<a id="item_img" href="javascript:;">Click me to play ShadowBox</a>

<a href="{original_img_link}" class="sbox"><img src="{thumb_img_link}"/></a>
<a href="{original_img_link}" class="sbox"><img src="{thumb_img_link}"/></a>
<a href="{original_img_link}" class="sbox"><img src="{thumb_img_link}"/></a>
<a href="{original_img_link}" class="sbox"><img src="{thumb_img_link}"/></a>
<a href="{original_img_link}" class="sbox"><img src="{thumb_img_link}"/></a>

<script>
//the array list going to be played
var play_array = [];

//we use jquery to insert the url into the list
$("a.sbox").each(function(index, element) {
		play_array.push({
			content:    element.href,
        	        player:     "img",
			title:	   element.title,
		});
});

Shadowbox.init({
		handleOversize: "resize",
		continuous: true,
		modal: false,
		skipSetup: true,
		counterType: "skip"
});

Shadowbox.setup("a.sbox", {
		gallery:        "sbox",
		continuous:     true,
		counterType:    "skip"
});

$("#item_img").click(function(){
    Shadowbox.open(play_array);
});

</script>

1. How to UNDO git merge?

git reset --hard HEAD~1 #HEAD~2是UNDO兩步的一次, --soft 不會刪掉原本修改過的部分, --hard會直接刪掉已修改的部分

2. 如果我發現我不小心git merge了, 而且還push到了遠端, 我要怎麼辦?

git reset --hard HEAD~1 # 這個指令會讓你的狀態回到還沒MERGE的狀態
git push -f origin local/origin # 這個指令是迫使遠端的狀態跟我本機端的一樣

3. 希望將本機的BRANCH 還原得跟遠端一模一樣 (小心使用)

git fetch --all
git reset --hard origin/master #master代表 branch的名稱

pecl_http is required for the php function: http_build_url()
in order to use this function, we need to install the package manually,
below is the steps that required to install on your centOS server.

1. Install PHP Pear if not installed yet:
yum install php-pear

2. Install GCC if not installed yet:
yum install gcc

3. Install cURL if not installed yet:
yum install curl-devel

4. Install following library if not installed yet:
yum install php-devel
yum install zlib-devel
yum install pcre-devel

5. Start the main installation (use default value for answering installation)
As version 1.* is largely different with version 2.*, so we suggest install 1.7.6
/usr/bin/pecl install pecl_http-1.7.6

6. Add the following line to /etc/php.ini file
extension=http.so

7. restart apache server so the extension can be loaded
service httpd restart

——

遇到磁碟空間不足時, 我們常常需要找出罪魁禍首, 所以需要知道哪個目錄快滿了(或已經滿了).
1. 磁碟空間的百分比
df -h
可以看到每個磁碟空間的百分比

2. 找出指定目錄下10大檔案 (這樣我們才知道要從何刪起)
du -a /var | sort -n -r | head -n 10
參考: http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/

3. 其他du的用法:
參考: http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/