2017年1月22日 星期日

[Mac] read & writer NTFS by ntfs-3g


  • 以前利用更改 /etc/fstab 或是利用工具 Paragon NTFS 來達成, 但在沒有購買軟體的情形下, 還是參考使用了 ntfs-3g
  • 癮科技的教學來看, 需使用 NTFS-3G+Fuse For OSX + fuse_wait, ...但我第一步下載安裝就一直給我顯示版本錯誤了, 後面提的
    mount -t ntfs-3g /dev/disk2s5 /Volumes/mountPoint
    我也失敗, 就先放棄這作法惹(我的理解, 安裝完應該要有
    /sbin/mount-ntfs03g
    之類的才是...)
  • 以下是我嘗試後, 目前可用的作法
    • 從 MacPort 安裝
    • sudo port install ntfs-3g
    • 查詢要 mount的 ntfs disk並先 unmount, 最後 mount到 newMountPoint
    • diskutil list
      diskutil unmount /dev/disk2s5
      sudo ntfg-3g /dev/disk2s5 /Volumes/newMountPoint
  • Reference

2017年1月17日 星期二

[Toolchain] Autotools & CMake

  • Autotools
    • autoconf, automake, libtools
      • Note: Mac OSX 自 XCode 4.3之後, 沒有內建這些 autotools了. 可以透過 port install autoconf automake
    • Open source 三部曲
      • ./configure
        • 產生 Makefile 及 config.h (所以程式中盡量少用 config.h)
      • make
      • make install
    • flowchart
      • 利用 autoscan 建立 configure.ac (舊版 autotool叫做 configure.in)
        • autoscan
          mv configure.scan configure.ac
          • 產生範本 configure.scan, 自行更名為 configure.ac供後面 autoconf使用. 同時會產生 autoscan.log (但成功的狀態似乎沒填任何東西, 要看過程反而是要用 autoscan --verbose來看)
          • 從 verbose可以看到這個 autoscan做了些什麼事, 從掃描 source files開始, 會以目前執行的 directory 當作 srcdir, 分別掃描 cfiles, makefiles, shfiles, 以及瀏覽用到的 function, header, install 及相關變數 lists, 如下 samples (可自行以 open source project 驗證, 或如 reference裡用的 LilyTerm來練習)
          • autoscan: srcdir = .
            cfiles: src/console.c src/console.h src/data.h src/dialog.c src/dialog.h src/font.c src/font.h src/lilyterm.h src/main.c src/main.h src/menu.c src/menu.h src/misc.c src/misc.h src/notebook.c src/notebook.h src/pagename.c src/pagename.h src/profile.c src/profile.h src/property.c src/property.h src/window.c src/window.h
            makefiles: data/Makefile po/Makefile
            shfiles: src/unit_test.sh
            
            function:
            bzero: src/main.c:314
            memset: src/menu.c:1995 src/menu.h:29
      • 修改 configure.ac
        • vi configure.ac
          • configure.ac 基本上就是個 script, 只是裡面呼叫非常多 macros以利 m4 (GNU Marco Processor) 處理, e.g. AC_*( ), 其中 [ ] 為區隔字元, 以及 AC prefix代表 AutoConf 相關 marco; AM_*代表 AutoMake相關marco. 另外注意, macro名稱與左括號 ( 中間不要有空格, e.g. AC_PREREQ([2.69]) 而不是 AC_PREREQ ([2.69])
            • #為註解
          • 未更改
          • #                                               -*- Autoconf -*-
            # Process this file with autoconf to produce a configure script.
            
            AC_PREREQ([2.69])
            AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
            AC_CONFIG_SRCDIR([src/console.c])
            AC_CONFIG_HEADERS([config.h])
            
            # Checks for programs.
            AC_PROG_CXX
            AC_PROG_CC
            AC_PROG_INSTALL
            AC_PROG_MAKE_SET
            
            # Checks for libraries.
            
            # Checks for header files.
            AC_PATH_X
            AC_CHECK_HEADERS([fcntl.h locale.h stdlib.h string.h sys/socket.h unistd.h])
            
            # Checks for typedefs, structures, and compiler characteristics.
            AC_TYPE_PID_T
            
            # Checks for library functions.
            AC_FUNC_FORK
            AC_CHECK_FUNCS([bzero memset setenv setlocale socket strcasecmp strstr])
            
            AC_CONFIG_FILES([data/Makefile
                             po/Makefile])
            AC_OUTPUT
            
            
    • Samples for practice
    • Reference:
  • CMake
    • front-end of make
    • CTest
  • MacPorts
    • 目的: 簡化 compile, install linux software to Mac. 可想成 apt-get, 即為 command line based package management
    • 操作: port install, port search, port contents
    • 通常會放在 /opt/local 底下
    • 亦可透過 pkg-config --cflags port, 找到需要的 installed port header與 library
  • pkg-config --cflags
  • port contents installed | grep gdkkeysyms.h

2017年1月15日 星期日

[Blog] 在 blog 中張貼程式碼

  • 原理:
    1. 以 HTML的 pre tag來實作, 如 HTML裡的 <img> 表示圖片、<h1>表示等級1的header等等, pre表示的是 pre-formatted text, 會以定寬字型以及保留空格與換行的方式來處理。
    2. 設計特別的 class 來指定這些程式碼, 如 Google 的 prettyprint
    3. 設計 CSS 來 highlight畫面
    4. 利用 javascript 來做是否為keyword等字的判斷, 來highlight特別的字 (每個語言都有自己的 keywords, 如: class、printf 等等, 這些 keywords因語言不同而不同, 所以應該也要有對不同語言提供不同 keywords highlight的功能)
  • 方法:
    1. 載入上面提到的 CSS (以blog-替程式碼上色提供的 sample為例)與 Javascript (以 Google Code Prettify 為例)
      1. 在 Blogger中, 新增 HTML/Javascript 小工具
      <style type='text/css'>
      .pre-highborder{
          border: 1px solid #ff0000;
          padding: 3px 3px 3px 0;
      }
      
      pre.prettyprint, code.prettyprint {
          border-radius: 8px;
          -moz-border-radius: 8px;
          -webkit-border-radius: 8px;
          padding: 5px;
          overflow: auto;
          background-color: #eee !important;
          color: black;
          box-shadow: 0 0 5px #999;
          -moz-box-shadow: 0 0 5px #999;
          -webkit-box-shadow: 0 0 5px #999;
      }
      
      /*font*/
      pre span, code span {
          font-family: 'Consolas', 'Courier New', 'Microsoft JhengHei', sans-serif !important;
          font-size: 12px !important;
      }
      
      /*each line*/
      li.L0, li.L1, li.L2, li.L3, li.L4, li.L5, li.L6, li.L7, li.L8, li.L9 {
          margin: 0 !important;
          padding: 2px 0 2px 4px !important;
          list-style-type:decimal !important;
          border-left: 1px solid #999;
      }
      
      /*even line*/
      li.L1, li.L3, li.L5, li.L7, li.L9 {
          background-color: #f6f6f6 !important;
      }
      
      /*odd line*/
      li.L0, li.L2, li.L4, li.L6, li.L8 {
          background-color: #FFF !important;
      }
      
      /*line-number background color*/
      ol.linenums {
          color: black;
          background-color: #eee;
          margin-left: 10px;
      }
      </style>
       
      <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js">
      </script>
    2. 在自己的程式碼中輸入程式碼區塊
      1. 指定為 pre block, 並指定 class 與特定 config (例如特別的語言: lang-*, support list, 或是顯示行號的 linenum)
        <pre class="prettyprint lang-cpp linenums">code snippet</pre>
      2. 需要注意的是, 這邊的 code snippet要經過處理, 也就是有經過 escape符號預處理, 簡單來說, 通常任何程式語言都會有 escape characters, 簡單就是用以告知 compiler/interpreter, 你就是要用該符號, 例如: printf的語法是 printf("what you want to print"), 但你就是要 print 引號 (")的時候怎麼辦咧? 就是加入 escape character (\), 而在 HTML則是輸入 &lt; &gt; 等等, 不過也有網頁服務直接幫你轉換 => HTMLEscape .net
    3. 另外, 也有很多類似的相關 js 可以套用, 如 SyntaxHighlighter

2017年1月14日 星期六

[Codec] Video Codec 參考書目

覺得不錯的參考書目:

  • H.264 and MPEG-4 Video Compression
    • 雖然年代有點久, 但內容滿適合入門以及了解相關知識,包含簡述codec 發展歷史codec 觀念 (Chapter Video Coding Concept - 包含 block diagram, e.g. DPCM/DCT video encoder/decoder架構)及 standard相關細節 (e.g. Chapter H.264/MPEG4 Part 10)
  • Video Demystified
    • 比較偏向訊號面來講解, e.g. 數位訊號(e.g. PAL, color space)、廣播制式(e.g. DVBC/ATSC)
  • Next Generation Video Coding and Streaming
    • 以 HEVC為主, 滿 spec. 導向, 另外在 container(e.g. mp4, ts), 以及 streaming 著墨較多
以上是目前覺得不錯的書目, 由於工作需要, 所以開始 K相關技術, 若有相關技術可以分享交流, 甚至一起來個讀書會. 都非常歡迎 feedback哦