2010年12月13日 星期一
從Ubuntu 10.10 server開始安裝
#pppoe安裝與使用
sudo pppoeconf # 基本上一直按yes跟注意輸入帳號密碼就行了
sudo pon dsl-provider # 開啟連線
sudo poff # 關閉連線
sudo plog # 檢查狀態
apt-get update # 要得先更新
#在Ubuntu 10.10 server 中 安裝xwindows
apt-get install xinit
apt-get install gnome-core
apt-get install gdm xscreensaver
apt-get install ttf-arphic*
startx
# 安裝了視窗介面 跟 網路 就可以隨意了
# 目前感覺起來真的功力有增加
#以下為好用工具
apt-get install jockey # 管理driver
apt-get install vim # 現在已經是沒有vim沒有辦法過日子了
sudo add-apt-repository ppa:lazyscripts/stable # 常用工具都在這裡 lazyscripts
sudo apt-get update && sudo apt-get install lazyscripts # 包括gcin、多媒體撥放等
apt-get install file-roller # 預設是把壓縮檔mount到桌面 改回跳出顯示壓縮檔內容的界面
apt-get install unrar lha p7zip-full p7zip-rar
sudo pppoeconf # 基本上一直按yes跟注意輸入帳號密碼就行了
sudo pon dsl-provider # 開啟連線
sudo poff # 關閉連線
sudo plog # 檢查狀態
apt-get update # 要得先更新
#在Ubuntu 10.10 server 中 安裝xwindows
apt-get install xinit
apt-get install gnome-core
apt-get install gdm xscreensaver
apt-get install ttf-arphic*
startx
# 安裝了視窗介面 跟 網路 就可以隨意了
# 目前感覺起來真的功力有增加
#以下為好用工具
apt-get install jockey # 管理driver
apt-get install vim # 現在已經是沒有vim沒有辦法過日子了
sudo add-apt-repository ppa:lazyscripts/stable # 常用工具都在這裡 lazyscripts
sudo apt-get update && sudo apt-get install lazyscripts # 包括gcin、多媒體撥放等
apt-get install file-roller # 預設是把壓縮檔mount到桌面 改回跳出顯示壓縮檔內容的界面
apt-get install unrar lha p7zip-full p7zip-rar
2010年12月10日 星期五
更改jvm
最近電腦常常當機 可是也不曉得為什麼 結果在~/裡面發現一些當機的資料
hs_err_pidxxxxx.log
仔細看了一看 發現是 jvm出了問題 也難怪開eclipse當機
依照網路上的資料 用了下面兩行顯示jvm跟更改jvm
出現了一堆錯誤訊息 大致上是說少了一些java plugin
於是先安裝 sun-java6-plugin 就完成了!!
語法如下:
hs_err_pidxxxxx.log
仔細看了一看 發現是 jvm出了問題 也難怪開eclipse當機
依照網路上的資料 用了下面兩行顯示jvm跟更改jvm
sudo update-java-alternatives -l
sudo update-java-alternatives -s java-6-sun
但是 鐺鐺~~ 沒有那麼順利就成功的!!!sudo update-java-alternatives -s java-6-sun
出現了一堆錯誤訊息 大致上是說少了一些java plugin
於是先安裝 sun-java6-plugin 就完成了!!
語法如下:
sudo apt-get install sun-java6-plugin
sudo update-java-alternatives -s java-6-sun
成功的更新了jvm!!
sudo update-java-alternatives -s java-6-sun
2010年12月8日 星期三
安裝 gcin
現在的linux也是越來越人性化了~~ 想當年~~ orz
兩行!!!!
sudo apt-get install gcin
im-switch -s gcin
gcin的介面還蠻舒服的 而且倚天鍵盤的設定 很容易找
雖然輸入不是很習慣 但是...是好物!!
兩行!!!!
sudo apt-get install gcin
im-switch -s gcin
gcin的介面還蠻舒服的 而且倚天鍵盤的設定 很容易找
雖然輸入不是很習慣 但是...是好物!!
2010年12月1日 星期三
ssh 免密碼登入
果然是已經學過的事情 在學一次果然很快 ="=
但是不紀錄下來 真的是不行
---------------------------------
三個步驟
1 ssh-keygen -t dsa
2 scp公鑰 到目標伺服器
3 連線到目標伺服器 將公鑰檔案附加到~/.ssh/authorized_key中
特別要注意的事情是
authorized_key的權限是600如果不是~~歹勢~ 是沒有辦法成功的!!!
至於scp的用法 scp 檔案 遠端帳號@遠端伺服器名稱
但是不紀錄下來 真的是不行
---------------------------------
三個步驟
1 ssh-keygen -t dsa
2 scp公鑰 到目標伺服器
3 連線到目標伺服器 將公鑰檔案附加到~/.ssh/authorized_key中
特別要注意的事情是
authorized_key的權限是600如果不是~~歹勢~ 是沒有辦法成功的!!!
至於scp的用法 scp 檔案 遠端帳號@遠端伺服器名稱
2010年11月21日 星期日
Expression Parser - 五則運算式解析
import java.util.HashMap;
public class OperatorPrioritySaver {
HashMap priorityMap = new HashMap();
public OperatorPrioritySaver() {
priorityMap.put("+", 1);
priorityMap.put("-", 1);
priorityMap.put("*", 2);
priorityMap.put("/", 2);
priorityMap.put("%", 2);
}
int comp(String op1, String op2) throws RuntimeException{
if(priorityMap.get(op1)==null ){
throw new RuntimeException("not an accept op :" +op1);
}
if(priorityMap.get(op2)==null ){
throw new RuntimeException("not an accept op :" +op2);
}
return priorityMap.get(op1).compareTo(priorityMap.get(op2));
}
boolean acceptOperator(String test){
return priorityMap.keySet().contains(test);
}
}
import java.util.Stack;
public class ExpressionParser {
private String exprString ;
private int value ;
OperatorPrioritySaver opsvr = new OperatorPrioritySaver();
Stack nums = new Stack();
Stack ops = new Stack();
public ExpressionParser(String exprString) {
this.exprString = exprString ;
}
public String getExprString(){
return exprString ;
}
public int getValue() {
return value;
}
public String toString() {
return exprString +" = " + value ;
}
public void parse() {
String terns[] = exprStr2Terns();
int num = 0 ;
String op = null ;
for(String tern : terns){
try{
num = Integer.parseInt(tern) ;
op = null ;
}catch(NumberFormatException e){
op = tern ;
}
if(op == null){ // number
nums.push(num);
}else{ // operator
String top = null ;
if("(".equals(op) || ")".equals(op)){
if("(".equals(op)){
ops.push(op);
}else if(")".equals(op)){
while( (top = ops.pop()) != null &&
(!top.equals("("))){
doOperator(top);
}
}
}else if(opsvr.acceptOperator(op)){
while( ops.size() > 0 &&
(top = ops.peek()) != null &&
(!top.equals("(")) &&
(opsvr.comp(top, op)>=0)){
top = ops.pop();
doOperator(top);
}
ops.push(op);
}else {
System.err.println("Unsupported operator : " + op);
}
}
}
while(ops.size() != 0){
doOperator(ops.pop());
}
value = nums.get(0);
}
private String[] exprStr2Terns() {
// 目前使用空格隔開所有的符號
// 想不用空格隔開 可以自行修改
return exprString.split(" ");
}
private void doOperator(String op) {
char opCh = op.toCharArray()[0];
int num2 = 0, num1 = 0;
switch(opCh){
case '+':
num2 = nums.pop();
num1 = nums.pop();
nums.push(num1+num2);
break;
case '-':
num2 = nums.pop();
num1 = nums.pop();
nums.push(num1-num2);
break;
case '*':
num2 = nums.pop();
num1 = nums.pop();
nums.push(num1*num2);
break;
case '/':
num2 = nums.pop();
num1 = nums.pop();
nums.push(num1/num2);
break;
case '%':
num2 = nums.pop();
num1 = nums.pop();
nums.push(num1%num2);
break;
}
}
public static void main(String[] args) {
ExpressionParser expr = new ExpressionParser("( 1 + 2 ) * 3");
expr.parse();
System.out.println(expr);
}
}
2010年11月19日 星期五
安裝了Ubuntu
昨晚失眠~~ (我到底再說什麼到底XD)
其實是因為最近睡覺時間都是四五點,昨晚又真的時間到了還很不想睡
於是起床開了我那見鬼的XP,竟然開不了機
在有著十分充分理由的情況下,我把他給format掉了!!!
安裝的過程也不是十分順利
因為我最先找的10.10並不是很順利的可以安裝
我本來以為是我自己硬碟怪怪的
還找了指令把|MBR給清乾淨
bs=446是因為 最前面的512 byte其實就是整個mbr
而之前的446個byte是在存開機程式的 後面的(512 - 446)byte則是 儲存磁區分割的資料
count參數呢~~ 待查!!
搞了半天 等我從燒了一片10.04以後就順利的安裝完成了!!! GOOD!!
Ubuntu + lazyscripts + apt-get 讓我省了不少時間
音樂影片都可以順利的撥放
看到deb結尾的副檔名就是很順利的ko了
目前要在我的ubuntu裡面安裝LAMP希望可以順利成功
PS.安裝MySQL時抓下來的是rpm檔 在安裝了rpm要來rpm -ivh時
沒想到竟然可以用alien將rpm轉換成deb 然後在點兩下就安裝了 真的是太方便了!!!!
還差把LAMP都整合在一起 這個感覺起來是大工程~~ 加油!!!
其實是因為最近睡覺時間都是四五點,昨晚又真的時間到了還很不想睡
於是起床開了我那見鬼的XP,竟然開不了機
在有著十分充分理由的情況下,我把他給format掉了!!!
安裝的過程也不是十分順利
因為我最先找的10.10並不是很順利的可以安裝
我本來以為是我自己硬碟怪怪的
還找了指令把|MBR給清乾淨
dd if=/dev/zero of=/mnt/sda bs=446 count=1
這個指令其實是在做複製位元的動作 把if複製到of去長度為bs 這個就是在將硬碟磁區的mbr清除bs=446是因為 最前面的512 byte其實就是整個mbr
而之前的446個byte是在存開機程式的 後面的(512 - 446)byte則是 儲存磁區分割的資料
count參數呢~~ 待查!!
搞了半天 等我從燒了一片10.04以後就順利的安裝完成了!!! GOOD!!
Ubuntu + lazyscripts + apt-get 讓我省了不少時間
音樂影片都可以順利的撥放
看到deb結尾的副檔名就是很順利的ko了
目前要在我的ubuntu裡面安裝LAMP希望可以順利成功
PS.安裝MySQL時抓下來的是rpm檔 在安裝了rpm要來rpm -ivh時
沒想到竟然可以用alien將rpm轉換成deb 然後在點兩下就安裝了 真的是太方便了!!!!
還差把LAMP都整合在一起 這個感覺起來是大工程~~ 加油!!!
2010年11月16日 星期二
國中時的題目 用天秤找出一堆砝碼中唯一過重的那一個。
import java.util.Arrays;
import java.util.Random;
public class DrawingPanel {
static int N = 8;
public static void main(String[] args) {
float balls[] = new float[N];
Arrays.fill(balls, 1f);
Random rand = new Random();
balls[rand.nextInt(N) % balls.length] = 1.2f;
int rs = compare(balls, 0, balls.length);
for(int i = 0 ; i < balls.length ;i++){
System.out.println(String.format("%c : %.1f", 'A'+i, balls[i]));
}
System.out.println("ans : " + (char)('A'+rs));
}
static int compare(float[] balls, int first, int last) {
int size = last-first;
if(size == 1){
return first ;
}
int group = size / 3 ;
if( size % 3 != 0)
group = size / 3 + 1 ;
float gp1 = sum(balls, first, first+group);
float gp2 = sum(balls, first+group, first+2*group);
if(gp1 > gp2){
return compare(balls, first, first+group);
}else if(gp1 < gp2){
return compare(balls, first+group, first+2*group);
}else{
return compare(balls, first+2*group, last);
}
}
static float sum(float arr[], int first, int last){
float sum = 0f ;
for(int i = first ; i < last ; i++)
sum += arr[i];
return sum ;
}
}
想到可以把他貼過來~~
2010年11月13日 星期六
Java - 字型處理
取得所有Font
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for(Font f: fonts){
System.out.println(f.getName());
}
自行設定字型for(Font f: fonts){
System.out.println(f.getName());
}
Font font = new Font(fontName, fontStyle, fontSize);
Font newFont = font.deriveFont(fontType); // int
Font newFont = font.deriveFont(fontSize); // float
Font newFont = font.deriveFont(fontType, fontSize); // int, float
設定Font(在JPanel中)Font newFont = font.deriveFont(fontSize); // float
Font newFont = font.deriveFont(fontType, fontSize); // int, float
setFont(font);
取得FontMetrics,並用其取得文字在某種字型時的資訊 FontMetrics metrics = getFontMetrics(font);
messageWidth = metrics.stringWidth(message);
messageWidth = metrics.stringWidth(message);
2010年11月12日 星期五
java - Regular Expression
Java Regular Expression 用法!!
String target = "a" ;
Pattern ptn = Pattern.compile("[a-zA-Z]");
if(ptn.matcher(target).find()){
System.out.print("find!!");
}
要找時間把正規表示式的寫法整理一下,每次用都要查真的是煩死人了!!
2010年11月6日 星期六
if和goto代替for
這是在知識家幫人家回答的題目,用if和goto代替for寫出九九乘法表(的格式)
想說打都打了,不要浪費!
============變成============
以下為完整的程式
想說打都打了,不要浪費!
for(int i = 0 ; i < 9 ; i++){
// work here
}
int i = 0 ;
LOOP_BEGIN :
if(i < 9){
// work here
i++ ;
goto LOOP_BEGIN ;
}else{
goto LOOP_END ;
}
LOOP_END :
#include <iostream>
#include <cstdlib>
using namespace std ;
int main(){
int i = 9;
LOOP_1_BEGIN:
if(i >= 1){
int j = 9 ;
LOOP_2_BEGIN:
if(j >= 1){
cout << i << "*" << j << " " ;
j-- ;
goto LOOP_2_BEGIN ;
}else{
goto END_LOOP_2 ;
}
END_LOOP_2 :
cout << endl ;
i-- ;
goto LOOP_1_BEGIN ;
}else{
goto END_LOOP_1 ;
}
END_LOOP_1 :
system("pause");
return 0 ;
}
2010年11月3日 星期三
mod_perl 安裝
只要選對了Perl的版本 就可以了!!!!
昨天弄了一個晚上,到ActiveState的網站上用新版的Perl 5.12.xxx要來安裝mod_perl,結果都是失敗的!
On不起來就是On不起來。雖然裡面有mod_cgi可以用,但是我的老毛病又犯了!! 硬是要弄到好 >"<
後來改用ActivePerl-5.8.xxx,在執行下面指令,並且依照安裝的過程的提示,一切就順利的OK了!! 感動!!
ppm install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd
執行完後,會在中間所指定的資料夾產生mod_perl,只要把它放在Apache2.2中的modules資料夾裡面,並且修改httpd.conf加入以下指令就行了。LoadFile "C:/Path/to/Perl/bin/perl58.dll" LoadModule perl_module modules/mod_perl.so
以上mod_perl的安裝算是完成了,phpinfo()已經可以看到mod_perl了,接著需要將路徑指派給perl。
<ifmodule perl_module> LoadFile "C:/Perl/bin/perl58.dll" <directory "C:/Apache2.2/cgi-bin"> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders AllowOverride all Options all Order allow,deny Allow from all </Directory> </IfModule>
2010年11月2日 星期二
安裝 Apache 2.2 和 設定PHP5
複製自php安裝目錄install.txt L652~L673
內容看起來是安裝php5到apache1.3
Installing as an Apache module
You should add the following lines to your Apache httpd.conf file:
Example 2-3. PHP as an Apache 1.3.x module
This assumes PHP is installed to c:\php. Adjust the path if this is not the case.
For PHP 5:
# Add to the end of the LoadModule section
LoadModule php5_module "C:/php/php5apache.dll" 我的路徑不一樣,檔案則是php5apache2_2.dll
# Add to the end of the AddModule section
AddModule mod_php5.c 在apache2.2中沒有AddModule所以我沒有用
For both:
# Add this line inside the <ifmodule> conditional brace</ifmodule>
AddType application/x-httpd-php .php
# For syntax highlighted .phps files, also add
AddType application/x-httpd-php-source .phps 這一行也沒有設定
- 安裝完apache2.2,
- 安裝PHP5
- 設定httpd.conf
- LoadModule php5_module "C:\Program Files\PHP\php5apache2_2.dll"
- <IfModule php5_module>
AddType application/x-httpd-php .php
</IfModule> - <IfModule dir_module>
DirectoryIndex index.php index.htm index.html
</IfModule>
接著,就是測試了,重點只有不要吧PHP的括胡用錯。 Orz
<?
phpinfo();
?>
phpinfo();
?>
PS.使用PHP5.2.14和PHP5.3.3的msi包裝安裝,在選擇了某些extension時,會讓Apache開不起來。
2010年7月15日 星期四
Ruby on Rails - 安裝
Ruby 1.8.7 + Rails 2.0.2 安裝
安裝 Ruby One Click Installer 1.8.7
執行 gem install -v=2.0.2 -r rails
安裝 Ruby One Click Installer 1.8.7
執行 gem install -v=2.0.2 -r rails
2010年7月8日 星期四
msvcrt-ruby18.dll missing!!!
http://www.ruby-forum.com/topic/205457
這篇說 安裝ruby 1.9可是卻顯示需要msvcrt-ruby18.dll
這個很奇怪的事情 明明就是1.9卻出現1.8
回應說 執行
gem install wxruby-ruby19
這篇說 安裝ruby 1.9可是卻顯示需要msvcrt-ruby18.dll
這個很奇怪的事情 明明就是1.9卻出現1.8
回應說 執行
gem install wxruby-ruby19
ERROR: While executing gem … (Gem::GemNotFoundException)
安裝了 One-Click Ruby Installer for Windows
接著要來安裝rails > gem install rails
結果出現了......
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find rails (> 0) in any repository
需要先升级gem
gem update --system
2010年2月2日 星期二
Shell Sort
終於弄懂這個了阿 哈哈
人家的說明我真的都看不懂 Orz
Shell Sort是利用insertion sort的一個特性
白話的說insertion sort是將未排序集合中拿一個出來,並且"插入"至以排序集合中自己應至的位置
將步驟標上順序
排序陣列E 且 n = |E|
1. FOR pos = n TO 1 STEP -1
2. 取出pos位置的元素
3. 將pos位置元素插入至pos+1到n這個以排序的部分
步驟3 假如不要用單純的陣列,改使用Linked List的話
插入的動作可以很省時間,而且不需要不斷地交換位置,只需要二元搜尋然後插入
說起來如果陣列本來就排的差不多的話 insertion sort是很快的
http://www.sorting-algorithms.com/insertion-sort
Shell Sort則是利用這個特性並衍生出下面的概念
利用Insertion Sort大致排好一些 > 再排一些 > 再排一些 > ... > 完成。
至於證明!! 在查一下吧!!
演算法如下
// 找出最大的間隔
人家的說明我真的都看不懂 Orz
Shell Sort是利用insertion sort的一個特性
白話的說insertion sort是將未排序集合中拿一個出來,並且"插入"至以排序集合中自己應至的位置
將步驟標上順序
排序陣列E 且 n = |E|
1. FOR pos = n TO 1 STEP -1
2. 取出pos位置的元素
3. 將pos位置元素插入至pos+1到n這個以排序的部分
步驟3 假如不要用單純的陣列,改使用Linked List的話
插入的動作可以很省時間,而且不需要不斷地交換位置,只需要二元搜尋然後插入
說起來如果陣列本來就排的差不多的話 insertion sort是很快的
http://www.sorting-algorithms.com/insertion-sort
Shell Sort則是利用這個特性並衍生出下面的概念
利用Insertion Sort大致排好一些 > 再排一些 > 再排一些 > ... > 完成。
至於證明!! 在查一下吧!!
演算法如下
// 找出最大的間隔
h = 1
while h < n, h = 3*h + 1
// 當間隔大於0的時候,用insertion sort排序
while h > 0,
h = h / 3
for k = 1:h, insertion sort a[k:h:n]
→ invariant: each h-sub-array is sorted
end
2010年1月26日 星期二
Java Compile
在compile java的時候
有兩個參數 -cp(-classpath) 和 -sourcepath
這個在compile的時候是很重要的。
今天在學校上SCJP的課程,老師是傳說中的良葛格!!
雖然我上課偷偷打網誌,不過我心裡還是很尊敬他的。
有兩個參數 -cp(-classpath) 和 -sourcepath
這個在compile的時候是很重要的。
今天在學校上SCJP的課程,老師是傳說中的良葛格!!
雖然我上課偷偷打網誌,不過我心裡還是很尊敬他的。
Java Compile Recusively on Windows
下面的語法是windows 的cmd語法,可以用來 Compile Java的程式碼。
1. 搜尋全部的路徑 放進檔案中
2. 將檔案的內容compile
3. 然後把他刪掉!!
dir src\*.java /B/S > _files.src
javac -d classes @_files.src
delete _files.src
P.S. 預設原始碼路徑放在src下面,編譯出來的class檔案放在classes中。
相對應還有linux版本
還有用java就會知道的ant版本的語法
可是......沒有簡單一點的嗎?? _Orz
1. 搜尋全部的路徑 放進檔案中
2. 將檔案的內容compile
3. 然後把他刪掉!!
dir src\*.java /B/S > _files.src
javac -d classes @_files.src
delete _files.src
P.S. 預設原始碼路徑放在src下面,編譯出來的class檔案放在classes中。
相對應還有linux版本
還有用java就會知道的ant版本的語法
可是......沒有簡單一點的嗎?? _Orz
2010年1月12日 星期二
Data
String
str1 = "abc"
str2 = String.new
Array
a = Array.new
a = [1,3,4,5,6,7]
Hash
h = Hash.new
h = { a => b, c => d }
str1 = "abc"
str2 = String.new
Array
a = Array.new
a = [1,3,4,5,6,7]
Hash
h = Hash.new
h = { a => b, c => d }
Variable
基本變數類型 | 說明 | 範例 |
| Local Variable | 不用於類別時,以英文或是底線開頭的非關鍵字單字。 用於類別,則可以表示成類別常數。 | in normal abc = 1 _abc = 2 in class class Math PI = 3.14159 end |
| Global Variable | 同上但是加上$符號 | $abc = 123 $_abc = 456 |
| Instance Variable | 用於類別的實體,當類別被建立成實體時才能使用。 | class Person |
| Class Variable | 用於類別,屬於類別的變數。 | class Person |
訂閱:
意見 (Atom)
