2011年12月29日 星期四
2011年11月21日 星期一
terminal 快捷鍵
Ctrl + a : 移到行首
Ctrl + e : 移到行尾
Ctrl + u : 刪除到行尾
Ctrl + k : 刪除到行尾
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
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
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'@'%';
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月17日 星期六
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]
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:
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}
依此類推
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
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:
time() include time.h
rand() and srand() 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
2011年6月26日 星期日
2011年6月20日 星期一
2011年6月17日 星期五
2011年6月16日 星期四
2011年6月15日 星期三
2011年6月9日 星期四
Ubuntu/Mint 系統邊框 標題列不見
mint ubuntu 系出同門,通常發生的問題一樣
今天開mint赫然發現 邊框跟標題列不見了
所以沒辦法按最小化或是x
參考網路上的方法
首先到home 按ctrl+h 顯示隱藏檔案
將.gonf(如果有.gonfd也要)重新命名
接著 重新啟動gnome
sudo /etc/init.d/gdm restart
(接著不知為啥,文字介面跑一跑就停了,手動重開機後,就恢復了
參考:http://fouvy.info/2011/02/02/ubuntu_gnome_reset/
今天開mint赫然發現 邊框跟標題列不見了
所以沒辦法按最小化或是x
參考網路上的方法
首先到home 按ctrl+h 顯示隱藏檔案
將.gonf(如果有.gonfd也要)重新命名
接著 重新啟動gnome
sudo /etc/init.d/gdm restart
(接著不知為啥,文字介面跑一跑就停了,手動重開機後,就恢復了
參考:http://fouvy.info/2011/02/02/ubuntu_gnome_reset/
Linux-sudoer
當要執行一些指令時,可能需要具有管理者的身份
可以先用su切換到root或是
sudo 指令
程式會去檢查/etc/sudoers 該使用者是否有執行sudo的權限
#install sudo
su
apt-get intstall sudo
#add user to sudoers
su
visudo
user ALL=(ALL) ALL (使用者帳號 登入者的來源主機名稱 可切換的身份 可下達的指令)
設定完該使用者即可使用sudo 執行root的指令
可以先用su切換到root或是
sudo 指令
程式會去檢查/etc/sudoers 該使用者是否有執行sudo的權限
#install sudo
su
apt-get intstall sudo
#add user to sudoers
su
visudo
user ALL=(ALL) ALL (使用者帳號 登入者的來源主機名稱 可切換的身份 可下達的指令)
設定完該使用者即可使用sudo 執行root的指令
2011年6月1日 星期三
2011年5月31日 星期二
Linux-vim gvim settings
#get colors ex:freya (my favorite color
#set
mkdir ~/.vim
cd .vim
mkdir colors
cp colorfile ~/.vim/colors/colorfile
#set vimrc(~/.vimrc)
#gvim_Startup Settings
set autoindent (自動縮排
colorscheme colorname (預設顏色 ex:colorscheme freya
set nu(行號
#if it can't work ,check the file's right
ls -all (to check colorfile's right
# 4space replace tab(tab usually
set expandtab (insert space whenever tab be pressed
set tabstop=4 (the characters of one tab, use :retab that make file match this settings
set shiftwidth=4 (the insertion of the indent
#有可能會有格式錯誤情況
doc2unix colorfile
此提供很多顏色可預覽http://code.google.com/p/vimcolorschemetest/
#set
mkdir ~/.vim
cd .vim
mkdir colors
cp colorfile ~/.vim/colors/colorfile
#set vimrc(~/.vimrc)
#gvim_Startup Settings
set autoindent (自動縮排
colorscheme colorname (預設顏色 ex:colorscheme freya
set nu(行號
#if it can't work ,check the file's right
ls -all (to check colorfile's right
# 4space replace tab(tab usually
set expandtab (insert space whenever tab be pressed
set tabstop=4 (the characters of one tab, use :retab that make file match this settings
set shiftwidth=4 (the insertion of the indent
#有可能會有格式錯誤情況
doc2unix colorfile
此提供很多顏色可預覽http://code.google.com/p/vimcolorschemetest/
2011年5月24日 星期二
Linux-cgit
//install git
sudo apt-get install git
//if can't find git
sudo vim /etc/apt/sources.list
>>deb http://ftp.de.debian.org/debian squeeze main
sudo apt-get update
//get cgit and git code
git clone git://hjemli.net/pub/git/cgit
cd ~/cgit
make get-git
//install need lib and package
sudo apt-get install
zlib1g.dev
libssl.dev
curl
make
cc
apache2
//install cgit
sudo make
sudo make install
//setting apache2
sudo vim /etc/apache2/sites-available/default
ScriptAlias /cgit/ /var/www/htdocs/cgit/ #http://localhost/cgit/cgit.cgi
<Directory "/var/www/htdocs/cgit/">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
//config 由於cgit不會自己建立設定檔,手動複製範例來改
cp ~/cgit/cgitrc.5.txt /etc/cgitrc
sudo apt-get install git
//if can't find git
sudo vim /etc/apt/sources.list
>>deb http://ftp.de.debian.org/debian squeeze main
sudo apt-get update
//get cgit and git code
git clone git://hjemli.net/pub/git/cgit
cd ~/cgit
make get-git
//install need lib and package
sudo apt-get install
zlib1g.dev
libssl.dev
curl
make
cc
apache2
//install cgit
sudo make
sudo make install
//setting apache2
sudo vim /etc/apache2/sites-available/default
ScriptAlias /cgit/ /var/www/htdocs/cgit/ #http://localhost/cgit/cgit.cgi
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
//config 由於cgit不會自己建立設定檔,手動複製範例來改
cp ~/cgit/cgitrc.5.txt /etc/cgitrc
Online Judge-Prime(質數建表)
Problem:輸入n (1<=n<=1,000,000) 判斷n是否為質數. 如果x為一非質數之正整數,必有小於等於根號x之質因數. 建立給定範圍開根號以內之質數表(一百萬根號即一千),接著判斷n是否能整除這些質數,如不可則為質數.
#include<stdio.h> #include<math.h> int main() { //建立質數表 int n,j,i,s=2,f[168],x; f[0]=2;f[1]=3; for(i=5;i<=1000;i++) { x=sqrt(i); for(j=2;j<=x;j++) { if(i%j==0)break; } if(j>x){f[s]=i;s++;} } while(scanf("%d",&n)!=EOF) { if(n==0)break; if(n==1){printf("1\n");continue;} if(n==2||n==3){printf("0\n");continue;} else { //判斷n是否可整除質數表裡的質數 i=0; x=sqrt(n); while(f[i]<=x) { if(n%f[i]==0){printf("1\n");break;} i++; } if(f[i]>x)printf("0\n"); } } return 0; }
2011年5月18日 星期三
Linux-Vim
//install vim on Linux mint/debian/ubuntu
sudo apt-get install vim
//gui
sudo apt-get install vim-gnome
//open
vim >>terminal直接進入vim
gvim >>terminal另外開啟gvim
**su 登入為root後 無法透過terminal開啟gvim
sudo apt-get install vim
//gui
sudo apt-get install vim-gnome
//open
vim >>terminal直接進入vim
gvim >>terminal另外開啟gvim
**su 登入為root後 無法透過terminal開啟gvim
Linux Mint10-Samba
//Samba share (無須帳號密碼
//install samba
sudo apt-get install samba
//vim /etc/samba/smb.conf(設定檔
[share](win 之目錄名稱
comment = share(註解
path = /var/share/
guest ok = yes
writable = yes
browseable = yes
//更改資料夾權限
chmod 777 /samba path
//win 網路芳鄰即可使用
//install samba
sudo apt-get install samba
//vim /etc/samba/smb.conf(設定檔
[share](win 之目錄名稱
comment = share(註解
path = /var/share/
guest ok = yes
writable = yes
browseable = yes
//更改資料夾權限
chmod 777 /samba path
//win 網路芳鄰即可使用
訂閱:
意見 (Atom)