2014年9月22日 星期一

Uber 和 計程車 比較 ( Uber vs Taxi )

來源: Uber - Taipei

單就客觀數字比較 Uber 和 計程車 (小黃) 。因Uber目前服務仍以北部為主,故以台北地區計程車資進行比較。

目前Uber在服務品質和車資上有其競爭力,但就車輛數與法規面來看則是相對弱勢和具有風險。

服務類型
服務車型
基本費用(NT$)
NT$/每分鐘
NT$/每公里
備註
車資估算 (台北車站 <-> 松山車站)
行車距離 6.7km / 約11~12mins
車資 (台北<->桃園機場) 車資(台北<->新竹)
UberX
TOYOTA CAMRY
NISSAN TEANA
MERCEDES-BENZ C-CLASS
50
3
14.5
最低消費 NT$ 70
取消費用 NT$ 50
NT$178~221
NT$1,000
NT$1,500
UberBLACK
MERCEDES-BENZ S-CLASS
SIENNA 7人座 SEATS
LEXUS ES
105
5
20
最低消費 NT$ 150
取消費用 NT$ 100
NT$294~357
NT$1,700
NT$2,200
台北地區計程車
-
70
3
20
起程NT$75/前1.25km
夜間加成 NT$20/趟
日間車資 NT$210~220
夜間車資 NT$230~250
-
-

參考資料:
#

2014年9月14日 星期日

替 Blogger.com 文章加上程式碼區塊(codeblock)和執行結果區塊(shellblock)

選擇 範本>編輯HTML ,在HTML程式碼中找到CSS區塊,最後新增.post .codeblock和.shellblock的CSS程式碼如下:

<style type='text/css'>    ...

    .post .codeblock { 
       display: block; /* fixes a strange ie margin bug */
       font-family: Courier New;
       font-size: 10pt;
       overflow:auto;
       background: #f7f7f7 url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5yQoXazjZmzOBl-CuDBezK44UwWVLs8GNNigHQmyKSv8EvcXCEtSlMQAPUeXgo0wlKey6nO9VbGG4VF-b4NxEJivH5avNfjYagrnLNQcx8l4TL9AbxT6JU3PUUKBgNzbG9WHP8WMGRmcX/s1600/Code_BG.gif) left top repeat-y;
       border: 1px solid #ccc;
       padding: 10px 10px 10px 21px;
       max-height:1000px; 
       line-height: 1.2em;
    }

    .post .shellblock { 
       display: block; /* fixes a strange ie margin bug */
       font-family: Courier New; 
       font-size: 10pt;
       overflow:auto;
       color: #00ff00;
       background: #000000;
       border: 1px solid #ccc;
       padding: 10px 10px 10px 21px;
       max-height:1000px; 
       line-height: 1.2em;
    }
</style>

另外在<head>和</head>之間,加上
<script src="//google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>

記得要「儲存範本」喔!

之後在寫部落格文章時,在HTML模式底下寫
 
<pre class="codeblock prettyprint">
public class first {
    public static void main (String[] args) {
        System.out.println("Hello, my first java!");
    }
}
</pre>
就會出現下列結果囉:
public class first {
    public static void main (String[] args) {
        System.out.println("Hello, my first java!");
    }
}
如果寫成
<pre class="shellblock">
  執行結果
  ...
</pre>
結果就會變成
  執行結果
  ...
#

Java Multithread Examples

Java MultiTread 程式的基本結構:
import java.util.*;

class firstThread implements Runnable {
   private Thread t;
   private String threadName;

   firstThread( String name) {
      threadName = name;
      ...
   }

   public void run() {
      ...
   }

   public void start() {
      if (t==null) {
        t = new Thread (this, threadName);
        t.start();
      }
   }
} // end of class firstThread

public class first {

 public static void main(String []args) {
    try {
       ...
    } catch (Exception e) {
       System.out.println(e);
    }
 } // end of main

} // end of class first 
編輯 first.java 程式碼範例如下:
import java.util.*;

class firstThread implements Runnable {
   private Thread t;
   private String threadName;

   firstThread( String name) {
      threadName = name;
      System.out.println("Creating " + threadName);
   }

   public void run() {
      long start = System.currentTimeMillis();
      System.out.println("Running " + threadName);
      try {
         for (int i=0; i<=10; i++) {
            Random ran = new Random();
            int j = ran.nextInt(1000) + 1;
            Thread.sleep( j );
            System.out.println(" Thread " + threadName + " : round " + i + " sleep " + j);
         }
         long end = System.currentTimeMillis();
         long diff = end - start;
         System.out.println("Difference of " + threadName + " is : " + diff);
      } catch (Exception e) {
         System.out.println("Thread " + threadName + " : " + e);
      }
      System.out.println("Thread " + threadName + " exiting.");
   }

