Tuesday, May 21, 2013

About Markup Language

Markup Language

寫文件或blog最困擾的就是排版, 大略看一下目前較流行的Markdown & reStructuredText, 決定用Markdown來寫, rst給我的感覺就是要再學另一種語言, 雖然強大, 但我只要夠用就好, 必竟都有人用Markdown寫書了 XD.

Markdown Setup

目前是用Vim + Pandoc來寫Markdown, 網路上也有Web editor, 或是windows平台的Markdownpad, 但Web用起來不順手, Markdownpad不能跨平台. 用Vim麻煩的是preview, 寫完要手動用Pandoc轉成html, 之後直接將轉出來的html, 直接貼到blogger.

一般沒有CSS的用法:

$ pandoc README.md -o out.html  

加入CSS依文件的方法是:

$ pandoc -c markdown.css README.md -o out.html  

但是會有一個問題, 貼上blogger時會無法正常顯示, 原因在於html裡是這樣寫的:

<link rel="stylesheet" href="markdown.css" type="text/css" />  

後來想到了一個workaround, 用-H參數將CSS放入Header, 但也不是直接帶入, 需要將一般的CSS file用style tag包起來, 如下:

<style type="text/css">  
Your CSS syntax....  
</style>  

另存成pandoc-markdown.css, 如此才是真正的fully standalone.

$ pandoc -H pandoc-markdown.css README.md -o out.html  

Vim Tips

修改vimrc將*.md標示為Markdown格式, 存檔自動產生HTML檔案.

" Markdown extention
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Auto Pandoc function
function! AutoPandoc()
    "check if pandoc exist
    if filereadable("/usr/bin/pandoc")
        " get current directory path and append CSS file
        let l:csspath=expand("%:p:h")."/pandoc-markdownpad-github.css"
        let l:outPut=expand("%:p:h")."/out.html"
        if filereadable(l:csspath)
            "remove old output
            if filereadable(l:outPut)
                let l:rmOut="!rm -rf ".l:outPut." && sync"
                silent execute l:rmOut
            endif

            " run command
            let l:runCmd="!pandoc -H ".l:csspath." -s ".expand("%:p")." -o ".l:outPut
            echo "Auto generated HTML at ".l:outPut
            silent execute l:runCmd
        endif
    endif
endfunction

"Audo gen html for markdown
autocmd BufWritePost *.markdown,*md call AutoPandoc()

Conclusion

  • 不用煩惱排版的問題, Blogger與Evernote排版不會差太多.
  • 可以用Git來做version control 及 backup.
  • 簡潔有力, 語法簡單.
  • Vim也有人做realtime preview的plug-in: vim-instant-markdown, 但我覺得沒有即時preview的需求.
  • 圖片使用Markdown語法無法調整大小, 可以使用HTML來放圖片.

<img src="http://3.bp.bloGspot.com/-BLhmfBdELH0/UBT3uUd7r5I/AAAAAAAAADw/-rnn2kz5vjY/s220/oops_monk01_120.jpg" width="100">

  • 影片也是用HTML, 以TEDTalk為例:

<iframe src="http://embed.ted.com/talks/lang/zh-tw/ken_robinson_how_to_escape_education_s_death_valley.html"
width="560" height="315" frameborder="0" scrolling="no"
webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

uWSGI & Nginx on Ubuntu

Install uWSGI

Configure uWSGI

$ sudo apt-get install python-dev python-pip  
$ sudo pip uwsgi  
################# uWSGI configuration #################  
pcre = False  
kernel = Linux  
malloc = libc  
execinfo = False  
ifaddrs = True  
ssl = True  
matheval = False  
zlib = True  
locking = pthread_mutex  
plugin_dir = .  
timer = timerfd  
yaml = True  
json = False  
filemonitor = inotify  
routing = False  
debug = False  
zeromq = False  
capabilities = False  
xml = expat  
event = epoll  
############## end of uWSGI configuration #############  
*** uWSGI is ready, launch it with /usr/local/bin/uwsgi ***  
Successfully installed uwsgi  
Cleaning up...  
$  

Test uWSGI

Create test file called hello.py:
def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"  
Run uWSGI:
uwsgi --http :8000 --wsgi-file hello.py  
Open browser connect on port 8000.
http://localhost:8000

Install Nginx

Configure nginx

$ sudo apt-get install nginx-full  
The configure file path : /etc/nginx/sites-enabled/default Add your site in nginx configure file.
    location /wsgi/ {
            uwsgi_pass 127.0.0.1:8001;
            include uwsgi_params;
    }  
