<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5252179981300499332</id><updated>2026-06-07T01:26:47.037+08:00</updated><category term="Java"/><category term="雜志"/><category term="Eclipse"/><category term="JavaScript"/><category term="EJB"/><category term="Ubuntu"/><category term="1Z0-895"/><category term="R"/><category term="MySQL"/><category term="Oracle"/><category term="PHP"/><category term="vim"/><category term="CSS"/><category term="Regular Express"/><category term="GIMP"/><category term="Android"/><category term="Canvas"/><category term="JSF"/><category term="Java EE"/><category term="Mac"/><category term="Windows"/><category term="Hadoop"/><category term="Struts2"/><category term="html5"/><category term="statistics"/><category term="小工具"/><category term="Android Studio"/><category term="English"/><category term="Free Video Converter"/><category term="Gmail"/><category term="JPA"/><category term="Linux"/><category term="Oracle認證"/><category term="SQL Server"/><category term="Subclipse"/><category term="Subversion"/><category term="html"/><category term="oceejbd6"/><category term="影片處理"/><category term="正規表示式"/><category term="疑難雜症"/><category term="英文"/><category term="1Z0-897"/><category term="Apache Commons"/><category term="Design Pattern"/><category term="EJB認證"/><category term="GlassFish"/><category term="Google"/><category term="Google Chrome"/><category term="Google Chrome小工具"/><category term="Gradle"/><category term="Java Developer Day"/><category term="Java Web Service"/><category term="MacBook Pro"/><category term="MongoDB"/><category term="NodeJs"/><category term="Redis"/><category term="Spring"/><category term="Win7"/><category term="Windows7"/><category term="jQuery"/><category term="備忘"/><category term="分享"/><category term="演算法"/><category term="生活"/><category term="紀念"/><category term="Algorithm"/><category term="BlueJ"/><category term="Content Assist"/><category term="DATALENGTH"/><category term="Database"/><category term="Derby"/><category term="Eclipse Debug"/><category term="Eclipse Hit count"/><category term="Eclipse plugin"/><category term="Eclipse theme"/><category term="Eclipse 偵錯技巧"/><category term="Evernote"/><category term="Git"/><category term="JAX-RS"/><category term="JSON"/><category term="Java DB"/><category term="LEN"/><category term="Line"/><category term="MapReduce"/><category term="Outlook"/><category term="PHP文件"/><category term="ReactJS"/><category term="SCWCD"/><category term="SQL Server limit"/><category term="SVN"/><category term="Shell"/><category term="Shell Script"/><category term="Solution"/><category term="SyntaxHighlighter"/><category term="Telnet"/><category term="Tomcat"/><category term="VirtualBox"/><category term="WSServlet"/><category term="Web service"/><category term="Windows XP"/><category term="Windows小工具"/><category term="XP"/><category term="_jspInit"/><category term="android 手機 print screen"/><category term="d3"/><category term="html parser"/><category term="icloud mail"/><category term="java exception"/><category term="java.lang.NullPointerException"/><category term="jax-ws"/><category term="jsp-api.jar"/><category term="limit"/><category term="org.apache.catalina.LifecycleException"/><category term="phpunit"/><category term="pie chart + doughnut chart"/><category term="python"/><category term="services command"/><category term="sql server join update"/><category term="tag"/><category term="thunderbird"/><category term="unit test"/><category term="update with select join"/><category term="web service endpoint failure"/><category term="youtube error"/><category term="前屋主的信件一直寄來"/><category term="好用的工具"/><category term="小技巧"/><category term="就服技士"/><category term="就業服務乙級技士證照"/><category term="生活趣事"/><category term="考試心得"/><category term="講義下載"/><category term="選取程式背景色"/><category term="閒聊"/><title type='text'>爪哇小子</title><subtitle type='html'>每日都是珍貴的一天，而您的堅持將使它更完美。</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>301</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-3557239440131026762</id><published>2019-11-14T22:57:00.000+08:00</published><updated>2019-11-14T22:57:00.974+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><title type='text'>【筆記】Git中用關鍵字刪除本地的分枝(branch)</title><content type='html'>先在終端機或Git Bash視窗輸入
&lt;pre class=&quot;brush: bash&quot;&gt;
git branch
&lt;/pre&gt;
來看目前本機的分枝有那些，例如目前在我的電腦中有：
&lt;pre class=&quot;brush: bash&quot;&gt;
  Dog
  Dog-101
* cat
  dog-123
  master
  video-store
  vv
&lt;/pre&gt;
現在你想刪掉名字中有「dog」，而且不分大小寫的分枝，可以先用下列指令先確認：
&lt;pre class=&quot;brush: bash&quot;&gt;
git branch | grep -i &#39;dog&#39;
&lt;/pre&gt;
結果就會列出名字中有「dog」的分技：
&lt;pre class=&quot;brush: bash&quot;&gt;
  Dog
  Dog-101
  dog-123
&lt;/pre&gt;
確認後，就可以執行下列的指令去刪掉想不需要的分枝：
&lt;pre class=&quot;brush: bash&quot;&gt;
git branch | grep -i &#39;dog&#39; | xargs git branch -D
&lt;/pre&gt;
注意！執行上列指令前，請先checkout到你要留下的分枝再執行，執行成功後，就會列出已被刪除的分枝：
&lt;pre class=&quot;brush: bash&quot;&gt;
Deleted branch Dog (was 21eb956).
Deleted branch Dog-101 (was 21eb956).
Deleted branch dog-123 (was 21eb956).
&lt;/pre&gt;
若你覺得這些指令好用，可以在
&lt;code&gt;.bashrc&lt;/code&gt;或&lt;code&gt;.bash_profile&lt;/code&gt;中自己新增簡單的function:
&lt;pre class=&quot;brush: bash&quot;&gt;
function git-list-all-match {
    git branch | grep -i $1
}

function git-del-all-match {
    git branch | grep -i $1 | xargs git branch -D
}
&lt;/pre&gt;
建立完成後，執行：
&lt;pre class=&quot;brush: bash&quot;&gt;
git-list-all-match dog
&lt;/pre&gt;
結果：
&lt;pre class=&quot;brush: bash&quot;&gt;
* Dog
  Dog-101
  dog-123
&lt;/pre&gt;
接著執行：
&lt;pre class=&quot;brush: bash&quot;&gt;
git-del-all-match dog
&lt;/pre&gt;
結果：
&lt;pre class=&quot;brush: bash&quot;&gt;
Deleted branch Dog (was 21eb956).
Deleted branch Dog-101 (was 21eb956).
Deleted branch dog-123 (was 21eb956).
&lt;/pre&gt;
注意！執行上列指令前，請先checkout到你要留下的分枝再執行喔！
你可以參考&lt;code&gt;grep&lt;/code&gt;指令的用法，去寫出最適合你自己的指令和function。
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;參考資料&lt;/b&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://medium.com/@rajsek/deleting-multiple-branches-in-git-e07be9f5073c&quot; target=&quot;_blank&quot;&gt;Deleting Multiple Branches in Git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux&quot; target=&quot;_blank&quot;&gt;Using Grep &amp; Regular Expressions to Search for Text Patterns in Linux&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://blog.gtwang.org/linux/xargs-command-examples-in-linux-unix/&quot; target=&quot;_blank&quot;&gt;Linux 系統 xargs 指令範例與教&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;









</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/3557239440131026762/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/3557239440131026762?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3557239440131026762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3557239440131026762'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2019/11/gitbranch.html' title='【筆記】Git中用關鍵字刪除本地的分枝(branch)'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-68452946387501758</id><published>2019-11-13T21:45:00.000+08:00</published><updated>2019-11-13T22:13:19.814+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>【筆記】河內塔 - 用Java實作</title><content type='html'>河內塔的問題是用來學習遞迴（Recursion），之前看了很多例子，寫法都大同小意，前陣子就自己也依樣畫葫蘆，並把註解寫在程式碼中，用意是讓自己可以一目瞭然，若你也曾被這樣的程式碼感到困惑過，希望這個例子可以讓你更明白。

&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.tryit.algorithm;

public class TowerOfHanoi {
    /**
     * 河內塔實作。在第一根柱子上的n個盤子，搬到第三根柱子上。規則：
     * 1. 一次搬一個盤子
     * 2. 搬運過程中大盤子必需在小盤子之下
     *
     * @param numberOfDisks 要移動的盤子數目
     * @param beginning     盤子的開始位置所在的柱子
     * @param auxiliary     移動過程中做為輔助暫放盤子用的柱子
     * @param destination   盤子的目的地位置所在的柱子
     */
    public void move(int numberOfDisks, 
                        String beginning, 
                        String auxiliary, 
                        String destination) {
        if (numberOfDisks == 1) {
            //遞迴的重點之一在於要有結束條件，就是當條件符合時，
            //就不會再呼叫自身的這個方法（method）
            System.out.println(String.format(&quot;Moving disk from %s to %s&quot;, 
                                                beginning, 
                                                destination));
        } else {
            
            //第一步，先把 n - 1 塊盤子從第一根柱子(beginning)搬到第二根柱子，
            //此時, 需要使用第三根柱子當做輔助。
            //所以最上面傳進來的 auxiliary 參數當成目的地的柱子, 
            //最上面傳進來的 destination 參數當成輔助的柱子。

            //下面這一行執行完後，在第一根柱子上，除了最下面的盤子以外的盤子，
            //都會被搬到第二根柱子上。
            move(numberOfDisks - 1, beginning, destination, auxiliary);

            
            //第二步，再把第一根柱子上剩下的最下面的盤子從第一根柱子搬到第三根柱子上。
            move(1, beginning, auxiliary, destination);

            //第三步，再把現在在第二根子上 n - 1 塊盤子從第二根柱子搬到第三根柱子，
            //此時, 需要使用第一根柱子當做輔助。
            //所以最上面傳進來的 auxiliary 參數當成開始的柱子, 
            //最上面傳進來的 beginning 參數當成輔助的柱子。
            move(numberOfDisks - 1, auxiliary, beginning, destination);
        }
    }

