<?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-8294609939460569030</id><updated>2024-09-01T09:23:54.814-07:00</updated><category term="javascript"/><category term="html"/><category term="other"/><category term="RoR"/><category term="ruby"/><category term="python"/><title type='text'>Brian on Programming</title><subtitle type='html'>this blog records some issues I faced when I was developing my program. &#xa;Hope these articles may help someone who faced the same problem.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8294609939460569030.post-787022811187105470</id><published>2012-11-29T08:09:00.001-08:00</published><updated>2012-12-30T23:51:43.197-08:00</updated><title type='text'>install pygame on mac os x 10.8 (mountain lion)</title><content type='html'>I highly recommend you to use another way to install pygame:&lt;br /&gt;
http://stackoverflow.com/a/14098938/938380&lt;br /&gt;
&lt;br /&gt;
________________ the original way is not recommended ____________&lt;br /&gt;
I have struggled to install pygame1.9.1 on my machine for a long time. there are so many dependencies issues.&lt;br /&gt;
fortunately, i solved all the issues finally.&lt;br /&gt;
I followed the instruction from&lt;a href=&quot;http://pygame.org/wiki/MacCompile&quot;&gt; pygame wiki&lt;/a&gt;, but the original step 7 was not working for me.&lt;br /&gt;
I have corrected step 7 as below:&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=8294609939460569030&quot; name=&quot; Mountain Lion install instructions &quot; style=&quot;font-family: sans-serif;&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre&gt;1. Installed python but using visual python version. This is based on python 2.7.x
In my system this installs files under Applications and /Library/Frameworks/Python.framework

http://www.vpython.org
From this site:

First, download and install the pure 32-bit Python, Python-2.7.3
(VPython does not work with Mac 64-bit/32-bit Python, but this 32-bit version of Python works fine on 64-bit Macs)

Second, download and install VPython-Mac-Py2.7-5.74

This includes version 1.5.1 of numpy.

The download of Python-2.7.3 is from the vpython site and designed to work with vpython.
You can use the python installer from http://www.python.org. However, you will have to install numpy.
You can get numpy from http://sourceforge.net/projects/numpy/files/

2. Installed the SDL libraries from dmg
http://www.libsdl.org/

SDL  1.2.15
SDL_mixer 1.2.12
SDL_ttf  2.0.11
SDL_image 1.2.12

3. Installed the libjpeg and libpng libraries from dmg
http://ethan.tira-thompson.com/Mac_OS_X_Ports.html

libpng v1.5.4
libjpeg 8c

4. Installed Xcode 4.4 from Apple apps. Need to add command line tools.
To do this start Xcode and go to Preferences under Xcode menu. Choose the Download tab and select Components.
Then install the Command Line Tools.

5. Installed XQuartz. Mountain Lion OS X no longer includes the X11 window system library.
This is different from Lion OS X.
http://xquartz.macosforge.org/landing/

XQuartz-2.7.2.dmg

6. Downloaded pygame tar file from 
http://pygame.org/download.shtml

pygame-1.9.1release.tar.gz 

Decompressed and extracted to create directory pygame1.9.1release

6. Before compilation of pygame:

  a. SDL_x header files refer to SDL as &lt;sdl yy.h=&quot;yy.h&quot;&gt; However, a SDL directory is not under
the include directory of SDL (SDL/Headers). To fix this in a simple way:

    i. Went to directory
          /Library/Frameworks/SDL.framework/Headers
     then made a link as follows:
          ln -s SDL ./

7. Changed to the pygame directory (normally pygame1.9.1release). Then switched to the super user.
However, you can use the sudo command instead.

I set the following compilation flags

export CC=&#39;/usr/bin/gcc&#39;
export CFLAGS=&#39;-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/opt/X11/include -arch i386&#39;
export LDFLAGS=&#39;-arch i386&#39;
export ARCHFLAGS=&#39;-arch i386&#39;&lt;/sdl&gt;&lt;/pre&gt;
ln -s /opt/X11/include/X11/ /usr/local/include/X11&lt;br /&gt;
&lt;pre&gt;edit src/scale_mmx64.c, and replace movsxl with movslq like &lt;a href=&quot;https://bitbucket.org/pygame/pygame/commits/e296ada67fad/&quot;&gt;this&lt;/a&gt;&lt;/pre&gt;
&lt;pre&gt;8. Now execute:
   python config.py
This should find the SDL, jpeg, png, and numpy libraries

   python setup.py build
This will build in the directory before installing. It should complete with no errors.
then
   python setup.py install

9. Confirmed that it worked:

   Out of super user mode and in a terminal shell

   python
   and within python
   import pygame

   this gave no error and a simple pygame program ran fine.&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
