tweet 002

如果看的到這篇文章代表 snpap (simple nikola post-admin platform) 的 0.01 版已經寫的差不多了,可喜可賀可喜可賀。

Comments

tweet 001

這幾天假日都在寫一個 nikola 的文章管理後台,我深信這是我會一直用的東西,不過開發的時候有幾件事超乎預料

  1. 這程式其實沒很難 (因為設定是給自己用),flask + jinja2 再加上以前自己對 python 的了解,其實要做到自己想要做到的事並不難。

  2. 這程式其實很麻煩 (如果想要釋出的話),因為 nikola 的 meta data 格式其實沒有這麼死,我自己是有加 "" 但是有些沒加有些有加,如果想要給大家用就得解決這個問題 (如果不想其實功能很快就做完了)。

  3. 我還是不會美工,所以我還是得自己學會怎麼把一些現成的 CSS 套上來,不過這大概要等開發結束。

這明明是 tweet ,怎麼會寫這麼長勒 XD。

Comments

Push without username/passwd in Github

這方法不是我發明的,但是找到就備忘一下。

方法來自 authentication - Git push requires username and password - Stack Overflow 照著這篇文章的說明,只要把自己的 repo 改成 ssh 就行

git remote set-url origin git@github.com:username/repo.git

所以完之後,在 nikola 的 output 的 github repo 上我輸入

git push -u origin master

就可以上傳了。所以現在就可以寫簡單的 Makefile 來做一些事了。

all:
        nikola build && nikola auto