    public static void main(final String[] argv) {
        /*
            第一根柱子標註為 A，
            第二根柱子標註為 B，
            第三根柱子標註為 C。
            現在要從 A 柱上的 3 個盤子搬到 C 柱上
         */
        new TowerOfHanoi().move(3, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;);
    }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/68452946387501758/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/68452946387501758?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/68452946387501758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/68452946387501758'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2019/11/java.html' title='【筆記】河內塔 - 用Java實作'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-8884530406037876288</id><published>2016-03-07T23:49:00.000+08:00</published><updated>2016-03-07T23:49:35.557+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows"/><title type='text'>【分享】安全地清理升級Windows 10後的舊安裝檔</title><content type='html'>在升級至&lt;span class=&quot;techn&quot;&gt;Windows 10&lt;/span&gt;之後，無意間在C槽發現了一個「Windows.old」的資料夾，Google了一下後，才發現是之前&lt;span class=&quot;techn&quot;&gt;Windows 8&lt;/span&gt;遺留下的資料夾，因為C槽快爆了，所以有必要將其刪除。&lt;br /&gt;
&lt;br /&gt;
首先找到「磁碟清理」這個工具：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS3m6mHyPJcmebJAXxVg8BeFjspIUYlkSUWbNgVzxGOi0JGWvHFyTlYz6tpm1yMcqnmHcAYcbZbqvqBoJ3VojHhMaNKnoncTW5o8C5JSTS9y4F97_PyexiTZokzeOtYMAcb7UbjRiYQBxQ/s1600/01_search_clean.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS3m6mHyPJcmebJAXxVg8BeFjspIUYlkSUWbNgVzxGOi0JGWvHFyTlYz6tpm1yMcqnmHcAYcbZbqvqBoJ3VojHhMaNKnoncTW5o8C5JSTS9y4F97_PyexiTZokzeOtYMAcb7UbjRiYQBxQ/s320/01_search_clean.png&quot; width=&quot;201&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
點選後，在開啟中，會先看到一個「計算中」的小視窗：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1bbsrtDD0Dk_o2NjjTCLATVJFt0xzmm5DpA4QMRR6gNoFAD_PZwrt81PFCJhVZ1PunhKPonv5mKNXf41f6NKfIHv5wb4qokha1kGixcxQff8XnUn3SxTU8Up0cfWg9QZF0fCAl6-XBOeR/s1600/02_calculating.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;133&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1bbsrtDD0Dk_o2NjjTCLATVJFt0xzmm5DpA4QMRR6gNoFAD_PZwrt81PFCJhVZ1PunhKPonv5mKNXf41f6NKfIHv5wb4qokha1kGixcxQff8XnUn3SxTU8Up0cfWg9QZF0fCAl6-XBOeR/s320/02_calculating.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
開啟後，再選擇要清理的磁碟機，因為之前是安裝在C槽，所以選擇如下：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio-xvX4mh6ncsB1p-YsNf10TgAZIENyqAeRYm_7M5T3isydDFR3gtSbb4HT808_QsD9egmRilqXr91HARZiBwVEvSkMzVD_TwogyVyRb7gAkPpZLeXEdswmGsfriA2CgbtzhwV1As28lm3/s1600/03_select_the_disk_you_installed_Windows.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;177&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio-xvX4mh6ncsB1p-YsNf10TgAZIENyqAeRYm_7M5T3isydDFR3gtSbb4HT808_QsD9egmRilqXr91HARZiBwVEvSkMzVD_TwogyVyRb7gAkPpZLeXEdswmGsfriA2CgbtzhwV1As28lm3/s320/03_select_the_disk_you_installed_Windows.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
再來，不要急著勾選要清理的項目，而是先點按【清理系統檔】：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-497HUrE4L7pgW4EbIUuAhGBMWvgFkFlj9NAvzt4hmvkPNvpJtJv9Uad37JYA19loYnhA3yiZAO4FOuoZqLMD1ZFwBzQxYNVolV78KQcQP8XGbYIfY8S-2YHSy9CZxS2MJnrsEEo5Aufi/s1600/04_Clean_up_system_files.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-497HUrE4L7pgW4EbIUuAhGBMWvgFkFlj9NAvzt4hmvkPNvpJtJv9Uad37JYA19loYnhA3yiZAO4FOuoZqLMD1ZFwBzQxYNVolV78KQcQP8XGbYIfY8S-2YHSy9CZxS2MJnrsEEo5Aufi/s320/04_Clean_up_system_files.png&quot; width=&quot;259&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
之後，會需要再次選擇要清理的磁碟機：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvn23dmrw4E_ayafX3Z71OiArib-i-Ef2AqvcHRn0ugUqFIfTTxq8LoB355wSoNqEHEt32wd8D4-Bs8pu5oLyQfBN1yycU9jAxyb2Xh_ZUrfVMaqq97b9ceLTMX_TmIN7cYp9lxDDx16uc/s1600/05_select_the_disk_you_installed_Windows.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;178&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvn23dmrw4E_ayafX3Z71OiArib-i-Ef2AqvcHRn0ugUqFIfTTxq8LoB355wSoNqEHEt32wd8D4-Bs8pu5oLyQfBN1yycU9jAxyb2Xh_ZUrfVMaqq97b9ceLTMX_TmIN7cYp9lxDDx16uc/s320/05_select_the_disk_you_installed_Windows.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
點按【確定】後，會再出現「計算中」的小視窗，耐心地等它執行完。&lt;br /&gt;
&lt;br /&gt;
再來找到要移除的「之前的Windows安裝」，再點按【確定】：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit0McyqRZwO_wm4RHZoPIgv2f2rdpTjxVhqMgtC3YYvo2ACpiTTt6hN1TglgFXR3JtdAXzltvp-DyYiqS-SS5-7SY8UBYeCta0g-MZVQq8Cb0Lp76tpjgSV3Ce4pOFu0I7vUSIqL9Jpzzw/s1600/06_previous_Windows_installation.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit0McyqRZwO_wm4RHZoPIgv2f2rdpTjxVhqMgtC3YYvo2ACpiTTt6hN1TglgFXR3JtdAXzltvp-DyYiqS-SS5-7SY8UBYeCta0g-MZVQq8Cb0Lp76tpjgSV3Ce4pOFu0I7vUSIqL9Jpzzw/s320/06_previous_Windows_installation.png&quot; width=&quot;260&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
再來會再次確定是否要刪除檔案，&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;務必請三思後並確認要刪除&lt;/span&gt;&lt;/b&gt;，再點按【刪除檔案】：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiStKvR0W1VPZAkfbA29gX3O-LE0-eyk7clAELxp3iDluFONwHjlSS8csE6cpqZDMXB-qrd_9RIfBxB7O1RCs7RWYha8FC-i7jh7LHEE_Jq-Ga9Y4i6vD4nuZ1xZroy_KWlrriq-oOjGapK/s1600/07_sure_to_delete.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;120&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiStKvR0W1VPZAkfbA29gX3O-LE0-eyk7clAELxp3iDluFONwHjlSS8csE6cpqZDMXB-qrd_9RIfBxB7O1RCs7RWYha8FC-i7jh7LHEE_Jq-Ga9Y4i6vD4nuZ1xZroy_KWlrriq-oOjGapK/s320/07_sure_to_delete.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
當磁碟清理程式發現刪除的是先前舊的安裝檔時，會再提示一次，&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;請再次確認真的要刪除後，再點按【是】&lt;/span&gt;&lt;/b&gt;：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ-zVfpYG685pgoivbiVxIiQNE6BGAnb13FEOxs5IZpKxYOI2fEJuThnRinaVFqOn-1qLJ1rZzdOsDqS8dd-3TEAlIOi3szgNNoaNMm_cKDmRnABaNoVqcW2Amn4KovwsfP_dOIPt2g-L-/s1600/08_r_u_sure_again.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;111&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ-zVfpYG685pgoivbiVxIiQNE6BGAnb13FEOxs5IZpKxYOI2fEJuThnRinaVFqOn-1qLJ1rZzdOsDqS8dd-3TEAlIOi3szgNNoaNMm_cKDmRnABaNoVqcW2Amn4KovwsfP_dOIPt2g-L-/s320/08_r_u_sure_again.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
下列小視窗會顯示目前的作業內容，等它關閉後，清理就完成了。&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR2KfasBYGVhzO3O7Z1B84ur-dRd891JIrHjHBIb6jtm8WhcBCn1hq830glnNt8liN8nmUK_Ew-tPSaEsIfJ6Zvgb1bTdMFzlr6cplbLU16DFaUxn8hVDaO2cmZN5jUq3H_xEP75s2qcdI/s1600/10_finally.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;133&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR2KfasBYGVhzO3O7Z1B84ur-dRd891JIrHjHBIb6jtm8WhcBCn1hq830glnNt8liN8nmUK_Ew-tPSaEsIfJ6Zvgb1bTdMFzlr6cplbLU16DFaUxn8hVDaO2cmZN5jUq3H_xEP75s2qcdI/s320/10_finally.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
參考資料&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.cnet.com/how-to/how-to-delete-the-windows-old-folder-from-windows-10/&quot; target=&quot;_blank&quot;&gt;How to delete the Windows.old folder from Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/8884530406037876288/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/8884530406037876288?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/8884530406037876288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/8884530406037876288'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2016/03/windows-10.html' title='【分享】安全地清理升級Windows 10後的舊安裝檔'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS3m6mHyPJcmebJAXxVg8BeFjspIUYlkSUWbNgVzxGOi0JGWvHFyTlYz6tpm1yMcqnmHcAYcbZbqvqBoJ3VojHhMaNKnoncTW5o8C5JSTS9y4F97_PyexiTZokzeOtYMAcb7UbjRiYQBxQ/s72-c/01_search_clean.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-5062596483485468477</id><published>2015-11-18T11:07:00.001+08:00</published><updated>2019-11-13T21:40:46.431+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="英文"/><title type='text'>【分享】收集個人覺得不錯的英文教學影片</title><content type='html'>經過朋友的介紹，知道這位Rachel老師的Youtube，最近很愛看這個，也著實學到很多美國人道地的說話方式，獲益匪淺。
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/OtT3GIO0Tqg&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
來看賴世雄老師談如何學英文，我大概在高二開始(二十年前)每天聽半時他的常春藤解析英語，一直到大學聯考，幫助是不管期中考試，或大學聯考，英文這科拜歐其實都不太需要準備，聯考也考了個還可以的89分。&lt;br /&gt;
&lt;br /&gt;
現在還會推薦賴世雄老師演講的原因在於，拜歐自己聽了一遍這影片一次，有點感慨，發現自己真能在前面的二十年前利用自己零星，虛渡過的那些時間，照影片中的方式去學習，現在英語無論在聽、說、讀、寫，跟現在比較，一定是雲泥之別。&lt;br /&gt;
&lt;br /&gt;
PS.若時間不多，你可以跳過前一小時，XD&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/d-wEagX2uI4&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;br /&gt;
【IDIOM 100】昰介紹一百個英語中的常用語，雖然字幕是日文和英文，但片中全部都是用英語講說，加上這個老師發音很標準，所以講的速度對拜歐來講，是適中且易懂的。&lt;br /&gt;
&lt;br /&gt;
她的講解都會搭配個情境小卡來幫助理解的，是個來學英語中慣用語很棒的教學影片。&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/videoseries?list=PL89B4E44876DF4867&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.ted.com/&quot; target=&quot;_blank&quot;&gt;TED&lt;/a&gt;對拜歐來講，有些演講者講得速度太快，而且有些主題是比較專業，可能會有很多不熟的單字出現，聽起來會很吃力，很難跟上。&lt;br /&gt;
&lt;br /&gt;
拜歐的方法是挑一些熟悉的主題，而且講者的速度是比較慢一點的，多看幾次，應該對聽力有所幫助。&lt;br /&gt;
&lt;br /&gt;
像下面這個講者的主題跟教育有關，而且速度比較慢且發音很標準，是拜歐比較聽得懂的。
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; mozallowfullscreen=&quot;&quot; scrolling=&quot;no&quot; src=&quot;https://embed-ssl.ted.com/talks/lang/en/carol_dweck_the_power_of_believing_that_you_can_improve.html&quot; webkitallowfullscreen=&quot;&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
【秧秧教英語】是拜歐無意間看到的影片，一系列用大家所熟悉的美國熱門影集來教大家美國日常會用到的慣用詞等，趣味性是一百分，也讓人覺得學英語是很有意思的，更一進步貼近生活。
&lt;br /&gt;
&lt;br /&gt;
應該因為是滿久前的影片了，大部份影片的畫質也不是很理想，還有拜歐喜歡的六人行，也只有這幾部，令人只覺得可惜，但也不失為一個學習英文的好地方。&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/videoseries?list=PLIVMZd1VIbdwbcle5Kns1vBHmVy-Pgd0g&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/5062596483485468477/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/5062596483485468477?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/5062596483485468477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/5062596483485468477'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/11/blog-post_18.html' title='【分享】收集個人覺得不錯的英文教學影片'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/OtT3GIO0Tqg/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-7085579190692191391</id><published>2015-10-16T13:04:00.000+08:00</published><updated>2015-10-16T13:04:35.606+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>【筆記】使用Java練習觀察者模式(Observer pattern)</title><content type='html'>&lt;code&gt;Subject.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.observer;

import java.util.ArrayList;
import java.util.List;

public abstract class Subject
{
    private String mMessage;
    List&lt;Observer&gt; mObserverList = new ArrayList&lt;Observer&gt;();

    public void add(Observer observer)
    {
        mObserverList.add(observer);
    }

    public void remove(Observer observer)
    {
        mObserverList.remove(observer);
    }

    public void broadcast()
    {
        for(Observer o : mObserverList)
        {
            o.update();
        }
    }

    public String getMessage()
    {
        return mMessage;
    }

    public void setMessage(String message)
    {
        this.mMessage = message;
    }
}
&lt;/pre&gt;
&lt;code&gt;Observer.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.observer;

public abstract class Observer
{
    protected String mName;
    protected Subject mSubject;

    public abstract void update();
}
&lt;/pre&gt;
&lt;code&gt;Sheep.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.observer;

public class Sheep extends Observer
{
    public Sheep(String name, Subject subject)
    {
        this.mName = name;
        this.mSubject = subject;
        subject.add(this);
    }

    @Override
    public void update()
    {
        System.out.printf(&quot;通知 %s：%s%n&quot;, mName, mSubject.getMessage());
    }
}
&lt;/pre&gt;
&lt;code&gt;SheepDog.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.observer;

public class SheepDog extends Subject
{
}
&lt;/pre&gt;
&lt;code&gt;Main.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.observer;

public class Main
{
    public static void main(String[] args)
    {
        //Shaun the sheep中的那隻牧羊犬
        SheepDog bitzer = new SheepDog();

        //chief actor
        Sheep shaun = new Sheep(&quot;Shaun&quot;, bitzer);

        //Shaun&#39;s cousin, is the flock&#39;s only lamb,
        Sheep timmy = new Sheep(&quot;Timmy&quot;, bitzer);

        //Shirley is the largest member of the flock
        Sheep shirley = new Sheep(&quot;Shirley&quot;, bitzer);

        //Nuts, is quite an eccentric, but useful sheep and usually like the rest of the flock, accompanies and helps Shaun.
        Sheep nuts = new Sheep(&quot;Nuts&quot;, bitzer);

        bitzer.setMessage(&quot;主人回來了，快點恢復正常羊的樣子&quot;);
        bitzer.broadcast();

        System.out.println(&quot;晚上了...&quot;);
        //晚上了，Timmy比較早睡，Bitzer就不通知他
        bitzer.remove(timmy);
        bitzer.setMessage(&quot;星星出來了，大家快來看啊&quot;);
        bitzer.broadcast();
    }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/7085579190692191391/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/7085579190692191391?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7085579190692191391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7085579190692191391'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/10/javaobserver-pattern.html' title='【筆記】使用Java練習觀察者模式(Observer pattern)'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-2866901001280914201</id><published>2015-10-13T22:03:00.001+08:00</published><updated>2015-10-13T22:03:58.727+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="演算法"/><title type='text'>【筆記】使用Java來做快速排序(quick sort)的簡單範例</title><content type='html'>上次真正去接觸、實作快速排序，想想是當年上職訓課，老實講，當時也是一知半解，XD
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.algorithm.sort;

/**
 * Created by bioyang on 2015/10/10.
 */
public class QuickSort
{
    public static void main(String[] args)
    {
        int[] numberArray = new int[]{6, 1, 2, 7, 9, 3, 4, 5, 10, 8};

        new QuickSort().quickSort(0, numberArray.length - 1, numberArray);

        for(int n : numberArray)
        {
            System.out.print(n + &quot;\t&quot;);
        }
    }

