2014年2月18日 星期二

JSON (JavaScript Object Notation) Format

完整的JSON寫法:

01{
02  'familys' = [
03    {'name' : 'Bruce',
04     'age' : 18,
05     'sex' : 'male'},
06    {'name' : 'Sherry',
07     'age' : 16,
08     'sex' : 'famale'}
09  ]
10}

JSON會建構出兩種結構:(1)「"名稱" : 值」的集合;(2)Array。

JSON的細節

比對上面範例,你會發現一點也不難。

JSON Object:
  1. 以"{"開始,以"}"結尾
  2. 每個名稱後跟著一個":"
  3. 每對"名稱:值"之間用","分隔
1{ // 以"{"開始
2  'name' : 'Bruce',  // 每個名稱後跟著一個":"
3  'age' : 18,        // 每對"名稱:值"之間用","分隔
4  'sex' : 'male'
5} // 以"}"結尾

JSON Array:
  1. 以"["開始,以"]"結尾
  2. 值之間使用","
01{
02  // familys為一維陣列,陣列裡包含兩筆物件資料
03  'familys' = [  // 以"["開始
04    {'name' : 'Bruce',
05     'age' : 18,
06     'sex' : 'male'},  // 值之間使用","
07    {'name' : 'Sherry',
08     'age' : 16,
09     'sex' : 'famale'}
10  ] // 以"]"結尾
11}

JSON Value:
  • 值本身可以是String、Number、true、false、null、Object、Array;

JSON String:
  • 由雙引號包圍的任意Unicode字元集合。可以使用"反斜線(\)"來轉義。
1{
2  "details" : "這是JSON的值. \n 此格式比XML合適Ajax交換資料使用."
3}

JSON Number:
  • 與一般數值相同,除8 / 16進制外。

2014年1月24日 星期五

TMUX (Terminal MUltipleXer )