deploy:
        cd output && git add posts/* && git commit -a -m "automatic push" && 
        git push -u origin master

不過其實要做什麼事我其實還沒有很清楚,想到再加上來好了。

Comments

Generate a default new post file in nikola

鑑於要產生新文章每次都要寫這些 tag 實在很煩,所以索性自己寫了一段 script 來做這些事。

在 nikola 的目錄下執行

./new_post_nikola.py "Generate a default new post in nikola"

就會產生相對應的檔案 posts/20130914_generate-a-default-new-post-file-in-nikola.md

雖然我最後想做的不是這個,不過先做這擋著用。

Comments

Fix error about generating pandoc-style html in nikola

> nikola build
Scanning posts..done!
.  render_posts:cache/posts/20130914_why_nikola.html
########################################
TaskError - taskid:render_posts:cache/posts/20130914_why_nikola.html
PythonAction Error
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/doit/action.py", line 324, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/nikola/plugins/compile/pandoc.py", line 59, in compile_html
    subprocess.check_call((pandoc_path, '-o', dest, source))
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 537, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

這其實是一個很白爛的問題,但是其實看到出錯訊息就知道為什麼了 … 我原本以為是找不到 pandoc 位在那,後來發現他是用 which 去找,理論上應該是找的到才對,後來發現,事情不是我想的這麼簡單,我查了一下出錯的地方 /usr/local/lib/python2.7/site-packages/nikola/plugins/compile/pandoc.py", line 59,那一行是這樣子寫的:

subprocess.check_call((pandoc_path, '-o', source, dest))

其實這一行的 source 和 dest 參數放反了,反過來就解決了,所以我就改成:

subprocess.check_call((pandoc_path, '-o', dest, source))

但是還是出錯 … Orz,後來我把每個變數印出來發現其中的 pandoc_path 長成:

'/Users/yen3/.cabal/bin/pandoc\n'

兇手找到了 (但是其實我蠻想知道 which 找到的東西為什麼會多一個 \n),所以最後那一行改成:

subprocess.check_call((pandoc_path.split('\n')[0], '-o', dest, source))

就能編譯成功了,如此一來就又有一個 blog system 可以寫 pandoc-style markdown 了。

我是還蠻想送 patch 給原作者啦,剛剛我有送一個 issue 上去,希望我不要被認為是白目啊 XDXD。


後記: 送了一個 issue 給原作者後,他不到十分鐘就修復了還抱歉 … 好 nice 的外國人喔~!

Comments

Some examples for reading/ writing files in Haskell

先貼材料,之後補文。

Read the clipboard's content in Mac OSX

processPaste' :: (String -> String) -> IO ()
processPaste' pd = putStrLn . pd =<< readProcess "pbpaste" [] []
Prelude System.Process> putStrLn =<< readProcess "pbpaste" [] []
http://hackage.haskell.org/packages/archive/process/1.0.1.1/doc/html/System-Process.html
Prelude System.Process> import Data.Char
Prelude System.Process Data.Char> putStrLn . (map toUpper) =<< readProcess "pbpaste" [] []
HTTP://HACKAGE.HASKELL.ORG/PACKAGES/ARCHIVE/PROCESS/1.0.1.1/DOC/HTML/SYSTEM-PROCESS.HTML

-- Read the contents of clipboard
-- Ref: http://stackoverflow.com/questions/1712347/closest-equivalent-to-subprocess-communicate-in-haskell

import System.Process

processData :: String -> String
processData = (id :: String -> String)

processPaste pd = do
    let cmd = "pbpaste"
        args = []
        instr = []
    (rc, out, err) <- readProcessWithExitCode cmd args instr
    putStrLn $ pd out

main = processPaste processData

-- Run in ghci
-- Prelude> :l read_pbpaste.hs
-- [1 of 1] Compiling Main             ( read_pbpaste.hs, interpreted )
-- Ok, modules loaded: Main.
-- *Main> import Data.Char
-- *Main Data.Char> processPaste Data.Char.to
-- Data.Char.toLower  Data.Char.toTitle  Data.Char.toUpper
-- *Main Data.Char> processPaste $ map Data.Char.toUpper
-- Loading package array-0.4.0.1 ... linking ... done.
-- Loading package deepseq-1.3.0.1 ... linking ... done.
-- Loading package filepath-1.3.0.1 ... linking ... done.
-- Loading package old-locale-1.0.0.5 ... linking ... done.
-- Loading package time-1.4.0.1 ... linking ... done.
-- Loading package bytestring-0.10.0.2 ... linking ... done.
-- Loading package unix-2.6.0.1 ... linking ... done.
-- Loading package directory-1.2.0.1 ... linking ... done.
-- Loading package process-1.1.0.2 ... linking ... done.
-- ING PACKAGE ARRAY-0.4.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE DEEPSEQ-1.3.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE FILEPATH-1.3.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE OLD-LOCALE-1.0.0.5 ... LINKING ... DONE.
-- LOADING PACKAGE TIME-1.4.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE BYTESTRING-0.10.0.2 ... LINKING ... DONE.
-- LOADING PACKAGE UNIX-2.6.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE DIRECTORY-1.2.0.1 ... LINKING ... DONE.
-- LOADING PACKAGE PROCESS-1.1.0.2 ... LINKING ... DONE.
-- HTTPS://EN.WIKIPEDIA.ORG/WIKI/CONTINUATION-PASSING_STYLE

Read/ Write files

出處: Real World Haskell: Chapter 7

processData :: String -> String
processData = (id :: String -> String)

main = interact $ processData

--- Run in command line
-- > runghc process_data.hs < input.txt
-- hello, world!
processData :: String -> String
processData = (id :: String -> String)

main = do
    inStr <- readFile "input.txt"
    putStrLn $ processData inStr
import System.IO

processData :: String -> String
processData = (id :: String -> String) 


main = do
    inh <- openFile "input.txt" ReadMode
    outh <- openFile "output.txt" WriteMode
    inpStr <- hGetContents inh

    let result = processData inpStr

    hPutStr outh result
    hClose inh
    hClose outh

出處: Tutorials/Programming Haskell/Argument handling: 2.1 Getting in arguments

import System.IO
import System.Environment
import System.Exit

main = getArgs >>= parse >>= putStr . processData

processData :: String -> String
processData = (id :: String -> String)

parse ["-h"] = usage   >> exit
parse []     = getContents
parse fs     = concat `fmap` mapM readFile fs

usage   = putStrLn "Usage: readData [-h] [file ..]"
exit    = exitWith ExitSuccess
die     = exitWith (ExitFailure 1)

Comments

iPad 推薦 app

買 iPad 接近兩週了,利用 iPad 閱讀是一件還蠻愉快的事,缺點就是不夠大還有螢幕很亮吧。以下是我有在用的 App

Reading

Internet

  • Feedly: Google Reader 死了之後的一個選擇,在 iPad 上看的體驗真的非常的好
  • Flipboard: 想要看有的沒有的最佳好物
  • Pocket: 主要是搭配 Feedly 使用。

Dictionary

Utility

  • Mercury: 可以用手勢操作的 browser
  • Gmail, Google Maps: 懶的解釋
  • AVPlayerHD for iPad: 經實驗證明連 7Gbytes 大小高畫質影片都可以播放
  • iA Writer: 雜記用,可以使用 iCloud 同步及直接存取 Dropbox (代表不能離線寫完再同步)
  • Penultimate: 速記用,但是我還是比較常用紙筆就是了。
  • 蝦拼詞庫: 嘸蝦米使用者必備。

Comments

Practice for H99

目前全部貼在 gist 上: Practice for H-99: Ninety-Nine Haskell Problems

有興趣的可以自行前往觀看。

Comments

Web Link Temp

單純做個測試。看看這次我對在網路上看到的連結可以記錄到什麼地步(笑)。

Web Links

Learning

Course

Formal Language and Theory of computation

Functional Programming & Haskell

Development

Libraries

Development Tools

Vim

ZFS

Interesting

Slides

Others

HCI

Apple

xdite

Research

Comments

Install Guide for Mac OSX 10.8 Mountain Lion

自己安裝,暫時備份一下。

SSD setting

  1. Enable the Trim

    sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
    
    # for Mountain Lion 10.8.3 - 10.8.4
    sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
    
    # for Mountain Lion 10.8.1-10.8.2 and Lion 10.7.5
    #sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
    
    # for Mountain Lion 10.8.0 and Lion 10.7.4 BELOW
    #sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
    
    sudo touch /System/Library/Extensions/
    
    # now reboot!
    
  2. Turn off local Time Machine snapshots

    sudo tmutil disablelocal
    
  3. Turn off hibernation

    sudo pmset -a hibernatemode 0
    
  4. Turn off sudden motion sensor (no HDD only)

    sudo pmset -a sms 0
    

Reference: Optimizing MacOS X Lion for SSD - Martin's Weekend Coding

System Preference

  1. General

    1. Apperance: Graphite
    2. Highlight color: Silver
  2. Mission Control

    1. Hot Corners -> right-up corner -> Show Desktop
    2. Uncheck: Show Dashboard as a space
    3. Uncheck: Automatically rearrange spaces based on most recent use
  3. Input Method

    • 嘸蝦米輸入法
      • Language & Text -> Input Sources -> Boshiamy
    • 小麥注音輸入法 McBopomofo
    • Keyboard
      • Change the shortcuts for spotlight and switching inputmethod
  4. Trackpad

    • Point & Click -> Tap to click
    • Uncheck: Scroll direction: natual
    • Swipe between pages
  5. Security & Privacy

    • General -> Anywhere(Allow applictions downloaded from:)
  6. Users & Groups

    1. Replace the profile photo
    2. Guest User -> Uncheck Allow guests to log in to this computer
    3. Login Options -> Show fast user switching menu as "Full Name"

Backup Recovery (using Time Machine)

  • Source to Destination
>
Time Machine PathHarddisk Path
`$BACKUP_PATH/$HOME/Documents` `$HOME/Documents`
`$BACKUP_PATH/$HOME/Music` `$HOME/Music/iTunes`
`$BACKUP_PATH/$HOME/Photo` `$HOME/Pictures/iPhoto 圖庫`
`$BACKUP_PATH/$HOME/Fonts` `$HOME/Fonts`
`$BACKUP_PATH/$HOME/Applications Setting` `$HOME/Library/Application Support`
`$BACKUP_PATH/$HOME/Dictionary` `/Library/Dictionaries`

Basic Enviroment

  1. TotalFinder (or XtraFinder)
  2. XCode
    • Command Line Tools: Preference -> Downloads -> Command Line Tools -> Install
  3. MacTeX
  4. XQuartz
  5. Dropbox
  6. VirtualBox (for Vagrant)
  7. iStat Menus

Dock Order

Screen Shot 2013-08-24 at 10.11.55 PM.png

Mission Control

The custom of Mission Control is using 6 regular Desktops.

  1. Programming Environment - iTrem, MacVim, Subline Text
  2. Writing - TeXShop, LaTeXiT, iWriter, Mou, Papers, Dictionary, Moe Dictionary
  3. Instant Message & Social Netkwork - Adium, Skype, Line, Twitter
  4. Web browsing - Google Chrome, Firefox, Nally, ReadKit
  5. Personal Scheduling - Sparrow, BusyCal, OmniFocus
  6. Music - iTunes, Tritag

Programming Enviroment

  1. Personal setting (Ref: Configuring Mac OS X Mountain Lion 10.8 | Hacker Codex)

    1. Show ~/Library

      chflags nohidden ~/Library/
      
    2. Add the following contents to ~/.bash_profile

      export ARCHFLAGS="-arch x86_64"
      export PATH=/usr/local/share/python:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH:$HOME/usr/bin
      
    3. Link dotfiles

  2. Homebrew

    ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
    brew update
    brew tap homebrew/dupes
    
  3. zsh

    brew install zsh zsh-syntax-highlighting
    sudo echo "/usr/lo cal/bin/zsh" >> /etc/shells
    chsh -s /usr/local/bin/zsh
    
  4. git

    brew install git
    
  5. Haskell platform

    brew install haskell-platform
    cd ~ && cabal update
    cabal install cabal-install
    
  6. Python (ref: Python and Virtualenv on Mac OS X Mountain Lion 10.8)

    brew install python --with-brewed-openssl
    brew install python3 --with-brewed-openssl
    
  7. vim

    brew install vim macvim
    
  8. tar

    brew install gnu-tar 
    sudo rm -rf /usr/bin/tar 
    sudo ln -s /usr/local/bin/gtar /usr/bin/tar
    
  9. cscope and ctags

    brew install cscope ctags
    sudo rm -rf /usr/bin/ctags
    sudo ln -s /usr/local/bin/ctags /usr/bin/ctags
    
  10. pandoc & gitit & hakyll

    cabal install pandoc
    cabal install gitit
    cabal insatll hakyll
    
  11. pyside & pyqt

    brew install pyside pyqt
    
  12. screen & tmux

    brew install screen tmux
    
  13. Others

    brew tap homebrew/dupes
    brew install ssh-copy-id wget unrar cgdb make vim p7zip gnu-time \
    gnuplot sshfs grep sqlite tig doxygen graphviz findutils gnu-getopt \ 
    gnu-which
    
  14. Link brew apps

    mkdir -p $HOME/Applications
    brew linkapps
    

這陣子會慢慢更新到 10.9 去,或許就直接寫一個安裝的 script 也說不定 XD。

  1. Install python packages

      brew install python --with-brewed-openssl
      pip install flask markdown nikola
      pip install numpy scipy scikit-learn matplotlib
      " pip install nltk
    
  2. Install haskell package

      cabal update
      cabal install cabal-install
      cabal install pandoc hakyll agda idris
    

Comments