發表文章

[工具] 前端 excel - Handsontable

Ref :  https://handsontable.com/ 最近有需要在網頁上用到類似 excel 的功能 於是使用 Handsontable 這個套件 這個套件有分 CE 跟 Pro 版本 CE也就是 Community Edition, 通常是免費的 Pro 則是有額外強大的功能, 要收費的 這邊就簡單筆記一下我用到的部分 (CE) <!-- 需要一個裝 handsontable 的容器 --> <div id="handsome-table"> <button class="btn btn-success pull-right" id="export-btn">匯出EXCEL</button> 底下是 js 的部分 // 定義好欄位名稱 const COL_HEADER = [ 'Permalink', '觸及', '點擊', '點擊率', '負評', '負評率' ]; let container = document.getElementById('handsome-table'); // 裝 handsontable 的 data array // handsontable 是直接操控 data, 也就是 data-binding // 這個到後面很好用 let data = []; // 定義匯出 handsontable 的按鈕 let $exportBtn = $('#export-btn'); // 初始化 handsontable let hot = new Handsontable(container, { data: data, // 定義資料的 schema, 讓資料不要只是用陣列呈現, 而是物件 dataSchema: { permalink: null, impression: null, click: null, clickRate: ...

[Linux] Linux 流量監測工具 - iftop

Ref: https://www.tecmint.com/iftop-linux-network-bandwidth-monitoring-tool/ https://www.adamfei.com/iftop-linux-traffic-monitoring-tool-most-comprehensive-iftop-tutorial/ https://blog.gtwang.org/linux/iftop-linux-network-traffic-monitor/ 不得不說 iftop 真的非常好用 安裝 # 在CentOS/RedHat中需要安裝epel-release yum install epel-release yum install iftop apt-get install iftop # 假設系統太老舊無法使用yum/apt安裝的話可以自己編譯 yum install flex byacc libpcap ncurses ncurses-devel libpcap-devel # Debian系列的使用以下 apt-get install flex byacc libpcap0.8 libncurses5 wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz tar zxvf iftop-0.17.tar.gz cd iftop-0.17 ./configure make && make install 常用方法: # 把 ip, port 都顯示出來 iftop -P # 指定網卡, 如果一開始使用iftop會跑出 # pcap_open_live That device is not up 這種訊息 # 就可以使用指定網卡這招 iftop -i eth0 TX:發送流量 RX:接收流量 TOTAL:總流量 Cumm:執行 iftop 到目前時間的總流量 peak:流量峰值 rates:分別表示過去 2s 10s 40s 的平均流量 常用的參數 -i 設定監測的網卡,如:# iftop -i eth1 -B 以 bytes 為單位顯示流量(預設是 bits),如:# iftop -...

[MySQL] 建資料庫小基礎 (2020.06.14)

產生一個 mysql user 給 test 資料庫 並且先綁定 user 只能從 localhost 再改為可以從任何地方 # 建立 test 資料庫 CREATE DATABSES test; # 給 user@localhost 有 test 資料庫所有的權限, 並設置密碼 GRANT ALL privileges on test.* to user@'%'identified by 'your_password'; # 刷新權限 flush privileges; # 將 user@localhost 改為 user@% RENAME USER 'user'@'localhost' TO 'user'@'%'; 如果要讓資料庫是可以允許從其他主機連線 可以去 /etc/mysql/conf.d/mysqld.conf 將 bind-address = 127.0.0.1 換成你想要的ip 同時建議設定防火牆 允許 ip 範圍 # ufw allow from 192.168.2.0/24 允許特定 ip # ufw allow from 192.168.2.235 預設規則都是拒絕 # ufw default deny

[PHP] 在CentOS 5 上手動安裝 php-redis

Ref:  http://www.weinidai.com/index.php/News/detail/id/114 Ref: 直接用 php -i 看 phpinfo() 的內容 Ref: php-redis使用方法 Ref: phpredis 安裝 由於工作所需, 需要在 CentOS 5, PHP 5.3.9 的版本安裝 Redis 套件 本來想找 phpize 自己弄, 後來發現還好從 5.3.9 就有 pecl 公司的這台PHP是由大陸工程師安裝 所以路徑是位於 /usr/local/php 在裡面找到有 phpize, pecl 但是無法直接使用 console 去使用 所以先讓指令可以直接從 console 上用 ln -s /usr/local/php/bin/phpize /usr/bin ln -s /usr/local/php/bin/pecl /usr/bin 這樣就可以直接使用 pecl install redis 來完成安裝 安裝完之後要設定php.ini 所以我一開始是直接找 /usr/local/php/php.ini編輯 但是後來發現, console 用的 php 並不是這個位置 使用 php --ini 去找出 console 用的 php 到底是用哪個 php.ini 檔 之後在最底下新增 [Redis] extension = "redis.so" 這樣就完成在沒辦法使用 os 本身的 package manager 下安裝套件的艱鉅任務了