Use localhost port 8001 for uwsgi protocol, and 80 port for nginx. Run uwsgi and start nginx.
$ uwsgi --socket :8001 --wsgi-file hello.py  
$ sudo service nginx start  
Test your web site:
http://your-ip/wsgi/  
or
http://localhost/wsgi/
Ref:
uWSGI Tutorial - Django and nginx
WSGI using uWSGI and nginx on Ubuntu 12.04 (Precise Pangolin)

Sunday, February 3, 2013

BT download use Raspberry Pi


install Transmission

$ sudo apt-get install transmission-daemon

config
$ cd /etc/transmission-daemon
$ sudo cp settings.json settings.json.sbak
$ sudo vi settings.json
"download-dir": "/home/oopsmonk/BT-Download"
"rpc-whitelist": "*.*.*.*"
"rpc-username": "oopsmonk"
"rpc-password": "web-login-pwd"

change permission on download folder.
$ chmod 777 /home/oopsmonk/BT-Download

The torrent file location
/var/lib/transmission-daemon/info/torrents/

test:
http://RaspberryPi-ip:9091

WebGUI use HTTP port

$ sudo install nginx
$ sudo vi /etc/nginx/sites-available/default
server{
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
...
        location /transmission {
                proxy_pass http://127.0.0.1:9091/transmission;
        }
...
}
$ sudo service nginx restart

Test:
http://ip/transmission/web/

Reference:
Setting Up Transmission’s Web Interface
Linux防健忘日誌No.69-Ubuntu 12.04 安裝及設定transmission-daemon

OpenNMS Architecture Introduction (Discovery & Monitor)

O.S. : Ubuntu12.04 LTS
OpenNMS Version : 1.10.7

OpenNMS base on TMN & FCAPS network management models.
OpenNMS Block Diagram


