2017年3月14日 星期二

how to build multi 443 port of web server in apache


//增加紅字設定才可以提供多個443 port of web server
$ sudo vi /etc/apache2/ports.conf

<IfModule mod_ssl.c>
    NameVirtualHost *:443
    Listen 443
</IfModule>


參考連結:

  1. http://serverfault.com/questions/399616/default-virtualhost-overlap-on-port-443-the-first-has-precedence

2016年10月25日 星期二

stored-function and stored-prcedure

註解
範例(黑字,青藍底):procedure and function的命名
範例(黑字,橘底):帶入參數
範例(紅字,白底):內部使用變數
範例(白字,黑底):如何執行範例



補充說明 - 常用方式解釋:

#宣告變數方式:
DECLARE 變數名稱 資料型態;
ex: DECLARE var1 INT;

#判斷式:
IF 判斷條件1 THEN
ELSEIF 判斷條件2 THEN
ELSE
END IF;
ex:
IF var1=1 THEN
  SET result=1
ELSEIF var1=2 THEN
  SET result=2
ELSE
  SET result=3
END IF;

#while:
WHILE 條件1 DO
END WHILE;
ex:
SET result = 'NO';
WHILE 1 < 2 DO
  SET result = 'YES';
END WHILE;



Stored-procedure

#取得BonusGame每日登入-開始時間

DROP PROCEDURE IF EXISTS  `stored-procedure-example`;
DELIMITER ;;
CREATE PROCEDURE `stored-procedure-example`(
IN id INT,
OUT outResult INT)
BEGIN

SET outResult= id;

END;;
DELIMITER ;

call spGetBonusGame_DailyLogin_User(411, @result);
select @result;



Stored-function

DROP FUNCTION IF EXISTS `stored-function-exmaple`;
DELIMITER $$
CREATE FUNCTION `stored-function-exmaple`
(
    id INT,
    created_at DATETIME
)
RETURNS DATETIME

BEGIN
    DECLARE outDatetime DATETIME;

    SELECT DATE_ADD(created_at,INTERVAL id MINUTE) INTO outDatetime;
    RETURN outDatetime;

END;
$$

DELIMITER ;


SELECT *, stored-function-exmaple(id, created_at) FROM TEST-TABLE;





相關連結:

  1. http://forum.slime.com.tw/thread222603.html
  2. http://www.codedata.com.tw/database/mysql-tutorial-13-stored-routines/

2016年7月12日 星期二

How to build Server Flask(Framework) Applications, uWsgi and nginx on CentOS 7

首先可參考此連結步驟
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7

you might meet some problems.
connect() to unix:myproject.sock failed (13: Permission denied) while connecting to upstream

you can using below command.
$ sudo ~/
$ sudo grep nginx /var/log/audit/audit.log | audit2allow -M nginx
$ sudo semodule -i nginx.pp

$ setenforce 1 //開啟
$ setenforce 0 //關閉

2016年6月14日 星期二

How to install mono on ubuntu(it can using C# and asp on ubuntu)

ubuntu 14.04

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install -y mono-complete
$ sudo apt-get install -y monodevelop
$ sudo apt-get install -y mono-xsp4



影片教學:


  1. https://www.youtube.com/watch?v=5akYkyo0g3s
  2. https://www.youtube.com/watch?v=yV5itt-G66o

2016年6月1日 星期三

bash shell keyboard-shortcuts


本文參考網址:
  1. https://blog.longwin.com.tw/2006/09/bash_hot_key_2006/
  2. http://blog.codylab.com/bash-shell-shortcut/

  • Alt-F: 到此行的後一個字
  • Alt-B: 到此行的前一個字
  • Ctrl-A: 回到此行最前面
  • Ctrl-E: 到此行的最後面
  • Ctrl-U: 清除一行中游標之前的所有文字
  • Ctrl-K: 清除一行字游標之後的所有文字
  • Ctrl-Z: 將該工作放到背景中暫停, 使用jobs看工作號碼(job number), fg 取回

2016年5月26日 星期四

SQL Command Line Interface(CLI)

//show tables index, unique
SHOW INDEX FROM [table];

//show table sehema
SHOW COLUMNS FROM [table];


// show foreign
 SELECT
  ke.referenced_table_name parent,
  ke.table_name child,
  ke.constraint_name
FROM
  information_schema.KEY_COLUMN_USAGE ke
WHERE
  ke.referenced_table_name IS NOT NULL;

2016年5月23日 星期一

2016年5月9日 星期一

[FB][分享]javascript sdk

參考網址:

  1. https://dotblogs.com.tw/suehilary/2012/02/08/68441
  2. [登入] https://developers.facebook.com/docs/javascript/examples#login
  3. [javascript sdk] https://developers.facebook.com/docs/javascript/examples

javascript範例:


//判斷是否登入中
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback3(response);
});
}

