Raspberry PI 3: How to install NodeJS in 4 easy steps
[Raspberry Pi 3] 老朋友,新功能!關於那些開箱後馬上要作的事 ~ IT 技術家
command line - Arrow keys, tab-complete not working - Ask Ubuntu
標籤
javascript loop array
var arr = [1, 2, 3, 4, 5], | |
len = arr.length; | |
// Method1 (逆) | |
while (len--) { | |
console.log(arr[len]); | |
} | |
// Method2 (逆) | |
for (var i = arr.length; i--;) { | |
console.log(arr[i]); | |
} | |
// Method3 (順) | |
for (var i = 0, a; a = arr[i++];) { | |
console.log(a); | |
} | |
// Method4 (順) | |
var el; | |
while (el = arr.shift()) { | |
console.log(el); | |
} |
Raspbian Jessie 初始設定
export NODE_PATH=/usr/local/lib/node_modules | |
function vv() { | |
for id in core sdram_c sdram_i sdram_p ; do \ | |
v=$(vcgencmd measure_volts $id) | |
v=${v:5} | |
echo -e "$id:\t$v" ; \ | |
done | |
} | |
alias ll="ls -al" | |
alias free="free -h" | |
alias cls="clear" | |
alias cd..="cd .." | |
alias vt="vcgencmd measure_temp" | |
alias psm="ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head" | |
alias psc="ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head" | |
alias t="tmux attach" | |
alias re="bash ~/MyNodeJS/Ptt/rescan.sh" | |
alias ptt="bash ~/MyShellScript/loop_Ptt.sh" | |
alias dcard="bash ~/MyShellScript/loop_DCard.sh" |
執行設定程式
sudo raspi-config
- Expand Filesystem (擴展第二個分割區,讓記憶卡的全部可用空間都可以使用。)
- Internationalisation Options
- Change Locale
- 取消
en_GB.UTF-8 UTF8
- 選取
zh_TW.UTF8 UTF8
- 選取
en_US.UTF8 UTF8
- 取消
- Change Timezone
Asia/Taipei
- Change Wi-fi Country
TW Taiwan
- Change Locale
- Advanced Options
- A2 Hostname (變更Hostname)
設定系統自動校時
sudo timedatectl set-ntp yes
檢查自動校時
timedatectl
module.exports init
module.exports = function(config) { | |
this.config = config; | |
this.myMethod = function() { | |
console.log('Has access to this'); | |
}; | |
return this; | |
}; |
var myModule = require('./a.js')(config); | |
myModule.myMethod(); //Prints 'Has access to this' |
indexOf to array object
pos = myArray.map(function(e) { return e.hello; }).indexOf('stevie'); |
find files by extension
var path = require('path'), | |
fs = require('fs'); | |
function fromDir(startPath, filter, callback) { | |
//console.log('Starting from dir '+startPath+'/'); | |
if (!fs.existsSync(startPath)) { | |
console.log("no dir ", startPath); | |
return; | |
} | |
var files = fs.readdirSync(startPath); | |
for (var i = 0; i < files.length; i++) { | |
var filename = path.join(startPath, files[i]); | |
var stat = fs.lstatSync(filename); | |
if (stat.isDirectory()) { | |
fromDir(filename, filter, callback); //recurse | |
} else if (filter.test(filename)) callback(filename); | |
}; | |
}; | |
fromDir('../LiteScript', /\.html$/, function(filename) { | |
console.log('-- found: ', filename); | |
}); |
Removing Duplicate Objects From An Array
var arrObj = [{ | |
id: 1, | |
title: 'a' | |
}, { | |
id: 1, | |
title: 'a' | |
}, { | |
id: 2, | |
title: 'b' | |
}]; | |
//過濾id重複 | |
var arrUnique = arrObj.filter((obj, pos, arr) => { | |
return arr.map(x => x['id']).indexOf(obj['id']) === pos | |
}); | |
//找出重複id | |
var arrDuplicate = arrObj.filter((obj, pos, arr) => { | |
return arr.map(x => x['id']).indexOf(obj['id']) !== pos | |
}); |
ADB command
取得su權限
adb shell
su
列出全部app
adb shell pm list packages
列出全部系統app
adb shell pm list packages -s
安裝apk
adb install test.apk
移除apk
adb uninstall <com.package.name>
顯示apk實體路徑
adb shell pm path com.android.phone
喚醒手機
adb shell input keyevent 26
adb shell input keyevent KEYCODE_POWER
停用app
adb shell pm disable <com.package.name>
啟用app
adb shell pm enable <com.package.name>
下載資料夾
adb pull /storage/0123-4567/beauty beauty/
上傳資料夾
adb push beauty storage/0123-4567/beauty/
Disable Close Button 停用視窗關閉鈕
SetTitleMatchMode, 2 | |
DisableCloseButton(WinExist("Notepad")) | |
DisableCloseButton(hWnd="") { | |
hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE) | |
nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu) | |
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-1,"Uint","0x400") | |
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-2,"Uint","0x400") | |
DllCall("DrawMenuBar","Int",hWnd) | |
} |
判斷JS日期物件
// Method 1 | |
typeof date.getMonth === 'function' | |
// Method 2 | |
date instanceof Date | |
// Method 3 | |
Object.prototype.toString.call(date) === '[object Date]' |
Javascript Unicode
console.log('好'.charCodeAt()); //22909 | |
console.log('好'.charCodeAt().toString(16)); //597d | |
console.log(String.fromCharCode(22909)); //好 | |
console.log(String.fromCharCode(0x597d)); //好 | |
console.log('\u597d'); //好 | |
console.log('\u{597d}'); //好 | |
//prototype 擴充類別定義 | |
//方法1 (Regex) | |
String.prototype.toUnicode = function() { | |
return this.replace(/./g, function(char) { | |
var v = char.charCodeAt(0).toString(16); | |
var pad = "0000"; | |
return (pad.substring(0, pad.length - v.length) + v).toUpperCase(); | |
}); | |
}; | |
console.log('狂'.toUnicode()); //72C2 | |
//方法2 (while) | |
String.prototype.toUnicode = function () { | |
return this.replace(/./g, function (char) { | |
var v = String.charCodeAt(char).toString(16); | |
if (v.length != 4) { | |
do { | |
v = '0' + v; | |
} while (v.length < 4) | |
} | |
return v; | |
}); | |
}; | |
console.log('狂'.toUnicode()); //72C2 |
尋找陣列中缺少的數字
function findLost(aryNum) { | |
aryNum.sort(function(a, b) { | |
return a > b; | |
}); | |
if (aryNum.length > 1) { | |
var intAryIndex = 0, | |
intNumIndex = 0, | |
aryAns = []; | |
while (intNumIndex < aryNum[aryNum.length - 1]) { | |
if (aryNum[intAryIndex] !== intNumIndex) { | |
aryAns.push(intNumIndex); | |
} else { | |
intAryIndex++; | |
} | |
intNumIndex++; | |
} | |
return aryAns; | |
} | |
} | |
function findLostV2(aryNum) { | |
var aryAns = []; | |
for (var i = 0; i < aryNum[aryNum.length - 1]; i++) { | |
if (aryNum.indexOf(i) === -1) { | |
aryAns.push(i); | |
} | |
} | |
return aryAns; | |
} | |
console.log(findLost([2, 4, 6, 8, 10])); | |
console.log(findLostV2([1, 3, 5, 7, 9])); |
document.evaluate
var links, thisLink; | |
links = document.evaluate("//a[@href]", | |
document, | |
null, | |
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, | |
null); | |
for (var i = 0; i < links.snapshotLength; i++) { | |
var thisLink = links.snapshotItem(i); | |
console.log(thisLink.href); | |
} |
error: device not found
# Wrong | |
root@g3:/storage/sdcard0/Download $ adb pull "/LMT icon" | |
error: device not found | |
#Right | |
C:\adb\adb pull "/storage/sdcard0/Download/LMT icon" "LMT icon" | |
pull: building file list... | |
pull: /storage/sdcard0/Download/LMT icon/pie10.png -> LMT icon/pie10.png | |
1 file pulled. 0 files skipped. | |
550 KB/s (19169 bytes in 0.034s) |
android - adb pull -> device not found - Stack Overflow android - How do i adb pull ALL files of a folder present in SD Card - Stack Overflow
Overwrite Ajax Request
// Method 1 | |
(function(open) { | |
XMLHttpRequest.prototype.open = function() { | |
this.addEventListener('load', function() { | |
console.log('ajax done'); | |
}, false); | |
open.apply(this, arguments); | |
}; | |
})(XMLHttpRequest.prototype.open); | |
// Method 2 | |
(function(open) { | |
XMLHttpRequest.prototype.open = function() { | |
this.addEventListener("readystatechange", function() { | |
if (this.readyState === 4 && this.status === 200) { | |
console.log('ajax done'); | |
} | |
}, false); | |
open.apply(this, arguments); | |
}; | |
})(XMLHttpRequest.prototype.open); |
javascript - How can I intercept XMLHttpRequests from a Greasemonkey script? - Stack Overflow XMLHttpRequest.readyState - Web APIs | MDN
Factory Images for Nexus Devices 安裝步驟
fastboot oem unlock
- adb/bootloader/recovery驅動安裝
- MTP → Android Composite ADB Interface
- fastboot (bootloader) → Android Bootloader Interface
- Recovery Mode → Android Composite ADB Interface
- adb sideload → Android Platform Sooner Single ADB Interface
- 驅動測試
- 開始狀態,輸入
adb devices
- Bootloader mode,輸入
fastboot devices
- TWRP Sideload,輸入
adb devices
- 開始狀態,輸入
- Factory Images 檔案
- SuperSU (需要root才要)
- twrp-x.x.x.x-bullhead.img (需要Custom Recovery才要)
-
找到
6.0.1 (MMB29Q)
-
點擊
Link
,下載檔案bullhead-mmb29q-factory-197bd207.tgz
-
解壓縮至此,資料夾結構如下
bullhead-mmb29q ├─bootloader-bullhead-bhz10k.img ├─flash-all.bat ├─flash-all.sh ├─flash-base.sh ├─image-bullhead-mmb29q.zip └─radio-bullhead-m8994f-2.6.30.0.68.img
-
進入Bootloader模式
開機狀態,輸入
adb reboot bootloader
關機狀態,使用Vol Down
+Power
執行 flash-all.bat
即可
註:如需保留個人資料請修改flash-all.bat
部份內容,如下
將
-w
刪除
fastboot -w update image-bullhead-mmb29q.zip
-
將
image-bullhead-mmb29q.zip
解壓縮至此,資料夾結構如下bullhead-mmb29q ├─android-info.txt ├─boot.img ├─bootloader-bullhead-bhz10k.img ├─cache.img ├─flash-all.bat ├─flash-all.sh ├─flash-base.sh ├─image-bullhead-mmb29q.zip ├─radio-bullhead-m8994f-2.6.30.0.68.img ├─recovery.img ├─system.img ├─userdata.img └─vendor.img
-
依序鍵入以下指令
fastboot flash bootloader bootloader-bullhead-bhz10k.img
fastboot reboot-bootloader
fastboot flash radio radio-bullhead-m8994f-2.6.31.1.09.img
fastboot reboot-bootloader
fastboot flash boot boot.img
fastboot erase cache
fastboot flash cache cache.img
fastboot flash recovery recovery.img
fastboot flash system system.img
fastboot flash vendor vendor.img
Note: 如需保留原有TWRP Recovery,請跳過步驟8
-
進入Bootloader模式
開機狀態,輸入
adb reboot bootloader
關機狀態,使用Vol Down
+Power
-
fastboot flash recovery twrp-3.0.2-2-bullhead.img
-
進入TWRP Recovery
- 開機狀態,輸入
adb reboot recovery
- 關機狀態
1. 使用
Vol Down
+Power
2. 使用音量鍵
選擇Recovery mode
,並按下電源鈕
確認
- 開機狀態,輸入
- 將
BETA-SuperSU-v2.67-20160121175247.zip
,放置手機內部記憶卡- 清除
Dalvik-Cache
和Cache
- 選擇
Install
- 選擇
BETA-SuperSU-v2.67-20160121175247.zip
- 與電腦連接
- 選擇
Advanced
→ADB Sideload
- 勾選
Wipe DalvikCache
和Wipe Cache
Swipe to start Sideload
- 電腦cmd,輸入
adb sideload BETA-SuperSU-v2.67-20160121175247.zip
Nexus 5X (bullhead) 初見面
adb devices
fastboot devices
- 開啟開發者人員選項
- 設定 → 系統 → 開發者人員選項
- OEM 解鎖 → 開啟
- USB Debugging → 開啟
adb shell
- 允許USB偵錯 → 確定
adb reboot bootloader
fastboot oem unlock
- 選
Yes
Unlock bootloader (may void warranty) - 在Bootloader畫面中,會顯示
DEVICE STATE - unlocked
為紅字
adb reboot bootloader
fastboot flash recovery twrp-3.0.2-2-bullhead.img
※ 使用者資料將全部重置 ※
- 刷入[FIX] FED-Patcher v8 (ForceEncrypt Disable Patcher)
adb reboot bootloader
fastboot format userdata
fastboot reboot
adb reboot recovery
- 選擇
Backup
- 只勾選
EFS
Swipe to Backup
- 在TWRP裡,將備份好的EFS,匯入電腦端,
adb pull /sdcard/TWRP TWRP
- 將TWRP資料夾備份至雲端空間
- 將
BETA-SuperSU-v2.67-20160121175247.zip
,放置於手機內部記憶卡 adb reboot recovery
- 選擇
Install
- 選取
BETA-SuperSU-v2.67-20160121175247.zip
Wipe Cache/Dalvik
- 重新開機