發表文章

目前顯示的是 5月, 2018的文章

ES6 一些特性

# 解構 const nums = [1,2,3]; const first = nums[0]; const second = nums[1]; 可以改用 const [first, second] = nums; # 要只取第二個 const [, second] = nums; # 預設值 # 原本 fourth 應該是 undefined, 但透過後面的 assign 給定預設值 const [, second, third, fourth = 0] = nums; # 值交換 let a = 1; let b = 2; [a, b] = [b, a]; # 剩餘部分 const nums = [1,2,3,4]; const [first, ...other] = nums; # nums => [2,3,4] # 物件解構 const points = {x:1,y:2}; # x = 1 const {x} = points; # rename x to px (只限定物件, 不可以用在Array) const {x:px} = points; Expression 表達式 Statement 陳述式 Expression => 可以用 ()包起來的 Statement => 無法用()包起來的 ex: if (1>2) 表達式 1+2; const a; a+2; 字串模板 字串模板內可以放入表達式 function greet(name, days) { console.log(`Hello, ${name}! It has been ${days * 24} hours not seen you!`); } # or function greet(name, days) { console.log(`Hello, ${name}! ${(days < 7) ? '' : 'Long time no see'}`); } 字串模板也支援多行字串 const str = ` 123456 12345 1234567 `; arrow function 內的 this 會

[Linux] 切割超過2TB的硬碟

Ref:  https://blog.gtwang.org/linux/parted-command-to-create-resize-rescue-linux-disk-partitions/ !! 注意 使用parted的指令是即刻生效, 請先確認該顆硬碟是要重新切割的 切割超過2TB硬碟需要用 parted #Ubuntu sudo apt-get install parted #CentOS sudo yum install parted # 進入parted parted # 選擇 /dev/sdc select /dev/sdc # 印出資訊 print # 建立磁碟分割表, 此處硬碟大小為4TB, 故只能使用gpt mklabel gpt # 印出資訊 double check print # 開始分割 mkpart # Partition name? []? my_part1 File system type? [ext2]? (按ENTER) Start? 1 (起始位置) End? 1000000 (結束位置 - 1TB(1000GB)) # mkpart # Partition name? []? my_part2 File system type? [ext2]? (按ENTER) Start? 1000001 (起始位置) End? 2000000 (結束位置 - 1TB(1000GB)) # ls /dev/sdc* # 應該會列出 /dev/sdc1, /dev/sdc2, /dev/sdc3 # 列出資訊 print # 會列出像是下列的資訊 Disk /dev/sdb: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000GB 1000GB my_part1 2 1000GB 2000GB 1000GB my_part2 3 2000GB 4000GB 2000GB

[Nginx] CentOS nginx 內如果沒有sites-available & sites-enabled

Ref: https://stackoverflow.com/questions/17413526/nginx-missing-sites-available-directory # 建立 sites-available mkdir sites-available # 建立 sites-enabled mkdir sites-enabled # vi /etc/nginx/nginx.conf # 修改 http block 中 include /etc/nginx/sites-enabled/*; service nginx restart