2012年7月4日 星期三

[應用程式] Templates of OpenOffice

最近在做投影片,沒有特別用HTML5做,只是用傳統的Impress而已
想要換個template爽一下,剛好逛到官方網站,目前覺得這個最順眼,不過不知道為什麼低分?

[JavaScript] Levels of JavaScript Knowledge

最近看到鐵神的舊文,簡單的評估一下自己的JavaScript能力,沒想到我只有在等級五而已...

等級一:會使用內建的函式
alert("Hello World");
等級二:會使用自訂的function
var WORLD = "World";
function hello(who) {
  alert("Hello " + who);
};
hello(WORLD);
等級三:會在HTML標籤內使用事件觸發來呼叫JavaScript
<button onclick="hello(WORLD)">Say Hello</button>
等級四:懂得DOM的基本架構並且將事件觸發處理函式移到JavaScript區塊
<button id="hello">Say Hello</button>
var button = document.all.hello;
button.onclick = function() {
  hello(WORLD);
};
等級五:會使用標準的DOM加上事件(Event)撰寫JavaScript
var button = document.getElementById("hello");
button.addEventListener("click", function(event) {
  hello(WORLD);
}, false);

等級六:回歸到Object Base的JavaScript的設計方式
var Hello = new Binding({
  greet: function(who) {
    alert("Hello " + who);
  },
  
  onclick: function() {
    this.greet(Hello.WORLD)
  }
}, {
  WORLD: "World"
});
document.bind("#hello", Hello);

reference:
* Levels of JavaScript Knowledge
* [分享] JavaScript 知識等級

2012年6月29日 星期五

[應用程式] 個人工作環境之.bashrc

