<?xml version="1.0" encoding="utf-8"?>

<feed xmlns="http://www.w3.org/2005/Atom">
 <title>GitHub Rebase</title>
 <link href="http://tech.manic.tw/atom.xml" rel="self"/>
 <link href="http://tech.manic.tw/"/>
 <updated>2012-02-22T01:32:29-08:00</updated>
 <id>http://tech.manic.tw/</id>
 <author>
   <name>Manic</name>
   <email>maniclf@gmail.com</email>
 </author>
 
 <entry>
   <title>Apache with Unicorn(Debian, Ubuntu, Rails)</title>
   <link href="http://tech.manic.tw/2012/02/22/Apache-with-Unicorn.html"/>
   <updated>2012-02-22T17:20:00-08:00</updated>
   <id>http://tech.manic.tw/2012/02/22/Apache-with-Unicorn</id>
   <content type="html">&lt;p&gt;在參考&lt;a href=&quot;https://github.com/teambox/teambox/wiki/Installing-on-Ubuntu-using-Apache-and-Unicorn&quot;&gt;Installing on Ubuntu using Apache and Unicorn&lt;/a&gt;這篇文章後，試著在自家的 Server 這麼做，卻沒辦法成功。於是花了點時間修正這個 script.&lt;/p&gt;

&lt;h3&gt;Step 1&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod rewrite
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Restart Apache&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 restart
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Step 2&lt;/h3&gt;

&lt;p&gt;Install unicorn (maybe you can specify it in Gemfile)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install unicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Step 3&lt;/h3&gt;

&lt;p&gt;Start your unicorn server of your project, I use 2007 port instead 8080&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;listen 2007 # by default Unicorn listens on port 8080, I use 2007 here.
worker_processes 4 # this should be &amp;gt;= nr_cpus
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Step 4&lt;/h3&gt;

&lt;p&gt;The most important part in this post.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;

  ServerName example.org
  DocumentRoot /dir/of/your/project

  RewriteEngine On

  # Redirect all non-static requests to unicorn
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]

  &amp;lt;Proxy balancer://unicornservers&amp;gt;
    BalancerMember http://127.0.0.1:2007
  &amp;lt;/Proxy&amp;gt;

&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Important&lt;/em&gt;: Dont use &lt;code&gt;ProxyPass / balancer://unicornservers/&lt;/code&gt;, it will override rewrite rule.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>[工具]快速解決 “invalid multibyte char (US-ASCII)” Error (magic_encoding)</title>
   <link href="http://tech.manic.tw/2012/02/21/Magic-Encoding-Gem.html"/>
   <updated>2012-02-21T11:28:00-08:00</updated>
   <id>http://tech.manic.tw/2012/02/21/Magic-Encoding-Gem</id>
   <content type="html">&lt;p&gt;在 ruby 1.9.x 系列，最常遇到的問題就是忘了補上 &lt;code&gt;# -*- encoding : utf-8 -*-&lt;/code&gt; 導致 error
用 magic_encoding 這個 gem 可以快速解決這個問題&lt;/p&gt;

&lt;h3&gt;Install&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;gem install magic_encoding
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Usage&lt;/h3&gt;

&lt;p&gt;在 Rails 專案底下&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;magic_encoding
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;就這樣，非常簡單&lt;/p&gt;

&lt;h3&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/m-ryan/magic_encoding&quot;&gt;Github:magic_encoding&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Proxy settings in various RC files</title>
   <link href="http://tech.manic.tw/2012/02/08/Proxy-Settings-In-Various-Rc-Files.html"/>
   <updated>2012-02-08T16:20:00-08:00</updated>
   <id>http://tech.manic.tw/2012/02/08/Proxy-Settings-In-Various-Rc-Files</id>
   <content type="html">&lt;p&gt;為了要讓一台在防火牆內的機器能夠成功安裝 rvm 與 gem，奮鬥後的結果。&lt;/p&gt;

&lt;p&gt;主要的問題在於有時候你不知道會出問題是因為 proxy 的原因，所以最好的方法是將你想得到的 rc 檔都加上 proxy 設定(如果有的話)&lt;/p&gt;

