vscode-Bracket Pair Colorizer-有了彩色括號不再眼花惹

code多了會對很多的括號們也一定會眼花, 今天在這不是要賣你藥吃, 吃了會一目十行百行, 因為你不是神童, 今天要來說一款好用Bracket Pair Colorizer外掛套件, 不廢言, 來吧.



雖然星星數不多, 反正好用就好了XD


如果你的NB或PC效能比較慢, 你會發現這個效果不會主立馬出現, 所以看你嘍XD



收工!



好用的線上產生HTML碼的彩色的程式碼-hilite.me, 幹好繞口

自己打完標題都覺的不好念XD, 算了...沒差啦
這個還不錯用, 也不用再你的blog加一些有的沒的外掛, 掛久了你也都不記的到底你掛了哪些套件了, 真的是這樣子XD...

BJ4了

http://hilite.me/

EJS常用標簽

常用EJS標簽XD

<% %>流程控制標簽
//例
<% var user.name = 'bruce - huang' %>
<% if(user.name !== null) { %>
<div>hi <%= user.name %></div>
<% } else { %>
<div>no user name</div>
<% } %>

<%= %>输出標簽(原文输出HTML標簽)
//例
<% var user.name = 'bruce - huang' %>
<%= user.name %>

<%- %>输出標簽(HTML会被浏览器解析)
//例
<%- data.htmlContent %>


<%# %>注释標簽
//例
<%# 我是注解,我不會被秀在源始碼上 %>

-%>去掉沒用的空格
//例
<% var user.name = 'bruce - huang 看己去試吧, 我是不知道他怎知道什麼叫沒用的空格XD' %>
<%= user.name -%>

ejs中的邏輯代碼全部用JavaScript

好了, 收工!!

pm2, App name

官方文件是長這樣

pm2 start app.js           # Start app.js

pm2 start app.js -- -a 23  # Pass arguments '-a 23' argument to app.js script

pm2 start app.js --name serverone # Start a process and name it as serverone
                                    # you can now stop the process by doing
                                    # pm2 stop serverone
別名其實是很方便的東西...

按官方指示, 在實際上使用時, 你會發現....


參數搭配別名時會變成這樣..

原來是....別名在前, 參數在後

完工

node-telegram-bot-api, 建立你的telegram機器人

登入telegram-web or telegram app 後選

填入@botFather, 進行尋找

對, 就是它, telegram bot 的爸爸XD, 將它加入
@botFather加入後你會發現這個對話框

對, 沒錯, 它告訴你使用/newbot來建立你的機器人, 如下

好了, 我的cn27529bot機器人己有了XD

接下來, 跟它talk講話吧~在講話的前提下, 需要建立跟它溝通的API管道, 我們用nodejs來進行

先安裝要用的套件

裝好後, 建立一個bot.js, 然後填入

// 建立一個 Bot
var TelegramBot = require('node-telegram-bot-api');

const token = '這是你的機器人token';
const bot = new TelegramBot(token, { polling: true });

bot.onText(/\/start/, message => {

console.log(message); // for debug
const chatId = message.chat.id;
bot.sendMessage(chatId, 'Hello World');

});

bot.onText(/\/吃飯飯/, message => {

console.log(message); // for debug
const chatId = message.chat.id;
bot.sendMessage(chatId, '去你的飯飯');

});

然後啟動node bot.js, 然後回到telegram web 或 telegram app對話框中, 填入/start與/吃飯飯

看, 我跟我的機器人, 開始對話了XD

所有對話過程都會在console中列出


收工

https://telegram.me/cn27529bot




pm2, node的程序(進程)管理工具, 使用與教學

今天的東東叫pm2, pm2是node的一個可監控程序的工具, 不多廢, 進主題