hope this article is helpful</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/787022811187105470/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2012/11/install-pygame-on-mac-os-x-108-mountain.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/787022811187105470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/787022811187105470'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2012/11/install-pygame-on-mac-os-x-108-mountain.html' title='install pygame on mac os x 10.8 (mountain lion)'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-8383985430081306407</id><published>2012-08-26T02:33:00.000-07:00</published><updated>2012-08-26T02:33:01.264-07:00</updated><title type='text'>git commit 流程 極簡易教學</title><content type='html'>這篇文章只提供用git提交code最簡單的方式，不包含細節觀念和例外狀況(conflict等)處理。想要知道相關細節的，煩請自行google。&lt;br /&gt;
&amp;nbsp;要commit（提交）自己的code，分成4個階段，這件事要首先keep in mind：&lt;br /&gt;
&amp;nbsp;修改需要更動的code -&amp;gt; 把更動過且確定要提交的code放到stage（沒有要提交的就不要放） -&amp;gt; commit（提交這次要更動的code） -&amp;gt; 把提交的code push到遠端&lt;br /&gt;
注意！放到stage和commit是不一樣的！要commit前，一定要先放到stage。因為你不一定需要將自己所有更動過的code都提交，先放到stage，git才知道你這次到底要提交哪些code。push時只會把你commit的code（有放到stage的code）放到遠端。&lt;br /&gt;
這點我自己當初也搞不太清楚，撞了很多次牆。&lt;br /&gt;
&lt;br /&gt;
有了上述大觀念後，以下是簡易流程&lt;br /&gt;
1.
為了避免不必要的conflict造成自己的麻煩，每次修改前都請先git pull，先把遠端最新版本的code抓回來&lt;br /&gt;
2.
修改code&lt;br /&gt;
3.
git status
列出目前的狀態（最好在這個git repository的根目錄下這個指令，不然接著要add時會有一些路徑上的問題）&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/AVvXsEjLvKVBTIGPhAVUSDSXHoCS9gNV7f9PM0syPwBICT7rW_1ewKXP2ZkT0A-TM-kkyFDCnbrIxJnHHxYgYaAa1_xTM_Y4zj9RYx72omjKvmjD5KUE0Qw3SgotTIENCw9ghMqcC3dvm3CzQwI/s1600/Screen+Shot+2012-08-26+at+4.33.57+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;211&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLvKVBTIGPhAVUSDSXHoCS9gNV7f9PM0syPwBICT7rW_1ewKXP2ZkT0A-TM-kkyFDCnbrIxJnHHxYgYaAa1_xTM_Y4zj9RYx72omjKvmjD5KUE0Qw3SgotTIENCw9ghMqcC3dvm3CzQwI/s320/Screen+Shot+2012-08-26+at+4.33.57+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
此處需要再知道一個觀念：git repository 下的檔案分成兩大類：tracked, untracked&lt;br /&gt;
簡單的說，git有紀錄過的是前者；反之是後者。&lt;br /&gt;
這張圖上半部紅色的，是已經被git追蹤，這次修改過的檔案（沒被修改過的就不會被列出）；下半部是這次新增，尚未被追蹤的檔案。&lt;br /&gt;
4. 把你這次要commit的檔案add到stage&lt;br /&gt;
你可以依序下 git add XXX/yyy（需要包含路徑），一個檔案一個檔案放&lt;br /&gt;
假如你這次更動的file全部都要提交，則可以下&lt;br /&gt;
git add .&lt;br /&gt;
或是直接在 commit 時加上 -a&lt;br /&gt;
git commit -a&lt;br /&gt;
不過需要特別注意的是，git commit -a 只會新增tracked file，亦即只會新增之前就存在、這次被修改的file；這次才新增的file不會被加入。要連這次才新增的file都加入，一定要用&lt;br /&gt;
git add .&lt;br /&gt;
&lt;br /&gt;
add完後，再下git status&lt;br /&gt;
就會看到剛剛被add的檔案已經變成準備被commit的情況&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/AVvXsEhK3EopnHfCbbLQ4wmb_xdr0sPcu1-1nBAO8GzZiw7Axzl75g6YmQaWLrFMMuN6FzihTG8YXgEp0iOoiRe4SC-UFgHfHERNmFeluVf_M1rln9ViimaTolSVIWR4EWhwaoYCNvTEyFIrut4/s1600/Screen+Shot+2012-08-26+at+5.21.26+PM.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/AVvXsEhK3EopnHfCbbLQ4wmb_xdr0sPcu1-1nBAO8GzZiw7Axzl75g6YmQaWLrFMMuN6FzihTG8YXgEp0iOoiRe4SC-UFgHfHERNmFeluVf_M1rln9ViimaTolSVIWR4EWhwaoYCNvTEyFIrut4/s320/Screen+Shot+2012-08-26+at+5.21.26+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
5.提交這次要push到遠端的code&lt;br /&gt;
git commit -m &quot;add aaa file&quot;&lt;br /&gt;
-m 後面接的是這次commit的註解，可長可短，以你的夥伴看得懂為原則，一定要加！&lt;br /&gt;
若要搭配-a使用，則要下&lt;br /&gt;
git commit -am &quot;add aaa file&quot;&lt;br /&gt;
&lt;br /&gt;
下完commit後，git 會在console上印出一些資訊，大致上是有哪幾份檔案被更動過、新增、刪除了幾行code&lt;br /&gt;
6. git push&lt;br /&gt;
基本上，這樣就完成你這次的提交了。git同樣會印出一些這次push的資料。&lt;br /&gt;
不過，假如你的同伴在你修改檔案時有push新的code到remote repository，這時候就需要merge你們各自的新code，git會要求你先pull你同伴的新code。&lt;br /&gt;
git pull後，運氣好的話，git會自動merge你們的新code；運氣不好時（通常是有對同一份檔案進行刪改），就會出現conflict的情形，需要手動解決conflict以merge檔案。&lt;br /&gt;
如何解決conflict超出本文討論範圍，請自行google。&lt;br /&gt;
&lt;br /&gt;
ps,&lt;br /&gt;
git status只是列出目前的狀態，非commit時必要的指令，若很確定自己的狀態，可以略過。</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/8383985430081306407/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2012/08/git-commit.html#comment-form' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8383985430081306407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8383985430081306407'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2012/08/git-commit.html' title='git commit 流程 極簡易教學'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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/AVvXsEjLvKVBTIGPhAVUSDSXHoCS9gNV7f9PM0syPwBICT7rW_1ewKXP2ZkT0A-TM-kkyFDCnbrIxJnHHxYgYaAa1_xTM_Y4zj9RYx72omjKvmjD5KUE0Qw3SgotTIENCw9ghMqcC3dvm3CzQwI/s72-c/Screen+Shot+2012-08-26+at+4.33.57+PM.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8294609939460569030.post-7853497335405505615</id><published>2012-05-04T00:16:00.000-07:00</published><updated>2012-05-04T00:18:25.886-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>用 jquery 實做 更多/減少 文字</title><content type='html'>本文主要參考&lt;a href=&quot;http://shakenandstirredweb.com/240/jquery-moreless-text&quot;&gt;jQuery More/Less Text&lt;/a&gt;一文。

