<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Idapted TechTeam</title>
	<atom:link href="http://developer.idapted.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://developer.idapted.com</link>
	<description></description>
	<lastBuildDate>Wed, 08 Sep 2010 09:25:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ajax_load improvement</title>
		<link>http://developer.idapted.com/2010/09/08/ajax_load-improvement/</link>
		<comments>http://developer.idapted.com/2010/09/08/ajax_load-improvement/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 08:24:30 +0000</pubDate>
		<dc:creator>guolei</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1042</guid>
		<description><![CDATA[Currently the ajax_load method is kind of messy. If there&#8217;s multiple ajax_load in one page, one can only send request when the previous request is finished. And there&#8217;s always one js error &#8220;doRequest_xx is not defined.&#8221; This is caused by the bad design of the first version. When I had lunch with @Blade this noon, [...]]]></description>
			<content:encoded><![CDATA[<p>Currently the ajax_load method is kind of messy. If there&#8217;s multiple ajax_load in one page, one can only send request when the previous request is finished. And there&#8217;s always one js error &#8220;doRequest_xx is not defined.&#8221;</p>
<p>This is caused by the bad design of the first version. When I had lunch with @Blade this noon, we got some new ideas. Here&#8217;s the refactored code.</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> ajax_load<span style="color:#006600; font-weight:bold;">&#40;</span>url, options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@ajax_counter</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>@ajax_counter <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; index = options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:index</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#0066ff; font-weight:bold;">@ajax_counter</span><br />
&nbsp; &nbsp; &nbsp; dom_id = <span style="color:#6666ff; font-weight:bold;">Idp::Util</span>.<span style="color:#9900CC;">uuid</span><br />
&nbsp; &nbsp; &nbsp; c = <span style="color:#996600;">&quot; &lt;script type='text/javascript'&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@ajax_counter</span> == <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; c <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; var xmlHttpQueue = [];<br />
&nbsp; &nbsp; &nbsp; &nbsp; var xmlHttpQueueWithIndex = [];<br />
&nbsp; &nbsp; &nbsp; &nbsp; function ajaxLoad(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(var i=0; i&lt; xmlHttpQueue.length; i++){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlHttpQueueWithIndex.sort()[i][1].send(null);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; function getXmlHttp(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xmlHttp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var optionID;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //generic code (www.w3schools.com (http://www.w3schools.com))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Firefox, Opera 8.0+, Safari<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlHttp=new XMLHttpRequest();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (e)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Internet Explorer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (e)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (e)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Your browser does not support AJAX!');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return xmlHttp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp; c <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; var xmlHttp = getXmlHttp();<br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlHttp.open('GET', '#{url}',true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlHttp.onreadystatechange=handleAjaxResponse_#{@ajax_counter};<br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlHttpQueue.push(xmlHttp);<br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlHttpQueueWithIndex.push([#{index}, xmlHttp]);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; function handleAjaxResponse_#{@ajax_counter}(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xmlHttp = xmlHttpQueue[#{@ajax_counter - 1}]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(xmlHttp.readyState == 4) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var dom = document.getElementById('#{dom_id}');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(xmlHttp.status == 200){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dom.innerHTML = xmlHttp.responseText;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dom.innerHTML = '#{t :load_error, :url=&gt;url}';<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;<br />
&nbsp; &nbsp; &nbsp; &quot;</span><br />
&nbsp; &nbsp; &nbsp; c <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&lt;</span>div id=<span style="color:#996600;">&quot;#{dom_id}&quot;</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;#{options[:class]}&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#008000; font-style:italic;">#{options[:show_loading]==false ? &quot;&quot; : idp_image_tag(&quot;loading.gif&quot;)}&lt;/div&gt;}</span><br />
&nbsp; &nbsp; &nbsp; c<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>After refactor ,all the requests are send at one time. And as there&#8217;s limited number of rails process, if you&#8217;d like one request to be sent earlier, you can identify &#8220;index&#8221;, like</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&lt;%</span>= ajax_load<span style="color:#006600; font-weight:bold;">&#40;</span>url, <span style="color:#ff3333; font-weight:bold;">:index</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></div></td></tr></tbody></table></div>
<p>The smaller the index is, the sooner it will be sent.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/09/08/ajax_load-improvement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Client HTTP Caching in Rails</title>
		<link>http://developer.idapted.com/2010/09/06/client-http-caching-in-rails/</link>
		<comments>http://developer.idapted.com/2010/09/06/client-http-caching-in-rails/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 08:48:36 +0000</pubDate>
		<dc:creator>blade</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Weekly Review]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1030</guid>
		<description><![CDATA[HTTP Cache is a browser Cache. HTTP is typically used for distributed information systems, where performance can be improved by the use of response caches. This kind of cache used for reduce request times and bandwidth. more info. Let&#8217;s talk about its principle. The Browser start a request. When request reach Web Server. the web [...]]]></description>
			<content:encoded><![CDATA[<p>HTTP Cache is a browser Cache.<br />
HTTP is typically used for distributed information systems, where performance can be improved by the use of response caches.<br />
This kind of cache used for reduce request times and bandwidth.<br />
<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html">more info.</a></p>
<p>Let&#8217;s talk about its principle.</p>
<p>The Browser start a request. When request reach Web Server. the web server will check the request head.<br />
if request head have description about cache-control and data have not modified. Web Server will return 304.<br />
the browser receive 304 will render the result last request.</p>
<p>In sales project. A student detail page use *ajax_load* split as multipart requests.<br />
I think every single ajax_load request can use HTTP Cache.</p>
<p>Before HTTP Cache Optimaztion:</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Firebug:<br />
GET http:<span style="color:#006600; font-weight:bold;">//</span>www.<span style="color:#9900CC;">veecue</span>.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>sales<span style="color:#006600; font-weight:bold;">/</span>students<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">60329</span><span style="color:#006600; font-weight:bold;">/</span>calls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006666;">200</span> OK&nbsp; &nbsp; &nbsp; 245ms &nbsp; <br />
<br />
Log:<br />
Processing <span style="color:#6666ff; font-weight:bold;">Student::CallsController</span><span style="color:#008000; font-style:italic;">#index (for 127.0.0.1 at 2010-09-06 16:35:13) [GET]</span><br />
&nbsp; Parameters: <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;student_id&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;60329&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; Student <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>1.3ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`students`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`students`</span>.<span style="color:#996600;">`id`</span> = <span style="color:#996600;">'60329'</span><span style="color:#006600; font-weight:bold;">&#41;</span> LIMIT <span style="color:#006666;">1</span><br />
&nbsp; Call <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>71.5ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> updated_at FROM <span style="color:#996600;">`calls`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`calls`</span>.<span style="color:#9900CC;">student_id</span> = <span style="color:#006666;">60329</span><span style="color:#006600; font-weight:bold;">&#41;</span> ORDER BY updated_at desc LIMIT <span style="color:#006666;">1</span><br />
&nbsp; Call <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>1.2ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`calls`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`calls`</span>.<span style="color:#9900CC;">student_id</span> = <span style="color:#006666;">60329</span><span style="color:#006600; font-weight:bold;">&#41;</span> ORDER BY created_at desc<br />
&nbsp; SaleStatus <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>0.8ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span>.<span style="color:#996600;">`id`</span> <span style="color:#9966CC; font-weight:bold;">IN</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">327</span>,<span style="color:#006666;">329</span>,<span style="color:#006666;">320</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
&nbsp; SaleStatus <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>0.8ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span>.<span style="color:#996600;">`id`</span> <span style="color:#9966CC; font-weight:bold;">IN</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">326</span>,<span style="color:#006666;">329</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
&nbsp; EqFollowType <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>0.8ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span>.<span style="color:#996600;">`id`</span> <span style="color:#9966CC; font-weight:bold;">IN</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">99</span>,<span style="color:#006666;">104</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
&nbsp; EqCallResult <span style="color:#CC0066; font-weight:bold;">Load</span> <span style="color:#006600; font-weight:bold;">&#40;</span>0.6ms<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">SELECT</span> <span style="color:#006600; font-weight:bold;">*</span> FROM <span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span> WHERE <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">`v2_system_production`</span>.<span style="color:#996600;">`list_items`</span>.<span style="color:#996600;">`id`</span> <span style="color:#9966CC; font-weight:bold;">IN</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">337</span>,<span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
Rendering student<span style="color:#006600; font-weight:bold;">/</span>calls<span style="color:#006600; font-weight:bold;">/</span>index<br />
Rendered student<span style="color:#006600; font-weight:bold;">/</span>calls<span style="color:#006600; font-weight:bold;">/</span>_list <span style="color:#006600; font-weight:bold;">&#40;</span>9.1ms<span style="color:#006600; font-weight:bold;">&#41;</span><br />
Completed <span style="color:#9966CC; font-weight:bold;">in</span> 245ms <span style="color:#006600; font-weight:bold;">&#40;</span>View: <span style="color:#006666;">170</span>, DB: <span style="color:#006666;">74</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006666;">200</span> OK <span style="color:#006600; font-weight:bold;">&#91;</span>http:<span style="color:#006600; font-weight:bold;">//</span>localhost<span style="color:#006600; font-weight:bold;">/</span>students<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">120490</span><span style="color:#006600; font-weight:bold;">/</span>calls<span style="color:#006600; font-weight:bold;">&#93;</span></div></td></tr></tbody></table></div>
<p>Use HTTP Cache</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Student::CallsController</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Student::BaseController</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> index<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> stale?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:last_modified</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@student</span>.<span style="color:#9900CC;">calls</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;updated_at desc&quot;</span>, :<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;updated_at&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">updated_at</span>.<span style="color:#9900CC;">utc</span>, <span style="color:#ff3333; font-weight:bold;">:etag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;call&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@calls</span> = <span style="color:#0066ff; font-weight:bold;">@student</span>.<span style="color:#9900CC;">calls</span>.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;created_at desc&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:status_before</span>, <span style="color:#ff3333; font-weight:bold;">:status_after</span>, <span style="color:#ff3333; font-weight:bold;">:eq_follow_type</span>, <span style="color:#ff3333; font-weight:bold;">:eq_call_result</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Restart server.<br />
Then open student detail page again.<br />
The first time return 200.</p>
<p>When I refresh.It return 304.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Firebug:<br />
GET http://localhost:3000/students/120490/calls &nbsp; &nbsp; &nbsp; 304 Not Modified&nbsp; &nbsp; &nbsp; 26m<br />
Log:<br />
Processing Student::CallsController#index (for 127.0.0.1 at 2010-09-06 16:38:33) [GET]<br />
&nbsp; Parameters: {&quot;student_id&quot;=&gt;&quot;120490&quot;}<br />
&nbsp; Student Load (1.4ms) &nbsp; SELECT * FROM `students` WHERE (`students`.`id` = '120490') LIMIT 1<br />
&nbsp; Call Load (0.8ms) &nbsp; SELECT updated_at FROM `calls` WHERE (`calls`.student_id = 120490) ORDER BY updated_at desc LIMIT 1<br />
Completed in 8ms (View: 0, DB: 2) | 304 Not Modified [http://localhost/students/120490/calls]</div></td></tr></tbody></table></div>
<p>The speed improve a lot. cool,</p>
<p>Summary:<br />
1.suit for a page not often modified.<br />
2.the are 3 ways to control HTTP Cache. need further learning.<br />
3.only GET request can use HTTP Cache.<br />
4.may be it has way for ajax use HTTP Cache.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/09/06/client-http-caching-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>development tips on Titanium</title>
		<link>http://developer.idapted.com/2010/09/01/development-tips-on-titanium/</link>
		<comments>http://developer.idapted.com/2010/09/01/development-tips-on-titanium/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 06:51:43 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile App]]></category>
		<category><![CDATA[Weekly Review]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Titanium]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1017</guid>
		<description><![CDATA[After releasing our first iPhone app, I just learned a lot about using Titanium SDK. Today I want to share some valuable development tips, which are mostly gathered from Titanium developer&#8217;s forum. 1. Remember that the device is not as speedy as the simulator. 2. When you need to use a webView, try to communicate [...]]]></description>
			<content:encoded><![CDATA[<p>After releasing our first iPhone app, I just learned a lot about using Titanium SDK. Today I want to share some valuable development tips, which are mostly gathered from Titanium developer&#8217;s forum.</p>
<p>1. Remember that the device is not as speedy as the simulator.<br />
2. When you need to use a webView, try to communicate with the app as less as possible. If you need to create new elements in the interface, do it before you launch the webView and not while the webView is active, and attach it to the window from the webView. If you need to make calculations ( for example to catch the touchmove coordinates) inside webView, do it in the javascript from inside he webView, and send the result to the app at the end ( on touchend maybe ).<br />
3. If you have to store persistent data, but is not an sql data ( for example you need to remember some settings the user is able to configure ) use Titanium.App.Properties and not Titanium.Database. Properties are persistent so you may want to &#8216;remove&#8217; them in your app.js &#8211; to start afresh.<br />
4. Test your application on the device( if possible ). You will find that you might need to improve the usability &#8211; for example you might ned to add a &#8220;Loading&#8230;&#8221; view to mask a slow loading component, and provide in the same time feedback to the user. ( this is somehow related to the point 1. )<br />
5. It takes minimal extra effort to target the Android platform as well as the iPhone. Take a bit of extra time to make sure your app works on both (using platform detection where you need to do something slightly differently, or need to skip a function that causes the app to crash on one device).</p>
<pre>
if (Titanium.Platform.name == 'android') {
    // Android stuff
}
</pre>
<p>Connect to test data-sources by detecting whether the app is running in a simulator.</p>
<pre>
if (Titanium.Platform.model == 'google_sdk' || Titanium.Platform.model == 'Simulator') {
    // Simulator variables
}
</pre>
<p>6. Ti.API.info the name of the JS file at the start, so you can capture the sequence of navigation when testing. Also useful if you could have obsolete files to check they are not used.<br />
7. About HTTPClient:<br />
   [1] Titanium HTTPClient runs in a separate thread and often (always?) doesnt release it. Use global client to download multiple files to minimize number of threads. You can make a recursive procedure, that gets called from onreadystatechange or onload (if it fires)<br />
   [2] HTTPClient.onload often doesnt fire, use onreadystatechange with readyState == 4<br />
   [3] Titanium HTTPClient doesnt close itself automatically, so before reopening it with a different direction, use &#8220;abort&#8221;, or it will bring you the same file as before.<br />
   [4] So if u create a client, all your subsequent events and timers will fire in several threads. Titanium threads seem to share variables, so if your event is sensitive to doubled execution, use a simple integer or boolean to create a semaphore.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/09/01/development-tips-on-titanium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic add class method in (class </title>
		<link>http://developer.idapted.com/2010/09/01/dynamic-add-class-method-in-class/</link>
		<comments>http://developer.idapted.com/2010/09/01/dynamic-add-class-method-in-class/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 06:26:22 +0000</pubDate>
		<dc:creator>fred</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Weekly Review]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1013</guid>
		<description><![CDATA[1&#160; @person = Person.new As you know, @person is a instance object of Person, in the other words @personal.class is Person. but do you know who is Person.class? sure, it&#8217;s Class, so we can say Person is a Class&#8217;s &#8220;instance object&#8221;. Next, we add some class methods to Person by difference ways. 1234567891011121314151617181920212223242526class Person &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#0066ff; font-weight:bold;">@person</span> = Person.<span style="color:#9900CC;">new</span></div></td></tr></tbody></table></div>
<p>As you know, @person is a instance object of Person, in the other words @personal.class is Person. but do you know who is Person.class? sure, it&#8217;s Class, so we can say Person is a Class&#8217;s &#8220;instance object&#8221;. Next, we add some class methods to Person by difference ways.</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Person<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">class_method1</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> class_method2<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> Person.<span style="color:#9900CC;">class_method3</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> Person<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> class_method4<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
........<br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> class_methodX<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Wait, does the last solution work? yes, not only we could call Person.class_methodX, but also call in any class. for example</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> whoami<br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'you are Class'</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> Me<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; Me.<span style="color:#9900CC;">whoami</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># =&gt; you are Class</span></div></td></tr></tbody></table></div>
<p>The last solution is bad because it effects too many classes, at the same time it can&#8217;t dynamic add class method in runtime, not only itself, all above solutions can&#8217;t. Therefore, I write a method like below</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Person<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">create_method</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:define_method</span>, name, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Person.<span style="color:#9900CC;">create_method</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:hello</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'hello'</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
Person.<span style="color:#9900CC;">hello</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; undefined method `hello' for Person:Class (NoMethodError)</span></div></td></tr></tbody></table></div>
<p>Why it doesn&#8217;t work? After a seconds, I got it.</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; Person.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">hello</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># =&gt; hello</span></div></td></tr></tbody></table></div>
<p>Look, we just add a method on &#8220;self&#8221;, then the &#8220;self&#8221; is Person, so the method is instance method instead of class method. But how we can add a class method dynamically? Shall we add method to Class? No, we should add it to a stuff who it like Class but only for Person. Yes, the &#8220;class << self; self; end" can do this. Change above code like this</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Person<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">create_method</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>; <span style="color:#0000FF; font-weight:bold;">self</span>; <span style="color:#9966CC; font-weight:bold;">end</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:define_method</span>, name, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
Person.<span style="color:#9900CC;">create_method</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:hello</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'hello'</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
Person.<span style="color:#9900CC;">hello</span><br />
<span style="color:#008000; font-style:italic;"># =&gt; hello</span></div></td></tr></tbody></table></div>
<p>Above is my experience to research how to use (class << self; self; end). Besides, I got some informations about it: (class << self; self; end) is a virtual class and it can't be instance</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Person<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">virtual_class</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>; <span style="color:#0000FF; font-weight:bold;">self</span>; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
v = Person.<span style="color:#9900CC;">virtual_class</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> v <span style="color:#008000; font-style:italic;">#=&gt; #&lt;Class:Person&gt;</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> v.<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#008000; font-style:italic;">#=&gt; Class</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#9966CC; font-weight:bold;">Class</span>.<span style="color:#9900CC;">new</span> <span style="color:#008000; font-style:italic;"># =&gt; #&lt;Class:0x1003a8e90&gt;</span><br />
v.<span style="color:#9900CC;">new</span> <span style="color:#008000; font-style:italic;">#=&gt; can't create instance of virtual class (TypeError)</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#9966CC; font-weight:bold;">Class</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">new</span> <span style="color:#008000; font-style:italic;"># =&gt; #&lt;#&lt;Class:0x10039f890&gt;:0x10039f840&gt;</span></div></td></tr></tbody></table></div>
<p>Summary<br />
    In above example, (class << self; self; end) is a kind of Class, it as same as Class but only for Person.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/09/01/dynamic-add-class-method-in-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to analyze and forecast?</title>
		<link>http://developer.idapted.com/2010/09/01/how-to-analyze-and-forecast/</link>
		<comments>http://developer.idapted.com/2010/09/01/how-to-analyze-and-forecast/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 03:20:31 +0000</pubDate>
		<dc:creator>denny</dc:creator>
				<category><![CDATA[Forecast and analyze]]></category>
		<category><![CDATA[Weekly Review]]></category>
		<category><![CDATA[Analyze]]></category>
		<category><![CDATA[Forecast]]></category>
		<category><![CDATA[Normal Dirtribution]]></category>
		<category><![CDATA[一元线性回归预测法]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1004</guid>
		<description><![CDATA[What we can get from history data? and how we can get it? These are two question when I face to the LPD function. and In trainer side , there are many statistics data. can we get something from these data? The answer is sure, we can get , but how? These two data I [...]]]></description>
			<content:encoded><![CDATA[<p>What we can get from history data? and how we can get it? These are two question when I face to the LPD function. and In trainer side , there are many statistics data. can we get something from these data? The answer is sure, we can get , but how?</p>
<p>These two data I think over it and get some idea, so share with us for discussing.</p>
<ul>
<li> <strong>Analyze Data</strong></li>
</ul>
<p>For LPD, we want to know how much time our almost learner spent on one page and scenario ? how many point they got ? we want to get the standard time_spent and point for every page or scenario, so we can apply right study method to our learner. Till now, we have the data about this. so we need analyze it and find some result.</p>
<p>From the aspect of Math, we can induce this to solve the function .</p>
<p><a href="http://developer.idapted.com/wp-content/uploads/2010/09/normal_distribution_function.jpg"><img class="aligncenter size-full wp-image-1006" title="normal_distribution_function" src="http://developer.idapted.com/wp-content/uploads/2010/09/normal_distribution_function.jpg" alt="" width="200" height="76" /></a></p>
<p>μ : 正态分布的位置参数，描述正态分布的集中趋势位置。正态分布以X=μ为对称轴，左右完全对称。正态分布的均数、中位数、众数相同，均等于μ</p>
<p>σ : 描述正态分布资料数据分布的离散程度，σ越大，数据分布越分散，σ越小，数据分布越集中。 也称为是正态分布的形状参数，σ越大，曲线越扁平，反之，σ越小，曲线越瘦高。</p>
<p>we want to get the value of μ for every page or scenario in time spent. so for this , we can draw one chart for this, and get the below value for analyzing.</p>
<ol>
<li>Mean (µ): sum of all data divided by the number of data points; aka the “average” Example: {4, 8, 10} µ = (4+8+10)/3 = 7.33</li>
<li>Median: the middle value of a set of data Example: {4, 8, 10} med = 8</li>
<li>Quartile: quarter of the data; ‘Q1’ and ‘Q3’ are the values at the 25th and 75th percentiles; (Q2 = med = 50%) Example: {2, 4, 8, 9, 10, 13} Q1 = 4; med (Q2) = (8+9)/2 = 8.5; Q3 = 10 </li>
<li>Standard Deviation (σ): measure of how spread out the data is or how close your data is to the mean Example: µ = 0; σ = 1</li>
</ol>
<p><a href="http://www.idapted.com/lpr/lpd/pages/84357?item=time_spent">http://www.idapted.com/lpr/lpd/pages/84357?item=time_spent</a></p>
<ul>
<li><strong>Forecast Data</strong></li>
</ul>
<p>For this task , it is so big and difficult that there is no good way for this, but we can start from some easy and simple case .</p>
<p>1. we want to know how many shift should be opened at pm platform , for this, we should first to know how many student will be valid in that time and forecast how many student will take a class.</p>
<p>2. we want to know the relationship between student who take the class and the interaction number</p>
<p>commit_shift_num(y) : the shift number of trainer signed during pm platform time</p>
<p>actual_student_num(x1) : the number of student who take a class during pm platform time</p>
<p>valid_student_num(x2) : the number of student who can take a class during pm platform time</p>
<p>history_num(x3) : the number of history_record which duration great than two mins</p>
<p>How to get this data, there are some statistics methods for this .</p>
<ul>
<li>一元线性回归预测分析法(<a href="http://wiki.mbalib.com/wiki/%E4%B8%80%E5%85%83%E5%9B%9E%E5%BD%92%E5%88%86%E6%9E%90%E9%A2%84%E6%B5%8B%E6%B3%95"><strong> </strong>1</a>)</li>
<li>二元线性回归预测分析法(<a href="http://wiki.mbalib.com/wiki/%E4%BA%8C%E5%85%83%E7%BA%BF%E6%80%A7%E5%9B%9E%E5%BD%92%E9%A2%84%E6%B5%8B%E6%B3%95">2</a>)</li>
<li>时间序列预测法(<a href="http://wiki.mbalib.com/wiki/%E6%97%B6%E9%97%B4%E5%BA%8F%E5%88%97%E9%A2%84%E6%B5%8B%E6%B3%95">3</a>)</li>
</ul>
<p><strong>Object </strong>:  y = a + b*x1</p>
<p><strong>Step</strong> :</p>
<p>1.  get the number of x2 , this should use the 时间序列预测法,</p>
<p>2. get the relationship between x1 and x2, this should be x1 = a + b*x2</p>
<p>3. get the y = a + b*x1</p>
<p><strong>Code </strong>:</p>
<p>1. the chart for flow (<a href="http://www.veecue.com/trainer/shift/samples/1?from=2010-01-01&amp;to=2010-09-01&amp;item=all&amp;commit=Process">4</a>), for this, i need more work, till now , it not finish, but we can get the trend about the number of valid student , it is up.</p>
<p>2. the code for 一元线性回归预测分析法</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> line_alg<span style="color:#006600; font-weight:bold;">&#40;</span>cond,x,y<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;*&quot;</span>.<span style="color:#9900CC;">center</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">58</span>, <span style="color:#996600;">&quot;-&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Sample : #{cond}&quot;</span><br />
n = Sample.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:conditions</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;cond<span style="color:#006600; font-weight:bold;">&#41;</span><br />
x_ave = Sample.<span style="color:#9900CC;">average</span><span style="color:#006600; font-weight:bold;">&#40;</span>x.<span style="color:#9900CC;">to_sym</span>,:conditions=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;cond<span style="color:#006600; font-weight:bold;">&#41;</span><br />
y_ave = Sample.<span style="color:#9900CC;">average</span><span style="color:#006600; font-weight:bold;">&#40;</span>y.<span style="color:#9900CC;">to_sym</span>,:conditions=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;cond<span style="color:#006600; font-weight:bold;">&#41;</span><br />
sxx = <span style="color:#006666;">0</span><br />
syy = <span style="color:#006666;">0</span><br />
sxy = <span style="color:#006666;">0</span><br />
Sample.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:conditions</span>=<span style="color:#006600; font-weight:bold;">&amp;</span>gt;cond<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span><br />
yi = s.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>y<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#commit_shift_num</span><br />
xi = s.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#actual_stu_num</span><br />
sxx <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#40;</span>xi<span style="color:#006600; font-weight:bold;">-</span>x_ave<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">**</span><span style="color:#006666;">2</span><br />
sxy <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#40;</span>xi<span style="color:#006600; font-weight:bold;">-</span>x_ave<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>yi<span style="color:#006600; font-weight:bold;">-</span>y_ave<span style="color:#006600; font-weight:bold;">&#41;</span><br />
syy <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#40;</span>yi<span style="color:#006600; font-weight:bold;">-</span>y_ave<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">**</span><span style="color:#006666;">2</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
b = sxy<span style="color:#006600; font-weight:bold;">/</span>sxx<br />
a = y_ave <span style="color:#006600; font-weight:bold;">-</span> b<span style="color:#006600; font-weight:bold;">*</span>x_ave<br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;sample number : #{n}&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;y_ave : #{y_ave}&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;x_ave : #{x_ave}&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;y = #{a.to_f.round(2)} + #{b.to_f.round(2)}*x&quot;</span><br />
r = sxy<span style="color:#006600; font-weight:bold;">/</span><span style="color:#CC00FF; font-weight:bold;">Math</span>.<span style="color:#9900CC;">sqrt</span><span style="color:#006600; font-weight:bold;">&#40;</span>sxx<span style="color:#006600; font-weight:bold;">*</span>syy<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;r = #{r.to_f.round(2)}&quot;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>Result</strong> :</p>
<p>1. the relation between actual_student_number and valid_student_number</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">y : valid_stu_num<br />
x : actual_stu_num<br />
Sample : valid_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span><br />
sample number : <span style="color:#006666;">225</span><br />
y_ave : <span style="color:#006666;">108.3289</span><br />
x_ave : <span style="color:#006666;">45.5733</span><br />
y = <span style="color:#006666;">24.64</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1.84</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.3</span></div></td></tr></tbody></table></div>
<p>From the result, we can get the relationship is loose, r <0.3, but I think the reason is the sample is so small and some of them is not right, so when we have large sample and correct data, we can get the function for this.<br />
2. the relation between actual_student_number and history_number</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">y : history_num<br />
x : actual_stu_num<br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : history_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span><br />
sample number : <span style="color:#006666;">1268</span><br />
y_ave : <span style="color:#006666;">43.6538</span><br />
x_ave : <span style="color:#006666;">22.0039</span><br />
y = <span style="color:#006666;">5.55</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1.73</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.97</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : history_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2010-07-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-08-01'</span><br />
sample number : <span style="color:#006666;">31</span><br />
y_ave : <span style="color:#006666;">83.129</span><br />
x_ave : <span style="color:#006666;">48.3548</span><br />
y = <span style="color:#006666;">1.52</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1.69</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.88</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : history_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2009-01-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-01-01'</span><br />
sample number : <span style="color:#006666;">352</span><br />
y_ave : <span style="color:#006666;">72.0881</span><br />
x_ave : <span style="color:#006666;">35.8665</span><br />
y = <span style="color:#006666;">14.17</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1.61</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.92</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : history_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2009-10-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-08-01'</span><br />
sample number : <span style="color:#006666;">295</span><br />
y_ave : <span style="color:#006666;">76.4949</span><br />
x_ave : <span style="color:#006666;">43.539</span><br />
y = <span style="color:#006666;">6.38</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1.61</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.91</span></div></td></tr></tbody></table></div>
<p>As you can seen, all the r greater than 0.9, so we can deduce the relation between these two item is very close.</p>
<p>3. relationship between actual_student_number and commit_shift_number</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">y : commit_shift_num<br />
x : actual_stu_num<br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : commit_shift_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span><br />
sample number : <span style="color:#006666;">1254</span><br />
y_ave : <span style="color:#006666;">29.6858</span><br />
x_ave : <span style="color:#006666;">21.7568</span><br />
y = <span style="color:#006666;">9.85</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">0.91</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.89</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : commit_shift_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2010-07-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-08-01'</span><br />
sample number : <span style="color:#006666;">31</span><br />
y_ave : <span style="color:#006666;">48.6129</span><br />
x_ave : <span style="color:#006666;">48.3548</span><br />
y = <span style="color:#006666;">37.78</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">0.22</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.33</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : commit_shift_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2009-01-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-01-01'</span><br />
sample number : <span style="color:#006666;">352</span><br />
y_ave : <span style="color:#006666;">46.4631</span><br />
x_ave : <span style="color:#006666;">35.8665</span><br />
y = <span style="color:#006666;">23.27</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">0.65</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.66</span><br />
<span style="color:#006600; font-weight:bold;">----------------------------*-----------------------------</span><br />
Sample : commit_shift_num <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> actual_stu_num <span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#996600;">'2009-10-01'</span> <span style="color:#9966CC; font-weight:bold;">and</span> sample_date <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">'2010-08-01'</span><br />
sample number : <span style="color:#006666;">295</span><br />
y_ave : <span style="color:#006666;">51.4441</span><br />
x_ave : <span style="color:#006666;">43.539</span><br />
y = <span style="color:#006666;">37.13</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">0.33</span><span style="color:#006600; font-weight:bold;">*</span>x<br />
r = <span style="color:#006666;">0.44</span></div></td></tr></tbody></table></div>
<p>all the r great than 0.3, even the sample number is 31, so we should build the relationship between these tow item, and get the factor for y = a +b*x, if we have this function, we can forecast the shift number be opened.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/09/01/how-to-analyze-and-forecast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First iPhone App : IELTS 31 Formuals</title>
		<link>http://developer.idapted.com/2010/08/28/first-iphone-app-ielts-31-formuals/</link>
		<comments>http://developer.idapted.com/2010/08/28/first-iphone-app-ielts-31-formuals/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 07:08:49 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile App]]></category>
		<category><![CDATA[Open-Source]]></category>
		<category><![CDATA[apple-store]]></category>
		<category><![CDATA[free-app]]></category>
		<category><![CDATA[iphone app]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[Titanium]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=1001</guid>
		<description><![CDATA[In last two month, our team worked for Idapted first iPhone App. We spent a lot time on releasing this app as Apple&#8217;s process is really awful to a first user. Well, everything was done in the last. Now our first iPhone App is available in Apple Store. It&#8217;s free in current version. you can [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://img.skitch.com/20100828-873u9f5mr8gmxt5r3jn8t4m7as.jpg"><img alt="" src="http://img.skitch.com/20100828-873u9f5mr8gmxt5r3jn8t4m7as.jpg" title="31 Formulas" class="aligncenter" width="688" height="514" /></a><br />
In last two month, our team worked for Idapted first iPhone App. We spent a lot time on releasing this app as Apple&#8217;s process is really awful to a first user. Well, everything was done in the last. Now our first iPhone App is available in Apple Store. It&#8217;s free in current version. you can install it from here: <a href="http://goo.gl/ht4p">http://goo.gl/ht4p</a>. It&#8217;s based on <a href="http://www.appcelerator.com/products/">Titanium 1.4</a>. so a big thanks to the brilliant <a href="http://www.appcelerator.com/company/leadership-team/">Appcelerator Team</a>.</p>
<p>We open sourced this app on our <a href="http://github.com/idapted/eq31formulas">github repos</a>. We also built a website for this app at <a href="http://www.31formulas.com">http://www.31formulas.com</a></p>
<p>Enjoy it and let us know if you have any feedback on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/08/28/first-iphone-app-ielts-31-formuals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apple iPhone app : Debug and Release through Titanium</title>
		<link>http://developer.idapted.com/2010/08/25/apple-iphone-app-debug-and-release-through-titanium/</link>
		<comments>http://developer.idapted.com/2010/08/25/apple-iphone-app-debug-and-release-through-titanium/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 04:16:09 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile App]]></category>
		<category><![CDATA[Weekly Review]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[iphone app]]></category>
		<category><![CDATA[provisioning profile]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[Titanium]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=948</guid>
		<description><![CDATA[Once people develop an iPhone App using Titanium1.4, they must be very happy when the App is running on iPhone simulator. They feel great until they decide to debug their app on their devices or even release their app to AppleAppStore. This happens specially to these who firstly do this. Why? There are many reasons [...]]]></description>
			<content:encoded><![CDATA[<p>Once people develop an iPhone App using <a href="http://www.appcelerator.com/">Titanium1.4</a>, they must be very happy when the App is running on iPhone simulator. They feel great until they decide to debug their app on their devices or even release their app to AppleAppStore. This happens specially to these who firstly do this. Why? There are many reasons that you will hate Apple during the debug or release process. I bat you are like me then.</p>
<p>Assume that: You&#8217;ve already finished coding an iPhone app in Titanium 1.4 framework. Now you want to install your app on your device. If you do this first time, guess what will happen to you? Let me tell you my story.</p>
<p>You will be blocked by Titanium certificates detections when you want to install your app to your device. see below image:</p>
<div class="thumbnail"><a href="http://skitch.com/yorzi/dut81/mail-1320x770"><img src="http://img.skitch.com/20100825-fuf9q1dac5ir21f5g4im2h93gi.jpg" alt="mail (1320շ70)" /></a></div>
<p>
Well, in order to become an iPhone developer, you should pay Apple for an iPhone Program Permission. My boss paid Apple for an iPhone Program Team permission, it cost him about one month to pass Apple&#8217;s approval. After that, he, as an admin agent iPhone developer, invited me as an iPhone developer member with admin permission. Here we had been running into issue for two days. Finally, we found that he only can invite my exist Apple ID as an iPhone developer, because I can&#8217;t finish a registration process after he invite me with a non-exist Apple ID. The evil is Apple indicates that, we should invite non-exist accounts as team members.</p>
<p>Now have I got the permission to debug my app on my iphone? Wait a moment. Actually I should be invited twice separately, one is for <a href="https://itunesconnect.apple.com/">iTunesconnect</a>. another one is for <a href="http://developer.apple.com/iphone/index.action">Provisioning Portal</a>(Dev Center). These two sites are different, only in Dev Center, I can config my provisioning profile, which is a main concept for releasing iPhone App or allowing to install App on certain devices. But in iTunesconnect, I need to release my app to iTunes/Apple App Store.</p>
<p>So far, I&#8217;ve got enough permission to debug the App on my own iPhone. But I am still unable to distribute my App to others&#8217; devices. How that happens? As an iPhone developer, I need to pass Titanium&#8217;s detection of several certificates. only after that, I can install app on my iPhone. (PS: if you want to test your app on Android, the only need is to connect your device.)</p>
<p>In following images, I will show you the steps through which you can pass all the Titanium detection of certificates.</p>
<div><a href="http://skitch.com/yorzi/dutdc/preparation-iphone-provisioning-portal-apple-developer"><img src="http://img.skitch.com/20100825-b8ne3uxkfenjthcgnscecb89t.jpg" alt="Preparation - iPhone Provisioning Portal - Apple Developer" /></a></div>
<p>
Then you will get the following files after your above configuration.</p>
<div class="thumbnail"><a href="http://skitch.com/yorzi/dutrp/users-andy-desktop-apple-developer-app"><img src="http://img.skitch.com/20100825-ds2k13epf4b7grcmabr89yk11r.jpg" alt="/Users/andy/Desktop/apple_developer/app" /></a></div>
<p>
After you import the above certificates to your keychain, you should see something similar in your Keychian.</p>
<div class="thumbnail"><a href="http://skitch.com/yorzi/dutds/keychain-access"><img src="http://img.skitch.com/20100825-ra2mqhmcu94pk7kuxcpa7c6i2g.jpg" alt="Keychain Access" /></a></div>
<p>
Finally, your Titanium will be the &#8220;ready status&#8221; for your debug and release on real device.</p>
<div class="thumbnail"><a href="http://skitch.com/yorzi/dutfb/titanium-developer-1.2.1"><img src="http://img.skitch.com/20100825-m5b6ugwjywb66qggswbsumsmfk.jpg" alt="Titanium Developer (1.2.1)" /></a></div>
<p>
The whole process might be painful unless you understand every concepts that Apple creates. I encounter problems when creating distribution provisioning profile. Only admin agent developer has permission to do so. Thus, you should ask admin agent for this provisioning profile, he can share this profile with a private key file, you import this key file to your Keychian, then you can distribute the app to whatever devices which is bundled into specific provisioning profile. </p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/08/25/apple-iphone-app-debug-and-release-through-titanium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails small tips</title>
		<link>http://developer.idapted.com/2010/08/04/rails-small-tips/</link>
		<comments>http://developer.idapted.com/2010/08/04/rails-small-tips/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 07:45:33 +0000</pubDate>
		<dc:creator>blade</dc:creator>
				<category><![CDATA[Weekly Review]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=873</guid>
		<description><![CDATA[1. flash and flash.now flash in rails used to pass messages.it is use session do this. 123456789def create &#160; if User.authorize&#40;params&#91;:login&#93;, params&#91;:password&#93;&#41; &#160; &#160; flash&#91;:notice&#93; = &#34;login success&#34; &#160; &#160; redirect_to target_path &#160; else &#160; &#160; flash&#91;:error&#93; = &#34;login fail&#34; &#160; &#160; render :new &#160; end end flash[:notice]. it effect after redirect_to. in this example [...]]]></description>
			<content:encoded><![CDATA[<p>1. flash and flash.now</p>
<p>flash in rails used to pass messages.it is use session do this.</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> create<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> User.<span style="color:#9900CC;">authorize</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:login</span><span style="color:#006600; font-weight:bold;">&#93;</span>, params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:password</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;login success&quot;</span><br />
&nbsp; &nbsp; redirect_to target_path<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:error</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;login fail&quot;</span><br />
&nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:new</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>flash[:notice].<br />
it effect after redirect_to.<br />
in this example if login failed the error message will not show in template &#8220;new&#8221; but show in next redirect page.</p>
<p>when we use render should use *flash.now*.<br />
flash.now[:notice] will effect in current page.</p>
<p>2.select and include</p>
<p>Rails &#8216;s ActiveRecord finders &#8216;s &#8220;select&#8221; option do not work when &#8220;include&#8221; preload assoic records。</p>
<p>condition:</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> Student <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;has_one <span style="color:#ff3333; font-weight:bold;">:call</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> Call <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;belongs_to <span style="color:#ff3333; font-weight:bold;">:student</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>how to show student&#8217;s call&#8217;s updated_at.</p>
<p>before optimize</p>
<div class="codecolorer-container ruby geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#0066ff; font-weight:bold;">@students</span> = Student.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:call</span><span style="color:#006600; font-weight:bold;">&#93;</span>, :<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;students.id, students.login, students.called_times, calls.updated_at as last_called_at&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>it do work, but in sql statment, It still preload &#8220;call&#8221; and return a full record.  </p>
<p>after optimize</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#include eql left outer join<br />
@students = Student.all(:select =&gt; &quot;students.id, students.login, students.called_times,<br />
calls.updated_at as last_called_at&quot;, :joins =&gt; &quot;left outer join calls on students.id = calls.student_id&quot;)</div></td></tr></tbody></table></div>
<p>now, table students only select the fields we need.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/08/04/rails-small-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>calculate results VS. store result sets</title>
		<link>http://developer.idapted.com/2010/08/04/calculate-results-vs-store-result-sets/</link>
		<comments>http://developer.idapted.com/2010/08/04/calculate-results-vs-store-result-sets/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 03:01:43 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cache data result]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dataset]]></category>
		<category><![CDATA[instant calculate]]></category>
		<category><![CDATA[result-set]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=855</guid>
		<description><![CDATA[Firstly, what&#8217;s the results in title? For example, the results may be learners who will be alive in coming two weeks, or the results may be study times of one learner, etc. Generally, results should be some data coming from analyzing other data. Here my question is, how can we get certain results much faster [...]]]></description>
			<content:encoded><![CDATA[<p>Firstly, what&#8217;s the results in title? For example, the results may be learners who will be alive in coming two weeks, or the results may be study times of one learner, etc. Generally, results should be some data coming from analyzing other data.</p>
<p>Here my question is, how can we get certain results much faster and easily?</p>
<p><strong>Case 1:</strong><br />
We want to pick up a name list, all people in the list should be under certain condition, say, condition A, condition B, condition C, so normally, we just select the results which obey the rule(condition). Right? It depends.</p>
<p>If name list is always dynamically different in condition A,B,C, it&#8217;s really hard to store the results set, we have to calculate instantly to make sure the results is accurate.</p>
<p>If name list is very difficult to figure out in condition A,B,C, we should store the stable part of the result set, so that we will not get stuck when calculate tons of data eevery time.</p>
<p><strong>Case 2.</strong><br />
We want to show study times of a learner, how can we do that? Should we store the study times as one attributor of study record or should we just make one study record as one-time study? Obviously, it depends on the complication of study record and the definition of one-time study. </p>
<p>In our case, one study record is instantly changed when it&#8217;s in different status, so storing study times in study record is not a good idea because the results might be locked when status changes. But if we calculate study times based on its status, it will be more reliable and accurate. and also it will not be locked when status is with exception.</p>
<p><strong>Conclusion:</strong><br />
To store result set, is a way to cache results, but some times it&#8217;s not easy to maintain the result sets, for instance, if there are too many conditions when getting a results set, it&#8217;s always in heavy load to update result sets, you have to listen to every condition level changes. If the situation is complex, remember to cache your result set and maintain it carefully.</p>
<p>To calculate results instantly lets you ignore the real data, you just need to use the rule carefully, that will be more accurate, because you every time select what the rule defines. However the disadvantage is, when the data sets is large, you have to pay more to do that instantly, so you want to do a cron job or just cache the stable part of previous result sets.  </p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/08/04/calculate-results-vs-store-result-sets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploy dozens of rails applications into one domain</title>
		<link>http://developer.idapted.com/2010/08/03/deploy-dozens-of-rails-applications-into-one-domain/</link>
		<comments>http://developer.idapted.com/2010/08/03/deploy-dozens-of-rails-applications-into-one-domain/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 02:35:07 +0000</pubDate>
		<dc:creator>seven</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[eco_apps]]></category>

		<guid isPermaLink="false">http://developer.idapted.com/?p=851</guid>
		<description><![CDATA[We eventually have more than 30 rails applications running. Back to the days when we had only 3, we deploy each to a separate domains: 123&#160; &#160; app1.example.com &#160; &#160; app2.example.com &#160; &#160; app3.example.com They are beautiful. But, the 3 apps actually working together to do one big task. It would looks better to be [...]]]></description>
			<content:encoded><![CDATA[<p>We eventually have more than 30 rails applications running. Back to the days when we had only 3, we deploy each to a separate domains:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; app1.example.com<br />
&nbsp; &nbsp; app2.example.com<br />
&nbsp; &nbsp; app3.example.com</div></td></tr></tbody></table></div>
<p>They are beautiful. But, the 3 apps actually working together to do one big task. It would looks better to be served in one domain:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; www.example.com/app1/<br />
&nbsp; &nbsp; www.example.com/app2/<br />
&nbsp; &nbsp; www.example.com/app3/</div></td></tr></tbody></table></div>
<p>The advantage to use one domain is that it&#8217;s more beautiful &#8211; You may don&#8217;t even notice it&#8217;s actually 3 apps! And now they finally grew to more than 30s by using the great framework and architecture &#8211; eco_apps (<a href="http://github.com/idapted/eco_apps">http://github.com/idapted/eco_apps</a>). </p>
<p>The other advantage more than beautiful is that you will never worry about the javascript cross-domain requests, direct or AJAX.</p>
<p>Perhaps the easiest way to deploy multiple apps to subdirs is to use passenger:</p>
<p><a href="http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rails_to_sub_uri">http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rails_to_sub_uri</a></p>
<p><a href="http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri">http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri</a></p>
<p>But we had bad experience with passenger. One rails app stuck on some memcache server failure. Passenger was trying to start it over and over again and blocked all processes &#8211; the whole server suddenly stopped responding to anything! Perhaps they already fixed that, but we still think it&#8217;s better to serve rails &#8220;out&#8221; of Nginx or Apache.</p>
<p>First we need all rails apps to run in a subdir, no matter mongrel</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; mongrel_rails --prefix=/app1 ...</div></td></tr></tbody></table></div>
<p>unicorn:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; unicorn_rails --path /app1</div></td></tr></tbody></table></div>
<p>or swiftiplied/evented mongrel or thin.</p>
<p>We use Unicorn(<a href="http://github.com/blog/517-unicorn">http://github.com/blog/517-unicorn</a>) for rails and Nginx as a reverse proxy:</p>
<p>Nginx conf:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">upstream app1{<br />
&nbsp; server localhost:10010;<br />
}<br />
<br />
upstream app2{<br />
&nbsp; server localhost:10020;<br />
}<br />
<br />
upstream app3{<br />
&nbsp; server localhost:10030;<br />
}<br />
<br />
...<br />
<br />
upstream app30{<br />
&nbsp; server localhost:10300;<br />
}<br />
<br />
<br />
server {<br />
&nbsp; &nbsp; &nbsp; &nbsp; listen &nbsp; 80;<br />
&nbsp; &nbsp; &nbsp; &nbsp; server_name &nbsp;www.example.com;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; location / {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root &nbsp; &nbsp;/home/app/root;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; location /app1 {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root &nbsp; /home/app/app1/current/public;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://app1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; location /app2 {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root &nbsp; /home/app/app2/current/public;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://app2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; .....<br />
}</div></td></tr></tbody></table></div>
<p>That&#8217;s it. Take a look at <a href="http://github.com/idapted/eco_apps">http://github.com/idapted/eco_apps</a> to see how we make dozens of rails apps working together.</p>
]]></content:encoded>
			<wfw:commentRss>http://developer.idapted.com/2010/08/03/deploy-dozens-of-rails-applications-into-one-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