進行全域安裝
workspace npm install pm2 -g                                                                                                                           
/home/cabox/.nvm/versions/node/v5.2.0/bin/pm2 -> /home/cabox/.nvm/versions/node/v5.2.0/lib/node_modules/pm2/bin/pm2                                       
/home/cabox/.nvm/versions/node/v5.2.0/bin/pm2-dev -> /home/cabox/.nvm/versions/node/v5.2.0/lib/node_modules/pm2/bin/pm2-dev                               
/home/cabox/.nvm/versions/node/v5.2.0/bin/pm2-docker -> /home/cabox/.nvm/versions/node/v5.2.0/lib/node_modules/pm2/bin/pm2-docker                         
/home/cabox/.nvm/versions/node/v5.2.0/bin/pm2-daemon -> /home/cabox/.nvm/versions/node/v5.2.0/lib/node_modules/pm2/bin/pm2-daemon                         
/home/cabox/.nvm/versions/node/v5.2.0/bin/pm2-runtime -> /home/cabox/.nvm/versions/node/v5.2.0/lib/node_modules/pm2/bin/pm2-runtime                       
/home/cabox/.nvm/versions/node/v5.2.0/lib                                                                                                                 
`-- pm2@2.5.0                                                                                                                                             
                                                                                                                                                          
npm WARN optional Skipping failed optional dependency /pm2/chokidar/fsevents:                                                                             
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2                                                                 
➜  workspace          
YA裝好了, 目前安裝的是2.5.0版本

如何使用它
進入到你的node app資夾, 一般情況下都是執行npm start啟動你的node app
start的內容多半是指定在package.json裡, 可以去看就道了, 如果你的啟動是index.js
那就是...
bk git:(master) pm2 start index.js                                                                                                                     
[PM2] Starting /home/cabox/workspace/bk/index.js in fork_mode (1 instance)                                                                                
[PM2] Done.                                                                                                                                               
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐                                                                  
 App name  id  mode  pid   status  restart  uptime  cpu  mem        watching                                                                   
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤                                                                  
 index     0   fork  9660  online  0        0s      0%   13.3 MB    disabled                                                                   
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘                                                                  
 Use `pm2 show ` to get more details about an app  
瞧, 有了! 這樣就開始被監控了, 然後你的app 也啟動了

也是可以將App name命名, 如
bk git:(master) pm2 start index.js --name myapp                                                                                                        
[PM2] Spawning PM2 daemon with pm2_home=/home/cabox/.pm2                                                                                                  
[PM2] PM2 Successfully daemonized                                                                                                                         
[PM2] Starting /home/cabox/workspace/bk/index.js in fork_mode (1 instance)                                                                                
[PM2] Done.                                                                                                                                               
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐                                                                 
 App name  id  mode  pid    status  restart  uptime  cpu  mem        watching                                                                  
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤                                                                 
 myapp     0   fork  10014  online  0        0s      0%   13.4 MB    disabled                                                                  
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘                                                                 
 Use `pm2 show ` to get more details about an app 
瞧, 有了! 己變成myapp, 然後你的app 也啟動了, 去看看吧
(app啟動無圖) XD

接下來看看監控的dashboard
bk git:(master) pm2 monit       
會出現下列
Process list ─────────────────────────────┐┌─ Global Logs ───────────────────────────────────────────────────────────────────────────────────────────┐ 
[ 0] myapp     Mem:  44 MB    CPU:  0 %  on │ myapp > Executing (default): SELECT `id`, `title`, `body`, `noteday`, `createdAt`, `updatedAt`,         │ 
                                            │ `ProfileId` FROM `Notes` AS `Note`;                                                                     │ 
                                            │ myapp > Executing (default): SELECT `id`, `email`, `password`, `createdAt`, `updatedAt` FROM            │ 
                                            │ `Accounts` AS `Account`;                                                                                │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
                                            │                                                                                                         │ 
└────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
┌─ Custom metrics (http://bit.ly/code-metric─┐┌─ Metadata ──────────────────────────────────────────────────────────────────────────────────────────────┐ 
│ Loop delay                         0.47ms  ││ App Name              myapp                                                                             │ 
│                                            ││ Restarts              0                                                                                 │ 
│                                            ││ Uptime                14m                                                                               │ 
│                                            ││ Script path           /home/cabox/workspace/bk/index.js                                                 │ 
│                                            ││ Script args           N/A                                                                               │ 
│                                            ││ Interpreter           node                                                                              │ 
│                                            ││ Interpreter args      N/A                                                                               │ 
│                                            ││ Exec mode             fork                                                                              │ 
│                                            ││ Node.js version       5.2.0                                                                             │ 
│                                            ││ watch & reload        ?                                                                                 │ 
└────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────────────────────────────────────────────────┘ 
瞧, 是不是, 監控畫面開啟了

如何停止它
workspace pm2 stop myapp                                                                                                                               
[PM2] Applying action stopProcessId on app [myapp](ids: 0)                                                                                                
[PM2] [myapp](0) ✓                                                                                                                                        
┌──────────┬────┬──────┬───────┬─────────┬─────────┬────────┬─────┬───────────┬──────────┐                                                                
 App name  id  mode  pid    status   restart  uptime  cpu  mem        watching                                                                 
├──────────┼────┼──────┼───────┼─────────┼─────────┼────────┼─────┼───────────┼──────────┤                                                                
 myapp     0   fork  0      stopped  0        0       0%   0 B        disabled                                                                 
 myapp2    1   fork  10826  online   0        2m      0%   24.2 MB    disabled                                                                 
└──────────┴────┴──────┴───────┴─────────┴─────────┴────────┴─────┴───────────┴──────────┘                                                                
 Use `pm2 show ` to get more details about an app                                 
瞧, myapp己停止了

如何刪除它
workspace pm2 delete myapp                                                                                                                             
[PM2] Applying action deleteProcessId on app [myapp](ids: 0)                                                                                              
[PM2] [myapp](0) ✓                                                                                                                                        
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐                                                                 
 App name  id  mode  pid    status  restart  uptime  cpu  mem        watching                                                                  
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤                                                                 
 myapp2    1   fork  10826  online  0        11m     0%   22.7 MB    disabled                                                                  
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘                                                                 
 Use `pm2 show ` to get more details about an app       
瞧, myapp己被刪了

不再用它時

好了, 關閉pm2的監控吧
bk git:(master) pm2 kill                                                                                                                               
[PM2] Stopping PM2...                                                                                                                                     
[PM2] Applying action deleteProcessId on app [all](ids: 0)                                                                                                
[PM2] [myapp](0) ✓                                                                                                                                        
[PM2] All processes have been stopped and deleted                                                                                                         
[PM2] PM2 stopped                                                 

workspace pm2 list                                                                                                                                     
[PM2] Spawning PM2 daemon with pm2_home=/home/cabox/.pm2                                                                                                  
[PM2] PM2 Successfully daemonized                                                                                                                         
┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────────┐                                                                         
 App name  id  mode  pid  status  restart  uptime  cpu  mem  watching                                                                          
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────────┘                                                                         
 Use `pm2 show ` to get more details about an app              
瞧, 己經沒有app被監控了

收工, 今天就介紹到這兒吧, 下次再做進階的應用, 881~