[Linux] 在CentOS5上面建立redis

當需要自己手動make redis的時候 連到 https://redis.io/download wget http://download.redis.io/releases/redis-4.0.11.tar.gz tar zxfv redis-4.0.11.tar.gz cd redis-4.0.11 如果tcl版本沒有到8.5, 在 make test 的時候會出錯 這時候就直接用以下三個指令, 不要 make test make clearn make make install 這時候基本上就已經裝好redis server了 在 /usr/local/bin/redis-server 這時候要先在建立存放 redis.conf 的地方 mkdir -p /etc/redis cd /etc/redis && wget http://download.redis.io/redis-stable/redis.conf 接著把 redis 做成系統服務: # redis script 的內容如下 # nohup 是讓程式不因離開 ssh 而中斷, &是放入背景執行 vi /etc/init.d/redis touch /var/log/redis.log chkconfig --add redis chkconfig redis on # 啟動/停止 redis /etc/init.d/redis start /etc/init.d/redis stop Ref:  https://www.linode.com/docs/databases/redis/redis-on-centos-5/ !/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis_6379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Descriptio...

[Node.js] Sequelize 小常識 (不定時更新這篇)

圖片
一般使用 sequelize-cli 前, 必須先執行下列指令做初始化 sequelize init --force 要建立model: sequelize model:generate --name User --attributes name:string,nickname:string,age:integer # 會自動產生 createdAt 與 updateAt 的欄位 # 如果是想要產生 created_at, updated_at 的欄位的話 # 可以加入 --underscored 這個參數 sequelize model:generate --name User --attributes name:string,nickname:string,age:integer --underscored 如果需要預設語系是utf8mb4 需要自己修改套件 vim /usr/local/lib/node_modules/sequelize-cli/lib/commands/database.js # 莫約第38行 # `` 為es6 的 string template 的功能, 超實用 `CREATE DATABASE ${sequelize.getQueryInterface().quoteIdentifier(config.database)} DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_general_ci` 之後下  sequelize db:create 就會直接是 utf8mb4 的語系囉 要像 Laravel 這樣可以去addColumn怎使用? ref:  https://stackoverflow.com/questions/46357533/how-to-add-delete-new-columns-in-sequelize-cli https://sequelize.readthedocs.io/en/latest/docs/migrations/ // 使用此指令建立 migration sequelize migration:create --name name_of_your_migration // 產生範例...

[Nginx] 在 abc.com/abc/def.htm 這個特定網址導向(rewrite) subdomain cba.def, 其餘參數不變

location ~ /abc/def.htm(.*)$ { rewrite ^/(.*) http://cba.def/$1 permanent; } location ~ // 使用正規表達式,有視大小寫 location ~* // 代表使用正規表達式,忽視大小寫 # 當路徑符合 /test/js/test.js 無視後面帶什麼參數時,進去裡面 location ~* /test/js/test.js(.*)$ { # 檢查如果你進來的網址是 /test/js/test.js # 後面帶的參數會被 /test/js/test.js(.*) 的 (.*) 捕捉到 $1 # 然後將流量導向 /test/js/test.php # 並將後面帶的所有東西也補在 /test/js/test.php 後 rewrite ^/test/js/test.js(.*) /test/js/test.php$1 last; } location 中的 rewirte: 不寫last和break - 那麼流程就是依次執行這些rewrite 1. rewrite break - url重寫後,直接使用當前資源,不再執行 location 裡面剩下的語句,完成本次請求,地址欄url不變 2. rewrite last - url重寫後,馬上發起一個新的請求,再次進入server塊,重試location匹配,超過10次匹配不到報500錯誤,地址欄url不變 3. rewrite redirect – 返回302臨時重定向,地址欄顯示重定向後的url,爬蟲不會更新url(因為是臨時) 4. rewrite permanent – 返回301永久重定向, 地址欄顯示重定向後的url,爬蟲更新url 使用last會對server標籤重新發起請求 如果location中rewrite後是對靜態資源的請求,不需要再進行其他匹配,一般要使用break或不寫,直接使用當前location中的數據源,完成本次請求 如果location中rewrite後,還需要進行其他處理,如動態fastcgi請求(.php,.jsp)等,要用last繼續發起新的請求 (根的location使用last比較好, 因為如果有.php等fastcgi請求還要繼續處理)