0%

Nodejs Tips

Child Process

exec, spawn

  • 是從 child_process 中出來
  • 要記得字串會先被 escape 一次
閱讀全文 »

新 SEO

  • 一般來說 SEO 可以從四個面向來探討
    • 技術
    • 內容
    • 推廣
    • 數據
閱讀全文 »

SEO (Search Engine Optimization)

Introduction

  • 這份指南中會出現幾個重要用語,以下為您說明這些用語的定義:
    • 索引:Google 會將所有已知網頁儲存在「索引」 中,每個網頁的索引項目都會記錄網頁的內容及位置 (網址)。 所謂的「建立索引」,是指 Google 擷取、讀取網頁,然後將網頁加入索引的過程:_Google 今天為我的網站建立了幾個網頁索引_。
    • 檢索:尋找新網頁或更新網頁的程序。Google 會透過追蹤連結、讀取 Sitemap 等多種方法發掘網址。Google 檢索網路的目的是尋找新網頁,必且 (在適當情況下) 為這些網頁建立索引。
    • 檢索器:指在網路上檢索 (擷取) 網頁並為網頁建立索引的自動化軟體。
    • Googlebot:Google 檢索器的通稱。Googlebot 會持續檢索網路。
    • SEO:指搜尋引擎最佳化 (讓搜尋引擎更容易發現網站的程序),或是搜尋引擎最佳化執行者的工作職稱:我們聘請了一位新的 SEO 來為我們提升網路曝光度。
  • SEO 並不僅僅是建構搜尋引擎友善的網頁,SEO可以讓網頁更容易被人們使用,並且帶給人們更多的資訊
閱讀全文 »

Time

  • 雙系統 linux, windows 系統時間差異問題
    • 因為 windows 認為BIOS時間是本地時間,linux 認為BIOS時間是UTC時間
    • 將 windows把系統硬體時間當作本地時間(local time),即操作系統中顯示的時間跟BIOS中顯示的時間是一樣的。
      1
      2
      3
      $ sudo apt-get install ntpdate
      // 確認時間已經和網路同步
      $ sudo ntpdate time.windows.com
      1
      2
      // 將時間更新到硬件上
      $ sudo hwclock --localtime --systohc
    • 重新進入windows10
閱讀全文 »

Unix input and output

Introduction

  • standard input/output/error
    • 標準輸入  (stdin) :代號為 0
    • 標準輸出  (stdout):代號為 1
    • 標準錯誤輸出(stderr):代號為 2
    • 一般來說指令的輸入輸出是鍵盤和螢幕
    • 而可以利用控制指令將資料流 (data stream) 引導到 file 中
閱讀全文 »

Linux File Access Permission

Introduction

  • 在 linux 中,每個檔案都會有自己的檔案權限,可以利用 ls -l 或是 ll 來查看
1
2
3
4
5
$ ls -l
drwxrwxr-x+ 46 root admin 1.4K 10 1 11:33 Applications/
drwxr-xr-x 67 root wheel 2.1K 8 30 09:18 Library/
drwxr-xr-x@ 8 root wheel 256B 8 11 02:18 System/
...
  • 第一個值
    • - 為檔案,d 表示目錄,l 表示連結檔案 (link)
  • 去除掉最一開頭的 d,分為三組值

    • r: readable
    • w: writable
    • x: executable
    • -: 表示無權限
    • 其實它是二進制的三個值
      • 無權限即為 000
  • 而分三組為

    • owner 的權限
    • member in group 的權限
    • others 的權限
    • 每組將其二進制轉為十進制
      Number Description
      7 (111) read, write, and execute
      6 (110) read and write
      5 (101) read and execute
      4 (100) read only
      3 (011) write and execute
      2 (010) write only
      1 (001) execute only
      0 (000) no permission
  • in nodejs
    1
    fs.chmodSync('my_file.txt', 0o765);
    • For example, the octal value 0o765 means:
      • The owner may read, write and execute the file.
      • The group may read and write the file.
      • Others may read and execute the file.