// 判斷登入狀態
function statusChangeCallback3(response) {
console.log('statusChangeCallback');
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
api_me(response);
// console.log(response);
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
console.log('not_authorized');
// document.getElementById('status').innerHTML = 'Please log ' + 'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
console.log('else');
// document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.';
}
}

// 登入中取得資訊後,像後端傳送資料
function api_me(login_status) {
var access_token = login_status.authResponse.accessToken;
FB.ui({
method: 'feed',
name: '分享標題',
link: 'https://google.com',//分享連結
picture: 'https://google.com',//分享圖片
caption: '分享資訊',
description: '分享資訊'
}, function(response) {
if (response && response.post_id) {
var post_id = response.post_id;
FB.api('/me?fields=email,name,first_name,last_name', function(response) {
email = response.email || "";
$.ajax({
url: "", //後台api
dataType: 'json',
method: 'POST',
data: {
'post_id' : post_id,
'name' : response.name,
'account' : response.id,
'email': email,
},
success: function(result) {
console.log(result);
if (result.status=='ok') {
alert('已完成');
} else {
alert('請與客服聯絡');
}
},
error: function(err) {
console.log(err);
alert('發生錯誤');
}
});
});
} else {
alert('Post was not published.');
}
});
}

nginx和centos php設定

nginx file:

fastcgi_pass unix:/var/run/php5-fpm.sock;

change to

fastcgi_pass 127.0.0.1:9000;

2016年4月27日 星期三

Multiple SSH Keys settings for different key with same host

由於連線位置都是155.100.xxx.xxx,但是key不同會產生,第二個相同git無法抓取到資料問題。
所以需要在~/.ssh/config動手腳。

原先:

$ vi ~/.ssh/config
Host 155.100.xxx.xxx
        Hostname 155.100.xxx.xxx
        User ex1_user
        IdentityFile ~/.ssh/ex1.pem

Host 155.100.xxx.xxx
        Hostname 155.100.xxx.xxx
        User ex1_user
        IdentityFile ~/.ssh/ex2.pem


$ git clone ex1@155.100.xxx.xxx:proj_1
success

$ git clone ex1@155.100.xxx.xxx:proj_2
Cloning into 'fs/server/warinode'...
FATAL: R any fs/server/warinode fttwsmt DENIED by fallthru
(or you mis-spelled the reponame)
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

會發現第二個無法正常clone




修改後:

下方紅色字體為增加內容。

$ sudo chmod 400 ~/.ssh/ex1.pem
$ sudo chmod 400 ~/.ssh/ex2.pem

$ vi ~/.ssh/config
Host ex1 155.100.xxx.xxx
        Hostname 155.100.xxx.xxx
        User ex1_user
        IdentityFile ~/.ssh/ex1.pem

Host ex2 155.100.xxx.xxx
        Hostname 155.100.xxx.xxx
        User ex1_user
        IdentityFile ~/.ssh/ex2.pem


$ git clone ex1@ex1:proj_1
success

$ git clone ex1@ex2:proj_2
success

2016年4月13日 星期三

linux port - make sock


error:
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:port
 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:port
no listening sockets available, shutting down
Unable to open logs


解決方法:
$ sudo setenforce 0

2016年3月24日 星期四

redis type 型態對照

reids type

set :
create -> SADD
get -> SMEMBERS


string :
create -> MSET, SET
get -> MGET, GET

zset :
create -> ZSET
get -> ZRANGE

hash :
create -> HMSET
get -> HGET