     /**
     *
     * @param left 最左邊那個數字的index
     * @param right 最右邊那個數字的index
     * @param numberArray 要排序的整數陣列
     */
    public void quickSort(int left, int right, int[] numberArray)
    {
        if(left &gt; right)
        {
            //代表排序已結束
            return;
        }
        int startIndex = left; //代表最左邊那個數字的起始index
        int endIndex = right;   //代表最右邊那個數字的起始index
        int baseValue = numberArray[left]; //用來儲存要排序的數字陣列最左邊的數字
        int temp;   //用來暫存交換時的值

        while (startIndex != endIndex)
        {
            //要先從右往左找
            while (numberArray[endIndex] &gt;= baseValue &amp;&amp; startIndex &lt; endIndex)
            {
                endIndex--;
            }

            while (numberArray[startIndex] &lt;= baseValue &amp;&amp; startIndex &lt; endIndex)
            {
                startIndex++;
            }

            if (startIndex &lt; endIndex)
            {
                temp = numberArray[startIndex];
                numberArray[startIndex] = numberArray[endIndex];
                numberArray[endIndex] = temp;
            }
        }

        numberArray[left] = numberArray[startIndex];
        numberArray[startIndex] = baseValue;

        //這裡會叫用遞迴，想起有次聽到良葛格說；「遞迴只應天上有，人間只能用迴圈」，XD
        //將原本最左邊的數字歸位後，開始排序以比這個數小的那群數字
        quickSort(left, startIndex - 1, numberArray);
        //將原本最左邊的數字歸位後，開始排序以比這個數大的那群數字
        quickSort(startIndex + 1, right, numberArray);

    }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/2866901001280914201/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/2866901001280914201?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/2866901001280914201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/2866901001280914201'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/10/javaquick-sort.html' title='【筆記】使用Java來做快速排序(quick sort)的簡單範例'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-4886996652342116079</id><published>2015-10-12T21:03:00.000+08:00</published><updated>2015-10-12T21:03:31.689+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>【筆記】用Java實作備忘錄(memoto)模式的簡單範例</title><content type='html'>嘗試用說故事的方弍來寫看看，XD
&lt;code&gt;Main.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.memoto;

/**
 * Created by bioyang on 2015/10/12.
 */
public class Main
{
    public static void main(String[] args)
    {
        //有一個叫小明的工程師
        Programmer smallMing = Programmer.beforeWork();
        //他在上班前的身心狀態
        System.out.printf(&quot;開始工作前的HP為 %d, 憤怒條為 %d\r\n&quot;, 
                            smallMing.getHitPoint(), smallMing.getAngryPoint());

        //為了確認明天是全新的一天，他的大腦要把上班前的狀態給記下來
        ProgrammerBrain brainOfSmallMing = new ProgrammerBrain();
        brainOfSmallMing.setBodyStateMemoto(smallMing.getBodyStateMemoto());

        //小明修了一個Bug
        smallMing.fixBug();
        //這對他的身心狀態沒有太大的影響
        System.out.printf(&quot;修了一個Bug的HP為 %d, 憤怒條為 %d\r\n&quot;, 
                            smallMing.getHitPoint(), smallMing.getAngryPoint());

        //客戶改了需求
        smallMing.requirementChanged();
        //要殺死一個工程師，只要改一個需求
        System.out.printf(&quot;知道客戶改了需求後的HP為 %d, 憤怒條為 %d\r\n&quot;, 
                            smallMing.getHitPoint(), smallMing.getAngryPoint());

        //但一天過去了，又是美好、新的一天
        smallMing.recoverBodyStateMemoto(brainOfSmallMing.getBodyStateMemoto());
        System.out.printf(&quot;隔天起床工作前的HP為 %d, 憤怒條為 %d\r\n&quot;, 
                            smallMing.getHitPoint(), smallMing.getAngryPoint());
    }
}
&lt;/pre&gt;
&lt;code&gt;Programmer.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.memoto;

/**
 * Created by bioyang on 2015/10/12.
 */
public class Programmer
{
    /**
     * 生命值
     */
    private int hitPoint;
    /**
     * 憤怒條
     */
    private int angryPoint;

    private BodyStateMemoto mBodyStateMemoto;

    public BodyStateMemoto saveState()
    {
        return new BodyStateMemoto(this.hitPoint, this.angryPoint);
    }

    public static Programmer beforeWork()
    {
        Programmer programmer = new Programmer();
        programmer.setHitPoint(100);
        programmer.setAngryPoint(0);
        return programmer;
    }

    public void fixBug()
    {
        this.hitPoint -= 5;
        this.angryPoint += 10;
    }

    public void requirementChanged()
    {
        this.hitPoint = 0;
        this.angryPoint = 200;
    }

    public BodyStateMemoto getBodyStateMemoto()
    {
        return new BodyStateMemoto(getHitPoint(), getAngryPoint());
    }

    public void recoverBodyStateMemoto(BodyStateMemoto bodyStateMemoto)
    {
        setHitPoint(bodyStateMemoto.getHitPoint());
        setAngryPoint(bodyStateMemoto.getAngryLevel());
    }

    public int getHitPoint()
    {
        return hitPoint;
    }

    public void setHitPoint(int hitPoint)
    {
        this.hitPoint = hitPoint;
    }

    public int getAngryPoint()
    {
        return angryPoint;
    }

    public void setAngryPoint(int angryPoint)
    {
        this.angryPoint = angryPoint;
    }
}
&lt;/pre&gt;
&lt;code&gt;BodyStateMemoto.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.memoto;

/**
 * Created by bioyang on 2015/10/12.
 */
public class BodyStateMemoto
{
    /**
     * 生命力
     */
    private int hitPoint;
    /**
     * 憤怒值
     */
    private int angryLevel;

    public BodyStateMemoto(int hitPoint, int angryLevel)
    {
        this.hitPoint = hitPoint;
        this.angryLevel = angryLevel;
    }

    public int getHitPoint()
    {
        return hitPoint;
    }

    public void setHitPoint(int hitPoint)
    {
        this.hitPoint = hitPoint;
    }

    public int getAngryLevel()
    {
        return angryLevel;
    }

    public void setAngryLevel(int angryLevel)
    {
        this.angryLevel = angryLevel;
    }
}
&lt;/pre&gt;
&lt;code&gt;ProgrammerBrain.java&lt;/code&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.study.designpattern.memoto;

/**
 * Created by bioyang on 2015/10/12.
 */
public class ProgrammerBrain
{
    private BodyStateMemoto mBodyStateMemoto;

    public void setBodyStateMemoto(BodyStateMemoto bodyStateMemoto)
    {
        this.mBodyStateMemoto = bodyStateMemoto;
    }