&lt;h3&gt;gemrc&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;gem: --http-proxy http://proxy.example.org:8080
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
http-proxy: &quot;http://proxy.example.org:8080&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;curlrc&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;proxy = proxy.example.org:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;wgetrc&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;http_proxy = http://proxy.example.org:8080
use_proxy = on
wait = 15
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;cshrc&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;setenv http_proxy 'http://proxy.example.org:8080'
setenv HTTP_proxy 'http://proxy.example.org:8080'
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;bashrc&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;export http_proxy=&quot;http://proxy.example.org:8080/'
&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>安裝 Heroku Plugin: heroku-accounts</title>
   <link href="http://tech.manic.tw/2011/11/04/Heroku-Plugin-Heroku-accounts.html"/>
   <updated>2011-11-04T15:20:00-07:00</updated>
   <id>http://tech.manic.tw/2011/11/04/Heroku-Plugin-Heroku-accounts</id>
   <content type="html">&lt;p&gt;現在公司也開始使用 &lt;a href=&quot;http://www.heroku.com/&quot;&gt;Heroku&lt;/a&gt; 為 hosting service 的工具， &lt;br/&gt;
因為自己也有在使用 Heroku 的服務， &lt;br/&gt;
於是切換 heroku account setting 就變得是一件擾人的事。&lt;/p&gt;

&lt;p&gt;這時候就是 &lt;a href=&quot;https://github.com/ddollar/heroku-accounts&quot;&gt;heroku-accounts&lt;/a&gt; 這個 plugin 派上用場的時候了。&lt;/p&gt;

&lt;h3&gt;安裝，設定步驟&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;heroku plugins:install git://github.com/ddollar/heroku-accounts.git&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku accounts:add {自己的帳號} -auto&lt;/code&gt; #加上 auto 可以自動設定好 .ssh/config，自己的帳號部分可以自由決定，並非指自己在 Heroku 上的帳號。我這裡是使用 manic&lt;/li&gt;
&lt;li&gt;會出現 &lt;code&gt;Enter your Heroku credentials.&lt;/code&gt; 的提示訊息，輸入自己在 Heroku 上的帳號密碼&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku accounts:add work -auto&lt;/code&gt; #加上公司帳號的資訊，加完後你會有兩組帳號可以使用 (work 可以換成任何英數組合名稱)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku accounts:default {帳號}&lt;/code&gt; #設定預設使用的帳號&lt;/li&gt;
&lt;li&gt;(in heroku project path) &lt;code&gt;heroku accounts:set {帳號}&lt;/code&gt; 設定此 project 使用的 heroku 帳號&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;~/.ssh/config&lt;/h3&gt;

&lt;p&gt;在你使用了 &lt;code&gt;heroku accounts:set work&lt;/code&gt; 後，在你專案底下的 .git/config 檔裡會發現原本指向 heroku.com 的 repository url 變成了 &lt;code&gt;git@heroku.work:{repo}.git&lt;/code&gt;，這是告訴 heroku 說你是要用 work 這個帳號管理這個 repo&lt;/p&gt;

&lt;p&gt;而在 ~/.ssh/config 這個檔案裡會發現多了一段關於 heroku 的設定&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Host heroku.work
  HostName heroku.com
  IdentityFile /home/.ssh/identity.heroku.work
  IdentitiesOnly yes
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;這就是 heroku-accounts 使用的技巧。&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Heroku app 的一些注意事項</title>
   <link href="http://tech.manic.tw/2011/08/19/Heroku-apps-note.html"/>
   <updated>2011-08-19T10:52:00-07:00</updated>
   <id>http://tech.manic.tw/2011/08/19/Heroku-apps-note</id>
   <content type="html">&lt;h4&gt;Ruby 版本&lt;/h4&gt;

&lt;p&gt;現在 Heroku 建立 App 時預設是使用 Ruby 1.9.2 &lt;a href=&quot;http://devcenter.heroku.com/articles/bamboo&quot;&gt;http://devcenter.heroku.com/articles/bamboo&lt;/a&gt;
如果是像我這樣還在使用 REE 1.8.7 的話，就要在建立時指定好:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;heroku create --stack bamboo-ree-1.8.7
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;如果是已經建好 App 的話要改也是可以的:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;heroku stack:migrate bamboo-ree-1.8.7
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;Config&lt;/h4&gt;

