發生災難時,我們難保雲端主機不會整個掛掉,造成連SSH都無法的窘境,
這個時候只剩下唯一的方法來救資料,那就是建立新的雲端主機,對舊主機做Snapshot或images。以外接硬碟的形式掛載在新的雲端主機上,透過mount的方式來存取舊資料。
以下是相關的指令:

建立一個虛擬資料夾,以下名為mount_directory_name

sudo mkdir -p /mnt/disks/mount_directory_name

用來看外接硬碟的實際路徑,假設是/dev/sdb1

sudo lsblk

將實體路徑掛載在虛擬資料夾上

sudo mount -o discard,defaults /dev/sdb1 /mnt/disks/mount_directory_name

賦予所有使用者權限

sudo chmod a+w /mnt/disks/mount_directory_name

如果你剛好遇到mysql資料庫需要從檔案還原,可以參考以下的單一資料庫復原的方式:

sudo cp -rf /mnt/disks/mount_directory_name/var/lib/mysql/databaseName /var/lib/mysql/
sudo chown -R mysql:mysql /var/lib/mysql/databaseName
sudo chown -R 660 /var/lib/mysql/databaseName
sudo chown mysql:mysql /var/lib/mysql/databaseName
sudo chmod 700 /var/lib/mysql/databaseName

經常使用PHP mktime()的開發者在使用JavaScript new Date()的時候最常忘記的狀況就是 javascript的月份參數必須要 -1, 因為他的月份是從0開始代表1月份。


$year = 2018; $month = 05; $day = 31; $h = "09"; $i = "10"; $s = "00"; echo mktime($h,$i,$s,$month,$day,$year);

var year = 2018; var month = "05"; var day = 31; var h = "09"; var i = "10"; var s = "00"; console.log(new Date(year, month-1, day, h, i, s));

splice的功能是把array裡面的某個片段切割出來,
他跟pop有點像但能夠做到的比pop更多。
但很常見的錯誤是切割出來我們會以為回傳的是Object/String/Number,
其實他依然是array的型態。

所以若如果你從array分離出來,return的東西依然是array。
即使只有一個物件在裡面,你還是得用 index = 0 提取出來。
如下:

var myArray = ["a","b","c"];
var theOne = myArray.splice(0,1); //trying to get "a" out

console.log(theOne[0]); // still in Array format, so we need to use index to get it out

很多時候angularJS的便利性讓我們在開發網路應用程式變得非常方便,尤其是ng-repeat與ng-model,能夠讓我們瞬間更換頁面上面的資訊,不用再像傳統的jQuery的做法,必須要根據selector去一一更換。

即便如此,我們還是有需要使用到jQuery的時候,尤其是當Web Designer不熟悉angularJS時,他設計好的模板就只能支援jQuery(如Modal的功能)。

因此,讓兩者可以並存並且共同發揮其專長就變得很重要了。

假設我們寫了一個 angularJS的 function,$scope.loadCandidate(),需要在jQuery去呼叫他,方法如下:

//HTML
<div id="myCtrl" ng-app="myApp" ng-controller="myCtrl">
</div>
//AngularJS
var app = angular.module("myApp",[]);
app.controller("myCtrl", function($scope){
   $scope.loadSmt = function(){
     //do something
   }
});

//jQuery
function callMe(){
angular.element(document.querySelector('#myCtrl')).scope().loadSmt(); //強迫angularjs的function被執行
angular.element(document.querySelector('#myCtrl')).scope().$apply(); //記得下apply來觸發angularjs的【update】機制
}

 

如果你想備份在tmp資料夾

cd /tmp
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
  1. 設定crontab
sudo vi /etc/crontab
  1. 內容如下(假設每日的晚上23時59分進行備份):
59 23 * * * root /tmp/backupday.sh

資料庫備份匯出成.sql.gz

mysqldump -uroot -p [databasename] | gzip > [databasename].sql.gz

資料庫匯入 (Linux)  (要先解壓縮)

mysql -u [username] -p [database_name] < dumpfilename.sql

資料庫匯入 (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>