Skip to main content

Tedshd's Dev note

Sublime - Command Line

# Sublime - Command Line in Mac OS X make a symlink ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl // sublimetext 3 ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /bin/subl And Use it subl --help Usage: subl [arguments] [files] edit the given files or: subl [arguments] [directories] open the given directories or: subl [arguments] - edit stdin Arguments: --project <project>: Load the given project --command <command>: Run the given command -n or --new-window: Open a new window -a or --add: Add folders to the current window -w or --wait: Wait for the files to be closed before returning -b or --background: Don't activate the application -s or --stay: Keep the application activated after closing the file -h or --help: Show help (this message) and exit -v or --version: Show version and exit --wait is implied if reading from stdin. ...

JavaScript - delete element

# JavaScript - delete element I use this way. var dom = document.querySelectorAll('.dom'); for (var i = 0; i < dom.length; i++) { dom[i].outerHTML = ''; delete dom[i]; }; // or var dom = document.querySelector('#dom'); var dom = document.querySelector('h1'); dom.outerHTML = ''; delete dom; If use IE document.querySelector only use IE8 up Refer - JavaScript: remove element by id ...

Clean Code(無暇的程式碼) - Note

# Clean Code(無暇的程式碼) - Note 最近跟同事借了這本書, 主要是因為以前沒寫過大專案, 在寫大專案被主管指出有不少的地方邏輯有問題, 變數的命名也有許多問題, 剛好有同事有這本書, 便借來閱讀, 以增進自己的功力, 書中作者是以 Java 為例, 但寫一個 Clean Code 是不分程式語言的. 以下算是閱讀筆記 劣質的程式碼導致了這家公司的倒閉 無暇的程式碼 P.3 我喜歡我程式優雅又有效率. 邏輯直接了當, 使得錯誤無處可躲. 儘量降低程式的相依性, 以減輕維護上的工夫. 根據清楚的策略, 完備處理錯誤的程式碼. 盡可能的最佳化程式效能, 以避免引起他人, 因對於程式進行無章法的最佳化, 而把程式弄得一團亂. Clean Code 只做好一件事. 無暇的程式碼 P.8 Clean Code 是可被原作者以外的開發者閱讀與增強的. …… 無暇的程式碼 P.10 當每個你看到的程式, 執行結果都與你想的差不多, 你會察覺到你正工作在 Clean Code 之上. …… 無暇的程式碼 P.11 ……所以讓程式碼更容易閱讀, 也會讓程式碼變得更容易撰寫. 無暇的程式碼 P.16 有意義的命名 使名稱代表意圖 避免編碼 函數 簡短 避免形成巢狀 只做一件事 形成由上往下閱讀的程式碼 減少需要參數量 不要重複 函式應該只做一件事. 它們應該把這件事做好. ...

JavaScript - time seconds to hh:mm:ss

# JavaScript - time seconds to hh:mm:ss function toHHMMSS(sec_num) { var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = Math.floor(sec_num - (hours * 3600) - (minutes * 60)); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} var time = hours+':'+minutes+':'+seconds; return time; } alert(toHHMMSS(1234)); Refer - JavaScript seconds to time with format hh:mm:ss ...

JavaScript - Scroll Progress

# JavaScript - Scroll Progress Show a progress bar about page scroll position. This used scroll event Progress bar must handle scroll position and scroll total height, and show it for percent View MDN document can find it can’t use scrollHeight, because when scroll bar scroll to bottom, scrollTop not equal scrollHeight dom = document.querySelector("body"); percent = (dom.scrollTop / (dom.scrollHeight - document.documentElement.clientHeight)) * 100 + "%"; Then find scrollTop didn’t work in firefox ...

Sublime - change layout view in 2 columns

# Sublime - change layout view in 2 columns Video ## Setting Preferences -> Key Bindings - User set key to use [ { "keys": ["super+ctrl+left"], "command": "set_layout", "args": { "cols": [0.0, 0.95, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] } }, { "keys": ["super+ctrl+right"], "command": "set_layout", "args": { "cols": [0.0, 0.05, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] } } ] # Update ## Add focus If add focus, it need 2 commands so need write a python plugin ...

JavaScript - jQuery index() in JavaScript

# JavaScript - jQuery index() in JavaScript ## JavaScript function indexInParent(node) { var children = node.parentNode.childNodes; var num = 0; for (var i=0; i<children.length; i++) { if (children[i]==node) return num; if (children[i].nodeType==1) num++; } return -1; } ## Example <ul> <li id="foo">foo</li> <li id="bar">bar</li> <li id="baz">baz</li> </ul> jQuery alert($('#bar').index()); javaScript var el = document.getElementById("bar"); function indexInParent(node) { var children = node.parentNode.childNodes; var num = 0; for (var i=0; i<children.length; i++) { if (children[i]==node) return num; if (children[i]. ...

JavaScript - Encryption

# JavaScript - Encryption 弱弱的加密 ## base64 Base64 encoding and decoding ## sha1(only js to js) Need utf8 encode JavaScript sha1 function ## utf8(only js to js) JavaScript utf8_encode function JavaScript utf8_decode function decode can handle php utf8_encode() ## Encrypt(js to php) Use crypto-js HMAC Refer - Javascript: Equivalent of PHP’s hash_hmac() with RAW BINARY output? ...

JavaScript - get element height

# JavaScript - get element height If we want get element height use JavaScript We can use clientHeight 、 offsetHeight or scrollHeight console.log(document.getElementById('div').clientHeight); console.log(document.getElementById('div').offsetHeight); console.log(document.getElementById('div').scrollHeight); Refer - Element - Web API Interfaces | MDN ...