2012年9月23日 星期日

Permutation in C

the permutation in c

the process is:
First,
find the first l from left to right that p[l]<p[l+1]
Next,
find the first r from left to right again that p[l]<p[r]
so p[r] is the only one bigger than p[l]
then
swap p[l] and p[r]
and
reverse p[l+1...n-1]
code:

2012年9月1日 星期六

Setting ThinkPad TrackPoint

Whatever I try, the rc.local still won't work when it boots or reboots.
That's mean I need to run the command manually to change trackpoint speed, sensitivity.


#!/bin/bash
echo -n xxx > /sys/devices/platform/i8042/serio1/speed
echo -n yyy > /sys/devices/platform/i8042/serio1/sensitivity
exit 0
put this shell in /bin/xxx.sh is a little more convenient to use.

2012年2月28日 星期二

python code

在文件 最上面加上
# coding=utf-8
or
# -*- coding:utf-8 -*-

代表此份文件是 utf-8 編碼格式
中文都會是 utf-8 編碼
但函式產生的字串是unicode
在字串應用時 得一致
所以得轉換

str.decode('utf-8')

將str 由utf-8解碼成unicode

str.encode('utf-8')

將str 由unicode編碼成utf-8

再轉換時 一定得先搞清楚str是什麼碼

2012年2月8日 星期三

C pointer


  • variable => one cell number 
  • type is used to inform the details about the variable
  • pointer is used to put an address

中文:
  • 任何變數都只是一段記憶體編號
  • 型別是用來說明此變數的資訊
  • 指標變數放的是記憶體位址
int *a; 
int **a;  ( 雙指標
int a[5];  ( a[0]的位址等於a
int *a[5]; ( array of 'pointer to int'
int (*a)[5]; ( pointer to array of int
int (*a)(); ( pointer to function

int (*(*a)())[5] ( 指標指向函式 其回傳一個指標指向5個元素的陣列

指標與陣列並不相等


關於函式指標
例子:用函式回傳一個指向陣列的指標



2012年1月19日 星期四

ThinkPad mint11 setup

scim(chewing,jp
terminator
gpointing-device-setting
vim
apache, mysql, php, myphpadmin
git
chrome, flash
python(python-setuptools, flask, python-mysqldb
sun-java6-jdk

2012年1月11日 星期三

Mint update google chrome

since chrome in my mint won't auto-update

so

sudo apt-get install google-chrome-stable

either flashplayer

sudo apt-get install adobe-flahplugin