使用Javascript產生細胞廣播告警聲響

NCC規範

使用Javascript Code:

<script>
  function play(music,time){
    //參考http://www.csie.ntnu.edu.tw/~u91029/Audio.html
    var sampleRate   = 10000;
    var sampleNumber = music[0].length*10000*time;
    var ctx    = new AudioContext();
    var buffer = ctx.createBuffer(2, sampleNumber, sampleRate);


    //製作聲音資料
    var data0   = buffer.getChannelData(0); //第1聲道
    var data1   = buffer.getChannelData(1); //第2聲道
    for (var i = 0; i < sampleNumber; ++i){
      var index=Math.floor(i/(sampleRate*time));
      data0[i] = Math.sin((Math.PI * 2) * i * music[0][index] / sampleRate);
      data1[i] = Math.sin((Math.PI * 2) * i * music[1][index] / sampleRate);
    }

    // 製作節點、串連節點、播放聲音
    var node    = ctx.createBufferSource();
    node.buffer = buffer;
    node.connect(ctx.destination);
    node.start(0);
  }

  var __=0;
  var S960=960;
  var S853=853;
  var music=[[ 
    S960,S960,S960,S960,  //2秒
    __,                   //停頓0.5sec
    S960,S960,            //1秒
    __,                   //停頓0.5秒
    S960,S960,            //1秒
    __,                   //停頓0.5秒
    S960,S960,S960,S960,  //2秒
    __,                   //停頓0.5sec
    S960,S960,            //1秒
    __,                   //停頓0.5秒
    S960,S960             //1秒
  ],[                     
    S853,S853,S853,S853,  
    __,                   
    S853,S853,            
    __,                   
    S853,S853,            
    __,                   
    S853,S853,S853,S853,  
    __,                   
    S853,S853,            
    __,                   
    S853,S853             
  ]]; 
  play(music,0.5);/**/
</script>

Latent Semantic Analysis (LSA) 測試

參考下列幾個網址寫出來的code (for Matlab)
http://lsa.colorado.edu/papers/dp1.LSAintro.pdf
https://blog.csdn.net/pipisorry/article/details/42560331
https://read01.com/zh-tw/0zeKRM.html#.W7C8PhMzbKZ

C=[ [ 0,0,1,1,0,0,0,0,0 ];
    [ 0,0,0,0,0,1,0,0,1 ];
    [ 0,1,0,0,0,0,0,1,0 ];
    [ 0,0,0,0,0,0,1,0,1 ];
    [ 1,0,0,0,0,1,0,0,0 ];
    [ 1,1,1,1,1,1,1,1,1 ];
    [ 1,0,1,0,0,0,0,0,0 ];
    [ 0,0,0,0,0,0,1,0,1 ];
    [ 0,0,0,0,0,2,0,0,1 ];
    [ 1,0,1,0,0,0,0,1,0 ];
    [ 0,0,0,1,1,0,0,0,0 ]; ];

[w,s,p]=svd(C);

plot(-p(:,2),-p(:,3),'.')
hold on
plot(-w(:,2),-w(:,3),'.')


Label_1={'book';'dads';'dummies';'estate';'guide';'investing';'market';'real';'rich';'stock';'value'};
text(-w(:,2),-w(:,3),Label_1,'Color','red','FontSize',14);

Label_2={'T1';'T2';'T3';'T4';'T5';'T6';'T7';'T8';'T9';};
text(-p(:,2),-p(:,3),Label_2,'Color','blue','FontSize',14);
hold off

結果呈現如下:

raspberry pi 關閉7寸觸控螢幕的方法

關閉:

sudo sh -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'

開啟:

sudo sh -c 'echo 0 > /sys/class/backlight/rpi_backlight/bl_power'

切換:

if [ "$(cat /sys/class/backlight/rpi_backlight/bl_power)" -eq "0" ]; then \
  sudo sh -c "echo 1 > /sys/class/backlight/rpi_backlight/bl_power"; \
else \
  sudo sh -c "echo 0 > /sys/class/backlight/rpi_backlight/bl_power"; fi

mongDB帳號設定

參考下列指令:

# 環境準備
docker rm -f mongodb_mongo_1
rm -r -f $PWD/db
mkdir -p $PWD/db

# 建立mongoDB
docker run \
  -d \
  --name mongodb_mongo_1 \
  -p 27017:27017 \
  -v $PWD/db:/data/db \
  mongo
sleep 5

# 建立超級管理者
docker exec -it mongodb_mongo_1 bash
mongo admin
db.createUser({ user: "admin" , pwd: "admin1234", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})
quit()
# 重新登入
mongo admin
db.auth("admin","admin1234")
use octblog
db.createUser({
    user: "gevin",
    pwd: "gevin1234",
    roles: [ { role: "readWrite", db: "octblog" },
             { role: "readWrite", db: "octblog-log" } ]
})
quit()

