0%

Makefile

Introduction

  • 編譯小型程式可用簡單的命令編譯或 shell script 編譯,但當程式很大且包含大量標頭檔和函式庫時,就需要使用 makefile。makefile 會將程式分成好幾個模組,根據裡面的目標 (target)、規則 (rule) 和檔案的修改時間進行判斷哪些需要重新編譯,可以省去大量重複編譯的時間,這在大型程式中尤為有用。

  • 另外,在閱讀大型程式碼時除了 Readme 檔案,Makefile 也能對整體架構有不錯的詮釋,先閱讀 makefile 是掌握程式碼架構一個良好的策略。

    閱讀全文 »

QR code

Introduction

  • 二維碼另一個名稱是QR Code(Quick Response Code)

  • 與傳統條形碼 (bar code) 相比,可以儲存更多的資訊。二維碼本質上是個密碼演算法,基本知識總結如下。

  • 首先,二維碼存在 40 種尺寸,在官方文件中,尺寸又被命名為 Version。尺寸與 Version 存線上性關係:Version 1 是 21×21 的矩陣,Version 2 是 25×25 的矩陣,每增加一個 Version,尺寸都會增加 4,故尺寸 Size 與 Version 的線性關係為:

  • $$Size=(Version−1)×4$$

  • Version 的最大值是 40,故尺寸最大值是(40-1)*4+21 = 177,即 177 x 177 的矩陣。

  • QR Code的4個容錯等級:

    • L(低):可修正7%的字碼。
    • M(中):可修正15%的字碼。
    • Q(中高):可修正25%的字碼。
    • H(高):可修正30%的字碼。
      閱讀全文 »

C++ tuple

For returning two values I use a std::pair (usually typedef’d). You should look at boost::tuple (in C++11 and newer, there’s std::tuple) for more than two return results.
With introduction of structured binding in C++ 17, returning std::tuple should probably become accepted standard.

閱讀全文 »

Git Command

steps

push

  1. gti init
    (new a .git file)
  2. git status
    (see what current state of our project)
  3. git add [file]
    (add files to to the staging area by using git add)
  4. git commit -m [commit name]
    (put commit into ready status)
  5. git log
    (can log like a journal that remember all the changes we have committed so far)
  6. git remote add origin [repository URL]
    (before pushing, we need to add a remote repository)
  7. git push -u origin master
    (push commit)
    閱讀全文 »

改變歷史的 50 個物理學實驗

早期的實驗 (-430~1307)

空氣一種東西嗎?

  • 已知最早的實驗
  • 用倒蓋罐子的方式,證明空氣是存在的東西,並非空無一物
  • 主動跳火山

    水量與體積的關係

  • 發現浮力的原理
  • 藉以判斷王冠是否純金製作

    測量地球的尺寸

  • 利用太陽的入射角和影子的偏角,計算地球半徑

    光是怎麼行進的

  • 怕死所以裝瘋,而被軟禁
  • 解剖公牛眼睛研究其構造並繪圖
  • 利用針孔成像來證明光是直線前進
  • 被尊為科學方法之父

    為什麼彩虹是彩色的

  • 利用三稜鏡來觀察光分析
  • 以及用裝水的燒杯來模擬雨滴思考彩虹的形成
    閱讀全文 »

Design Pattern

  • 一般軟體圈講的設計模式是指 GoF (「四人幫設計模式」(Gang of Four) 的23個 design pattern ,而 GoF 的23個設計模式全名是 object oriented design pattern,所以設計模式是指在物件導向基礎上的一套設計原則,但這些設計原則也不是 GoF 憑空想出來的,而是結合前人的經驗整理總結出來的一套原則,是一套檢驗過、行之有效的方法
  • 描述在各種不同情況下,要怎麼解決問題的一種方案
  • 核心概念就是,讓程式碼更有彈性並更有利用性
閱讀全文 »

各種商數 Quotient

IQ (Intelligence Quotient)

EQ (Emotional Intelligence Quotient)

AQ (Adversity Quotient)

  • 抗壓商數

    SQ

  • Social Intelligence Quotient
  • Spiritual Quotient
閱讀全文 »

Javascript String Search

  • 在 javascript 中 string 的 substring 有三個 searchincludesmatch
  • 看起來功能相似,參數和回傳函數還是有差
  • str.search(regexp)
    • 參數是 regular expression
      • 如果不是,則會自動生成 RegExp 物件
    • 回傳搜尋到的 index,如果沒有搜尋到則回傳 -1
      1
      2
      3
      4
      5
      let str = "hey JudE"
      let re = /[A-Z]/g
      let reDot = /[.]/g
      console.log(str.search(re)) // returns 4, which is the index of the first capital letter "J"
      console.log(str.search(reDot)) // returns -1 cannot find '.' dot punctuation

includes

  • str.includes(searchString[, position])

    • 參數是字串,以及從第幾個開始
    • 只回傳 true 或 false
      1
      'Blue Whale'.includes('blue')  // returns false

      This method has been added to the ECMAScript 2015 specification and may not be available in all JavaScript implementations yet.

      match

  • str.match(regexp)

    • 參數是 regular expression

      • 如果不是,則會自動生成 RegExp 物件
    • 回傳的是一組 array,每一個元素都是符合的字串,如果沒有符合的結果,則是回傳 null

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      var str = "Nothing will come of nothing.";
      str.match(); // returns [""]

      var str = 'For more information, see Chapter 3.4.5.1';
      var re = /see (chapter \d+(\.\d)*)/i;
      var found = str.match(re);

      console.log(found);

      // logs [ 'see Chapter 3.4.5.1',
      // 'Chapter 3.4.5.1',
      // '.1',
      // index: 22,
      // input: 'For more information, see Chapter 3.4.5.1' ]

      // 'see Chapter 3.4.5.1' is the whole match.
      // 'Chapter 3.4.5.1' was captured by '(chapter \d+(\.\d)*)'.
      // '.1' was the last value captured by '(\.\d)'.
      // The 'index' property (22) is the zero-based index of the whole match.
      // The 'input' property is the original string that was parsed.

Others

  • str.indexOf(searchValue [, fromIndex])
    • 參數是字串,以及從第幾個開始
    • 回傳搜尋到的 index,如果沒有搜尋到則回傳 -1
      1
      2
      3
      4
      5
      'Blue Whale'.indexOf('Blue')      // returns  0
      'Blue Whale'.indexOf('Blute') // returns -1
      'Blue Whale'.indexOf('Whale', 0) // returns 5
      'Blue Whale'.indexOf('Whale', 5) // returns 5
      'Blue Whale'.indexOf('Whale', 7) // returns -1

Reference

錯覺圖

  • 這裡火車正往哪個方向走呢?

  • 這張圖的背景是什麼顏色呢?