&lt;p&gt;如果有用到像 Oauth 這種會需要 API key/password 的 gem, 那麼我們必須做好設定檔讓 Heroku App 正式上線時也能正常運作。&lt;br/&gt;
而因為安全上的顧慮，我們不應該在 repository 裡將&quot;密碼&quot;放入，當然包含你的 API 帳號密碼&lt;br/&gt;
Heroku 提供了 &lt;code&gt;heroku config:add #{KEY}:#{VALUE}&lt;/code&gt; 的指令讓你能夠設定帳號密碼，然後你可以用在程式碼裡用 ENV['KEY'] 的方式存取。&lt;/p&gt;

&lt;p&gt;參考：&lt;a href=&quot;http://devcenter.heroku.com/articles/config-vars&quot;&gt;http://devcenter.heroku.com/articles/config-vars&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;時區&lt;/h4&gt;

&lt;p&gt;這是最近發現的，可能算地雷。&lt;/p&gt;

&lt;p&gt;Heroku App 其實不會完全吃 &lt;code&gt;config.time_zone = 'Taipei'&lt;/code&gt; 這種時區指定，而是要用 &lt;code&gt;heroku config&lt;/code&gt; 來指定:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;heroku config:add TZ=Asia/Taipei
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;然後你的時間操作才會完全正常，不然會像我一樣 Time.zone 回傳 Taipei 但時區卻是在 -0700 的詭異情況&lt;/p&gt;

&lt;p&gt;參考: &lt;a href=&quot;http://stackoverflow.com/questions/2719330/heroku-time-zone-problem-logging-local-server-time&quot;&gt;http://stackoverflow.com/questions/2719330/heroku-time-zone-problem-logging-local-server-time&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Console&lt;/h4&gt;

&lt;p&gt;Heroku 同樣提供 console 介面: &lt;code&gt;heroku console&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;參考: &lt;a href=&quot;http://devcenter.heroku.com/articles/console&quot;&gt;http://devcenter.heroku.com/articles/console&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Backup&lt;/h4&gt;

&lt;p&gt;Heroku 同樣提供 backup addon，而且是免費的: &lt;code&gt;heroku addons:add pgbackups&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;參考: &lt;a href=&quot;http://devcenter.heroku.com/articles/pgbackups&quot;&gt;http://devcenter.heroku.com/articles/pgbackups&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;個人用 Heroku App initial script&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;heroku create --stack bamboo-ree-1.8.7
heroku config:add TZ=Asia/Taipei
heroku addons:add pgbackups
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;記一下免得下次又要重找。&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Github behind a proxy</title>
   <link href="http://tech.manic.tw/2011/07/15/Github-behind-a-proxy.html"/>
   <updated>2011-07-15T17:45:00-07:00</updated>
   <id>http://tech.manic.tw/2011/07/15/Github-behind-a-proxy</id>
   <content type="html">&lt;h3&gt;Environment&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Debian 6.0 (squeeze)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Install corkscrew&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get install corkscrew
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Add config in .ssh/config&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;Host github.com
  User git
  HostName ssh.github.com
  Port 443
  ProxyCommand corkscrew {proxy} {port} %h %p
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://petitesnouvelles.wordpress.com/2009/04/10/github-behind-a-proxy/&quot;&gt;http://petitesnouvelles.wordpress.com/2009/04/10/github-behind-a-proxy/&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Active Record: 取出特定欄位不重覆的資料</title>
   <link href="http://tech.manic.tw/2011/07/13/Active-Record%3A-Fetch-data-without-duplicate-field.html"/>
   <updated>2011-07-13T15:39:00-07:00</updated>
   <id>http://tech.manic.tw/2011/07/13/Active-Record:-Fetch-data-without-duplicate-field</id>
   <content type="html">&lt;p&gt;在翻程式碼的時候發現一段看起來怪怪的程式，研究了一下原本需求:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;在 notes 這個資料表中，取出最新 6 筆合法資料，其中 user 不得重覆