mongo octblog
db.auth("gevin","gevin1234")
use octblog
db.collection.insert({'test':1234});
quit()
exit

# 重啟mongoDB
docker rm -f mongodb_mongo_1
docker run \
  -d \
  --name mongodb_mongo_1 \
  -p 27017:27017 \
  -v $PWD/db:/data/db \
  mongo mongod --auth

重新產生k8s join指令

因為新版的k8s的token已經有時間效期,
所以在安裝完後,隔一陣子想要加入新的節點就會出現舊的join token無法使用.
這時候可以用kubeadm token generate重新產生新的token,並用下列語法印出join指令.

kubeadm token create `kubeadm token generate` --print-join-command --ttl=0

以helm在k8s上部署mariaDB

環境變數:

PASSWORD="1234567890"
NAME="db"
SERVICE="${NAME}-mariadb"
NAMESPACE="default"

儲存裝置為nfs

helm install \
  --namespace ${NAMESPACE} \
  --name ${NAME} stable/mariadb \
  --set slave.replicas=3 \
  --set rootUser.password=replicator \
  --set replication.user="${PASSWORD}" \
  --set replication.password="${PASSWORD}" \
  --set master.persistence.storageClass=managed-nfs-storage \
  --set slave.persistence.storageClass=managed-nfs-storage

參數參考

允許root@%登入(注意:密碼不能隨意變動)

kubectl exec -it -n ${NAMESPACE} ${SERVICE}-master-0 -- mysql -uroot -p${PASSWORD} -e "grant all privileges on *.* to 'root' @'%' identified by '${PASSWORD}'; FLUSH PRIVILEGES;"

變更密碼正確方式:

NEW_PASSWORD="0987654321"
PASSWORD=$(kubectl get secret -n ${NAMESPACE} ${SERVICE} -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
echo "Password: ${PASSWORD}"
helm upgrade ${NAME} stable/mariadb --set rootUser.password=${NEW_PASSWORD}

MongoDB Replica Set高可用性的建置

  1. 建立三個MongoDB
echo "[info] 建立測試環境";
docker network create mongo-cluster >/dev/null 2>&1
docker rm -f mongo1 mongo2 mongo3 >/dev/null 2>&1
for i in 1 2 3
do
  echo "       mongo${i} 建立"
  docker run \
    -d \
    -p 3000$i:27017 \
    --name mongo$i \
    --net mongo-cluster \
    mongo mongod --replSet my-mongo-set >/dev/null 2>&1
done
  1. 接著設定三者關係,並強制設定electionTimeoutMillis為500ms.
echo "       設定mongo cluster"
docker exec -it mongo3 mongo --eval "config={\"_id\":\"my-mongo-set\",\"members\":[{\"_id\":0,\"host\":\"mongo1:27017\"},{\"_id\":1,\"host\":\"mongo2:27017\"},{\"_id\":2,\"host\":\"mongo3:27017\"}],\"settings\": { \"electionTimeoutMillis\": 500 }}; rs.initiate(config)"
  1. PHP測試
#https://github.com/mongodb/mongo-php-library
require_once __DIR__ . "/vendor/autoload.php";

try{
  $client = new MongoDB\Client("mongodb://mongo1:27017,mongo2:27017,mongo3:27017",[],[
    'typeMap' => [
      'array' => 'array',
      'document' => 'array',
      'root' => 'array',
    ],
  ]);
  $db = $client->selectDatabase('test');
  $cursor = $db->command(['isMaster' => 1]);
  echo "[info] 成功連線至: {$cursor->toArray()[0]['primary']}\n";

} catch(Exception $e) {
  echo "[error] 無法線連\n";
  exit;
}

{  //若Collection:testA不存在則建立.
  if((iterator_count($db->listCollections([
    'filter'=>[
      'name'=>'testA'
    ]
  ])))==0) //當數量為0時,建立testA
    $db->createCollection('testA');
}

//連線至Collection:testA
$collection=$db->selectCollection('testA');

//若沒有任何資料,則建立100則隨機資料
if($collection->count()==0){
  for($i=0;$i<100;$i++){
    $insertOneResult = $collection->insertOne([
      'idx' => $i,
      'value' => "{$i}, rand: ".rand(0,9999),
    ]);
  }
}

//取得最後三筆資料
foreach($collection->find([],[
  'limit' => 3,
  'projection' => ['_id'=>0],
  'sort' => [
    'idx'=>-1
  ]
]) as $rs){
  echo "\tidx:{$rs['idx']}\tvalue:{$rs['value']}\n";
}