Discovery & Monitor daemons
* Eventd
Event handling daemon
Configuration files:
eventconf.xml -> Defines the UEI (Universal Event Identifiers).
eventd-configuration.xml -> Defines operating parameters for eventd such as timeouts, listener threads and listener port.
events-archiver-configuation.xml -> Configuration for event archive daemon.
events.archiver.properties -> Fine tune events archive subsystem.
etc/events/*.xml -> Vendor UEI define files.
Listening "eventsConfigChange" event.

* Discovery (discovery-configuration.xml)
Discovery service implement the Singleton pattern.
Listening events: discPause, interfaceDeleted, discResume, nodeGainedInterface, discoveryConfigChange and reloadDaemonConfig.

* Capsd (Capabilities daemon, capsd-configuration.xml)
Notified by the discovery process when a new node is discovered, the polls for all the capabilities for this node and loading the data collected into the database.
Listening events: deleteService, changeService, deleteInterface, newSuspect, froceRescan, addInterface, nodeDeleted, addNode, updateServer, nodeAdded, duplicateNodeDeleted, deleteNode and updateService.

* Collectd (collectd-configuration.xml)  
Responsible for gathering and storing data from various sources, including SNMP, JMX, HTTP and NSClient.
Listening events: nodeGainedService, primarySnmpInterfaceChanged, reinitializePrimarySnmpInterface, interfaceReparented, nodeDeleted, duplicateNodeDeleted, interfaceDeleted, serviceDeleted, schedOutagesChanged, configureSNMP, thresholdConfigChange, reloadDaemonConfig and nodeCategoryMembershipChanged.

* Poller (poller-configuration.xml)
Polling services, including ICMP, DNS, FTP, HTTP, HTTPS, SSH, MySQL....
Listening events: nodeGaineService, serviceDeleted, interfaceReparented, nodeDeleted, nodeLabelChanged, duplicateNodeDeleted, interfaceDeleted, suspendPollingService, resumePollingService, schedOutagesChanged, demandPollService, thresholdConfigChange, assetInfoChanged and nodeCategoryMembershipChanged.

* RTC (Real-Time Collector)
The RTC initializes its data from the database when it comes up then subscribes to the events subsystem to receive events of interest to keep the data up-to-date.
Listening events: nodeGainedService, nodeLostService, interfaceDown, nodeDown, nodeUp, nodeCategoryMembershipChanged, interfaceUp, nodeRegainedService, serviceDeleted, serviceunmanaged, interfaceReparented, subscribe, unsubscribe and assetInfoChanged.

Note:
There are two major ways that OpenNMS gathers data about the network.
The first is through polling. Processes called monitors connect to a network resource and perform a simple test to see if the resource is responding correctly. If not, events are generated.
The second is through data collection using collectors. Currently, the only collector is for SNMP data.
Collectd record SNMP data to RRDTool in /share/rrd/snmp/NodeID/*,  Ex:  tcpOutSegs.jrb, icmpInEchos.jrb, tcpInSegs.jrb, ifInOctets.jrb, ifoutOctets.jrb...
Poller record Service data to RRDTool in /share/rrd/response/IP/*,  Ex: icmp.jrb ssh.jrd...

OpenNMS configuration files:

Discovery & Monitor Flow
Here is the event flow then press "Save and Restart Discovery" button on WebGUI.
Figure 1

Figure 2


References :

Saturday, February 2, 2013

Create S3 on AWS use s3cmd

1. open S3 web console


2. Create Bucket
You can use any names for your objects, but bucket names must be unique across all of Amazon S3. 
Objects stored in Amazon S3 are addressable using the REST API under the domain bucketname.s3.amazonaws.com. 
For example, if the object homepage.html is stored in the Amazon S3 bucket mybucket its address would be http://mybucket.s3.amazonaws.com/homepage.html. 
For more information, see Virtual Hosting of Buckets. 


Install s3cmd
download s3cmd from http://s3tools.org/s3cmd

install on Ubuntu 12.04 
$ sudo python setup.py install

configure s3cmd
$ s3cmd --configure

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3
Access Key: AWS_ACCESS_KEY
Secret Key:
AWS_SECRET_KEY

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: PWD_WHAT_U_WANT
Path to GPG program [/usr/bin/gpg]:

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]: Yes

New settings:
  Access Key:
AWS_ACCESS_KEY
  Secret Key:
AWS_SECRET_KEY
  Encryption password: PWD_WHAT_U_WANT
  Path to GPG program: /usr/bin/gpg
  Use HTTPS protocol: True
  HTTP Proxy server name:
  HTTP Proxy server port: 0

Test access with supplied credentials? [Y/n]
Please wait, attempting to list all buckets...
Success. Encryption and decryption worked fine :-)

Save settings? [y/N] y
Configuration saved to '/home/oopsmonk/.s3cfg'
$
Change .s3cfg permission.
$ chmod 600 /home/oopsmonk/.s3cfg

$ s3cmd mb s3://test.s3cmd.cli
Bucket 's3://test.s3cmd.cli/' created



put file
$ s3cmd put ./README s3://test.s3cmd.cli/
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
./README -> s3://test.s3cmd.cli/README  [1 of 1]
13130 of 13130   100% in    1s    11.64 kB/s  done

delete file
$ s3cmd del s3://test.s3cmd.cli/README
File s3://test.s3cmd.cli/README deleted

delete Bucket
$ s3cmd rb s3://test.s3cmd.cli
Bucket 's3://test.s3cmd.cli/' removed



Commands:
  Make bucket
      s3cmd mb s3://BUCKET
  Remove bucket
      s3cmd rb s3://BUCKET
  List objects or buckets
      s3cmd ls [s3://BUCKET[/PREFIX]]
  List all object in all buckets
      s3cmd la
  Put file into bucket
      s3cmd put FILE [FILE...] s3://BUCKET[/PREFIX]
  Get file from bucket
      s3cmd get s3://BUCKET/OBJECT LOCAL_FILE
  Delete file from bucket
      s3cmd del s3://BUCKET/OBJECT
  Synchronize a directory tree to S3
      s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX] or s3://BUCKET[/PREFIX] LOCAL_DIR
  Disk usage by buckets
      s3cmd du [s3://BUCKET[/PREFIX]]
  Get various information about Buckets or Files
      s3cmd info s3://BUCKET[/OBJECT]
  Copy object
      s3cmd cp s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
  Move object
      s3cmd mv s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
  Modify Access control list for Bucket or Files
      s3cmd setacl s3://BUCKET[/OBJECT]
  Enable/disable bucket access logging
      s3cmd accesslog s3://BUCKET
  Sign arbitrary string using the secret key
      s3cmd sign STRING-TO-SIGN
  Fix invalid file names in a bucket
      s3cmd fixbucket s3://BUCKET[/PREFIX]
  Create Website from bucket
      s3cmd ws-create s3://BUCKET
  Delete Website
      s3cmd ws-delete s3://BUCKET
  Info about Website
      s3cmd ws-info s3://BUCKET
  List CloudFront distribution points
      s3cmd cflist
  Display CloudFront distribution point parameters
      s3cmd cfinfo [cf://DIST_ID]
  Create CloudFront distribution point
      s3cmd cfcreate s3://BUCKET
  Delete CloudFront distribution point
      s3cmd cfdelete cf://DIST_ID
  Change CloudFront distribution point parameters
      s3cmd cfmodify cf://DIST_ID
  Display CloudFront invalidation request(s) status
      s3cmd cfinvalinfo cf://DIST_ID[/INVAL_ID]

Friday, November 30, 2012

About Bread!!

結束上份工作後, 不想閒著, 也就開始找新"玩具",
做麵包好像滿有趣的, 又不用出門可以在家陪小朋友,
於是爬了2~3天的文章,了解需要的東西,
Google什麼是yeast(Active dry, Instant dry, Fresh)?
什麼是麵粉(高筋, 中筋, 低筋, 法國粉)?
什麼是麵糰(擴展, 完成)?
什麼是揉麵?
天真的以為"吐司"很簡單,麵糰整好丟進烤模..done.
結果烤到第五條吐司, 才達成滿模的標準.

失敗品之一:


接著白吐司太無聊了, 所以做了其它嚐試,
全麥鮪魚麵包
高粉 270g
全麥粉 30g
Instant dry 3/4t
奶油 20g
塩 1/2t
糖 20g
水 185g

整形參考: 蒔蘿鮪魚麵包


海蒂的白麵包
配方跟做法參考 【肉桂打噴嚏】海蒂的白麵包


全麥豆漿枸杞葡萄乾
高粉 270g
全麥粉 30g
Instant dry 3/4t
奶油 20g
塩 1/2t
糖 20g
豆漿 185g
枸杞 + 葡萄乾 適量.


做了這些後, 深深感到...
萬能的雙手真的累人又吵, 尤其吐司要揉到完成階段.
再上鄰居來關切說: "你家是不是最近在釘東西?"...XD

於是開始Google解決辦法..
沒想到真的有人研發出No-Knead Bread...OMG

不過缺點是要"長時間發酵"..
後來又改善了長時間發酵的缺點:
Speedy No-Knead Bread
  
於是No-Knead Bread成了目前主要的做法
優點:
1. 免揉 == 不累沒噪音
2. 麵糰不加奶油 and 糖, 感覺較健康.
3. 我愛歐包的脆皮及咬勁
缺點:
麵糰水份高, 不易操作.

 使用陶鍋試了這個方法5次後, 覺得缺點還可以接受,
反正自己吃不用做美美的..XD
麵糰配方:
高粉 200g
Instant dry 1/8t
塩 1/4t
水 170~175g
 
今天特別做了一個大size的:
蜂蜜乾果全麥歐包, 乾果是葡萄乾+核桃
 
整形再發酵60分鐘就入烤箱了,
烤箱中的大陶鍋, 上色時表皮的乾果烤焦了..
 
出爐几分鐘後還量了一下,
沒想到裡面還有90几度的高溫@@..

Wednesday, September 12, 2012

How to split boot.img and get kernel config.

boot_cm9.img  file from mk802_legacy-compatibility_v1.zip
Device: Rikomagic MK802
Script files : Split_bootimg.pl , extract-ikconfig ( in {kernel_source}/script )

1. split boot.img
$ mkdir split_boot
$ cd split_boot
Copy boot_cm9.img, Split_bootimg.pl, extract-ikconfig into 'split_boot'
$ ./split_bootimg.pl boot_cm9.img
Page size: 2048 (0x00000800)
Kernel size: 8094708 (0x007b83f4)
Ramdisk size: 178940 (0x0002bafc)
Second size: 0 (0x00000000)
Board name:
Command line: console=ttyS0,115200 rw init=/init loglevel=8
Writing boot_cm9.img-kernel ... complete.
Writing boot_cm9.img-ramdisk.gz ... complete.

Get kernel image (boot_cm9.img-kernel) and ramdisk (boot_cm9.img-ramdisk.gz)

2. extract kernel config
$ dd if=boot_cm9.img-kernel of=dd_uImage bs=1024 skip=1
7903+1 records in
7903+1 records out
8093684 bytes (8.1 MB) copied, 0.0178518 s, 453 MB/s
$./extract-ikconfig dd_uImage > kernel_config


3. extract ramdisk
$ mkdir ramdisk
$ cd ramdisk
$ gzip -dc ../boot_cm9.img-ramdisk.gz | cpio -i
6677 blocks
$ tree .
.
├── data
├── default.prop
├── dev
├── init
├── init.goldfish.rc
├── initlogo.rle
├── init.rc
├── init.sun4i.rc
├── init.sun4i.usb.rc
├── proc
├── sbin
│   ├── adbd
│   └── ueventd -> ../init
├── sys
├── system
├── ueventd.goldfish.rc
├── ueventd.rc
└── ueventd.sun4i.rc


Ref : HOWTO: Unpack, Edit, and Re-Pack Boot Images