notes belongs_to user
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;在原本的設計裡，是寫了一個迴圈，先去找最新一筆合法 note 的 user 資料，然後再去 note 問&quot;不包含此 user 的最新一筆合法 note&quot;
這個解法覺得不夠漂亮，於是研究了一下怎麼處理。&lt;/p&gt;

&lt;p&gt;因為 user 要不重覆，所以很直覺得用 &lt;code&gt;group by user_id&lt;/code&gt; 來做，但 group by 後的資料會沒辦法取得最新一筆。
和同事討教後才發現可以搭配 SQL 的 MAX(column) 和 GROUP BY。
最後整理成兩個 SQL，再回頭用 Active Record 生出我想要的 query code.&lt;/p&gt;

&lt;p&gt;SQL 版本如下:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;sql&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;MAX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maximum_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_valid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;GROUP&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;ORDER&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maximum_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DESC&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;LIMIT&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(...);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Rails Code 如下:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;lineno&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:is_valid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;maximum_id DESC&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number_of_users&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maximum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;lineno&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Note&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;id DESC&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
 </entry>
 
 <entry>
   <title>jQuery UJS 範例: Simple Slideshow</title>
   <link href="http://tech.manic.tw/2011/05/27/jQuery-UJS-Example%3A-Simple-Slideshow.html"/>
   <updated>2011-05-27T13:16:44-07:00</updated>
   <id>http://tech.manic.tw/2011/05/27/jQuery-UJS-Example:-Simple-Slideshow</id>
   <content type="html">&lt;p&gt;原本程式碼&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;erb&quot;&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;div class=&amp;quot;box-text&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each_with_index&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  &amp;lt;div class=&amp;#39;grid &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;mydiary-event-&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;#39;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;link_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;img&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;160x100&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;link&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;h3&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;link_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;title&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;link&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;description&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;span&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;duration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;start_at&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;end_at&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  &amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  $(&amp;quot;#activity&amp;quot;).find(&amp;quot;.grid&amp;quot;).hide();&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  $(&amp;quot;#activity&amp;quot;).find(&amp;quot;.mydiary-event-1&amp;quot;).show();&lt;/span&gt;