Command

  • chmod

    • 修改權限
    • 用法
      • \[ugoa...\]\[\[+-=\]\[rwxX\]...\]\[,...\]
        • u 表示該檔案的擁有者 (user)
        • g 表示該 group
        • o 表示其他以外的人 (others)
        • a 表示這三者皆是 (all)
        • + 表示增加權限
        • - 表示取消權限
        • = 表示唯一設定權限
        • -R 目錄下所有檔案皆做相同權限操作
          1
          2
          3
          4
          5
          $ chmod ugo+r file1.txt
          $ chmod a+w file1.txt
          // 將檔案 file1.txt 與 file2.txt 設為該檔案擁有者,與其所屬同一個群體者可寫入,但其他以外的人則不可寫入
          $ chmod ug+w,o-w file1.txt file2.txt
          $ chmod 777 file.txt
  • chown

    • 修改擁有者或是群組
      1
      2
      3
      4
      5
      6
      // 將 temp.txt 的 owner 改為 user2
      $ chown user2 temp.txt
      // 將 temp.txt 的 group 改為 group2
      $ chown :group2 temp.txt
      // 將 temp.txt 的 owner 改為 user2 並 group 改為 group2
      $ chown user2:group2 temp.txt

Reference

File System

  • ls
    • 列出資料 (list)
    • 可以配合 -a,來顯示詳細資訊及隱藏資料 (all)
    • 而在 fish shell 上,簡化 ls -lll 指令
      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
      $ ls
      Applications/ Katalon Studio/ Pictures/ ncku-team/ temp.txt
      Desktop/ Library/ Postman/ repos/
      Documents/ Movies/ Public/ sideex/
      Downloads/ Music/ github-recovery-codes.txt system/

      $ ls -a
      ./ .conda/ .oracle_jre_usage/ Documents/ github-recovery-codes.txt
      .CFUserTextEncoding .cups/ .ssh/ Katalon Studio/ repos/
      .DS_Store .gitconfig .viminfo Library/ sideex/
      ...

      $ ls *.txt
      temp.txt

      // access permissions, # of hard link, ower, user group, size, date and time, name
      $ ls -l
      total 16
      drwx------@ 4 linyunwen staff 128B 8 27 16:36 Applications/
      drwx------@ 5 linyunwen staff 160B 8 27 20:00 Desktop/
      drwx------@ 10 linyunwen staff 320B 9 5 10:29 Documents/
      drwx------@ 26 linyunwen staff 832B 10 1 20:52 Downloads/
      drwx------@ 75 linyunwen staff 2.3K 9 22 11:52 Library/
      drwx------+ 8 linyunwen staff 256B 9 1 23:44 Movies/
      drwx------+ 4 linyunwen staff 128B 8 30 22:41 Music/
      drwx------+ 5 linyunwen staff 160B 8 31 11:08 Pictures/
      drwxr-xr-x+ 4 linyunwen staff 128B 8 27 16:30 Public/
      drwxr-xr-x@ 32 linyunwen staff 1.0K 9 3 13:20 system/
      -rw-r--r--@ 1 linyunwen staff 129B 9 29 23:20 temp.txt
      閱讀全文 »

Linux 檔案系統基本架構

  • 理論上所有的 Linux 發佈版本應該都要遵守檔案系統的標準(Filesystem Hierarchy Standard, FHS)
  • 以目錄的資訊可分為 shareable, unshareable 和 static, variable
閱讀全文 »

grep

  • grep 這個指令名稱其實是來自於正規表示法的 g/RE/p,其意義是代表以正規表示法全域搜尋並列印出來(globally search for RE and print it)

基本使用

1
2
3
4
5
// temp.txt
It is a great day, and IS sunny day
he want to say hello world for each one
there are many works to do
let's keep moving forward
  • 用法

    1
    grep key_word file1 file2 ...
  • e.g.

    1
    2
    3
    4
    5
    6
    $ grep "hello world" ~/temp.txt
    i want to say hello world for each one

    $ grep "hello world" ~/*.txt
    *
    /Users/linyunwen/temp.txt:i want to say hello world for each one
    閱讀全文 »

npm

install

  • mostly install it with nodejs
  • brew
  • zip
閱讀全文 »