   public void start() {
      System.out.println("Starting " + threadName);
      if (t==null) {
         t = new Thread (this, threadName);
         t.start();
      }
   }
} // end of class firstThread

public class first {
   public static void main(String []args) {
      try {
         firstThread r1 = new firstThread("Thread-1");
         r1.start();

         firstThread r2 = new firstThread("Thread-2");
         r2.start();

         firstThread r3 = new firstThread("Thread-3");
         r3.start();
      } catch (Exception e) {
         System.out.println(e);
      }
   } // end of main
} // end of class first
編譯 first.java
$ javac first.java
執行 java first,因為 MultiThread 和 Random sleep 的影響,結果可能和下列範例有些不同。
$ java first

Creating Thread-1
Starting Thread-1
Creating Thread-2
Starting Thread-2
Running Thread-1
Creating Thread-3
Starting Thread-3
Running Thread-2
Running Thread-3
 Thread Thread-3 : round 0 sleep 660
 Thread Thread-2 : round 0 sleep 730
 Thread Thread-1 : round 0 sleep 837
 Thread Thread-2 : round 1 sleep 213
 Thread Thread-2 : round 2 sleep 363
 Thread Thread-1 : round 1 sleep 794
 Thread Thread-3 : round 1 sleep 995
 Thread Thread-1 : round 2 sleep 112
 Thread Thread-1 : round 3 sleep 158
 Thread Thread-2 : round 3 sleep 649
 Thread Thread-3 : round 2 sleep 578
 Thread Thread-1 : round 4 sleep 427
 Thread Thread-2 : round 4 sleep 893
 Thread Thread-2 : round 5 sleep 8
 Thread Thread-3 : round 3 sleep 625
 Thread Thread-2 : round 6 sleep 159
 Thread Thread-3 : round 4 sleep 260
 Thread Thread-1 : round 5 sleep 879
 Thread Thread-2 : round 7 sleep 667
 Thread Thread-2 : round 8 sleep 58
 Thread Thread-3 : round 5 sleep 824
 Thread Thread-2 : round 9 sleep 392
 Thread Thread-2 : round 10 sleep 2
Difference of Thread-2 is : 4146
Thread Thread-2 exiting.
 Thread Thread-1 : round 6 sleep 985
 Thread Thread-3 : round 6 sleep 667
 Thread Thread-1 : round 7 sleep 839
 Thread Thread-3 : round 7 sleep 665
 Thread Thread-1 : round 8 sleep 354
 Thread Thread-1 : round 9 sleep 96
 Thread Thread-1 : round 10 sleep 171
Difference of Thread-1 is : 5666
Thread Thread-1 exiting.
 Thread Thread-3 : round 8 sleep 559
 Thread Thread-3 : round 9 sleep 61
 Thread Thread-3 : round 10 sleep 201
Difference of Thread-3 is : 6108
Thread Thread-3 exiting.

2014年9月7日 星期日

亂,也要找對方法 - bash shell 隨機亂數產生方法

# random.sh
#!/bin/bash

# 想要產生 1..500之間的亂數
n=500
echo $n

# 執行隨機亂數 500 x 100 = 50000 回合
for ((i=1; i<=50000; i++))
do
  # 顯示是第幾回合
  echo $i

  # 方法1
  RANDOM=`date +%s`
  echo $(( RANDOM % n + 1 )) >> 1.list

  # 方法2
  RANDOM=$$
  echo $(( RANDOM % n + 1 )) >> 2.list

  # 方法3
  # 目前相對好的bash隨機亂數方法, 隨機結果相對比較平衡
  echo $(( $(od -An -N3 -i /dev/random) % n + 1)) >> 3.list


done

----------
以R來檢驗亂數產生結果

方法1產生結果:

> d1<-read.table('1.list', header = F)
> d1=as.martix(d1)
> summary(d1)
       V1       
 Min.   :  1.0  
 1st Qu.:136.0  
 Median :256.0  
 Mean   :234.9  
 3rd Qu.:316.0  
 Max.   :500.0

> hist(d1)














方法2產生結果:

> summary(d2)
       V1       
 Min.   :  0.0  
 1st Qu.:263.0  
 Median :263.0  
 Mean   :258.7  
 3rd Qu.:321.0  
 Max.   :472.0 

> hist(d2)
















> summary(d3)
       V1     
 Min.   :  0  
 1st Qu.:125  
 Median :250  
 Mean   :250  
 3rd Qu.:375  
 Max.   :500


> hist(d3)
















ps. 其實上述範例產生出來的亂數範圍有點小錯 XD