發表文章

目前顯示的是 2019的文章

[Web] Mac 安裝 Telnet

在10.12及以下版本,都有內建telnet命令,但在10.13以後,都已经取消了。 Last login: Sun Aug 11 11:44:10 on ttys000 HaoKi$ telnet -bash: telnet: command not found 打開终端機 安裝Homebrew -> /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” 再輸入密碼 指令在這裡-> https://brew.sh/index_zh-tw.html HaoKi$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ==> This script will install: /usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /usr/local/Homebrew ==> The following existing directories will be made group writable: /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 ==> The following existing directories will have their owner set to HaoKi: /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 ==> The following existing directories will have

[Java] String 轉換 Integer

String -> Integer //將 String 轉換成 Integer public static void main(String[] args) { String str = "1234"; int intValue1 = Integer.parseInt(str); int intValue2 = Integer.parseInt("12345"); int intValue3 = Integer.valueOf("12345"); } Integer -> String //將 Integer 轉換成 String public static void main(String[] args) { int intValue = "1234"; String str1 = String.valueOf(intValue); String str2 = Integer.toString(intValue); String str3 = "" + intValue; } By Hao★

[Java] replace()、trim()

replace( ) 取代 Code: public static void main(String[] args) { String s1 = "ABC123ABC123"; String s2 = "ABC 123"; String s3 = "ABC_123"; System.out.println(s1.replace("ABC","abc")); // System.out.println(s1); System.out.println(s2.replace(" ","")); System.out.println(s3.replace("_"," ")); } 輸出: abc123abc123 ABC123 ABC 123 ABC123ABC123 trim( ) 去掉頭尾空白字元 Code: public static void main(String[] args) { String s1 = " 123 "; String s2 = " abc 123 "; System.out.println(s1. trim()); System.out.println(s2. trim()); //只會去掉前後的空白 } 輸出: 123 abc 123 By Hao★

[Java] indexOf()、lastIndexOf()

indexOf( ) Code: public static void main(String[] args) { String s1 = "ABCDEFG"; if(s1.indexOf("CDE")) //s1.indexOf("CDE") = 2 System.out.println("CDE is located at index 2"); if(s1.indexOf("Test") < 0) //s1.indexOf("Test") = -1 System.out.println("s1 not contain Test"); } 輸出: CDE is located at index 2 s1 not contain Test lastIndexOf( )  Code: public static void main(String[] args) { String s1 = "ABCDEFG_ABCDEFG"; if(s1.lastIndexOf("CDE")) //s1.lastIndexOf("CDE") = 10 System.out.println("CDE is located at index 10"); if(s1.lastIndexOf("Test") >= 0) //s1.lastIndexOf("Test") = -1 System.out.println("s1 not contain Test"); } 輸出: CDE is located at index 10 By Hao★

[Java] startsWith()、endsWith()

startsWith( ) Code: public static void main(String[] args) { String s1 = "Hello World"; if(s1.startsWith("Hello")) System.out.println("s1 starts with Hello"); if(s1.startsWith("W",6)) System.out.println("s1 starts with W at position 6"); } 輸出: s1 starts with Hello endsWith( )  Code: public static void main(String[] args) { String s1 = "Hello World"; if(s1.endsWith("World")) System.out.println("s1 ends with World"); } 輸出: s1 ends with World By Hao★

[Java] equals()、equalsIgnoreCase()

equals( ) Code: public static void main(String[] args) { String s1 = "hello"; if(s1.equals("hello")) System.out.println("s1 equals hello"); else System.out.println("s1 not equals hello"); } 輸出: s1 equals hello equalsIgnoreCase( )  Code: public static void main(String[] args) { String s1 = "hello"; String s2 = "Hello"; if(s1.equalsIgnoreCase(s2)) System.out.println("s1 equals s2"); else System.out.println("s1 not equals s2"); } //equalsIgnoreCase會忽略大小寫 輸出: s1 equals s2 By Hao★

[Linux] 執行Shell Script

設定執行權  開啟user/group/other三者的執行權限   chmod +x test.sh  如果需要只為某些使用者開權限可以用   chmod u+x test.sh #user   chmod g+x test.sh #group   chmod o+x test.sh #other  如果需要關掉權限   chmod -x test.sh 執行Shell 執行現在目錄下的Shell ./test.sh 讓Shell在背景執行 ./test.sh & 一一一一一一一一一一 $ ./test.sh & [1] 10182 [1]+ Done       ./test.sh 一一一一一一一一一一 顯示Shell中執行的步驟 csh -x test.sh bash -x test.sh By Hao★

[Linux] Shell Script 語法

#兩個『 ` 』中間為可以先執行的指令,亦可使用 $( ) set str = 'Current directory is '`pwd` echo "Output : $str" ------------------------------------------------------ Output : Output : Current directory is /Users/Project/Test By Hao★

[Linux] Shell Script "==" and "=~"

# "==" set text0 = "World" set text1 = "World" set text2 = "Hello World" set text3 = "Hello World !!" if( $text2 == $text3) then echo "$text2 == $text3" else echo "$text2 != $text3" endif if( $text0 == text1) then echo "$text0 == $text1" else echo "$text0 != $text1" endif ------------------------------------------- output: Hello World !! != Hello World !! World == World # "=~" set text1 = "World" set text2 = "Hello World" set text3 = "Hello World !!" if( $text3 =~ $text2) then echo "$text2 is $text3 Substring" else echo "$text2 not $text3 Substring" endif if( $text2 =~ text1) then echo "$text1 is $text2 Substring" else echo "$text1 not $text2 Substring" endif ------------------------------------------- output: Hello World is Hello World !! Substring World is Hello World Substring By Hao★

[Network] NS2 simulator

圖片
  #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam &amp; exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for link (n2-n3). (for NAM) $ns duplex-link-op $n2 $n3 queuePos