    public BodyStateMemoto getBodyStateMemoto()
    {
        return mBodyStateMemoto;
    }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/4886996652342116079/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/4886996652342116079?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4886996652342116079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4886996652342116079'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/10/javamemoto.html' title='【筆記】用Java實作備忘錄(memoto)模式的簡單範例'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-1986022626231314501</id><published>2015-10-10T17:55:00.000+08:00</published><updated>2015-10-15T10:00:37.847+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJS"/><title type='text'>【筆記】ReactJS呼叫外部API練習-顯示YouBike站點列表</title><content type='html'>最近有機會碰到&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://facebook.github.io/react/&quot; target=&quot;_blank&quot;&gt;React&lt;/a&gt;&lt;/span&gt;除了做完它的&lt;a href=&quot;https://facebook.github.io/react/docs/tutorial.html&quot; target=&quot;_blank&quot;&gt;教學&lt;/a&gt;增加點自信外，再來嘗試做一些套用API的練習，這裡使用台北市政府提供的&lt;a href=&quot;http://data.taipei/opendata/datalist/datasetMeta;jsessionid=2C200B6BB0296D86774D2EDC16C61F90?oid=8ef1626a-892a-4218-8344-f7ac46e1aa48&quot; target=&quot;_blank&quot;&gt;YouBike臺北市公共自行車即時資訊&lt;/a&gt;來取得YouBike站點資訊。
&lt;br /&gt;
&lt;br /&gt;
這裡拜歐先用
&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://nodejs.org/en/&quot; target=&quot;_blank&quot;&gt;Node JS&lt;/a&gt;&lt;/span&gt;開一個網頁伺服器，主要是因為若用&lt;span class=&quot;techn&quot;&gt;JavaScript&lt;/span&gt;去對上述的&lt;span class=&quot;techn&quot;&gt;API&lt;/span&gt;送要求的話，會有&lt;span class=&quot;techn&quot;&gt;Cross Domain&lt;/span&gt;呼叫的問題，會比較麻煩，所以這裡就用&lt;span class=&quot;techn&quot;&gt;Node&lt;/span&gt;在伺服器送出要求，取回所需要的資料。
&lt;br /&gt;
&lt;br /&gt;
先寫一支名為&lt;code&gt;server.js&lt;/code&gt;的程式：
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var path = require(&#39;path&#39;);
var express = require(&#39;express&#39;);
var bodyParser = require(&#39;body-parser&#39;);
var app = express();
var request = require(&#39;request&#39;);

app.set(&#39;port&#39;, (process.env.PORT || 9999));

app.use(&#39;/&#39;, express.static(path.join(__dirname, &#39;public&#39;)));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.get(&#39;/api/comments&#39;, function(req, res) {
 res.end(&#39;abc&#39;);
});

    app.get(&#39;/youbike/:pageSize/:offset&#39;, function(req, res){
    var pageSize = req.params.pageSize,
      offset = req.params.offset;
    request(&#39;http://data.taipei/opendata/datalist/apiAccess?scope=resourceAquire&amp;amp;rid=ddb80380-f1b3-4f8e-8016-7ed9cba571d5&amp;amp;limit=&#39; + pageSize + &#39;&amp;amp;offset=&#39; + offset, 
        function(err, response, body){
          if(err)
          {
            console.log(err);
          }
          else if(response.statusCode == 200)
          {
            res.end(body);
          }
    })
    });

app.listen(app.get(&#39;port&#39;), function() {
  console.log(&#39;Server started: http://localhost:&#39; + app.get(&#39;port&#39;) + &#39;/&#39;);
});
&lt;/pre&gt;
上列程式中，會用到&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;http://expressjs.com/&quot; target=&quot;_blank&quot;&gt;Express&lt;/a&gt;&lt;/span&gt;這個&lt;span class=&quot;techn&quot;&gt;Framwork&lt;/span&gt;，以及&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://www.npmjs.com/package/request&quot; target=&quot;_blank&quot;&gt;request&lt;/a&gt;&lt;/span&gt;這個&lt;span class=&quot;techn&quot;&gt;package&lt;/span&gt;，它主要的功能就是在受到用戶端的要求時，再組成查詢的&lt;span class=&quot;techn&quot;&gt;URL&lt;/span&gt;向&lt;span class=&quot;techn&quot;&gt;API&lt;/span&gt;送出要求，取回&lt;span class=&quot;techn&quot;&gt;JSON&lt;/span&gt;格式的資料。&lt;br /&gt;
&lt;br /&gt;
再來會有一支名為&lt;code&gt;index.html&lt;/code&gt;的&lt;span class=&quot;techn&quot;&gt;HTML&lt;/span&gt;程式來顯示資料：
&lt;pre class=&quot;brush: html&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
        &lt;link rel=&quot;stylesheet&quot; href=&quot;/css/youbike.css&quot;/&gt;
 &lt;style&gt;
  div#container{width:80%;margin:auto;}
  button{margin:5px;}
 &lt;/style&gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &lt;div id=&quot;container&quot;&gt;

    &lt;/div&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/js/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/js/react.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/js/react-dom.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot; src=&quot;/js/youbike.jsx&quot;&gt;&lt;/script&gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
那我們主要的
&lt;span class=&quot;techn&quot;&gt;React&lt;/span&gt;是寫在&lt;code&gt;youbiks.jsx&lt;/code&gt;中，其中主要定義了&lt;code&gt;YouBikeSite&lt;/code&gt;、&lt;code&gt;YouBikeSiteRow&lt;/code&gt;和&lt;code&gt;YouBikeTable&lt;/code&gt;等三個元件：
&lt;pre class=&quot;brush: javascript&quot;&gt;
var YouBikeSite = React.createClass({
 getInitialState : function(){
  return {
   site : [],
  };
 },
   render : function(){
  var site = this.props.site;
    return (
     &lt;div className=&quot;row&quot;&gt;
      &lt;div className=&quot;column&quot;&gt;{site.sno}&lt;/div&gt;
      &lt;div className=&quot;column&quot;&gt;{site.sarea}&lt;/div&gt;
      &lt;div className=&quot;column&quot;&gt;{site.sna}&lt;/div&gt;
      &lt;div className=&quot;column&quot;&gt;{site.sbi}&lt;/div&gt;
      &lt;div className=&quot;column&quot;&gt;{site.mday}&lt;/div&gt;
     &lt;/div&gt;
    );
   }
});
var YouBikeSiteRow = React.createClass({
 render : function(){
  console.log(&#39;YouBikeSiteList&#39;);
  return (
   &lt;div className=&quot;dataBody&quot;&gt;
    {this.props.siteList.map(function(site) {
     //console.log(site);
            return (&amp;lt;YouBikeSite site={site} /&amp;gt;);
           })}
   &lt;/div&gt;
  );
 }
});
var YouBikeTable = React.createClass({
 getInitialState : function(){
  return {
   siteList : [],
   page : 1 
  };
 },
 componentDidMount : function(){
  this.loadYouBikeSiteInfo();
 },
 loadYouBikeSiteInfo : function(){
  console.log(&#39;this.state.page: &#39; + this.state.page);
  var pageSize = 10,
   offset = (this.state.page &gt;= 1 ? this.state.page - 1 : 0) * pageSize; 
  console.log(offset);
  var youBikeSiteUrl = &#39;/youbike/&#39; + pageSize + &#39;/&#39; + offset;
  $.ajax({
   url : youBikeSiteUrl,
   dataType : &#39;json&#39;,
   cache : false,
   success : function(data){
    if(data.result &amp;&amp; data.result.results)
    {
     this.setState({
      siteList : data.result.results
     });
    }
    //console.log(this.state.siteList);
   }.bind(this),
   error : function(xhr, status, err){
    console.error(youBikeSiteUrl, status, err.toString());
   }.bind(this)
  });
 },
 nextPage : function()
 {
  this.state.page += 1;
  this.loadYouBikeSiteInfo();
 },
 previousPage : function()
 {
  this.state.page -= 1;
  if(this.state.page &lt; 0)
  {
   this.state.page = 0;
  }
  this.loadYouBikeSiteInfo();
 },
 render : function(){
  return (
   &lt;div className=&quot;youBikeView&quot;&gt;
    &lt;h2&gt;YouBike Site Information&lt;/h2&gt;
    &lt;div className=&quot;youBikeTable&quot;&gt;
     &lt;div className=&quot;dataHead&quot;&gt;
      &lt;div className=&quot;row&quot;&gt;
       &lt;div className=&quot;column&quot;&gt;場站代號&lt;/div&gt;
       &lt;div className=&quot;column&quot;&gt;場站區域&lt;/div&gt;
       &lt;div className=&quot;column&quot;&gt;場站名稱&lt;/div&gt;
       &lt;div className=&quot;column&quot;&gt;目前車輛數&lt;/div&gt;
       &lt;div className=&quot;column&quot;&gt;資料更新時間&lt;/div&gt;
      &lt;/div&gt;
     &lt;/div&gt;
     &amp;lt;YouBikeSiteRow siteList={this.state.siteList}/&amp;gt;
    &lt;/div&gt;
    &lt;div className=&quot;buttonList&quot;&gt;
     &lt;button onClick={this.previousPage}&gt;上一頁&lt;/button&gt;
     &lt;button onClick={this.nextPage}&gt;下一頁&lt;/button&gt;
    &lt;/div&gt;
   &lt;/div&gt;
  )
 }
});
ReactDOM.render(
    &amp;lt;YouBikeTable /&amp;gt;,
    document.getElementById(&#39;container&#39;)
);
&lt;/pre&gt;
完整的範例可以到
&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://github.com/javakidx/node-react&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt;&lt;/span&gt;下載。</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/1986022626231314501/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/1986022626231314501?isPopup=true' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/1986022626231314501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/1986022626231314501'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/10/reactjs-youbike.html' title='【筆記】ReactJS呼叫外部API練習-顯示YouBike站點列表'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-8488108643113168839</id><published>2015-09-23T00:15:00.001+08:00</published><updated>2015-09-24T01:25:40.564+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="演算法"/><title type='text'>【筆記】用Java來做氣泡排序法的簡單範例</title><content type='html'>一直以來，想給自己補一下在演算法等基礎的不足，所以就從最基本的排序法開始，希望可以持續下去，XD
&lt;br /&gt;
&lt;br /&gt;
下列程式是拜歐依書中的範例改成&lt;span class=&quot;techn&quot;&gt;Java&lt;/span&gt;版本的。
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package idv.jk.study.algorithm.sort;

import java.util.Scanner;

/**
 * Created by javakid on 15/9/22.
 */
public class BubbleSort
{
    public static void main(String[] args)
    {
        int scores[] = new int[100];
        int size;
        System.out.println(&quot;輸入分數的總數...&quot;);
        Scanner scanner = new Scanner(System.in);

        size = scanner.nextInt();

        System.out.println(&quot;輸入分數(用,隔開)...&quot;);
        String strNumbers = scanner.next();

        String numbers[] = strNumbers.split(&quot;,&quot;);

        //把輸入的數字存入到陣列中
        for(int i = 0; i &amp;lt; numbers.length; i++)
        {
            scores[i] = Integer.parseInt(numbers[i]);
        }

        int temp;   //於大小比對時暫存數字的變數

        //開始對所有數字做排列
        for(int i = 0; i &amp;lt; size; i++)
        {
            //size - i表第2次只要比對size-1個數字，
            // 第3次只要比對size-2個數字，以此類推
            for (int j = 0; j &amp;lt; size - i; j++)
            {
                //由小至大，兩兩比對做數字交換
                if (scores[j] &amp;lt; scores[j+1])
                {
                    temp = scores[j];
                    scores[j] = scores[j+1];
                    scores[j+1] = temp;
                }
            }
        }

        //印出結果
        for(int i = 0; i &amp;lt; size; i++)
        {
            System.out.printf(&quot;%d &quot;, scores[i]);
        }
    }
}
&lt;/pre&gt;
重點
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;若有 &lt;i&gt;n&lt;/i&gt; 個數字要進行排多，只需將 &lt;i&gt;n-1&lt;/i&gt; 個數字歸位&lt;/li&gt;
&lt;li&gt;相鄰的數字比較後，依需要做大小交換&lt;/li&gt;
&lt;li&gt;時間複雜度為&lt;i&gt;O(N&lt;sup&gt;2&lt;/sup&gt;)&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;

若真想打好演算法的底子，建議您拜歐正在念的這本：


&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://www.books.com.tw/exep/assp.php/bioankeyang/products/0010656544?utm_source=bioankeyang&amp;amp;utm_medium=ap-books&amp;amp;utm_content=recommend&amp;amp;utm_campaign=ap-201509&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDHOAyVnS0FBJHc-wK9cq1NfSFYvJXrjiZUI3jpT6W3eRQQfGKHKBgXYD6QXSqrvyaIik_PfAAsIkR-o31OdPDTd_06auDT-Xms1egaqDm877SaKmqY1RKxj0jUEFxasJT74ffi5gfQm-j/s200/getImage.jpeg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/8488108643113168839/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/8488108643113168839?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/8488108643113168839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/8488108643113168839'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/09/blog-post.html' title='【筆記】用Java來做氣泡排序法的簡單範例'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDHOAyVnS0FBJHc-wK9cq1NfSFYvJXrjiZUI3jpT6W3eRQQfGKHKBgXYD6QXSqrvyaIik_PfAAsIkR-o31OdPDTd_06auDT-Xms1egaqDm877SaKmqY1RKxj0jUEFxasJT74ffi5gfQm-j/s72-c/getImage.jpeg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-7602200896244952349</id><published>2015-08-28T12:12:00.001+08:00</published><updated>2015-08-28T12:12:14.850+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="雜志"/><title type='text'>【心得】初老宣言XD</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7DrzMD-eIyQDYrDCs5GUJw0f9Vw67Fndx38bWo52DmgdZvC7WknxFUHt2XLA9MYMA5dy8iztS5Ad7eFBDljCeAUFyjK2BNClsuTIov3BVzh-0J6qKhsV9SNWsycO6dpTX_zMmiVZtvpiO/s1600/photo-1429198739803-7db875882052.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7DrzMD-eIyQDYrDCs5GUJw0f9Vw67Fndx38bWo52DmgdZvC7WknxFUHt2XLA9MYMA5dy8iztS5Ad7eFBDljCeAUFyjK2BNClsuTIov3BVzh-0J6qKhsV9SNWsycO6dpTX_zMmiVZtvpiO/s400/photo-1429198739803-7db875882052.jpg&quot; width=&quot;266&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;圖片來源：https://images.unsplash.com/photo-1429198739803-7db875882052?q=80&amp;amp;fm=jpg&amp;amp;s=73fc6976c560896a0561a6d4119803a0&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;趁年輕好好聽歌，好好流淚。&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/7602200896244952349/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/7602200896244952349?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7602200896244952349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7602200896244952349'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/08/xd.html' title='【心得】初老宣言XD'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7DrzMD-eIyQDYrDCs5GUJw0f9Vw67Fndx38bWo52DmgdZvC7WknxFUHt2XLA9MYMA5dy8iztS5Ad7eFBDljCeAUFyjK2BNClsuTIov3BVzh-0J6qKhsV9SNWsycO6dpTX_zMmiVZtvpiO/s72-c/photo-1429198739803-7db875882052.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-7553746147750229560</id><published>2015-08-27T00:21:00.001+08:00</published><updated>2015-09-10T00:40:09.348+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android Studio"/><title type='text'>【筆記】Android Studio的快捷鍵</title><content type='html'>交互地用&lt;span class=&quot;techn&quot;&gt;Mac&lt;/span&gt;和&lt;span class=&quot;techn&quot;&gt;Windows&lt;/span&gt;，有些快捷鍵真的會忘，來記一下吧！&lt;br /&gt;
&lt;br /&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;data_table&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Mac快捷鍵&lt;/b&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Windows快捷鍵&lt;/b&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;動作&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Alt&lt;/b&gt; + ↑(方向鍵上)、&lt;b&gt;Alt&lt;/b&gt; + ↓(方向鍵上)&lt;/td&gt;
&lt;td&gt;在相鄰的方法間上下來回&lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;command&lt;/b&gt;+ &lt;b&gt;delete&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Ctrl&lt;/b&gt; + &lt;b&gt;Y&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;刪除整行&lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;command&lt;/b&gt; + &lt;b&gt;fn&lt;/b&gt; + &lt;b&gt;F12&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Ctrl&lt;/b&gt; + &lt;b&gt;F12&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;在類別中搜尋方法&lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;command&lt;/b&gt; + &lt;b&gt;N&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Alt&lt;/b&gt; + &lt;b&gt;insert&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;Generate，可以產生建構子、Getter、Setter、覆寫方法等&lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;command&lt;/b&gt; + &lt;b&gt;shift&lt;/b&gt; + &lt;b&gt;U&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;選取的字串轉換大小寫&lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;Ctrl&lt;/b&gt; + &lt;b&gt;I&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;Ctrl&lt;/b&gt; + &lt;b&gt;I&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;實現(implement)介面或抽像類別的方法(method)&lt;/td&gt;

&lt;/tr&gt;
&lt;!--
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;

&lt;/tr&gt;
--&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
參考資料
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/sdk/installing/studio-tips.html&quot; target=&quot;_blank&quot;&gt;Android Studio Tips and Tricks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/7553746147750229560/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/7553746147750229560?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7553746147750229560'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7553746147750229560'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/08/android-studio.html' title='【筆記】Android Studio的快捷鍵'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-3172870776140404152</id><published>2015-08-21T18:39:00.000+08:00</published><updated>2015-11-05T09:36:08.041+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="雜志"/><title type='text'>【心得】工作上的一些想法</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbGLVbutCtv_Pplv9sjzJ6GD2H2FXFoylsPiVYsvq34SCjVZYwFTbgk8Qki-m4Pcms4b7L7R_N08LAaMEuIUvvaAdnvhOVIFI05DVQirrFdeFeWyM7BOGjUuSeOLVpq2k0DcvNJzesyih/s1600/photo-1436915947297-3a94186c8133.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbGLVbutCtv_Pplv9sjzJ6GD2H2FXFoylsPiVYsvq34SCjVZYwFTbgk8Qki-m4Pcms4b7L7R_N08LAaMEuIUvvaAdnvhOVIFI05DVQirrFdeFeWyM7BOGjUuSeOLVpq2k0DcvNJzesyih/s400/photo-1436915947297-3a94186c8133.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;某產品還沒受精時，就在想老闆怎麼會打分數，可以直接跟該產品說：「你已經死了」。&lt;/li&gt;
&lt;li&gt;愛抱怨的小孩，很難長大。&lt;/li&gt;
&lt;li&gt;做事不要只擔心著會被老闆打搶，偶爾也想想怎樣能給老闆打一槍。&lt;/li&gt;
&lt;li&gt;適時的溝通很重要，不要忍著讓原本可以討論的事變成抱怨；最後，把工作環境染成互相消費的氣圍。&lt;/li&gt;
&lt;li&gt;不要選擇太安逸的環境，這個時代，安逸代表很低的機會可以長進。&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/3172870776140404152/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/3172870776140404152?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3172870776140404152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3172870776140404152'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/08/blog-post.html' title='【心得】工作上的一些想法'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbGLVbutCtv_Pplv9sjzJ6GD2H2FXFoylsPiVYsvq34SCjVZYwFTbgk8Qki-m4Pcms4b7L7R_N08LAaMEuIUvvaAdnvhOVIFI05DVQirrFdeFeWyM7BOGjUuSeOLVpq2k0DcvNJzesyih/s72-c/photo-1436915947297-3a94186c8133.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-7279804815021943065</id><published>2015-08-20T20:35:00.003+08:00</published><updated>2015-08-20T20:48:33.891+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Android Studio"/><title type='text'>【筆記】Android模擬器(emulator)的快捷鍵</title><content type='html'>&lt;table cellspacing=&quot;0&quot; class=&quot;data_table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Mac快捷鍵&lt;/b&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Windows快捷鍵&lt;/b&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;效用&lt;/b&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;備註&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Ctrl + F12&lt;/td&gt;
&lt;td&gt;垂直、水平翻轉&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Esc&lt;/td&gt;
&lt;td&gt;返回&lt;/td&gt;
&lt;td&gt;對應到裝置的「Back」按鈕&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;F7&lt;/td&gt;
&lt;td&gt;鎖定螢幕，解除螢幕鎖定&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Home&lt;/td&gt;
&lt;td&gt;回首頁畫面&lt;/td&gt;
&lt;td&gt;對應到裝置的「Home」按鈕&lt;/td&gt;
&lt;/tr&gt;
&lt;!--
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
--&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
參考資料
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://developer.android.com/tools/help/emulator.html&quot; target=&quot;_blank&quot;&gt;Android Emulator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/7279804815021943065/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/7279804815021943065?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7279804815021943065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7279804815021943065'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/08/androidemulator.html' title='【筆記】Android模擬器(emulator)的快捷鍵'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-6239506315692012112</id><published>2015-06-24T23:52:00.000+08:00</published><updated>2015-06-24T23:52:37.155+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>【筆記】用Java做蛇與樓梯(snakes and ladders)遊戲的簡單範例</title><content type='html'>今天在書上看到一個蛇與樓梯的程式，其規則大致如下：&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;擲骰子來決定要走的步數。&lt;/li&gt;
&lt;li&gt;從數字1開始走到最大數字(如下圖中的25)。&lt;/li&gt;
&lt;li&gt;若走到梯子下，就可以延著梯子爬上去(前進)。&lt;/li&gt;
&lt;li&gt;若走到蛇頭，就要延著蛇身滑下去(倒退)。&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvrGF7ZGsRtYzJ4qVwigJ2IbmrttU9ef49cqYf44ckUhY9pymJn-zEM5wBmtWvJzyU2k1lE0cMyJQk1LIhvzfmxgsgX_QVNOpdDYM_Egj0UEfB9Xjg0ld80qh30zRIAw8hyphenhyphengf7q8qMf2H_/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-06-24+23.37.04.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvrGF7ZGsRtYzJ4qVwigJ2IbmrttU9ef49cqYf44ckUhY9pymJn-zEM5wBmtWvJzyU2k1lE0cMyJQk1LIhvzfmxgsgX_QVNOpdDYM_Egj0UEfB9Xjg0ld80qh30zRIAw8hyphenhyphengf7q8qMf2H_/s320/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-06-24+23.37.04.png&quot; width=&quot;318&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br/&gt;
其程式碼如下：
&lt;pre class=&quot;brush: java&quot;&gt;
package idv.jk.fun;

public class SnakesAndLadders
{
    private static final int finalSquare = 25;

    public static void main(String[] args)
    {
        int[] board = new int[finalSquare + 1];

        for(int i = 0; i &lt;= finalSquare; i++)
        {
            board[i] = 0;
        }

        //定義走到的格子要上樓梯或滑下蛇後，要前進或後退幾格
        board[3] = +8;
        board[6] = +11;
        board[9] = +9;
        board[10] = +2;

        board[14] = -10;
        board[19] = -11;
        board[22] = -2;
        board[24] = -8;


        int diceNumber = 0;//擲出的點數

        int step = 0; //走到第幾格

        while(step &lt; finalSquare)
        {
            //擲骰子
            diceNumber = (int)(Math.random() * 6 + 1);
            System.out.print(&quot;擲出的點數: &quot; + diceNumber + &quot;, &quot;);
            step += diceNumber;

            if(step &lt; board.length)
            {
                if(board[step] &gt; 0)
                {
                    System.out.print(&quot;上樓梯, 爬上 &quot; + board[step] + &quot; 格, &quot;);
                }
                else if(board[step] &lt; 0)
                {
                    System.out.print(&quot;下蛇身, 滑下 &quot; + board[step] + &quot; 格, &quot;);
                }
                step += board[step];
            }
            System.out.println(&quot;前進到第 &quot; + step + &quot; 格&quot;);
        }
        System.out.println(&quot;結束&quot;);
    }
}
&lt;/pre&gt;
執行結果為：
&lt;pre&gt;
擲出的點數: 3, 上樓梯, 爬上 8 格, 前進到第 11 格
擲出的點數: 3, 下蛇身, 滑下 -10 格, 前進到第 4 格
擲出的點數: 3, 前進到第 7 格
擲出的點數: 5, 前進到第 12 格
擲出的點數: 1, 前進到第 13 格
擲出的點數: 1, 下蛇身, 滑下 -10 格, 前進到第 4 格
擲出的點數: 4, 前進到第 8 格
擲出的點數: 4, 前進到第 12 格
擲出的點數: 6, 前進到第 18 格
擲出的點數: 6, 下蛇身, 滑下 -8 格, 前進到第 16 格
擲出的點數: 4, 前進到第 20 格
擲出的點數: 1, 前進到第 21 格
擲出的點數: 4, 前進到第 25 格
結束
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/6239506315692012112/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/6239506315692012112?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/6239506315692012112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/6239506315692012112'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/06/javasnakes-and-ladders.html' title='【筆記】用Java做蛇與樓梯(snakes and ladders)遊戲的簡單範例'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvrGF7ZGsRtYzJ4qVwigJ2IbmrttU9ef49cqYf44ckUhY9pymJn-zEM5wBmtWvJzyU2k1lE0cMyJQk1LIhvzfmxgsgX_QVNOpdDYM_Egj0UEfB9Xjg0ld80qh30zRIAw8hyphenhyphengf7q8qMf2H_/s72-c/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-06-24+23.37.04.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-2582159825086877669</id><published>2015-06-09T00:16:00.000+08:00</published><updated>2015-06-09T21:14:51.086+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MySQL"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>【筆記】在Ubuntu 14.04中，用python來連線並查詢MySQL中的資料</title><content type='html'>先到&lt;a href=&quot;http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python_2.0.4-1debian7.6_all.deb&quot; target=&quot;_blank&quot;&gt;這裡&lt;/a&gt;下載&lt;code&gt;mysql-connector-python_2.0.4-1debian7.6_all.deb&lt;/code&gt;：
&lt;pre class=&quot;brush: bash&quot;&gt;
wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python_2.0.4-1debian7.6_all.deb
&lt;/pre&gt;
並將其安裝：
&lt;pre class=&quot;brush: bash&quot;&gt;
sudo dpkg -i mysql-connector-python_2.0.4-1debian7.6_all.deb
&lt;/pre&gt;
安裝完成後，就開始來寫程式吧！這裡將程式存成&lt;code&gt;mysql_query.py&lt;/code&gt;：
&lt;pre class=&quot;brush: python&quot;&gt;
#!/usr/bin/python
import mysql.connector
cnx = mysql.connector.connect(user=&#39;cbuser&#39;, password=&#39;cbpass&#39;,
                              host=&#39;127.0.0.1&#39;,
                              database=&#39;cookbook&#39;)

cursor = cnx.cursor();
query = &quot;select a, b from test&quot;
cursor.execute(query)

for(a, b) in cursor:
        print(&quot;column a is {}, column b is {}&quot;.
                format(a, b))

cursor.close()
cnx.close()
&lt;/pre&gt;
在&lt;code&gt;test&lt;/code&gt;這個資料表中的資料如下：
&lt;pre&gt;
+---+------+
| a | b    |
+---+------+
| 1 | abc  |
| 2 | xyz  |
+---+------+
&lt;/pre&gt;
最後執行程式：
&lt;pre class=&quot;brush: bash&quot;&gt;
python mysql_query.py 
&lt;/pre&gt;
執行結果為：
&lt;pre&gt;
column a is 1, column b is abc
column a is 2, column b is xyz
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/2582159825086877669/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/2582159825086877669?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/2582159825086877669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/2582159825086877669'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/06/ubuntu-1404pythonmysql.html' title='【筆記】在Ubuntu 14.04中，用python來連線並查詢MySQL中的資料'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-4369604958818372180</id><published>2015-06-03T01:33:00.001+08:00</published><updated>2015-06-04T23:14:21.522+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="MapReduce"/><title type='text'>【筆記】使用MapReduce來替換字串(replace string)的簡單程式</title><content type='html'>拜歐先把要替換的檔案上傳到&lt;span class=&quot;techn&quot;&gt;HDFS&lt;/span&gt;中。
&lt;br /&gt;
&lt;br /&gt;
上傳完成後，使用下列指令檢視其內容：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;hdfs dfs -cat /user/javakid/replace/replace.txt&lt;/pre&gt;
輸入的檔案為&lt;code&gt;replace.txt&lt;/code&gt;，其內容如下：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
foo1234foo567foo890foo123foo
&lt;/pre&gt;
再來開始寫程式，拜歐是用&lt;span class=&quot;techn&quot;&gt;Intellij IDEA&lt;/span&gt;來撰寫程式，在專案設定中，將編譯的輸出目錄(compile output path)設定為&lt;code class=&quot;folder&quot;&gt;/home/javakid/study/hadoop/classpath&lt;/code&gt;。&lt;br /&gt;
&lt;br /&gt;
第一個要寫的是   &lt;span class=&quot;techn&quot;&gt;mapper&lt;/span&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: java;highlight: 27&quot;&gt;package idv.jk.study.hadoop.myself;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created by javakid on 2015/6/3.
 */
public class StringReplaceMapper
        extends Mapper&amp;lt;LongWritable, Text, NullWritable, Text&amp;gt;
{
    private static final String TARGET = &quot;foo&quot;;
    private static final String REPLACEMENT = &quot;bar&quot;;

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException
    {
        String line = value.toString();

        if(line.indexOf(TARGET) &amp;gt;= 0)
        {
            context.write(NullWritable.get(),
                            new Text(line.replaceAll(TARGET, REPLACEMENT)));
        }
    }
}
&lt;/pre&gt;
在&lt;span class=&quot;techn&quot;&gt;mapper&lt;/span&gt;的輸出，拜歐要的只是替換後的每一行字串，這些值的key是什麼，並不重要，所以在上列程式中的第27行，用&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/NullWritable.html&quot; target=&quot;_blank&quot;&gt;NullWritable&lt;/a&gt;&lt;/span&gt;來做為輸出的key。
&lt;br /&gt;
&lt;br /&gt;
再來要寫的是   &lt;span class=&quot;techn&quot;&gt;reducer&lt;/span&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: java;highlight: 21&quot;&gt;package idv.jk.study.hadoop.myself;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by javakid on 2015/6/3.
 */
public class StringReplaceReducer
        extends Reducer&amp;lt;NullWritable, Text, NullWritable, Text&amp;gt;
{
    @Override
    protected void reduce(NullWritable key, Iterable&amp;lt;Text&amp;gt; values, Context context)
            throws IOException, InterruptedException
    {
        for(Text text : values)
        {
            context.write(NullWritable.get(), text);
        }
    }
}
&lt;/pre&gt;
在&lt;span class=&quot;techn&quot;&gt;reducer&lt;/span&gt;中，拜歐要的也只是將已經在&lt;span class=&quot;techn&quot;&gt;mapper&lt;/span&gt;替換好的字串輸出，在第21行一樣使用&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/NullWritable.html&quot; target=&quot;_blank&quot;&gt;NullWritable&lt;/a&gt;&lt;/span&gt;來做為輸出的key。
&lt;br /&gt;
&lt;br /&gt;
最後是主程式：
&lt;br /&gt;
&lt;pre class=&quot;brush: java;highlight:[36,37]&quot;&gt;package idv.jk.study.hadoop.myself;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Created by javakid on 2015/6/3.
 */
public class StringReplace
{
    public static void main(String[] argv)
            throws IOException, ClassNotFoundException, InterruptedException
    {
        if(argv.length != 2)
        {
            System.err.println(&quot;Usage: StringReplace &amp;lt;input path&amp;gt; &amp;lt;output path&amp;gt;&quot;);
            System.exit(-1);
        }

        Job job = new Job();
        job.setJarByClass(StringReplace.class);
        job.setJobName(&quot;String replacement&quot;);

        FileInputFormat.addInputPath(job, new Path(argv[0]));
        FileOutputFormat.setOutputPath(job, new Path(argv[1]));

        job.setMapperClass(StringReplaceMapper.class);
        job.setReducerClass(StringReplaceReducer.class);

        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        System.out.println(job.waitForCompletion(true) ? 0 : 1);
    }
}
&lt;/pre&gt;
上列&lt;code&gt;setOutputKeyClass&lt;/code&gt;和&lt;code&gt;setOutputValueClass&lt;/code&gt;這兩個方法控制&lt;span class=&quot;techn&quot;&gt;reduce&lt;/span&gt;方法中輸出的型別，而且與&lt;span class=&quot;techn&quot;&gt;reducer&lt;/span&gt;中產出的輸出中設定，兩者必須是相同的。&lt;br /&gt;
&lt;br /&gt;
先將&lt;code&gt;HADOOP_CLASSPATH&lt;/code&gt;設定好後，用&lt;code&gt;hadoop&lt;/code&gt;指令來執行主程式：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;export HADOOP_CLASSPATH=/home/javakid/study/hadoop/classpath
hadoop idv.jk.study.hadoop.myself.StringReplace \
/user/javakid/replace/replace.txt /user/javakid/replace/output
&lt;/pre&gt;
執行完成後，使用下列指令來確認結果：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;hdfs dfs -cat /user/javakid/replace/output/part-r-00000
&lt;/pre&gt;
預期結果如下：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
bar1234bar567bar890bar123bar
&lt;/pre&gt;
你可以在這裡找到&lt;a href=&quot;https://github.com/javakidx/hadoopstudy&quot; target=&quot;_blank&quot;&gt;原始&lt;/a&gt;碼。</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/4369604958818372180/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/4369604958818372180?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4369604958818372180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4369604958818372180'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/06/mapreducereplace-string.html' title='【筆記】使用MapReduce來替換字串(replace string)的簡單程式'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-3217749555752857564</id><published>2015-05-30T01:07:00.003+08:00</published><updated>2015-09-17T10:00:52.627+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>【筆記】在Ubuntu 14.04建立Hadoop多節點叢集-分散式架構(Multi-node cluster)</title><content type='html'>這裡使用的版本是&lt;code&gt;2.6.0&lt;/code&gt;，之前有些設定如設定&lt;span class=&quot;techn&quot;&gt;JAVA_HOME&lt;/span&gt;&lt;br /&gt;
或是&lt;span class=&quot;techn&quot;&gt;ssh&lt;/span&gt;等，在&lt;a href=&quot;http://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-common/SingleCluster.html&quot; target=&quot;_blank&quot;&gt;Setting up a Single Node Cluster&lt;/a&gt;己經完成，若有撞牆的地方，可以回去參考一下。&lt;br /&gt;
&lt;br /&gt;
在拜歐的&lt;span class=&quot;techn&quot;&gt;cluster&lt;/span&gt;中，會有四台機器，分別為：&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;techn&quot;&gt;javakid01&lt;/span&gt;：做為&lt;span class=&quot;techn&quot;&gt;master&lt;/span&gt;，會用它來跑&lt;span class=&quot;techn&quot;&gt;NameNode&lt;/span&gt;和&lt;span class=&quot;techn&quot;&gt;SecondaryNameNode&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;techn&quot;&gt;jkserver01&lt;/span&gt;：做為&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;，會用它來跑&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;techn&quot;&gt;jkserver02&lt;/span&gt;：做為&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;，會用它來跑&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;techn&quot;&gt;jkserver03&lt;/span&gt;：做為&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;，會用它來跑&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
若要改&lt;code&gt;hostname&lt;/code&gt;，你可以這樣做：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;sudo vi /etc/hostname
&lt;/pre&gt;
上列四台機器中，先確認已經安裝好&lt;span class=&quot;techn&quot;&gt;Java&lt;/span&gt;和&lt;span class=&quot;techn&quot;&gt;Hadoop&lt;/span&gt;。
&lt;br /&gt;
&lt;br /&gt;
先對&lt;span class=&quot;techn&quot;&gt;javakid01&lt;/span&gt;(master)，進行設定，在&lt;code class=&quot;folder&quot;&gt;/etc/hosts&lt;/code&gt;中加入：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;10.211.55.10    javakid01
10.211.55.7     jkserver01
10.211.55.13    jkserver02
10.211.55.14    jkserver03
&lt;/pre&gt;
再來編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/core-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;fs.defaultFS&lt;/name&gt;
                &lt;value&gt;hdfs://javakid01:9000&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/hdfs-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;dfs.replication&lt;/name&gt;
                &lt;value&gt;3&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;dfs.namenode.name.dir&lt;/name&gt;
                &lt;value&gt;file:/opt/data/hadoop/hadoop_data/hdfs/namenode&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
上面設定好後，使用下列指令建立上列設定的目錄，建立前請確定有足夠的權限：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;mkdir -p opt/data/hadoop/hadoop_data/hdfs/namenode
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/mapred-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;mapred.job.tracker&lt;/name&gt;
                &lt;value&gt;javakid01:54311&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/yarn-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
&lt;!-- Site specific YARN configuration properties --&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.nodemanager.aux-services&lt;/name&gt;
                &lt;value&gt;mapreduce_shuffle&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.nodemanager.aux-services.mapreduce.shuffle.class&lt;/name&gt;
                &lt;value&gt;org.apache.hadoop.mapred.ShuffleHandler&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.resource-tracker.address&lt;/name&gt;
                &lt;value&gt;javakid01:8025&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.scheduler.address&lt;/name&gt;
                &lt;value&gt;javakid01:8030&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.address&lt;/name&gt;
                &lt;value&gt;javakid01:8050&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
最後，在&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/slaves&lt;/code&gt;中加入做為&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;的&lt;code&gt;hostname&lt;/code&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;jkserver01
jkserver02
jkserver03
&lt;/pre&gt;
下面要開始對做為&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;的機器進行設定，其中&lt;code&gt;jkserver01&lt;/code&gt;、&lt;code&gt;jkserver02&lt;/code&gt;與&lt;code&gt;jkserver03&lt;/code&gt;的設定幾乎是相同的。
&lt;br /&gt;
&lt;br /&gt;
&lt;!-- data node --&gt;
一樣先在&lt;code class=&quot;folder&quot;&gt;/etc/hosts&lt;/code&gt;中加入：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;10.211.55.10    javakid01
10.211.55.7     jkserver01
10.211.55.13    jkserver02
10.211.55.14    jkserver03
&lt;/pre&gt;
請注意！上列的IP會因機器不同而有差異，這裡設定是以我的機器為例。
&lt;br/&gt;&lt;br/&gt;
再來編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/core-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;fs.defaultFS&lt;/name&gt;
                &lt;value&gt;hdfs://javakid01:9000&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/hdfs-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;dfs.replication&lt;/name&gt;
                &lt;value&gt;3&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;dfs.datanode.data.dir&lt;/name&gt;
                &lt;value&gt;file:/opt/data/hadoop/hadoop_data/hdfs/datanode&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
上面設定好後，使用下列指令建立上列設定的目錄，建立前請確定有足夠的權限：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;mkdir -p opt/data/hadoop/hadoop_data/hdfs/datanode
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/mapred-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
        &lt;property&gt;
                &lt;name&gt;mapred.job.tracker&lt;/name&gt;
                &lt;value&gt;javakid01:54311&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
接著編輯&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/yarn-site.xml&lt;/code&gt;加入下列設定：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;configuration&gt;
&lt;!-- Site specific YARN configuration properties --&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.nodemanager.aux-services&lt;/name&gt;
                &lt;value&gt;mapreduce_shuffle&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.nodemanager.aux-services.mapreduce.shuffle.class&lt;/name&gt;
                &lt;value&gt;org.apache.hadoop.mapred.ShuffleHandler&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.resource-tracker.address&lt;/name&gt;
                &lt;value&gt;javakid01:8025&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.scheduler.address&lt;/name&gt;
                &lt;value&gt;javakid01:8030&lt;/value&gt;
        &lt;/property&gt;
        &lt;property&gt;
                &lt;name&gt;yarn.resourcemanager.address&lt;/name&gt;
                &lt;value&gt;javakid01:8050&lt;/value&gt;
        &lt;/property&gt;
&lt;/configuration&gt;
&lt;/pre&gt;
最後，也要將讓&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;知道&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;的設定。在&lt;code class=&quot;folder&quot;&gt;$HADOOP_INSTALL/etc/hadoop/slaves&lt;/code&gt;中加入做為&lt;span class=&quot;techn&quot;&gt;DataNode&lt;/span&gt;的&lt;code&gt;hostname&lt;/code&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;jkserver01
jkserver02
jkserver03
&lt;/pre&gt;
接下來，為了讓&lt;span class=&quot;techn&quot;&gt;master&lt;/span&gt;不用密碼就可登入&lt;span class=&quot;techn&quot;&gt;slaves&lt;/span&gt;的話，需要進行&lt;span class=&quot;techn&quot;&gt;SSH&lt;/span&gt;連線的設定。
&lt;br /&gt;
&lt;br /&gt;
回到&lt;code&gt;javakid01&lt;/code&gt;這台機器，在終端機下執行：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;ssh-keygen -t rsa -P &#39;&#39; -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub &amp;gt;&amp;gt; ~/.ssh/authorized_keys
&lt;/pre&gt;
然後執行：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;ssh-copy-id -i ~/.ssh/id_rsa.pub javakid@jkserver01
&lt;/pre&gt;
完成後，由&lt;code&gt;javakid01&lt;/code&gt;登入&lt;code&gt;jkserver01&lt;/code&gt;，第一次登入會需要在&lt;code&gt;jkserver01&lt;/code&gt;上的使用者密碼：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;ssh jkserver01
&lt;/pre&gt;
對&lt;code&gt;jkserver02&lt;/code&gt;與&lt;code&gt;jkserver03&lt;/code&gt;進行相同設定，在&lt;code&gt;javakid01&lt;/code&gt;執行：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;ssh-copy-id -i ~/.ssh/id_rsa.pub javakid@jkserver02
&lt;/pre&gt;
登入&lt;code&gt;jkserver02&lt;/code&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;ssh jkserver02
&lt;/pre&gt;
接著執行：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;ssh-copy-id -i ~/.ssh/id_rsa.pub javakid@jkserver03
&lt;/pre&gt;
登入&lt;code&gt;jkserver03&lt;/code&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;ssh jkserver03
&lt;/pre&gt;
全部設定完成後，在&lt;code&gt;javakid01&lt;/code&gt;執行下列指令對&lt;span class=&quot;techn&quot;&gt;HDFS&lt;/span&gt;進行格式化：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;hadoop namenode -format
&lt;/pre&gt;
接著啟動&lt;span class=&quot;techn&quot;&gt; HDFS Daemons&lt;/span&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;$HADOOP_INSTALL/sbin/start-dfs.sh
&lt;/pre&gt;
成功啟動後，在&lt;code&gt;javakid01&lt;/code&gt;執行&lt;code&gt;jps&lt;/code&gt;指令：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;jps
&lt;/pre&gt;
應該可以看到下列的結果：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;27964 NameNode
28220 SecondaryNameNode
29695 Jps
&lt;/pre&gt;
再來若是到&lt;code&gt;jkserver01&lt;/code&gt;、&lt;code&gt;jkserver02&lt;/code&gt;或&lt;code&gt;jkserver03&lt;/code&gt;任一台機器執行&lt;code&gt;jps&lt;/code&gt;，應該可以看到下列結果：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;2204 DataNode
2378 Jps
&lt;/pre&gt;
若在瀏覽器輸入&lt;code&gt;http://javakid01:50070&lt;/code&gt;這個網址，應該在&lt;span class=&quot;techn&quot;&gt;Datanodes&lt;/span&gt;這個頁籤看到三台機器的資訊：
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjME_QZ-A-_crZW9mCFKYy199KfPxVBJMedK_w6E2ljvmhGmAoOTmNRWA9IecZC6OSuMeYjgTgeVtdvufgDIoEU8UIdjJ5R3MrmHyl8CU7Eh92qSCSAYuF9oVlDE_lyvBI5x8sa959mRn-F/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-05-30+01.06.38.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;135&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjME_QZ-A-_crZW9mCFKYy199KfPxVBJMedK_w6E2ljvmhGmAoOTmNRWA9IecZC6OSuMeYjgTgeVtdvufgDIoEU8UIdjJ5R3MrmHyl8CU7Eh92qSCSAYuF9oVlDE_lyvBI5x8sa959mRn-F/s400/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-05-30+01.06.38.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/3217749555752857564/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/3217749555752857564?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3217749555752857564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/3217749555752857564'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/05/ubuntu-1404hadoopmulti-node-cluster.html' title='【筆記】在Ubuntu 14.04建立Hadoop多節點叢集-分散式架構(Multi-node cluster)'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjME_QZ-A-_crZW9mCFKYy199KfPxVBJMedK_w6E2ljvmhGmAoOTmNRWA9IecZC6OSuMeYjgTgeVtdvufgDIoEU8UIdjJ5R3MrmHyl8CU7Eh92qSCSAYuF9oVlDE_lyvBI5x8sa959mRn-F/s72-c/%25E8%259E%25A2%25E5%25B9%2595%25E6%2588%25AA%25E5%259C%2596+2015-05-30+01.06.38.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-4216964986128276465</id><published>2015-05-26T12:55:00.000+08:00</published><updated>2015-06-30T13:05:36.833+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><title type='text'>【筆記】Hadoop名詞解釋</title><content type='html'>&lt;table cellspacing=&quot;0&quot; class=&quot;data_table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;header&quot;&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;名詞&lt;/b&gt;&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;意思&lt;/b&gt;&lt;/td&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;b&gt;備註&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;metrics&lt;/td&gt;&lt;td&gt;HDFS與MapReduce daemon會收集一些與事件以及量測相關的資訊，這些總稱為metrics&lt;/td&gt;&lt;td&gt;例如，datanode會收集已寫入的byte數、已複製的block總數等metrics&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;data locality optimization&lt;/td&gt;
&lt;td&gt;Hadoop在執行map task時，會盡全力將該task放到存放輸入該task資料的那台node去執行，以免使用到寶貴的頻寬進行資料的傳送&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;shuffle&lt;/td&gt;
&lt;td&gt;A proccess by which the system performs the sort and transfers the map outputs to the reducers as inputs.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;speculative execution&lt;/td&gt;
&lt;td&gt;Hadoop doesn&#39;t try to diagnose and fix slow-running tasks; instead, it tries to detect when a task is running slower than expected and launches another equivalent task as a backup.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/4216964986128276465/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/4216964986128276465?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4216964986128276465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/4216964986128276465'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/05/hadoop_26.html' title='【筆記】Hadoop名詞解釋'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-254623998873275425</id><published>2015-05-05T01:49:00.000+08:00</published><updated>2015-05-05T01:49:28.804+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="MongoDB"/><title type='text'>【分享】解決Java連Mongo DB時，出現no such cmd: saslStart錯誤</title><content type='html'>今天在使用&lt;span class=&quot;techn&quot;&gt;Java&lt;/span&gt;連
&lt;span class=&quot;techn&quot;&gt;Mongo DB&lt;/span&gt;時發生了一個錯誤，訊息如下：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;Exception in thread &quot;main&quot; com.mongodb.CommandFailureException: { &quot;serverUsed&quot; : &quot;192.168.55.12:22004&quot; , &quot;ok&quot; : 0.0 , &quot;errmsg&quot; : &quot;no such cmd: saslStart&quot;}
&lt;/pre&gt;
我使用的
&lt;span class=&quot;techn&quot;&gt;Java MongoDB Driver&lt;/span&gt;是
&lt;span class=&quot;techn&quot;&gt;2.12.3&lt;/span&gt;而連線的&lt;span class=&quot;techn&quot;&gt;Mongo DB&lt;/span&gt;版本是&lt;span class=&quot;techn&quot;&gt;2.4.3&lt;/span&gt;。&lt;br /&gt;
&lt;br /&gt;
使用的程式碼如下：
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
MongoCredential credential = MongoCredential.createPlainCredential(&quot;foo&quot;, &quot;testDB&quot;, &quot;bar&quot;.toCharArray());
MongoClient mongoClient = new MongoClient(new ServerAddress(&quot;192.168.55.12&quot;, 22004), Arrays.asList(credential));
DB db = mongoClient.getDB(&quot;testDB&quot;);
&lt;/pre&gt;
後來發現在使用&lt;code&gt;MongoCredential.createPlainCredential&lt;/code&gt;這個方法時，在&lt;span class=&quot;techn&quot;&gt;Mongo DB&lt;/span&gt;的&lt;span class=&quot;techn&quot;&gt;2.6&lt;/span&gt;版本是才支援的，詳細可以參考&lt;a href=&quot;http://api.mongodb.org/java/2.12/&quot; target=&quot;_blank&quot;&gt;文件&lt;/a&gt;內說明。
&lt;span class=&quot;techn&quot;&gt;&lt;/span&gt;&lt;span class=&quot;techn&quot;&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/254623998873275425/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/254623998873275425?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/254623998873275425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/254623998873275425'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/05/javamongo-dbno-such-cmd-saslstart.html' title='【分享】解決Java連Mongo DB時，出現no such cmd: saslStart錯誤'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-936507502128267534</id><published>2015-04-28T01:25:00.000+08:00</published><updated>2015-04-28T01:39:36.744+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MacBook Pro"/><title type='text'>【分享】解決MacBook Pro 開機、關機變慢的問題</title><content type='html'>&lt;h3&gt;
開機變慢&lt;/h3&gt;
&lt;br /&gt;
好像在上周更新過&lt;span class=&quot;techn&quot;&gt;OS X Yosemite&lt;/span&gt;之後，開機就明顯變得很慢：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdFmYSCOUYq3Y277aCQqxh_6yRGiwSt-UCu6DyMQV5gMHQw6WMDII_PVTxd1t2GrvZXwpqrd9pCh4-cPHsQpcUMx92Ov_GqjLeAnTGSyYD-iuAQYOFBJWCpwELJr7dOueRYlMKBFJS6yz5/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+00.24.51.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdFmYSCOUYq3Y277aCQqxh_6yRGiwSt-UCu6DyMQV5gMHQw6WMDII_PVTxd1t2GrvZXwpqrd9pCh4-cPHsQpcUMx92Ov_GqjLeAnTGSyYD-iuAQYOFBJWCpwELJr7dOueRYlMKBFJS6yz5/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+00.24.51.png&quot; height=&quot;95&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;這裡無法確認更新是否為確切造成開機變慢的原因，只是剛好在此時間點後，狀況變得明顯。&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
一開始在網路上找到的解法，不外乎是「修復磁碟權限」、把不必要的「登入項目」關閉，或是清除桌面等，該試的都試過了，拜歐一開機等白蘋果出來前，還是要望著非常久的黑螢幕，想著為何會變這麼慢。
&lt;br /&gt;
&lt;br /&gt;
後來找到這串討論串：&lt;a href=&quot;http://www.mobile01.com/topicdetail.php?f=177&amp;amp;t=978067&quot; target=&quot;_blank&quot;&gt;請問各位大哥 為什麼MBP 開機會變慢&lt;/a&gt;，六樓朋友的回應，解決了拜歐開機速度慢的問題。&lt;br /&gt;
&lt;br /&gt;
拜歐是這樣做的，先到【系統徧好設定】，在下方倒收第二排有個【啟動磁碟】：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbgBMlL5TVn6CZgj16rix7v4b_AxR5jzOFhR19PbTqNy0pqRm289DeXUNfMxqb1zR0wD_9e3imQLdw2Ae7d9_2a2gFSQm4yBlZ4ihH8N4W1Bxz6Fbp2mOB9t8DHZBmkwWlzhnzgapvUdkQ/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+01.15.49_02.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbgBMlL5TVn6CZgj16rix7v4b_AxR5jzOFhR19PbTqNy0pqRm289DeXUNfMxqb1zR0wD_9e3imQLdw2Ae7d9_2a2gFSQm4yBlZ4ihH8N4W1Bxz6Fbp2mOB9t8DHZBmkwWlzhnzgapvUdkQ/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+01.15.49_02.png&quot; height=&quot;357&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
點進去後，在「請選擇要用來開機的系統」中，選擇要開機的硬碟後，再重新開機：&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtCwCROs-aUmy0kjuSo1fhEx82ho5doIuh29nFkouCqJw2AxyHa_7WLxmmjmACAbuJlcNNz1bTjxvVz0Fd19lEmQF1YVNEauWhBUqDQXU5Ha-HU3EUEdXeFVapZ_dTrOjrqvujRB5ewCSG/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+01.19.09.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtCwCROs-aUmy0kjuSo1fhEx82ho5doIuh29nFkouCqJw2AxyHa_7WLxmmjmACAbuJlcNNz1bTjxvVz0Fd19lEmQF1YVNEauWhBUqDQXU5Ha-HU3EUEdXeFVapZ_dTrOjrqvujRB5ewCSG/s1600/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+01.19.09.png&quot; height=&quot;212&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
上面的做法解決了拜歐的問題，不禁猜想，會不會是兒子三不五時，找到機會就偷敲鍵盤造成設定跑掉的，XD&lt;br /&gt;&lt;br /&gt;
&lt;h3&gt;
關機變慢&lt;/h3&gt;
&lt;br /&gt;
在&lt;span class=&quot;techn&quot;&gt;Google&lt;/span&gt;上打了「macbook pro 關機變慢」的關鍵字，第一筆出現這一篇：&lt;a href=&quot;http://www.mobile01.com/topicdetail.php?f=481&amp;amp;t=4124704&quot; target=&quot;_blank&quot;&gt;解決升上Yosemite-OS X10.10關機速度慢的問題&lt;/a&gt;，這位樓主分享了一篇在&lt;span class=&quot;techn&quot;&gt;&lt;a href=&quot;https://discussions.apple.com/welcome&quot; target=&quot;_blank&quot;&gt;Apple Support Communities&lt;/a&gt;&lt;/span&gt;上討論到&lt;a href=&quot;https://discussions.apple.com/thread/6603318&quot; target=&quot;_blank&quot;&gt;Slow shutdown on Yosemite&lt;/a&gt;的問題。&lt;br /&gt;
&lt;br /&gt;
這個提到&lt;span class=&quot;techn&quot;&gt;MacBook Pro&lt;/span&gt;會變慢的原因，可能是有裝舊版本的&lt;span class=&quot;techn&quot;&gt;Parallels Desktop&lt;/span&gt;，受其影響的關係，拜歐的&lt;span class=&quot;techn&quot;&gt;MacBook Pro&lt;/span&gt;也有裝，心想，有可能是這個原因。&lt;br /&gt;
&lt;br /&gt;
其解決方法提到，要到&lt;code class=&quot;folder&quot;&gt;~/Library/LaunchAgents&lt;/code&gt;和&lt;code class=&quot;folder&quot;&gt;~/Library/LaunchDaemons&lt;/code&gt;把有「parallels」字眼的檔案都清掉，在拜歐的電腦中只找到&lt;code class=&quot;folder&quot;&gt;~/Library/LaunchAgents&lt;/code&gt;這個資料夾，而就索性把&lt;code class=&quot;folder&quot;&gt;~/Library/LaunchAgents&lt;/code&gt;裡面的檔案全刪了，果然，關機就感覺有恢復跟原來一樣的速度，而&lt;span class=&quot;techn&quot;&gt;Parallels Desktop&lt;/span&gt;也能正常運作。
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;請注意，這解決了拜歐的問題，不一定適用看倌您的情境，請在刪不知用途的檔案前，請三思而後行XDD
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
討論串中還有一位仁兄提到&lt;code class=&quot;folder&quot;&gt;~/Library/Preferences&lt;/code&gt;這個資料夾中和「parallels」有關的檔案也要刪，這裡面的拜歐沒動，就不知道有沒有助益了。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/936507502128267534/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/936507502128267534?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/936507502128267534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/936507502128267534'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/macbook-pro.html' title='【分享】解決MacBook Pro 開機、關機變慢的問題'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdFmYSCOUYq3Y277aCQqxh_6yRGiwSt-UCu6DyMQV5gMHQw6WMDII_PVTxd1t2GrvZXwpqrd9pCh4-cPHsQpcUMx92Ov_GqjLeAnTGSyYD-iuAQYOFBJWCpwELJr7dOueRYlMKBFJS6yz5/s72-c/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96+2015-04-28+00.24.51.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-7596441100924480679</id><published>2015-04-25T02:05:00.000+08:00</published><updated>2015-04-25T02:09:32.157+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>【筆記】在PHP中太長的數字以科學符號(scientific notation)顯示的解決方案</title><content type='html'>寫過&lt;span class=&quot;techn&quot;&gt;PHP&lt;/span&gt;的人一定遇到，過長的數字&lt;code&gt;echo&lt;/code&gt;出來後，非所預期地以科學符號顯示的問題，如：
&lt;br /&gt;
&lt;pre class=&quot;brush: php&quot;&gt;$f1 = 201504242111234; 
$f2 = 201504191213211;

echo $f1 . &#39;,&#39; . $f2;
&lt;/pre&gt;
一般預期的結果應該為：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;201504242111234,201504191213211
&lt;/pre&gt;
但實際上，結果可能為：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;2.0150424211123E+14,2.0150419121321E+14
&lt;/pre&gt;
這時若只是要在網頁上顯示所要的格式，可以使用&lt;code&gt;printf&lt;/code&gt;(&lt;a href=&quot;http://php.net/manual/zh/function.printf.php&quot; target=&quot;_blank&quot;&gt;文件&lt;/a&gt;)這個方法，它的用法是：


&lt;br /&gt;
&lt;pre class=&quot;brush: php&quot;&gt;int printf ( string $format [, mixed $args [, mixed $... ]] )
&lt;/pre&gt;
其中，第一個參數為要印出的格式設定，詳細說明可以參考&lt;a href=&quot;http://php.net/manual/zh/function.sprintf.php&quot; target=&quot;_blank&quot;&gt;這裡&lt;/a&gt;。
&lt;br /&gt;&lt;br /&gt;
據此，可以把上面&lt;code&gt;echo&lt;/code&gt;的這一行替換成下面程式：
&lt;br /&gt;
&lt;pre class=&quot;brush: php&quot;&gt;printf(&#39;%.0f,%.0f&#39;, $f1, $f2);
&lt;/pre&gt;
這裡&lt;code&gt;%.0f&lt;/code&gt;的意思是說，以浮點數的格式去顯示後面傳入的參數，在其中的&lt;code&gt;0&lt;/code&gt;是指小數點後要顯示的位數為「0」。
&lt;br /&gt;
&lt;br /&gt;
另外，因為&lt;code&gt;%.0f&lt;/code&gt;有兩個，後面要傳入對應的兩個浮點數。
&lt;br /&gt;
&lt;br /&gt;
有時，在一些情況下需要在程式中將兩個浮數數串在一起，好讓後面的程式使，這時就要使用到&lt;code&gt;sprintf&lt;/code&gt;(&lt;a href=&quot;http://php.net/manual/zh/function.sprintf.php&quot; target=&quot;_blank&quot;&gt;文件&lt;/a&gt;)這個方法：
&lt;br /&gt;
&lt;pre class=&quot;brush: php&quot;&gt;
string sprintf ( string $format [, mixed $args [, mixed $... ]] )
&lt;/pre&gt;
從上面可以看到，它回傳的是一個字串，所以可以這樣使用：
&lt;pre class=&quot;brush: php&quot;&gt;
$s1 = sprintf(&#39;%.0f&#39;, $f1);
$s2 = sprintf(&#39;%.0f&#39;, $f2);

$s3 = $s1 . &#39;,&#39; . $s2;

//$s3有可能有其他如做為SQL的運用
//這裡僅把它印出來
echo $s3;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/7596441100924480679/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/7596441100924480679?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7596441100924480679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/7596441100924480679'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/phpscientific-notation.html' title='【筆記】在PHP中太長的數字以科學符號(scientific notation)顯示的解決方案'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-5876223148123935439</id><published>2015-04-25T01:30:00.000+08:00</published><updated>2015-04-25T01:30:39.725+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Regular Express"/><title type='text'>【分享】學習正規表示式(Regular Expression)的資源</title><content type='html'>&lt;span class=&quot;techn&quot;&gt;Regular Expression&lt;/span&gt;翻做中文為正規表示式，又稱正則表達式、正規表示法、正規運算式、規則運算式、常規表示法(&lt;a href=&quot;http://zh.wikipedia.org/wiki/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F&quot; target=&quot;_blank&quot;&gt;wiki&lt;/a&gt;)，在此拜歐習慣使用正規表示式這個翻譯，因為它唸起來最順，XD。
&lt;br /&gt;
&lt;br /&gt;
之前斷斷續續地涉略或鑽研正規表示式的用法，期間也找到一些在網路上覺得不錯的資源，因此在此記錄與分享。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
OCPSoft&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1vTOi-lmcsq3FxP2v-MGMLMIjn7WNFVQ2n7hZX4PWxvPYXGswT1QfL9R8NAszCoO_9psrpmIUDm1_FGkC71osaclZlIUAPR9p4mbpPrhCMXRRxSY4RszuZk1BsbYo3wrgM89edc5MaiWM/s1600/2015-04-24_110414.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1vTOi-lmcsq3FxP2v-MGMLMIjn7WNFVQ2n7hZX4PWxvPYXGswT1QfL9R8NAszCoO_9psrpmIUDm1_FGkC71osaclZlIUAPR9p4mbpPrhCMXRRxSY4RszuZk1BsbYo3wrgM89edc5MaiWM/s1600/2015-04-24_110414.png&quot; height=&quot;195&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.ocpsoft.org/&quot; target=&quot;_blank&quot;&gt;OCPSoft&lt;/a&gt;是一群喜好開放原始碼開發者的組織，在它的網站上找到兩篇講述&lt;span class=&quot;techn&quot;&gt;Java&lt;/span&gt;和正規表示式的教學資源。&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;a href=&quot;http://www.ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-1/&quot; target=&quot;_blank&quot;&gt;Guide to Regular Expressions in Java (Part 1)&lt;/a&gt;&lt;/h4&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;a href=&quot;http://www.ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-2/&quot; target=&quot;_blank&quot;&gt;Guide to Regular Expressions in Java (Part 2)&lt;/a&gt;&lt;/h4&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/5876223148123935439/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/5876223148123935439?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/5876223148123935439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/5876223148123935439'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/regular-expression.html' title='【分享】學習正規表示式(Regular Expression)的資源'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1vTOi-lmcsq3FxP2v-MGMLMIjn7WNFVQ2n7hZX4PWxvPYXGswT1QfL9R8NAszCoO_9psrpmIUDm1_FGkC71osaclZlIUAPR9p4mbpPrhCMXRRxSY4RszuZk1BsbYo3wrgM89edc5MaiWM/s72-c/2015-04-24_110414.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-208846504999637547</id><published>2015-04-24T00:31:00.000+08:00</published><updated>2015-04-24T00:31:57.951+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Regular Express"/><title type='text'>【筆記】在JavaScript中使用正規表示式擷取目標字串</title><content type='html'>&lt;pre class=&quot;brush: javascript&quot;&gt;
(function(){

 var input = &#39;1990Mar02Taipei35&#39;;

 var num = /(\d+)\D+(\d+)(\D+)(\d+)/g;
 
 var result = num.exec(input);

  console.log(RegExp.$1 + &#39; 年在 &#39; + RegExp.$3 + &#39; 的數值是: &#39; 
              + RegExp.$4);

})();
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/208846504999637547/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/208846504999637547?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/208846504999637547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/208846504999637547'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/javascript.html' title='【筆記】在JavaScript中使用正規表示式擷取目標字串'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-6517951974117607665</id><published>2015-04-24T00:23:00.004+08:00</published><updated>2015-05-28T09:01:09.499+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Regular Express"/><title type='text'>【筆記】在Java中使用正規表示式(Regular Expression)切割字串</title><content type='html'>在工作上若碰到要在一行字串去擷取資料時，如下面記錄某年某月某日某地區的某個數值：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;1990Mar02Taipei28
&lt;/pre&gt;
常是以&lt;code&gt;substring&lt;/code&gt;算好位置去截取各個資料，若有時可能應程式更新造成了一些例外，如上面的月份是英文簡寫，但程式更新後，記錄月份的方式變成：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;1991March03Tainan35
&lt;/pre&gt;
這時若再用&lt;code&gt;substring&lt;/code&gt;來切字串，就可能要做一些判斷來算位置。
&lt;br /&gt;
&lt;br /&gt;
當每一行資料的模式都是一樣時，如上面兩筆資料，都是數字、英文字、數字、英文字、數字時，就可以使用&lt;code&gt;Pattern&lt;/code&gt;(&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#MULTILINE&quot;&gt;文件&lt;/a&gt;)搭配&lt;code&gt;Matcher&lt;/code&gt;(&lt;a href=&quot;http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html&quot;&gt;文件&lt;/a&gt;)，以正規表示式來切字串：
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package idv.jk.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MatcherTest
{
    public static void main(String[] arv)
    {
        String input = &quot;1990Mar02Taipei28\r\n1991March03Tainan35&quot;;
        Pattern pattern = Pattern.compile(&quot;(\\d+)(\\D+)(\\d+)(\\D+)(\\d+)&quot;,
                                            Pattern.MULTILINE);

        Matcher matcher = pattern.matcher(input);

        while(matcher.find())
        {
            System.out.println(&quot;The value at &quot; + matcher.group(4) +
                                    &quot; in &quot; + matcher.group(2) +
                                    &quot; &quot; + matcher.group(1)+
                                    &quot; is &quot; + matcher.group(5));
        }
    }
}
&lt;/pre&gt;
結果為：
&lt;br /&gt;
&lt;pre class=&quot;plain&quot;&gt;The value at Taipei in Mar 1990 is 28
The value at Tainan in March 1991 is 35
&lt;/pre&gt;
上面範例用簡單的資料，來說明正規表示式的功用，在現實的工作上，資料模式通常都複雜許多，但若能熟悉正規表示式並應用得當，在檔案處理上必能得心應手。
&lt;br /&gt;
&lt;br /&gt;
若想進一步鑽研，可以考慮這一本：
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&amp;amp;OneJS=1&amp;amp;Operation=GetAdHtml&amp;amp;MarketPlace=US&amp;amp;source=ac&amp;amp;ref=qf_sp_asin_til&amp;amp;ad_type=product_link&amp;amp;tracking_id=javakid-20&amp;amp;marketplace=amazon&amp;amp;region=US&amp;amp;placement=0596528124&amp;amp;asins=0596528124&amp;amp;linkId=UDVMLCB3MNPLQCOG&amp;amp;show_border=true&amp;amp;link_opens_in_new_window=true&quot; style=&quot;height: 240px; width: 120px;&quot;&gt;
&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
它也有&lt;a href=&quot;http://www.books.com.tw/exep/assp.php/bioankeyang/products/0010546974?utm_source=bioankeyang&amp;amp;utm_medium=ap-books&amp;amp;utm_content=recommend&amp;amp;utm_campaign=ap-201504&quot; target=&quot;_blank&quot;&gt;中文版&lt;/a&gt;，XD</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/6517951974117607665/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/6517951974117607665?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/6517951974117607665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/6517951974117607665'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/javaregular-expression.html' title='【筆記】在Java中使用正規表示式(Regular Expression)切割字串'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5252179981300499332.post-1101476943174302606</id><published>2015-04-22T13:20:00.000+08:00</published><updated>2015-04-22T13:23:49.268+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Redis"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>【筆記】在Ubuntu 14.04.2 Server安裝Redis(版本3.0.0)</title><content type='html'>&lt;span class=&quot;techn&quot;&gt;Redis&lt;/span&gt;目前官方有支援的版本就是&lt;span class=&quot;techn&quot;&gt;Linux-based&lt;/span&gt;的作業系統，在這裡拜歐是在&lt;span class=&quot;techn&quot;&gt;Ubuntu 14.04.2 Server&lt;/span&gt;安裝&lt;span class=&quot;techn&quot;&gt;Redis&lt;/span&gt;，版本為&lt;span class=&quot;techn&quot;&gt;3.0&lt;/span&gt;，先到&lt;a href=&quot;http://download.redis.io/releases/redis-3.0.0.tar.gz&quot; target=&quot;_blank&quot;&gt;這裡&lt;/a&gt;下載&lt;span class=&quot;techn&quot;&gt;Redis&lt;/span&gt;。&lt;br /&gt;&lt;br /&gt;
在終端機中，輸入下列指令下載：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;wget http://download.redis.io/releases/redis-3.0.0.tar.gz
&lt;/pre&gt;

下載完成後，將其解壓縮：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;  
tar xzv -f redis-3.0.0.tar.gz
&lt;/pre&gt;
進入&lt;code&gt;redis-3.0.0&lt;/code&gt;目錄中執行&lt;code&gt;make&lt;/code&gt;指令：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt; 
cd redis-3.0.0
make 
&lt;/pre&gt;
若顯示找不到&lt;code&gt;make&lt;/code&gt;指令的訊息，請執行下列指令進行安裝：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt; 
sudo apt-get install make
&lt;/pre&gt;
再來若遇到下列錯誤訊息：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain;highlight:1&quot;&gt;/bin/sh: 1: cc: not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/javakid/tools/nosql/redis-3.0.0/src&#39;
make: *** [all] Error 2
&lt;/pre&gt;
這裡要注意的是第一行的訊息，若是出現這個訊息，請執行下列指令進行安裝：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt; sudo apt-get install build-essential
&lt;/pre&gt;
若有什麼檔案找不到的，如下列訊息：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include &amp;lt;jemalloc/jemalloc.h&amp;gt;
                               ^
&lt;/pre&gt;
解決辦法只要去把缺的檔案make出來：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;cd deps 
make jemalloc
&lt;/pre&gt;
然後再回到redis-3.0.0目錄，再執行&lt;code&gt;make&lt;/code&gt;&lt;br /&gt;
。
&lt;br /&gt;
若是有再遇到下列訊息：
&lt;br /&gt;
&lt;pre class=&quot;brush: plain&quot;&gt;cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/home/javakid/tools/nosql/redis-3.0.0/src&#39;
make: *** [all] Error 2
&lt;/pre&gt;
一樣先到&lt;code class=&quot;techn&quot;&gt;deps&lt;/code&gt;執行，把缺的檔案make出來：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;cd deps
make hiredis lua jemalloc linenoise
&lt;/pre&gt;
完成後，再回到上一層再執行&lt;code&gt;make&lt;/code&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt;cd ../
make
&lt;/pre&gt;
&lt;code&gt;make&lt;/code&gt;執行完畢後，執行下列指令，開始執行指令啟動&lt;span class=&quot;techn&quot;&gt;Redis&lt;/span&gt;：
&lt;br /&gt;
&lt;pre class=&quot;brush: bash&quot;&gt; src/redis-server
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bioankeyang.blogspot.com/feeds/1101476943174302606/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/5252179981300499332/1101476943174302606?isPopup=true' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/1101476943174302606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5252179981300499332/posts/default/1101476943174302606'/><link rel='alternate' type='text/html' href='http://bioankeyang.blogspot.com/2015/04/ubuntu-14042-serverredis300.html' title='【筆記】在Ubuntu 14.04.2 Server安裝Redis(版本3.0.0)'/><author><name>Bio</name><uri>http://www.blogger.com/profile/07925546615867453817</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>