November 2024 S M T W T F S « Jan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -
Recent Posts
Recent Comments
Categories
Links
Author Archives: Enrico
let scope
雖然let引入block scope,避免了var的variable hoisting,但是須注意 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let let bindings are created at the top of the (block) scope containing the declaration, commonly referred to as “hoisting”. Unlike variables declared with var, which will start with the value undefined, let variables are not initialized … Continue reading
Posted in nodejs
Leave a comment
JSON5
JSON5 (https://spec.json5.org) https://github.com/json5/json5 nodejs讀取設定檔常使用json格式(http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf, https://tools.ietf.org/html/rfc8259), 但是json在描述時限制較多,例如在key要雙引號,字串要用雙引號不能用單引號,不能有註解等。 因此可讀性變差,JSON5主要將ECMAScript 5.1語法引入,整體看來,syntax對於熟悉javascript的使用者更友善 幾個比較大的差異 key不一定需要引號(根據ECMAScript 5.1 IdentifierName規則) Objects may have a single trailing comma. Arrays may have a single trailing comma. Strings may be single quoted/支援多行/支援 \x的escape (U+0000 through U+00FF) String更寬容的escape字元包含 JSON:All Unicode characters may … Continue reading
Posted in nodejs
Leave a comment
find files modified in 1 day
找出最近更動的檔案(1 day),這在清查設定檔或是程式被更動時方便使用的指令 find . -mtime -1 -ls 參考:https://stackoverflow.com/questions/16085958/scripts-find-the-files-have-been-changed-in-last-24-hours
Posted in System Administration
Leave a comment
rootpath module
https://www.npmjs.com/package/rootpath 在vsphere rest sdk sample看到的一個用法,這對於library更動目錄時不需要再改寫require path非常方便,但是須注意webpack使用時,應該用webpack resolve configuration來處理
Posted in nodejs
Leave a comment
git tips
delete a tag locally and remotely git push –delete origin tagNamegit tag -d tagName
Posted in System Administration
Leave a comment
socks5 proxy
SOCKS5 rfc可參考1996年 rfc 1928 (其他: rfc 3089 socks based gateway)須注意socks5本身並未加密,最好是透過ssh port forwarding SOCKS5 proxy設置最簡單的方式 是 putty ssh tunnel ssh -D 1080 user@server 注意port number 1024以下的權限問題(root) -D [bind_address:]port Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket … Continue reading
Posted in System Administration
Leave a comment
callback style與promise的整合
在需要呼叫多次callback時,async await可改善callback hell的現象而nodejs在8.x支援原生的async await,在設計callback api時,可設計成同時支援舊的callback style與新的promise style,這樣一來可以使api同時支援’async’ library與async/await語法 作法1: 作法2: 參考: https://zaiste.net/node_js_functions_simultaneously_supporting_callbacks_promises/ 使用:
Posted in nodejs
Leave a comment
mysql shell clear screen
mysql>system clear system呼叫系統shell執行
Posted in System Administration
Leave a comment
express error handler
在 https://github.com/expressjs/express/blob/master/lib/router/index.js#L46 function router(req, res, next) { router.handle(req, res, next); } express router不會catch error,所以error handler定義在router內無法作用 要直接定義在app那層,參考doc Error-handling middleware app.use(function(err, req, res, next) { console.error(err.stack); res.status(500).send(‘Something broke!’); }); 另外是順序也很重要,next(err)會依照順序往下找,因此error handler應該定義在最後面 參考來源: https://stackoverflow.com/questions/45431595/express-error-handler-inside-router-doesnt-work
Posted in nodejs
Leave a comment
pkg-config整理
config search path: (search for .pc) pkg-config –variable pc_path pkg-config /usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig PKG_CONFIG_PATH 範例 prefix=/usr exec_prefix=${prefix} libdir=/usr/lib/x86_64-linux-gnu includedir=${prefix}/include Name: x264 Description: H.264 (MPEG4 AVC) encoder library Version: 0.148.2643 5c65704 Libs: -L/usr/lib/x86_64-linux-gnu -lx264 Libs.private: -lpthread -lm -ldl Cflags: -I${prefix}/include pkg-config exits with … Continue reading
Posted in Library
Leave a comment