首先，請在html中增加下列 elements&lt;br /&gt;
&amp;nbsp;&amp;lt;div class=\&quot;more-less\&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;lt;div class=\&quot;more-block\&quot; &amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;lt;a href=\&quot;#\&quot; class=\&quot;adjust\&quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;
接著是 js:&lt;br /&gt;
&lt;pre class=&quot;brush: js&quot;&gt;  $(function(){                                                                   
                                                                                
// The height of the content block when it&#39;s not expanded                       
var adjustheight = 52;                                                          
// The &quot;more&quot; link text                                                         
var moreText = &quot;+  More&quot;;                                                       
// The &quot;less&quot; link text                                                         
var lessText = &quot;- Less&quot;;                                                        
                                                                                
// Sets the .more-block div to the specified height and hides any content that overflows
$(&quot;.more-less .more-block&quot;).css(&#39;height&#39;, adjustheight).css(&#39;overflow&#39;, &#39;hidden&#39;);
                                                                                
// The section added to the bottom of the &quot;more-less&quot; div                       
//$(&quot;.more-less&quot;).append(&quot;[...]&quot;);                                              
// Set the &quot;More&quot; text                                                          
$(&quot;a.adjust&quot;).text(moreText);                                                   
                                                                                
$(&quot;.adjust&quot;).toggle(function() {                                                
        $(this).parents(&quot;div:first&quot;).find(&quot;.more-block&quot;).css(&#39;height&#39;, &#39;auto&#39;).css(&#39;overflow&#39;, &#39;visible&#39;);
        // Hide the [...] when expanded                                         
        //$(this).parents(&quot;div:first&quot;).find(&quot;p.continued&quot;).css(&#39;display&#39;, &#39;none&#39;);
        $(this).text(lessText);                                                 
    }, function() {                                                             
        $(this).parents(&quot;div:first&quot;).find(&quot;.more-block&quot;).css(&#39;height&#39;, adjustheight).css(&#39;overflow&#39;, &#39;hidden&#39;);
        //$(this).parents(&quot;div:first&quot;).find(&quot;p.continued&quot;).css(&#39;display&#39;, &#39;block&#39;);
        $(this).text(moreText);                                                 
});                                                                             
});      &amp;nbsp;&lt;/pre&gt;


其中14,21,25是原文中用來增加 [...] 字串的。
我自己覺得不需要，所以註解掉了。</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/7853497335405505615/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2012/05/jquery.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/7853497335405505615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/7853497335405505615'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2012/05/jquery.html' title='用 jquery 實做 更多/減少 文字'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-6370519572642982872</id><published>2012-02-14T01:15:00.001-08:00</published><updated>2012-02-14T01:15:21.815-08:00</updated><title type='text'>讀取下一頁或ajax局部更新時以jquery顯示 loading 訊息</title><content type='html'>不論是使用ajax局部更新或整頁換新，假如loading時間過長，都容易讓user以為網站掛點了。
&lt;br /&gt;
使用&lt;a href=&quot;http://jquery.malsup.com/block/#demos&quot;&gt;blockUI&lt;/a&gt;這個jquery pulgin可以在讀取時顯示相關資訊，讓user知道正在讀取資料（其實&lt;a href=&quot;http://www.designyourway.net/blog/resources/30-efficient-jquery-lightbox-plugins/&quot;&gt;類似的jquery plug in&lt;/a&gt;很多，但我只用過這個，也覺得blockUI使用簡單且功能夠強）&lt;br /&gt;
首先當然要在 html 的 head 中讀入 jquery 及這個plugin，此處不贅敘。（注意！要把jquery放在前面plugin放後面，否則會有bug導致無法執行。）&lt;br /&gt;
假設是要整頁換新，可以將負責換新的那個DOM設個id（此處為block），然後使用以下code，就可以在點擊該DOM後，以iphone的形式顯示「please wait」的資訊，直到下一頁出現。&lt;br /&gt;
&lt;pre class=&quot;brush: js&quot;&gt;            $(&#39;#block&#39;).click(function(){
                 $.blockUI({ css: { 
                            border: &#39;none&#39;, 
                            padding: &#39;15px&#39;, 
                            backgroundColor: &#39;#000&#39;, 
                            &#39;-webkit-border-radius&#39;: &#39;10px&#39;, 
                            &#39;-moz-border-radius&#39;: &#39;10px&#39;, 
                            opacity: .5, 
                            color: &#39;#fff&#39; 
                        } }); 
            });
&lt;/pre&gt;
blockUI的官網有很多DEMO和sample code，可以挑自己喜歡的套用。</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/6370519572642982872/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2012/02/ajaxjquery-loading.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6370519572642982872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6370519572642982872'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2012/02/ajaxjquery-loading.html' title='讀取下一頁或ajax局部更新時以jquery顯示 loading 訊息'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-1821310378020680106</id><published>2011-12-15T00:18:00.000-08:00</published><updated>2011-12-15T00:18:57.801-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><title type='text'>檢視 ruby 和 python 的變數型態</title><content type='html'>ruby和python這兩個script language分別有內建的函式可以讀取變數的型態，只是用法不太一樣。&lt;br /&gt;
&lt;br /&gt;
自己常常搞混，特此紀錄一下：&lt;br /&gt;
&lt;pre class=&quot;brush: py&quot;&gt;#python
s=&#39;ww&#39;
type(s)
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;#ruby
s=&#39;qq&#39;
s.type()
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/1821310378020680106/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/12/ruby-python.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/1821310378020680106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/1821310378020680106'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/12/ruby-python.html' title='檢視 ruby 和 python 的變數型態'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-6280035489554763101</id><published>2011-11-30T03:47:00.000-08:00</published><updated>2011-11-30T05:46:14.036-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><title type='text'>將ruby script編譯成exe檔</title><content type='html'>網路上有幾個將ruby script編譯成windows可執行的exe檔的工具，常見的包括exerb、rubyscript2exe，可是我自己實際使用，這兩個工具都有一些難解的bug，用了一下就放棄了。&lt;br /&gt;
&lt;div&gt;
最後找到ocra這個工具，它其實也有bug，但很好解決。&lt;/div&gt;
&lt;div&gt;
首先，請在command line用gem安裝ocra（我是用linux系統，windows下指令可能會有點不一樣，但應該大同小異，請自己變通）&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;gem install ocra
&lt;/pre&gt;
接著，用ocra compile你的.rb檔&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;ocra example.rb
&lt;/pre&gt;
第一次使用時，可能會產生下列錯誤（因為我已經解決下列錯誤，所以以下訊息是google來的）&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;Invalid gemspec in [c:/Ruby187/lib/ruby/gems/1.8/specifications/ocra-1.3.0.gemspec]: invalid date format in specification: &quot;2011-06-19 00:00:00.000000000Z &quot;
Invalid gemspec in [c:/Ruby187/lib/ruby/gems/1.8/specifications/win32-autogui-0.5.0.gemspec]: invalid date format in specification: &quot;2011-08-17 00:00:00.000000000Z&quot; 1.8.8
&lt;/pre&gt;
循著錯誤訊息的路徑（&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; white-space: pre;&quot;&gt;c:/Ruby187/lib/ruby/gems/1.8/specifications/）&lt;/span&gt;找到「ocra-1.3.0.gemspec」這分檔案後，把&quot;2011-06-19 00:00:00.000000000Z&quot;改成&quot;2011-06-19&quot;即可。&lt;br /&gt;
第二個錯誤訊息我自己其實沒碰到，是google時發現別人有這個問題。不過依法修改它的date format應該就沒問題了。&lt;br /&gt;
&lt;br /&gt;
接著，重新執行第二個指令，應該就會產生一份example.exe&lt;br /&gt;
這份.exe檔在沒有安裝ruby的windows上也可以執行。&lt;br /&gt;
&lt;br /&gt;
ps, 我用的ruby是1.8.7&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px; line-height: 20px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/6280035489554763101/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/ruby-scriptexe.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6280035489554763101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6280035489554763101'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/ruby-scriptexe.html' title='將ruby script編譯成exe檔'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-7146164878142031546</id><published>2011-11-25T01:18:00.000-08:00</published><updated>2011-11-25T01:29:33.810-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="html"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>讓html中的元素隨著捲軸移動</title><content type='html'>如題，這個功能在比較動態的網頁應該都很常用，以前要用長的可怕的js code才有辦法達成，現在用jquery，幾行code就輕鬆搞定&lt;br /&gt;
當然，要使用這個功能，務必在html的head中讀入jquery，此處不贅言，直接切入script&lt;br /&gt;
以下code主要參考&lt;a href=&quot;http://www.wduffy.co.uk/blog/keep-element-in-view-while-scrolling-using-jquery/&quot;&gt;Keep element in view while scrolling using jQuery&lt;/a&gt;這篇文章&lt;br /&gt;
&lt;pre class=&quot;brush: js&quot;&gt; $().ready(function() {  
  var $scrollingDiv = $(&quot;#scrollingDiv&quot;); // #scrollingDiv請改成自己要移動的元素
 
  $(window).scroll(function(){ 
   $scrollingDiv
    .stop()
    .animate({&quot;marginTop&quot;: ($(window).scrollTop() + 30) + &quot;px&quot;}, &quot;slow&quot; );   
  });
 });
&lt;/pre&gt;
&lt;br /&gt;
有幾行值得特別說明&lt;br /&gt;
2.因為捲軸一移動，就會用到這個function，假如直接把這個DOM選取的動作存成一個jquery object，可以省去每次都尋找element的運算，效率會比較好&lt;br /&gt;
6.捲軸轉動的幅度可能很大，在第7行調整元素位置前，要先確保上個動作停止&lt;br /&gt;
7.animate是jquery內建調整css的函式；scrollTop是計算捲軸位置的函式。此處讓選取到的div的top margin隨著捲軸位置增加30px，即可確保這個div永遠距離頁面頂端30px</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/7146164878142031546/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/html.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/7146164878142031546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/7146164878142031546'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/html.html' title='讓html中的元素隨著捲軸移動'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-6105409579276214468</id><published>2011-11-23T07:04:00.000-08:00</published><updated>2011-11-23T07:04:10.834-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="html"/><title type='text'>取消iframe的scroll bar</title><content type='html'>在iframe的tag中加上scrolling=&quot;no&quot;這個attribute即可&lt;br /&gt;
簡潔有力！</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/6105409579276214468/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/iframescroll-bar.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6105409579276214468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/6105409579276214468'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/iframescroll-bar.html' title='取消iframe的scroll bar'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-8839468181582612016</id><published>2011-11-22T21:55:00.001-08:00</published><updated>2011-11-22T22:00:07.611-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="other"/><title type='text'>js計算某字元出現的次數</title><content type='html'>假設有個字串

s=&quot;abbbbc&quot;

我們要用js計算這個字串中b出現了幾次，可以用

s.split(&quot;b&quot;).length-1

其他語言也大同小異</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/8839468181582612016/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/js.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8839468181582612016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8839468181582612016'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/js.html' title='js計算某字元出現的次數'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-1856695657556897042</id><published>2011-11-15T02:10:00.000-08:00</published><updated>2011-11-15T02:22:29.093-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="html"/><category scheme="http://www.blogger.com/atom/ns#" term="RoR"/><title type='text'>在RoR架構上自動導入手機版網頁</title><content type='html'>行動裝置的成長趨勢有目共睹，針對螢幕較小的行動裝置設計版型也因而變成重要學問。&lt;br /&gt;
&lt;br /&gt;
一般做行動裝置版的網頁有三種方法：&lt;br /&gt;
1. 直接做兩套系統，偵測到user是用行動裝置連上網頁時，自動轉址到行動裝置系統的url&lt;br /&gt;
2. 同一套系統，但提供不同的url和html，行動裝置登入時轉址到該url。&lt;br /&gt;
3. 同一套系統，但做兩套css，使用者用行動裝置進入時，套用行動裝置版的css&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
這篇文章針對RoR架構，討論第二種方法的實做方式。&lt;br /&gt;
&lt;br /&gt;
一、&lt;br /&gt;
設計行動版網頁url時，在網域前加上「m」（mobile）算是很常見的習慣，例如m.facebook.com&lt;br /&gt;
但使用免費的平台，例如heroku，不太可能這樣做&lt;br /&gt;
所以這邊設定的網址是在主網址後加上m，例如ptttranspost.heroku.com/m&lt;br /&gt;
&lt;br /&gt;
假設user用電腦登入時的頁面，對應的controller是「home」，那我們就在app/views/home下新增&quot;m.html.erb&quot;。&lt;br /&gt;
接著，請到config/routes.rb 新增路徑&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;match &#39;m&#39; =&amp;gt; &#39;home#m&#39;
&lt;/pre&gt;
&lt;br /&gt;
二、&lt;br /&gt;
編輯app/controllers/home_controller.rb&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;class HomeController &amp;lt; ApplicationController
        layout &#39;application&#39;, :except =&amp;gt;&quot;m&quot; #avoid applying layout config to m.html.erb 
    def index
        platform=request.env[&quot;HTTP_USER_AGENT&quot;] #get user agent to check users&#39; platform
        if /android/i =~ platform or /iPhone/i =~ platform #if users&#39; platforms are phones, redirect it
            redirect_to m_path
        end 
    end 

    def m
    end 
end
&lt;/pre&gt;
第二行的用意是防止layouts/application.html.erb 裡的設定干擾行動版網頁&lt;br /&gt;
假如也要將layouts的設定套用到行動版網頁，則不用加上這行，甚至也不用做第一步驟和新增一個「m」action，因為上述兩動作都是為了避免m.html.erb被layouts影響而做。
不考慮會被layouts影響的話，第六行直接「render &quot;m.html.erb&quot;」即可&lt;br /&gt;
&lt;br /&gt;
ps.應該也可以針對行動版網頁設計layouts，不過我用不到，所以還沒研究&lt;br /&gt;
要這樣用的話，可以參考這個語法：&lt;br /&gt;
layout false, :only =&gt; :your_action_name 
&lt;br /&gt;
三、&lt;br /&gt;
編輯m.html.erb，將其編輯成想要的版型&lt;br /&gt;
剩下的就依此類推！&lt;br /&gt;
&lt;br /&gt;
研究了好一陣子，希望能幫上忙</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/1856695657556897042/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/ror.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/1856695657556897042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/1856695657556897042'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/ror.html' title='在RoR架構上自動導入手機版網頁'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-496560519692136840</id><published>2011-11-03T02:13:00.000-07:00</published><updated>2012-02-18T03:07:20.113-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="other"/><title type='text'>vimrc的好用設定</title><content type='html'>&lt;pre class=&quot;brush: rb&quot;&gt;set number  &quot;顯示行數&quot;
set autoindent  &quot;自動縮排&quot;
set shiftwidth=4  &quot;使用&#39;&amp;gt;&#39;或&#39;&amp;lt;&#39;調整縮排時，一次調4格&quot;
set tabstop=4  &quot;讓每個tab空4格，而非預設的8格&quot;

autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab
&quot;假如檔案為.py檔，則讓tab=空白。因為python視tab和space為不同的東西，這個設定可以避免不必要的困擾&quot;

syntax on  &quot;依檔案副檔名顯示色碼&quot;
filetype on
filetype plugin on  &quot;開啟plug in&quot;

nnoremap &amp;lt;c-n&amp;gt; :NERDTree &amp;lt;cr&amp;gt;  &quot;以ctrl+n開啟NERDTree這個plugin&quot;

nmap &amp;lt;silent&amp;gt; &amp;lt;c-l&amp;gt; :tabnext&amp;lt;cr&amp;gt;  &quot;以ctrl+l 切到下一個vim tab&quot;
nmap &amp;lt;silent&amp;gt; &amp;lt;c-k&amp;gt; :tabprev&amp;lt;cr&amp;gt;  &quot;以ctrl+k 切到上一個vim tab&quot;

&lt;/pre&gt;
以上中文解說皆是註解，可以直接複製貼上到.vimrc中</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/496560519692136840/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/11/vimrc.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/496560519692136840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/496560519692136840'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/11/vimrc.html' title='vimrc的好用設定'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-4698619662304681627</id><published>2011-10-19T09:11:00.000-07:00</published><updated>2013-11-06T20:00:10.261-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="html"/><title type='text'>讓div並排</title><content type='html'>div大概是當今html最常用的element，不過div會換行的特性也常常造成排版的困擾。要解決這個問題讓div並排有不少方法，一般最常見的是用float這個attribute：&lt;br /&gt;
&amp;lt;div id=&quot;1&quot; style=&quot;float:left;&quot;&amp;gt;aaa&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div id=&quot;2&quot; style=&quot;float:left;&quot;&amp;gt;bbb&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
需要特別注意的是，如果把position設成absolute，這招就沒用了，詳見&lt;a href=&quot;http://stackoverflow.com/questions/11333624/css-float-right-and-position-absolute-doesnt-work-together&quot;&gt;這串討論&lt;/a&gt;。&lt;br /&gt;
&lt;br /&gt;
關於&lt;a href=&quot;http://www.hsiu28.net/style/style_8.php&quot;&gt;float&lt;/a&gt;：&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-text-size-adjust: none; background-color: #efefef; font-family: tahoma, verdana, arial, 細明體, sans-serif; font-size: 11px; letter-spacing: 1px; line-height: 20px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul class=&quot;css_property&quot; style=&quot;-webkit-text-size-adjust: none; list-style-type: none; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;li class=&quot;txtgreen&quot; style=&quot;-webkit-text-size-adjust: none; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; color: #91ad3a;&quot;&gt;設定標籤元素與文字間的相對位置&lt;strong style=&quot;-webkit-text-size-adjust: none;&quot;&gt;float&lt;/strong&gt;屬性 ：&lt;/li&gt;
&lt;li style=&quot;-webkit-text-size-adjust: none; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px;&quot;&gt;float : right; /*標籤元素向右靠.文字圍繞在左邊*/&lt;/li&gt;
&lt;li style=&quot;-webkit-text-size-adjust: none; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px;&quot;&gt;float : left; /*標籤元素向左靠.文字圍繞在右邊*/&lt;/li&gt;
&lt;li style=&quot;-webkit-text-size-adjust: none; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px;&quot;&gt;float : none; /*以預設位置顯示*/&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/4698619662304681627/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/div.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/4698619662304681627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/4698619662304681627'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/div.html' title='讓div並排'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-3149069804594112353</id><published>2011-10-14T04:33:00.000-07:00</published><updated>2011-10-14T23:32:26.620-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>打亂javascript</title><content type='html'>因為各種不同的考量，有時候會希望別人看不到自己網頁上的javascript&lt;br /&gt;
目前並沒有任何方法可以防止他人看到你的js code&lt;br /&gt;
但是可以打亂你的code，在不影響code正常運作的前提下，讓別人無法肉眼辨識你在寫什麼&lt;br /&gt;
以下網頁提供這樣的功能：&lt;br /&gt;
&lt;a href=&quot;http://dean.edwards.name/packer/&quot;&gt;http://dean.edwards.name/packer/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://javascriptcompressor.com/&quot;&gt;http://javascriptcompressor.com/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/3149069804594112353/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/javascript.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/3149069804594112353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/3149069804594112353'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/javascript.html' title='打亂javascript'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-4806103666602458765</id><published>2011-10-13T06:54:00.000-07:00</published><updated>2011-10-14T05:07:00.314-07:00</updated><title type='text'>終端機的編碼方式會影響檔案的讀取</title><content type='html'>今天發現我用vim開某些檔案時，會陷入像是bug的情境，無法正常顯示、編輯該檔案&lt;br /&gt;
在terminal中下&quot;cat&quot;指令讀這些檔案，也不會顯示任何東西。更怪的是，這些code還是可以正常執行！&lt;br /&gt;
困擾好一陣子，終於得知是編碼問題：&lt;br /&gt;
有這些問題的檔案，裡面都有用utf8編碼的中文，可是我昨天為了一些原因，把我的終端機編碼方式改為big5，因此產生這個問題。&lt;br /&gt;
改回utf8就ok了</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/4806103666602458765/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/4806103666602458765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/4806103666602458765'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/blog-post.html' title='終端機的編碼方式會影響檔案的讀取'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-5066668790858465042</id><published>2011-10-12T05:40:00.001-07:00</published><updated>2022-08-27T23:34:32.878-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="other"/><title type='text'>用SyntaxHighlighter在blogger上貼美麗的code</title><content type='html'>研究了一個下午，終於研究出解法，特此和大家分享：&lt;br /&gt;
&lt;br /&gt;
1.&lt;br /&gt;
至&lt;a href=&quot;http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html&quot;&gt;SyntaxHighlighter官網&lt;/a&gt;下載他的source，並把自己需要的部分上傳到自己的空間&lt;br /&gt;
&lt;br /&gt;
其中shCore.js、shCore.css、shThemeDefault.css三份檔案是必備的&lt;br /&gt;
其他的則是看自己需求做選擇&lt;br /&gt;
&lt;br /&gt;
噹噹！這步是讓我困擾最久的，因為我一開始不知道要上傳到哪....&lt;br /&gt;
不過我現在已經上傳到學校提供的空間，後文會分享連結&lt;br /&gt;
&lt;br /&gt;
2.&lt;br /&gt;
修改blogger的html檔，在head標籤中貼上&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&amp;lt;link href=&#39;http://homepage.ntu.edu.tw/~b97103021/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/link&amp;gt; &amp;lt;href=&#39;http://homepage.ntu.edu.tw/~b97103021/shThemeDefault.css&#39;rel=&#39;stylesheet&#39;type=&#39;text/css&#39;&amp;gt;&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shCore.js&#39;/&amp;gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
以上三者為必備&lt;br /&gt;
&lt;br /&gt;
以下為選擇性&lt;br /&gt;
使用css&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shBrushCss.js&#39;/&amp;gt;&lt;br /&gt;
使用javascript&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shBrushJScript.js&#39;/&amp;gt;&lt;br /&gt;
使用python&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shBrushPython.js&#39;/&amp;gt;&lt;br /&gt;
使用ruby&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shBrushRuby.js&#39;/&amp;gt;&lt;br /&gt;
使用java&lt;br /&gt;
&amp;lt;script language=&#39;javascript&#39; src=&#39;http://homepage.ntu.edu.tw/~b97103021/shBrushJava.js&#39;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
因為我自己通常只會用到上述5種，所以只有上傳這5種到我的空間上&lt;br /&gt;
見者有份，歡迎直接取用；若有自己的空間，則把src改為自己的link&lt;br /&gt;
&lt;br /&gt;
4.&lt;br /&gt;
在同一份html檔的body tag中，記得要call SyntaxHighlighter.all() 這個function&lt;br /&gt;
例如&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
SyntaxHighlighter.all()&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5.&lt;br /&gt;
之後寫文章時，就可以用&lt;br /&gt;&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #b2aca2; font-family: Consolas, Monaco, monospace; font-size: 13.3333px; white-space: pre;&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot; style=&quot;color: #dfdcd7;&quot;&gt;pre&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #b2aca2; font-family: Consolas, Monaco, monospace; font-size: 13.3333px; white-space: pre;&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot; style=&quot;color: #dfdcd7;&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #ff6d6d;&quot;&gt;&quot;language-html&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;div&gt;&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #b2aca2; font-family: Consolas, Monaco, monospace; font-size: 13.3333px; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #440000;&quot;&gt;//code&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #b2aca2; font-family: Consolas, Monaco, monospace; font-size: 13.3333px; white-space: pre;&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot; style=&quot;color: #dfdcd7;&quot;&gt;code&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #b2aca2; font-family: Consolas, Monaco, monospace; font-size: 13.3333px; white-space: pre;&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot; style=&quot;color: #dfdcd7;&quot;&gt;pre&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;
或&lt;br /&gt;
&amp;lt;pre class=&quot;brush: rb&quot;&amp;gt;&lt;br /&gt;
#your code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
之類的語法貼code，如此一來code就會被上色，且會顯示行數&lt;br /&gt;
&lt;br /&gt;
以上的code依序會顯示&lt;br /&gt;
&lt;pre class=&quot;brush: js&quot;&gt;//your code
&lt;/pre&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;#your code
&lt;/pre&gt;
&lt;br /&gt;
另外，blogger目前似乎不支援跳脫html字元的功能（有選項，但似乎沒用）&lt;br /&gt;
想要顯示html的tag時，分別要用跳脫字元 &amp;amp; l t  和 &amp;amp; g t取代&amp;lt;和&amp;gt; （我為了正確顯示，所以中間加了空白，使用時不需空白）&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/5066668790858465042/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/syntaxhighlighterbloggercode.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/5066668790858465042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/5066668790858465042'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/syntaxhighlighterbloggercode.html' title='用SyntaxHighlighter在blogger上貼美麗的code'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-8907214396446533385</id><published>2011-10-12T02:01:00.000-07:00</published><updated>2011-10-12T05:16:08.702-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>利用javascript把form的內容儲存在cookie中</title><content type='html'>有時候user會需要不斷重填某份表單，但這份表單中有些內容是不需重填的，這時候就會希望把不需重填的部份存到cookie，並且在user每次進入網頁時自動讀取，以減少user使用上的麻煩。&lt;br /&gt;
我們可以用jquery達到這個目標：&lt;br /&gt;
&lt;pre class=&quot;brush: js&quot;&gt;function remember( selector ){
    $(selector).each(
        function(){
            //if this item has been cookied, restore it
            var name = $(this).attr(&#39;name&#39;);
            if( $.cookie( name ) ){
                    $(this).val( $.cookie(name) );
            }
            //assign a change function to the item to cookie it
            $(this).change(
                function(){
                        $.cookie(name, $(this).val(), { path: &#39;/&#39;, expires: 6 });
                }
            );
        }
    );
}
$(document).ready(
    function(){
        if($.cookie(&#39;host&#39;)==&#39;ptt2&#39;)
            $(&quot;#host_ptt2&quot;).attr(&quot;checked&quot;,&quot;checked&quot;);
        else
            $(&quot;#host_ptt&quot;).attr(&quot;checked&quot;,&quot;checked&quot;);
        remember(&#39;[name=ptt_ID]&#39;);
        remember(&#39;[name=aid]&#39;);
        remember(&#39;[name=board]&#39;);
    }
);
&lt;/pre&gt;本文未完成，有待補完</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/8907214396446533385/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/javascriptformcookie.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8907214396446533385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/8907214396446533385'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/javascriptformcookie.html' title='利用javascript把form的內容儲存在cookie中'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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-8294609939460569030.post-2495746447005682531</id><published>2011-10-12T00:23:00.000-07:00</published><updated>2011-10-12T05:46:03.753-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="RoR"/><title type='text'>更改rails server的port</title><content type='html'>要在啟動rails內建server時更改port（預設為3000），可以在terminal中輸入以下語法&lt;br /&gt;
&lt;pre class=&quot;brush: rb&quot;&gt;rails server -p xxxx #xxxx為想要的port
rails s -p xxxx #亦可用縮寫s取代server
&lt;/pre&gt;如此一來，就可以同時測試不同版本的project！</content><link rel='replies' type='application/atom+xml' href='http://techjotting.blogspot.com/feeds/2495746447005682531/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://techjotting.blogspot.com/2011/10/rails-serverport.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/2495746447005682531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8294609939460569030/posts/default/2495746447005682531'/><link rel='alternate' type='text/html' href='http://techjotting.blogspot.com/2011/10/rails-serverport.html' title='更改rails server的port'/><author><name>Brian</name><uri>http://www.blogger.com/profile/13098204986407759200</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>