screen 與 tmux 的比較  (from http://josephj.com/entry.php?id=373)

稍微整理一下 screen 與 tmux,大家就會知道 tmux 有多好了。

screen

screen 架構
screen 的架構很簡單,一個 screen 連線只能被一個 SSH 連線存取、
一個 screen 可有多個 window、
只支援水平分割、同時觀看多個 window。

tmux

tmux 的架構
tmux 管理的東西較多:包括 Session(連線)、Window(視窗)與 Pane(窗格)。

tmux 優點 1 - 可以被多個 SSH 同時連線

tmux Session 可以被多個 SSH 同時連線,這點跟 Screen 很不同。
過去用 screen 你離開辦公桌的電腦,晚上回到家裡繼續工作時,必定得 detach 再 attach。
但是用 tmux 的話,你可以在家裡 attach,隔天到公司 tmux 並不會被 detach。
所以若你開兩個 tmux 同時 attach 到同一個 Session 時,可以看到兩個視窗同時動作的有趣畫面喔。
所以在這樣的架構下,你就不用擔心像 screen 不正常斷線無法 detach 再 attach 的問題了。

tmux 優點 2 - 可在 Session 中切換到不同 Session

過去要從 screen 到另一個 screen 得先 detach,
但 tmux 只要用快速鍵(預設 Ctrl-b + s)即可切換到其他 Session。
是不是很方便呢?

tmux 優點 3 - 強大的分割視窗

screen 只能做單一水平分割,但是 tmux 可以自由自在地水平或垂直分割。
一個窗格被稱為 Pane,分割會被記錄至 Window 保存(screen 只要一 detach 就沒了)
且一個 Pane 可隨時轉換成 Window,Pane 調整大小、位置的功能更是完整。
---------------------------------------------------------------------------------------------------
操作方式、常用快捷键:
大寫的C==>Control鍵
C+b c 開新視窗
C+b n 或 space 切換到下一個視窗
C+b P 切換到上一個視窗
====視窗分割功能======
C+b " 水平分割視窗
C+b % 垂直分割視窗
C+b up or down 切換分割視窗
C+b C上 or C下 分割視窗大小調整
C+b C左 or C右 分割視窗大小調整
C+b space 重新佈置分割的視窗
C+b ! 取消所有分割視窗
指令 exit 跳出當前分割視窗
C+b + Ctrl + 方向鍵上/下/左/右
# 可以調整當前分割視窗的長寬,好用!
作用鍵 + d
# 將目前的 Tmux Session 丟到背景去
tmux ls
# 列出主機上所有的 Tmux Session
tmux a -t 0
# 將背景的第 0 號 Tmux Session 叫回,a 代表 attach
Ctrl+b激活控制台;此时以下按键生效
系统操作?列出所有快捷键;按q返回
d脱离当前会话;这样可以暂时返回Shell界面,输入tmux attach能够重新进入之前的会话
D选择要脱离的会话;在同时开启了多个会话时使用
Ctrl+z挂起当前会话
r强制重绘未脱离的会话
s选择并切换会话;在同时开启了多个会话时使用
:进入命令行模式;此时可以输入支持的命令,例如kill-server可以关闭服务器
[进入复制模式;此时的操作与vi/emacs相同,按q/Esc退出
~列出提示信息缓存;其中包含了之前tmux返回的各种提示信息
窗口操作c创建新窗口
&关闭当前窗口
数字键切换至指定窗口
p切换至上一窗口
n切换至下一窗口
l在前后两个窗口间互相切换
w通过窗口列表切换窗口
,重命名当前窗口;这样便于识别
.修改当前窗口编号;相当于窗口重新排序
f在所有窗口中查找指定文本
面板操作”将当前面板平分为上下两块
%将当前面板平分为左右两块
x关闭当前面板
!将当前面板置于新窗口;即新建一个窗口,其中仅包含当前面板
Ctrl+方向键以1个单元格为单位移动边缘以调整当前面板大小
Alt+方向键以5个单元格为单位移动边缘以调整当前面板大小
Space在预置的面板布局中循环切换;依次包括even-horizontal、even-vertical、main-horizontal、main-vertical、tiled
q显示面板编号
o在当前窗口中选择下一面板
方向键移动光标以选择面板
{向前置换当前面板
}向后置换当前面板
Alt+o逆时针旋转当前窗口的面板
Ctrl+o顺时针旋转当前窗口的面板
視窗取回
screen -r
tmux attach
視窗取回 by session name
screen -r session-name
tmux attach -t session-id
視窗開啟自訂 session-name
screen -S session-name
tmux new -s session-name # ex: tmux new -s irc
列出所有 session
screen -ls
tmux ls # tmux list-sessions
----------------------------------------------------------------------------
http://www.slideshare.net/slideshow/embed_code/30000994?rel=0&hostedIn=slideshare&no_embed_cta=true

2014年1月16日 星期四

undefined reference to rpl_malloc

如果編譯的時候遇到未定義引用rpl_malloc這個錯誤,有兩個方法可以解決。
  • 配置的時候加上了 - with-GNU-ld的這個參數
  • 或者在config.h中裡加上的#undef rpl_malloc

2013年12月20日 星期五

特殊MAC地址---官方保留

IEEE Std 802.1D and IEEE Std 802.1Q Reserved Addresses
Group MAC address value
Organization
using the value
Standard using the value
Notes
01-80-C2-00-00-00
IEEE 802
IEEE Std 802.1D
IEEE Std 802.1Q
IEEE Std 802.1D Bridge Group Address
01-80-C2-00-00-01
IEEE 802
"
IEEE MAC-specific control protocols
01-80-C2-00-00-02
IEEE 802
"
IEEE Std 802.3 Slow Protocols multicast address
01-80-C2-00-00-03
IEEE 802
"
IEEE Std 802.1X PAE address
01-80-C2-00-00-04
IEEE 802
"
IEEE MAC-specific control protocols
01-80-C2-00-00-05
IEEE 802
"
Reserved for media access method specific use
01-80-C2-00-00-06
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-07
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-08
IEEE 802
"
Provider Bridge group address
01-80-C2-00-00-09
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0A
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0B
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0C
IEEE 802
"
Reserved for future standardization
01-80-C2-00-00-0D
IEEE 802
"
Provider Bridge MVRP address
01-80-C2-00-00-0E
IEEE 802
"
Std 802.1AB Link Layer Discovery Protocol address
01-80-C2-00-00-0F
IEEE 802
"
Reserved for future standardization

Standard Group MAC Addresses
Group MAC address value
Organization
using the value
Standard using the value
Notes
01-80-C2-00-00-10
IEEE 802
IEEE Std 802.1D
All LANs Bridge Management Group Address (deprectated)
01-80-C2-00-00-11
IEEE 802
IEEE Std 802.1E
Load Server Generic Address
01-80-C2-00-00-12
IEEE 802
IEEE Std 802.1E
Loadable Device Generic Address
01-80-C2-00-00-13
unassigned
  
01-80-C2-00-00-14
ISO/IEC JTC1/SC6
ISO/IEC 10589
All Level 1 Intermediate Systems Address
01-80-C2-00-00-15
ISO/IEC JTC1/SC6
ISO/IEC 10589
All Level 2 Intermediate Systems Address
01-80-C2-00-00-16
ISO/IEC JTC1/SC6
ISO/IEC 10030
All CONS End Systems Address
01-80-C2-00-00-17
ISO/IEC JTC1/SC6
ISO/IEC 10030
All CONS SNARES Address
01-80-C2-00-00-18
IEEE 802
IEEE Std 802.1B
Generic Address for All Manager Stations
01-80-C2-00-00-19
unassigned
  
01-80-C2-00-00-1A
IEEE 802
IEEE Std 802.1B
Generic Address for All Agent Stations
01-80-C2-00-00-1B
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Capable End Systems Address
01-80-C2-00-00-1C
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Announcements Address
01-80-C2-00-00-1D
ISO/IEC JTC1/SC6
ISO/IEC 9542
All Multicast Capable Intermediate Systems Address
01-80-C2-00-00-1E
ISO/IEC JTC1/SC6
ISO/IEC 8802-5
All DTR Concentrators MAC Group Address
01-80-C2-00-00-1F
unassigned
  
01-80-C2-00-00-20 —
01-80-C2-00-00-2F
IEEE 802
IEEE Std 802.1Q
Reserved for use by Multiple Registration Protocol (MRP) applications


01-80-C2-00-00-30 —
01-80-C2-00-00-3F
IEEE 802
IEEE Std 802.1ag
Destination group MAC addresses for CCM and Linktrace messages
01-80-C2-00-00-40 to 01-80-C2-00-00-4F
IETF
TRILL
Group MAC addresses used by the TRILL protocols
01-80-C2-00-00-40 —
01-80-C2-00-00-FF
unassigned
  
01-80-C2-00-01-00
 
ISO/IEC 9314-6
Ring Management Directed Beacon Multicast Address
01-80-C2-00-01-01 —
01-80-C2-00-01-0F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-10
ISO/IEC JTC1/SC25
ISO/IEC 9314-6
Status Report Frame Status Report Protocol Multicast Address
01-80-C2-00-01-11 —
01-80-C2-00-01-1F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-20
ISO/IEC JTC1/SC25
ISO/IEC 9314-2
All FDDI Concentrator MACs
01-80-C2-00-01-21 —
01-80-C2-00-01-2F
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-01-30
ISO/IEC JTC1/SC25
ISO/IEC 9314-6
Synchronous Bandwidth Allocation Address
01-80-C2-00-01-31 —
01-80-C2-00-01-FF
ISO/IEC JTC1/SC25
 
Assigned to ISO/IEC JTC1/SC25 for future use
01-80-C2-00-02-00 —
01-80-C2-00-02-FF
ETSI
 
Assigned to ETSI for future use
01-80-C2-00-03-00 —
01-80-C2-FF-FF-FF
unassigned
  

Group MAC Addresses Used in ISO 9542 ES-IS Protocol
Group MAC address value
Organization
using the value
Standard using the value
Notes
09-00-2B-00-00-04
ISO/IEC JTC1/SC6
ISO 9542
All End System Network Entities Address
09-00-2B-00-00-05
ISO/IEC JTC1/SC6
ISO 9542
All Intermediate System Network Entities Address
Locally Administered Group MAC Addresses Used by IEEE Std 802.5
(IEEE Std 802.5 Functional Addresses)
Group MAC address value
Organization
using the value
Standard using the value
Notes
03-00-00-00-00-08
IEEE 802
IEEE Std 802.5
Configuration Report Server (CRS) MAC Group Address
03-00-00-00-00-10
IEEE 802
IEEE Std 802.5
Ring Error Monitor (REM) MAC Group Address
03-00-00-00-00-40
IEEE 802
IEEE Std 802.5
Ring Parameter Server (RPS) MAC Group Address
03-00-00-00-01-00
IEEE 802
ISO 9542
All Intermediate System Network Entities Address
03-00-00-00-02-00
ISO/IEC JTC1/SC6,
IEEE 802
ISO 9542, and
IEEE Std 802.5
All End System Network Entities Address, and Lobe Media Test (LMT) MAC Group Address
03-00-00-00-04-00
IEEE 802
IEEE Std 802.1B
Generic Address for all Manager Stations
03-00-00-00-08-00
IEEE 802
ISO/IEC 10030
All CONs SNARES Address
03-00-00-00-10-00
IEEE 802
ISO/IEC 10030
All CONs End System Address
03-00-00-00-20-00
IEEE 802
IEEE Std 802.1E
Loadable Device Generic Address
03-00-00-00-40-00
IEEE 802
IEEE Std 802.1E
Load Server Generic Address
03-00-00-40-00-00
IEEE 802
IEEE Std 802.1B
Generic Address for all Agent Stations

2013年12月10日 星期二

Raspberri-Pi Debian Tuning

Speedup CPU:
we can easily modify the cpu work frequency modifying the config.txt file. Just edit /boot/config.txt
arm_freq=900
i always use this hack and my rpi run without problem
Change scheduler/elevator at boot time:
we use more responsive/less disk io usage scheduler:
modify the /boot/cmdline.txt 
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback elevator=deadline rootwait quiet
Tuning sysctl.conf:
as manual say, sysctl.conf is the “Configuration file for setting system variables”... well there are lot of variables you can put inside this file and for everyone we can write a book.
Our goal is to gain more speed and tell our system to use less io/ram. Let’s put in the /etc/sysctl.conf:
vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 1200
vm.overcommit_ratio = 2
vm.laptop_mode = 5
vm.swappiness = 10
Removing unused services:
Removing services is a must to do for every system or computer, i have see some linux server with 256Mb of RAM with bluetooth, pcmcia etc etc service enabled... or pc with 100% cpu busy to run some 3d tube screensaver installed by default... also in Debian RaspberryPi official distro...
Automatically startx on boot:
I didn't use session/desktop manager like gdm, xdm or slim, it’s take ram and slow down starting up. Simply way is to use inittab:
vi /etc/inittab
1:2345:respawn:/bin/login -f root tty1

/dev/tty1 2>&1 (default is 1:23:respawn:/sbin/getty 38400 tty1)
and add this to .bash_profile on root home:
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  exec startx >/dev/null 2>&1
fi 

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...