設定 hugo 和 org-mode

設定 hugo 而且用 org-mode 當作來源

如何做

  • 安裝 hugo
brew install hugo
  • 開新專案
hugo new site blog
  • 安裝佈景

    我用 git submodule 來解決這個記錄

git submodule add https://github.com/halogenica/beautifulhugo.git themes/beautifulhugo~
  • 建立新文章
hugo new post/new-post.org
  • 產生網站
hugo

目前使用 hugo v0.21 版(0.19版後就有支援), 可以直接吃 org 檔,範例如下:

#+TITLE: 設定 hugo 和 org-mode
#+DATE: 2017-05-29T09:4:78+08:00
#+SLUG: setup-hugo-with-orgmode
#+TAGS: hugo org-mode

文章內容… balabala

本來用 +, - 之類包起來的檔頭已經不用再加上,hugo 會用 org-mode 本身的特別前綴詞去當作關鍵字來使用,這是新版才有的功能。 像是 title 就是在 #+ 之後的字,這個就會拿去當作區域變數來使用;若同時存在會以前面包起來的檔頭為主

因為用 org-mode 的方式寫,tags 之類的分類只要用空白就好,字串也不用引號包起來,算是非常貼近原生的使用的

[閱讀全文]
Tags: hugo org-mode 

從 XIB 建立 UITableViewCell 的問題

自己試著使用 XIB 把不同東西切割出來,像是 UITableViewCell

在 UITableView 的 viewDidLoad 裡面建立好相關的參照

- (void)viewDidLoad {
  [super viewDidLoad];

  [self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell"
                                             bundle:[NSBundle mainBundle]]
       forCellReuseIdentifier:cellIdentifier];
}

再建立 cell 時候,大概像這樣使用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    // do cell things ...
    return cell;
}

然後執行之後會出錯,大概會看到像這樣的錯誤

*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier MyTableViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

原因是使用 dequeueReusableCellWithIdentifier:forIndexPath: 會去 UITableView 查用把 XIB 裡面要的東西建立起來,這個動作會順便檢查 XIB 裡面的 View 是不是 UITableViewCell,若不是的話會吐 NSInternalInconsistencyException

[閱讀全文]
Tags: iOS XIB UITableView 

使用 rsync 和 launchd 自動備份

備份在現在是一件非常重要的事情,所以要把重要的東西備份,以免之後會哭哭

基於 rsync 可以細微的調整,而且擴充性好很多,所以就用 rsync 來當作主要備份工具

經過自己的需求和測試,目前自己使用的 rsync 大概會長這樣

rsync -auzthv --exclude-from=rsync_exclude --delete-after project/ /volumes/backup/project/

在 Mac 上要能跑的東西目前有 cron 或是 launchd 這兩個方式,前面的是一般 unix 常用的方式,基於要試新的玩意,就小玩了一下 launchd。(launchctl 是用來操作 launchd 用的命令列工具)

依照官方說明,我就做了一個這樣的 plist 出來

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Debug</key>
    <true/>
    <key>Label</key>
    <string>org.superbil.rsync</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/rsync</string>
        <string>-auzthv</string>
        <string>--delete-after</string>
        <string>--exclude-from=rsync_exclude</string>
        <string>project/</string>
        <string>/volumes/backup/project/</string>
    </array>
    <key>StandardErrorPath</key>
    <string>~/Library/Logs/rsync/project.log</string>
    <key>StandardOutPath</key>
    <string>~/Library/Logs/rsync/project_err.log</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>6</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

這個 plist, ProgramArguments 這項單行和多行都可以,launchd 會幫你組成一行。 StartCalendarInterval 就是重復執行的時間間隔,這個跟 unix 習慣一樣,沒有輸入的值他會當通用批配值。

[閱讀全文]
Tags: rsync mac launchd launchctl 

XCode 5 註記

XCode 5 內建支援的標記有

// FIXME: I really need to fix this
// TODO: make some money
// MARK: mom, I am here !
// ???: what r u doing?
// !!!: this is magic code.

比對的條件是 // <Keyword>: 冒號是必要的

Tags: XCode5 editor 

產生 lame for iOS

lame 官方沒有提供 iOS 的版本只能自己動手做,但是網路上的都是 XCode 4 和用 gcc 編譯的方式

修正一些編譯上會遇到的問題,只要先去抓 lame 官方的程式碼 ,然後把以下的 script 放在解壓縮出來的資料夾中,再執行即可

東西會產生在 build 這個資料夾之下

PS.本來想用別的語言實作的,但是後來覺得 bash 的普及性比較高,所以就不再用其他語言實作

目前已經 fork 到我的 Github project build-lame-for-iOS,可以直接 fork 使用

Tags: build XCode5 iOS lipo bash 

在 emacs 中呼叫 clang 的自動完成

一開始是在 homebrew 發現這個 emacs-clang-complete-async東西

安裝完之後,再參照 github上的說明,在自己的 init.el 裡面放入以下的設定

(require 'auto-complete-clang-async)
(defun ac-cc-mode-setup ()
  (setq ac-clang-complete-executable "/usr/local/opt/emacs-clang-complete-async/bin/clang-complete")
  (setq ac-sources '(ac-source-clang-async))
  (ac-clang-launch-completion-process))

(defun my-ac-config ()
  (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)
  (global-auto-complete-mode t))

(my-ac-config)

/usr/local/opt/emacs-clang-complete-async/bin/clang-complete 這個是使用 homebrew 安裝的預設路徑,只要把這個參數設對,就會正常的跑起來 PS. 也可以用 brew --prefix emacs-clang-complete-async 拿到路徑

不過目前只能當下的檔案,可以再使用 M-x ac-clang-set-cflags 來設定 cFlags,不過目前還沒有成功 XD

Tags: emacs clang Homebrew 

sort Xcode project

I found this perl script can sort Xcode Project

sort-Xcode-project-file

just download it and run it

$ curl -O https://raw.github.com/WebKit/webkit/master/Tools/Scripts/sort-Xcode-project-file
$ chmod +x sort-Xcode-project-file
$ ./sort-Xcode-project-file MyProject.xcodeproj/project.pbxproj

you need to change MyProject to you xcode project name

Tags: xcode perl 

iOS enter background

If yout want to do something in background…

__block UIBackgroundTaskIdentifier backgroundId =
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    [[UIApplication sharedApplication] endBackgroundTask:backgroundId];
    backgroundId = UIBackgroundTaskInvalid;
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^{
    // do some thing you want to ...
});
Tags: iOS cocoa