&lt;span class=&quot;x&quot;&gt;  $(function(){&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    var event_num = 1;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    var event_total = &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    $(document).everyTime(&amp;quot;15s&amp;quot;, function(i) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      event_num = i % event_total + 1;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      $(&amp;quot;#activity&amp;quot;).find(&amp;quot;.grid&amp;quot;).hide();&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      $(&amp;quot;#activity&amp;quot;).find(&amp;quot;.mydiary-event-&amp;quot;+event_num).show();&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    });&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  });&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;可以看到這是一個客制化的特效，缺點是如果有別的 html block 要用同樣的特效，就得再為他寫上一段類似的程式碼。
於是參考 &lt;a href=&quot;https://github.com/rails/jquery-ujs&quot;&gt;jquery-ujs&lt;/a&gt; 的寫法來改寫。&lt;/p&gt;

&lt;p&gt;改寫之後的原程式碼分成兩部分, 原來的 erb 與 獨立的 js&lt;/p&gt;

&lt;p&gt;erb 區塊&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;erb&quot;&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;div class=&amp;quot;box-text&amp;quot; data-simple-slideshow=&amp;quot;true&amp;quot; data-second=&amp;quot;15&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;div class=&amp;quot;grid&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;link_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image_tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;img&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;160x100&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;link&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      &amp;lt;h3&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;link_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;title&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;link&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      &amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;description&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      &amp;lt;span&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;duration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;start_at&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;end_at&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;js 區塊(我是習慣放到 application.js)&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;js&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// simple-slideshow&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;div[data-simple-slideshow]&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;second&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$children&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;$children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hide&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;everyTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;everyTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;s&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;$children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hide&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;$children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;eq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</content>
 </entry>
 
 <entry>
   <title>如何在 Ubuntu 下安裝 solr search engine</title>
   <link href="http://tech.manic.tw/2011/05/03/How-to%3A-Install-Solr-on-Ubuntu.html"/>
   <updated>2011-05-03T14:50:00-07:00</updated>
   <id>http://tech.manic.tw/2011/05/03/How-to:-Install-Solr-on-Ubuntu</id>
   <content type="html">&lt;h3&gt;版本資訊&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu 11.04 (Natty)&lt;/li&gt;
&lt;li&gt;Solr 3.1&lt;/li&gt;
&lt;li&gt;JAVA (sun-java6)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Install JAVA&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sudo add-apt-repository &quot;deb http://archive.canonical.com/ natty partner&quot;
sudo apt-get update   
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Install Solr&lt;/h3&gt;

&lt;p&gt;Download from here: &lt;a href=&quot;http://www.apache.org/dyn/closer.cgi/lucene/solr&quot;&gt;http://www.apache.org/dyn/closer.cgi/lucene/solr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;在此為了方便介紹, 會以個人身份而非 root 身份來安裝, 請根據個人狀況來調整。&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir -p ~/solr
cd ~/solr
wget 'http://ftp.tc.edu.tw/pub/Apache//lucene/solr/3.1.0/apache-solr-3.1.0.tgz'
tar xvfz apache-solr-3.1.0.tgz
cd apache-solr-3.1.0/example
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;以下執行看要跑 single core 或是 multi core&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;java -jar start.jar #default single core
java -Dsolr.solr.home=multicore -jar start.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以參考 apache-solr-3.1.0/example/README.txt&lt;/p&gt;

&lt;p&gt;預設會跑在 http://localhost:8983&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>如何在 64 位元 Ubuntu 下安裝 Juniper Networks VPN Client</title>
   <link href="http://tech.manic.tw/2011/04/30/How-to%3A-Juniper-Networks-VPN-on-64-bit-Ubuntu.html"/>
   <updated>2011-04-30T00:00:00-07:00</updated>
   <id>http://tech.manic.tw/2011/04/30/How-to:-Juniper-Networks-VPN-on-64-bit-Ubuntu</id>
   <content type="html">&lt;p&gt;參考 &lt;a href=&quot;http://devinfee.com/blog/2011/03/22/how-to-juniper-networks-vpn-on-64-bit-ubuntu&quot;&gt;這邊&lt;/a&gt; 寫出來的心得&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;新增軟體來源&lt;/p&gt;

&lt;p&gt;增加 Canonical 的 'partner' 套件&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/1d676ab9f558c6b92ca25f78f6d093d7.png&quot; alt=&quot;軟體來源&quot; /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;執行 sudo apt-get install ia32-sun-java6-bin&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;到你的客戶端 Juniper Networks VPN site 進行登入&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;執行 Network Connect&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/873af0f1d27717f316275b02674de53f.png?v=1304151738&quot; alt=&quot;Network Connect&quot; /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;執行 4. 後會下載 ncLinuxApp.jar, 請允許他下載, 會放到 ~/.juniper_networks 底下，此時會有要求輸入密碼的要求。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;執行&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget http://mad-scientist.net/junipernc
chmod 755 junipernc
sudo cp junipernc ~/bin/
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;執行 junipernc 並輸入需要的資訊&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/0f7bd31a0640b9b15a91248aba1bedfe.png?v=1304152755&quot; alt=&quot;輸入你的 VPN Site Name&quot; /&gt;&lt;/p&gt;

&lt;p&gt;輸入你的VPN SITE NAME&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/6857ac41621de302adca439c46ae059e.png?v=1304152755&quot; alt=&quot;Account&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/b5585b7fb3b3a7b6883626427b08230e.png?v=1304152755&quot; alt=&quot;Realm&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/ca3e31bb39df878f4d8dbebfd75d5556.png?v=1304152755&quot; alt=&quot;Alert JAVA&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/53d63a34e8feb65a97a6b1a2d7a07e5f.png?v=1304152755&quot; alt=&quot;ia32-java-6-sun&quot; /&gt;&lt;/p&gt;

&lt;p&gt;請選擇 ia32-java-6-sun&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/75fcce2f4a675272afcdef5cf944acd6.png?v=1304152755&quot; alt=&quot;Password&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://pic.pimg.tw/manic/3803f1ee4da0b23f83a960603b55cf84.png?v=1304152755&quot; alt=&quot;OK&quot; /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
</feed>
