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

2011年11月21日 星期一

terminal 快捷鍵


Ctrl + a : 移到行首
Ctrl + e : 移到行尾
Ctrl + u : 刪除到行尾
Ctrl + k : 刪除到行尾
Ctrl + f : 光標以字元向右移動
Ctrl + b :光標以字元向左移動


Alt + f : 光標以單字向右移動
Alt + b :光標以單字向左移動

Ctrl + l:清除螢幕

最小化当前窗口 = Alt + F9
最大化当前窗口 = Alt + F10 

ctrl+alt+f2=linux终端用户(alt + f7返回xwindows,alt+ <- 或-> 进行终端切换)
桌面選擇= Ctrl + Alt + 下箭头,然后按住 Ctrl + Alt 和左/右箭头选择桌面
http://linuxtoy.org/archives/bash-shortcuts.html

河內塔

河內塔
ABC三跟柱子
一次移一個盤子
大盤子不能在小盤子之上
print  each steps
void hanoi(int n,char A,char B,char C)
{
    if(n==1)
        printf(" Move sheet from %c to %c\n",A,C);
    else{
        hanoi(n-1,A,C,B);
        hanoi(1,A,B,C);
        hanoi(n-1,B,A,C);
    }
}

2011年10月29日 星期六

LAMP

#how to install lamp - apache2 , mysql , php

sudo apt-get install apache2

#test if http://localhost/  has been works.
_________________________________________________
#install php5 and dependecy

sudo apt-get install php5 libapache2-mod-php5
sudo /etc/init.d/apache2 restart
_________________________________________________
#install mysql

sudo apt-get install mysql-server

#set mysql root password

_________________________________________________

Then get phpmyadmin to control you MySQL by browser

follow instruction in such sample.config file
and rename to erase 'sample'

It should be put in /var/www/

ps.
if  http://localhost/phpmyadmin is not found

check /etc/apache2/apache2.conf
remember restart

PS
if phpmyadmin has something wrong
remove all php5
install php5 / php5-mysql / php5-mcrypt at same time

2011年10月28日 星期五

SQL-add user

add a newuser in mysql by SQL below:


CREATE USER 'cfg'@'%' IDENTIFIED BY '***';

GRANT ALL PRIVILEGES ON * . * TO 'cfg'@'%' IDENTIFIED BY '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0MAX_USER_CONNECTIONS 0 ;

GRANT ALL PRIVILEGES ON `mysql` . * TO 'cfg'@'%';

2011年9月13日 星期二

Linux-tar

tar是Linux上用來封裝(打包)檔案用的

tar [-j|-z] [-cv] -f tar_name target
打包target

tar [-j|-z] [-tv] -f tar_name
察看tar之檔

tar [-j|-z] [-xv] -f tar_name [-C director]
解開tar
-C可指定愈放置檔案之目錄
預設是在當前目錄

-j -z 不要亂加
-j為支援bzip2,tarname要是*.tar.bz2
-z為支援gzip,tarname要是*.tar.gz

-c 打包
-t 察看
-x 解開
-v 顯示詳細內容
-f 檔案
一般用此即可
tar -cvf xxx.tar file
tar -xvf xxx.tar [-C director]

2011年9月1日 星期四

Algorithms-simple binary search

first,you need sort

then you could search the 'numeber'

variable t show the recursive times

code:

2011年8月23日 星期二

C-集合

列出{1,2,....,n}之所有子集,包括空集合ϕ

code:(參考名題百則)


notion:
產生布林表
利用i,j找出對應值
0000 --> {}
1000 --> {1}
0100 --> {2}
1100 --> {1,2}
0010 --> {3}
1010 --> {1,3}
0110 --> {2,3}
依此類推

2011年8月15日 星期一

Linux vim copy and paste

if copy and paste can't work

in vim

:h gui-clipboard

add this line in _vimrc
source $VIMRUNTIME/mswin.vim

2011年7月1日 星期五

C/C++ - rand()

#include<stdlib.h>

if you need a random number between a(min) and b(max) ,
use:

int x = (rand()%(max-min+1))+min

usually use srand() to build random base

ex:
1 int randnum(int min,int max)
2 {
3         int a;
4         srand(time(NULL));
5         a =(rand()%(max-min+1))+min;
6         return a;
7 }

time() include time.h
rand() and srand() include stdlib.h