.bashrc一般是*nix login程序最後會套用到的個人環境變數設定檔,要建立舒適的個人化設定就需要在這檔案下功夫,比如說
要有Git的branch提示,可能會添加這樣的指令:
GIT_PS1_SHOWDIRTYSTATE=1
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\[\033[01;31m\]$(__git_ps1)\[\033[00m\]\$\[\033[00m\] '
要能顯示history的時間,可以這樣加:
export HISTTIMEFORMAT="%F %T " 

持續更新中...

reference:
* Show current Git branch and status in your prompt
* LIST COMMAND LINE HISTORY WITH TIMESTAMP

2012年6月14日 星期四

[轉貼][應用程式] 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples

原文標題: 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples
原文作者: RAMESH NATARAJAN
發表日期: OCTOBER 21, 2011
原文來源: http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/

Question: Can you explain how to use OR, AND and NOT operators in Unix grep command with some examples?

Answer: In grep, we have options equivalent to OR and NOT operators. There is no grep AND opearator. But, you can simulate AND using patterns. The examples mentioned below will help you to understand how to use OR, AND and NOT in Linux grep command.

The following employee.txt file is used in the following examples.

$ cat employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
400  Nisha   Manager    Marketing   $9,500
500  Randy   Manager    Sales       $6,000

You already knew that grep is extremely powerful based on these grep command examples.

Grep OR Operator 
Use any one of the following 4 methods for grep OR. I prefer method number 3 mentioned below for grep OR operator.

1. Grep OR Using \| 

If you use the grep command without any option, you need to use \| to separate multiple patterns for the or condition.

grep 'pattern1\|pattern2' filename

For example, grep either Tech or Sales from the employee.txt file. Without the back slash in front of the pipe, the following will not work.

$ grep 'Tech\|Sales' employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
500  Randy   Manager    Sales       $6,000

2. Grep OR Using -E 

grep -E option is for extended regexp. If you use the grep command with -E option, you just need to use | to separate multiple patterns for the or condition.

grep -E 'pattern1|pattern2' filename

For example, grep either Tech or Sales from the employee.txt file. Just use the | to separate multiple OR patterns.

$ grep -E 'Tech|Sales' employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
500  Randy   Manager    Sales       $6,000

3. Grep OR Using egrep 

egrep is exactly same as 'grep -E'. So, use egrep (without any option) and separate multiple patterns for the or condition.

egrep 'pattern1|pattern2' filename

For example, grep either Tech or Sales from the employee.txt file. Just use the | to separate multiple OR patterns.

$ egrep 'Tech|Sales' employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
500  Randy   Manager    Sales       $6,000

4. Grep OR Using grep -e 

Using grep -e option you can pass only one parameter. Use multiple -e option in a single command to use multiple patterns for the or condition.

grep -e pattern1 -e pattern2 filename

For example, grep either Tech or Sales from the employee.txt file. Use multiple -e option with grep for the multiple OR patterns.

$ grep -e Tech -e Sales employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
500  Randy   Manager    Sales       $6,000

Grep AND 

5. Grep AND using -E 'pattern1.*pattern2'

There is no AND operator in grep. But, you can simulate AND using grep -E option.

grep -E 'pattern1.*pattern2' filename
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename

The following example will grep all the lines that contain both "Dev" and "Tech" in it (in the same order).

$ grep -E 'Dev.*Tech' employee.txt
200  Jason   Developer  Technology  $5,500

The following example will grep all the lines that contain both "Manager" and "Sales" in it (in any order).

$ grep -E 'Manager.*Sales|Sales.*Manager' employee.txt

Note: Using regular expressions in grep is very powerful if you know how to use it effectively.

6. Grep AND using Multiple grep command 

You can also use multiple grep command separated by pipe to simulate AND scenario.

grep -E 'pattern1' filename | grep -E 'pattern2'

The following example will grep all the lines that contain both "Manager" and "Sales" in the same line.

$ grep Manager employee.txt | grep Sales
100  Thomas  Manager    Sales       $5,000
500  Randy   Manager    Sales       $6,000

Grep NOT 

7. Grep NOT using grep -v 

Using grep -v you can simulate the NOT conditions. -v option is for invert match. i.e It matches all the lines except the given pattern.

grep -v 'pattern1' filename

For example, display all the lines except those that contains the keyword “Sales”.

$ grep -v Sales employee.txt
200  Jason   Developer  Technology  $5,500
300  Raj     Sysadmin   Technology  $7,000
400  Nisha   Manager    Marketing   $9,500

You can also combine NOT with other operator to get some powerful combinations. For example, the following will display either Manager or Developer (bot ignore Sales).

$ egrep 'Manager|Developer' employee.txt | grep -v Sales
200  Jason   Developer  Technology  $5,500
400  Nisha   Manager    Marketing   $9,500

2012年4月25日 星期三

[Tips] How to configure ThinkPad trackpoint in Linux?

最近對比了一下另外一台裝Windows XP的X61,驚覺在Linux上的trackpoint速度不是很快,也不夠靈敏,想要調整卻找不到在哪裡調,找到這篇發現直接寫入driver就可以了

預設設定是這樣的,
$ cat /sys/devices/platform/i8042/serio1/sensitivity 128
$ cat /sys/devices/platform/i8042/serio1/speed 97
$ cat /sys/devices/platform/i8042/serio1/press_to_select 0
$ cat /sys/devices/platform/i8042/serio1/upthresh 255

如果不是root而直接sudo可能會出現
bash: /sys/devices/platform/i8042/serio1/sensitivity: Permission denied

遇到這樣就把指令寫成.sh然後再sudo執行就沒問題了,最後我改成
#!/bin/sh
echo -n 160 > /sys/devices/platform/i8042/serio1/sensitivity                                                                 
echo -n 120 > /sys/devices/platform/i8042/serio1/speed

reference: [Solved] How to configure ThinkPad trackpoint in arch?

2012年4月23日 星期一

[Embedded] undefined reference to `rpl_malloc'

今天在交叉編譯mhash時發生編譯的錯誤,
../lib/.libs/libmhash.so: undefined reference to `rpl_malloc'

一開始看不出什麼問題,後來爬了一下文,才知道原來malloc被換掉了... 
所以把mhash_config.h的define註解掉就可以了

$ vim include/mutils/mhash_config.h
257 /* #define malloc rpl_malloc */ 

2012年4月10日 星期二

[科技新知] Twitter open sources its MySQL

Twitter open sources its MySQL,at github,and document

Features in Twitter MySQL
* Additional status variables
* Optimization of memory allocation under NUMA
* Server-side query timeout
* Buffer pool export and restore by prefetch
* Optimization for solid-state drives (SSDs)