<?xml version="1.0" encoding="UTF-8"?>
<cookbooks type="array">
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>has_attached_file :avatar,
    :styles =&gt; { :medium =&gt; &quot;200x200&gt;&quot;, :thumb =&gt; &quot;100x100&gt;&quot; }

validates_attachment_content_type :avatar,
    :content_type =&gt; ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png'],
    :message =&gt; &quot;only image files are allowed&quot;

validates_attachment_size :avatar,
    :less_than =&gt; 1.megabyte, #another option is :greater_than
    :message =&gt; &quot;max size is 1M&quot;
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;has_attached_file &lt;span style=&quot;color:#ff6213&quot;&gt;:avatar&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:styles&lt;/span&gt; =&amp;gt; { &lt;span style=&quot;color:#ff6213&quot;&gt;:medium&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;200x200&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#ff6213&quot;&gt;:thumb&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;100x100&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; }&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;validates_attachment_content_type &lt;span style=&quot;color:#ff6213&quot;&gt;:avatar&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:content_type&lt;/span&gt; =&amp;gt; [&lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/jpg&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/jpeg&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/pjpeg&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/gif&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/png&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;image/x-png&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;],&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:message&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;only image files are allowed&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;validates_attachment_size &lt;span style=&quot;color:#ff6213&quot;&gt;:avatar&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:less_than&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;1&lt;/span&gt;.megabyte, &lt;span style=&quot;color:#666&quot;&gt;#another option is :greater_than&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:message&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;max size is 1M&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2009-01-08T13:02:16+08:00</created-at>
    <id type="integer">83</id>
    <title>Paperclip&#22522;&#26412;&#37197;&#32622;&#65292;&#22270;&#29255;&#30340;content_type&#26159;&#27604;&#36739;&#20840;&#20102;</title>
    <updated-at type="datetime">2009-01-08T13:02:16+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>class &lt;&lt;ActiveRecord::Base
  alias_method :[], :find
end

Person[5]
Person[:last]
Person[:all, :conditions =&gt; { :name =&gt; &quot;Jamis&quot; }]
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#f3d72d;font-weight:bold&quot;&gt;class&lt;/span&gt; &amp;lt;&amp;lt;&lt;span style=&quot;color:#B06;font-weight:bold&quot;&gt;ActiveRecord::Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  alias_method &lt;span style=&quot;color:#ff6213&quot;&gt;:[]&lt;/span&gt;, &lt;span style=&quot;color:#ff6213&quot;&gt;:find&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#f3d72d;font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Person&lt;/span&gt;[&lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;5&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Person&lt;/span&gt;[&lt;span style=&quot;color:#ff6213&quot;&gt;:last&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Person&lt;/span&gt;[&lt;span style=&quot;color:#ff6213&quot;&gt;:all&lt;/span&gt;, &lt;span style=&quot;color:#ff6213&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; { &lt;span style=&quot;color:#ff6213&quot;&gt;:name&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;Jamis&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; }]&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2009-01-08T12:33:41+08:00</created-at>
    <id type="integer">82</id>
    <title>Alias for find</title>
    <updated-at type="datetime">2009-01-08T12:34:07+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>function readablizeBytes(bytes) {
    var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
    var e = Math.floor(Math.log(bytes)/Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+&quot; &quot;+s[e];
}

readablizeBytes(5000); // 4.88 kb
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;function readablizeBytes(bytes) {&lt;tt&gt;
&lt;/tt&gt;    var s = [&lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;kb&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;MB&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;GB&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;TB&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;PB&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;'&lt;/span&gt;&lt;/span&gt;];&lt;tt&gt;
&lt;/tt&gt;    var e = &lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Math&lt;/span&gt;.floor(&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Math&lt;/span&gt;.log(bytes)/&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Math&lt;/span&gt;.log(&lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;1024&lt;/span&gt;));&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#f3d72d;font-weight:bold&quot;&gt;return&lt;/span&gt; (bytes/&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Math&lt;/span&gt;.pow(&lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;1024&lt;/span&gt;, &lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Math&lt;/span&gt;.floor(e))).toFixed(&lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;2&lt;/span&gt;)+&lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;+s[e];&lt;tt&gt;
&lt;/tt&gt;}&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;readablizeBytes(&lt;span style=&quot;color:#00D;font-weight:bold&quot;&gt;5000&lt;/span&gt;); &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#60E;font-weight:bold&quot;&gt;4.88&lt;/span&gt; kb&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2009-01-07T12:33:19+08:00</created-at>
    <id type="integer">81</id>
    <title>Convert Filesize Bytes to Readable String in Javascript </title>
    <updated-at type="datetime">2009-01-07T12:33:19+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>ActionView::Base.new(Rails::Configuration.new.view_path).render(
    :partial =&gt; &quot;shared/someview&quot;,
    :locals =&gt; {:somevar =&gt; somevar}
)</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;ActionView&lt;/span&gt;::&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Base&lt;/span&gt;.new(&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Rails&lt;/span&gt;::&lt;span style=&quot;color:#88a6ce;font-weight:bold&quot;&gt;Configuration&lt;/span&gt;.new.view_path).render(&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:partial&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#0c1021&quot;&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;shared/someview&lt;/span&gt;&lt;span style=&quot;color:#5cce3c;background:#0c1021&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#ff6213&quot;&gt;:locals&lt;/span&gt; =&amp;gt; {&lt;span style=&quot;color:#ff6213&quot;&gt;:somevar&lt;/span&gt; =&amp;gt; somevar}&lt;tt&gt;
&lt;/tt&gt;)&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-31T10:03:55+08:00</created-at>
    <id type="integer">80</id>
    <title>Render in model</title>
    <updated-at type="datetime">2008-12-31T10:03:55+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>rhtml</category>
    <code>&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
Event.observe(window, 'load',
function() {
	alert('&#19978;&#20256;&#25104;&#21151;');
	parent.upload_call_back('&lt;%= @photo.photo.url -%&gt;');
	close_parent_wedgit_window();
}
);
&lt;/script&gt;</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;lt;script&lt;/span&gt; &lt;span style=&quot;color:#007&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;text/javascript&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#007&quot;&gt;charset&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;Event.observe(window, 'load',&lt;tt&gt;
&lt;/tt&gt;function() {&lt;tt&gt;
&lt;/tt&gt;        alert('&#19978;&#20256;&#25104;&#21151;');&lt;tt&gt;
&lt;/tt&gt;        parent.upload_call_back('&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span style=&quot;color:#33B&quot;&gt;@photo&lt;/span&gt;.photo.url &lt;span style=&quot;color:black&quot;&gt;-%&amp;gt;&lt;/span&gt;&lt;/span&gt;');&lt;tt&gt;
&lt;/tt&gt;        close_parent_wedgit_window();&lt;tt&gt;
&lt;/tt&gt;}&lt;tt&gt;
&lt;/tt&gt;);&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-23T14:31:38+08:00</created-at>
    <id type="integer">79</id>
    <title>&#27880;&#20876;window onload&#20107;&#20214;</title>
    <updated-at type="datetime">2008-12-23T14:31:38+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>class LineItem &lt; ActiveRecord::Base
  class &lt;&lt; self
    def find(*args)
      self.with_scope(:find =&gt; {:order =&gt; 'added_at'}) { super }
    end
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;LineItem&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;self&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;find&lt;/span&gt;(*args)&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;self&lt;/span&gt;.with_scope(&lt;span style=&quot;color:#A60&quot;&gt;:find&lt;/span&gt; =&amp;gt; {&lt;span style=&quot;color:#A60&quot;&gt;:order&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;added_at&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;}) { &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;super&lt;/span&gt; }&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-17T08:07:53+08:00</created-at>
    <id type="integer">78</id>
    <title>&#37325;&#36733;model&#30340;find&#26041;&#27861;</title>
    <updated-at type="datetime">2008-12-17T08:07:53+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>class String 
 def utf8?
    begin
      utf8_arr = self.unpack('U*')
      true if utf8_arr &amp;&amp; utf8_arr.size &gt; 0
    rescue
      false
    end
  end
end

'&#20013;&#25991;'.utf8&#65311;</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;String&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;utf8?&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      utf8_arr = &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;self&lt;/span&gt;.unpack(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;U*&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; utf8_arr &amp;amp;&amp;amp; utf8_arr.size &amp;gt; &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;rescue&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&#20013;&#25991;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;.utf8&#65311;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-11T11:07:35+08:00</created-at>
    <id type="integer">77</id>
    <title>&#26816;&#26597;&#23383;&#31526;utf8&#32534;&#30721;</title>
    <updated-at type="datetime">2008-12-11T11:31:22+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>d1 = Date.new( 2006, 12, 1 ) 

d2 = Date.new( 2007, 1, 15 )

weekdays = (d1..d2).reject { |d| [0,6].include? d.wday } 

weekdays.length</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;d1 = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Date&lt;/span&gt;.new( &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;2006&lt;/span&gt;, &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;12&lt;/span&gt;, &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt; ) &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;d2 = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Date&lt;/span&gt;.new( &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;2007&lt;/span&gt;, &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;15&lt;/span&gt; )&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;weekdays = (d1..d2).reject { |d| [&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;6&lt;/span&gt;].include? d.wday } &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;weekdays.length&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-04T22:05:38+08:00</created-at>
    <id type="integer">76</id>
    <title>&#35745;&#31639;&#20004;&#20010;&#26085;&#26399;&#38388;&#26377;&#22810;&#23569;&#20010;&#24037;&#20316;&#26085;</title>
    <updated-at type="datetime">2008-12-04T22:05:38+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&#25209;&#37327;&#29983;&#25104; named_scope.</body>
    <category>ruby</category>
    <code>class User &lt; ActiveRecord::Base
   STATES = [ 'pending', 'approved', 'denied' ]

   validates_inclusion_of :state, :in =&gt; STATES

   # Define a named scope for each state in STATES
   STATES.each { |s| named_scope s, :conditions =&gt; { :state =&gt; s } }
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;User&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;STATES&lt;/span&gt; = [ &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;pending&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;approved&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;denied&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; ]&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;   validates_inclusion_of &lt;span style=&quot;color:#A60&quot;&gt;:state&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:in&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;STATES&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;   &lt;span style=&quot;color:#888&quot;&gt;# Define a named scope for each state in STATES&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;STATES&lt;/span&gt;.each { |s| named_scope s, &lt;span style=&quot;color:#A60&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; { &lt;span style=&quot;color:#A60&quot;&gt;:state&lt;/span&gt; =&amp;gt; s } }&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-12-03T15:50:35+08:00</created-at>
    <id type="integer">75</id>
    <title>add scope for each states</title>
    <updated-at type="datetime">2008-12-03T15:50:35+08:00</updated-at>
    <user-id type="integer">7</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>class PaperJsView &lt; ActionView::Base
  attr_accessor :questions, :scores
end

view = PaperJsView.new(Rails::Configuration.new.view_path)
view.questions = questions
view.scores = scores

s = view.render(:partial =&gt; &quot;subjects/papers/paper.js.erb&quot;) </code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;PaperJsView&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActionView&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  attr_accessor &lt;span style=&quot;color:#A60&quot;&gt;:questions&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:scores&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;view = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;PaperJsView&lt;/span&gt;.new(&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Rails&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Configuration&lt;/span&gt;.new.view_path)&lt;tt&gt;
&lt;/tt&gt;view.questions = questions&lt;tt&gt;
&lt;/tt&gt;view.scores = scores&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;s = view.render(&lt;span style=&quot;color:#A60&quot;&gt;:partial&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;subjects/papers/paper.js.erb&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-11-25T14:29:34+08:00</created-at>
    <id type="integer">74</id>
    <title>Render in model or backgroundrb</title>
    <updated-at type="datetime">2008-11-25T14:29:34+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body>@conditions = [] 
@conditions &lt;&lt; xx if xx
:conditions =&gt; @conditions.join(&quot; and &quot;) 

</body>
    <category>ruby</category>
    <code>@conditions = [] 
@con1 = params[:category] ? (@conditions &lt;&lt; &quot;company_categories.cat_name = '#{params[:category]}'&quot;) : nil 
@con2 = params[:alpha] ? (@conditions &lt;&lt; &quot;companies.name LIKE '#{params[:alpha]}%'&quot;) : nil 

# count the number of records returned with includes and conditions set 
@company_count = Company.count(:include =&gt; includes, :conditions =&gt; @conditions.join(&quot; and &quot;)) 

# Finally, our find 
@companies = Company.paginate :page =&gt; params[:page], :per_page =&gt; 10, :order =&gt; 'name', :include =&gt; includes, :conditions =&gt; @conditions.join(&quot; and &quot;) 

</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#33B&quot;&gt;@conditions&lt;/span&gt; = [] &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#33B&quot;&gt;@con1&lt;/span&gt; = params[&lt;span style=&quot;color:#A60&quot;&gt;:category&lt;/span&gt;] ? (&lt;span style=&quot;color:#33B&quot;&gt;@conditions&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;company_categories.cat_name = '&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;params[&lt;span style=&quot;color:#A60&quot;&gt;:category&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) : &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;nil&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#33B&quot;&gt;@con2&lt;/span&gt; = params[&lt;span style=&quot;color:#A60&quot;&gt;:alpha&lt;/span&gt;] ? (&lt;span style=&quot;color:#33B&quot;&gt;@conditions&lt;/span&gt; &amp;lt;&amp;lt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;companies.name LIKE '&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;params[&lt;span style=&quot;color:#A60&quot;&gt;:alpha&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;%'&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) : &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;nil&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# count the number of records returned with includes and conditions set &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#33B&quot;&gt;@company_count&lt;/span&gt; = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Company&lt;/span&gt;.count(&lt;span style=&quot;color:#A60&quot;&gt;:include&lt;/span&gt; =&amp;gt; includes, &lt;span style=&quot;color:#A60&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#33B&quot;&gt;@conditions&lt;/span&gt;.join(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)) &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# Finally, our find &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#33B&quot;&gt;@companies&lt;/span&gt; = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Company&lt;/span&gt;.paginate &lt;span style=&quot;color:#A60&quot;&gt;:page&lt;/span&gt; =&amp;gt; params[&lt;span style=&quot;color:#A60&quot;&gt;:page&lt;/span&gt;], &lt;span style=&quot;color:#A60&quot;&gt;:per_page&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:order&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:include&lt;/span&gt; =&amp;gt; includes, &lt;span style=&quot;color:#A60&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#33B&quot;&gt;@conditions&lt;/span&gt;.join(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-10-25T19:19:21+08:00</created-at>
    <id type="integer">73</id>
    <title>&#21512;&#24182; conditions</title>
    <updated-at type="datetime">2008-10-25T19:19:47+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>require 'find'
require 'fileutils'

def dir_move( target,dirpath=Dir.pwd)
    ## check if path valid
    if !File.directory?(dirpath)  
        puts &quot;error first path&quot;
        return
    elsif File.file?(target)
        puts &quot;error :target is a file exist&quot;
        return
    end
    ###
    Dir.mkdir target unless File.exist? target
    Find.find dirpath do |path|
        path_lite=path.gsub(dirpath,'')
        target_path=(target+path_lite).gsub(/[^a-zA-Z0-9\.\-\+_\(\)\/]/,&quot;_&quot;).gsub(/(__)+/,&quot;zhongwen&quot;)
        begin
            if File.directory? path
                Dir.mkdir target_path
            else
                FileUtils.copy path,target_path
            end
        rescue
            # if type(path) != type(target_path)
            #            puts &quot;waring: type unmatch, local=&gt;#{path} is a #{type(path)},target=&gt;#{target_path} is a #{type(target_path)}&quot;
            #            end
        end
    end
    puts &quot;everyting is ok&quot;
end

def type(file)
    return unless File.exist? file
    if File.file? file
        &quot;file&quot;
    else
        &quot;directory&quot;
    end
end

dir_move(&quot;/Users/holin/bin2&quot;, &quot;/Users/holin/bin&quot;)
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;35&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;fileutils&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;dir_move&lt;/span&gt;( target,dirpath=&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.pwd)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#888&quot;&gt;## check if path valid&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; !&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.directory?(dirpath)  &lt;tt&gt;
&lt;/tt&gt;        puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;error first path&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;elsif&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.file?(target)&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;error :target is a file exist&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#888&quot;&gt;###&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.mkdir target &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exist? target&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Find&lt;/span&gt;.find dirpath &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |path|&lt;tt&gt;
&lt;/tt&gt;        path_lite=path.gsub(dirpath,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        target_path=(target+path_lite).gsub(&lt;span style=&quot;background-color:#fff0ff&quot;&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;[^a-zA-Z0-9&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\.&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\-&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\+&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\(&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\)&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\/&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;/span&gt;,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;).gsub(&lt;span style=&quot;background-color:#fff0ff&quot;&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;(__)+&lt;/span&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;/span&gt;,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;zhongwen&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.directory? path&lt;tt&gt;
&lt;/tt&gt;                &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.mkdir target_path&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;                &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;FileUtils&lt;/span&gt;.copy path,target_path&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;rescue&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#888&quot;&gt;# if type(path) != type(target_path)&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#888&quot;&gt;#            puts &amp;quot;waring: type unmatch, local=&amp;gt;#{path} is a #{type(path)},target=&amp;gt;#{target_path} is a #{type(target_path)}&amp;quot;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#888&quot;&gt;#            end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;everyting is ok&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;type&lt;/span&gt;(file)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exist? file&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.file? file&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;directory&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;dir_move(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;/Users/holin/bin2&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;/Users/holin/bin&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-10-15T16:54:14+08:00</created-at>
    <id type="integer">72</id>
    <title>&#22797;&#21046;&#25991;&#20214;&#24182;&#21435;&#38500;&#29305;&#27530;&#23383;&#31526;&#25991;&#20214;&#21517;</title>
    <updated-at type="datetime">2008-10-15T16:54:14+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body>&#19978;&#35838;&#21069;&#20020;&#26102;&#20889;&#30340;&#65292;&#22238;&#26469;&#21152;&#24378;&#12290;</body>
    <category>ruby</category>
    <code>##
##  this is design for calculate the totals line of code in your project
##  version 1 @october 8th,2008 
##
 

module Enumerable
  # function to get total lines for file
  def total_lines
    lines = 0
    each_with_index {|content,lines|}
    return lines+1
  end
end


class CheckLines
  require 'find'


  @check_type = %w{txt rb erb yml html css xml}
  def initialize(directory)
    @total_lines = 0
    if  File.directory?(directory)
          @directory = directory 
          @contents = {}
          self.go
    else puts &quot;#{directory} is not a directory! check it out!&quot; and return
    end
  end
  
  def go
    if @directory
      Find.find @directory do |path|
        pathlite = path.gsub(@directory,'')
        if File.file? path
          File.open path do |f|
              tmp_line = f.total_lines  
             @contents.store(pathlite,tmp_line) 
             @total_lines += tmp_line
          end
        end
      end
      puts @total_lines
    end
  end
  
  def details
    @contents.each do |key,value|
      puts &quot;#{key} file has lines of #{value}&quot;
    end
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;35&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;45&lt;tt&gt;
&lt;/tt&gt;46&lt;tt&gt;
&lt;/tt&gt;47&lt;tt&gt;
&lt;/tt&gt;48&lt;tt&gt;
&lt;/tt&gt;49&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;50&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;51&lt;tt&gt;
&lt;/tt&gt;52&lt;tt&gt;
&lt;/tt&gt;53&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#888&quot;&gt;##&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;##  this is design for calculate the totals line of code in your project&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;##  version 1 @october 8th,2008 &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;##&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;module&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;Enumerable&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#888&quot;&gt;# function to get total lines for file&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;total_lines&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    lines = &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    each_with_index {|content,lines|}&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt; lines&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;+1&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;CheckLines&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#33B&quot;&gt;@check_type&lt;/span&gt; = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;%w{&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;txt rb erb yml html css xml&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;initialize&lt;/span&gt;(directory)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#33B&quot;&gt;@total_lines&lt;/span&gt; = &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt;  &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.directory?(directory)&lt;tt&gt;
&lt;/tt&gt;          &lt;span style=&quot;color:#33B&quot;&gt;@directory&lt;/span&gt; = directory &lt;tt&gt;
&lt;/tt&gt;          &lt;span style=&quot;color:#33B&quot;&gt;@contents&lt;/span&gt; = {}&lt;tt&gt;
&lt;/tt&gt;          &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;self&lt;/span&gt;.go&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt; puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;directory&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; is not a directory! check it out!&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;and&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;go&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#33B&quot;&gt;@directory&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Find&lt;/span&gt;.find &lt;span style=&quot;color:#33B&quot;&gt;@directory&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |path|&lt;tt&gt;
&lt;/tt&gt;        pathlite = path.gsub(&lt;span style=&quot;color:#33B&quot;&gt;@directory&lt;/span&gt;,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.file? path&lt;tt&gt;
&lt;/tt&gt;          &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.open path &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |f|&lt;tt&gt;
&lt;/tt&gt;              tmp_line = f.total_lines  &lt;tt&gt;
&lt;/tt&gt;             &lt;span style=&quot;color:#33B&quot;&gt;@contents&lt;/span&gt;.store(pathlite,tmp_line) &lt;tt&gt;
&lt;/tt&gt;             &lt;span style=&quot;color:#33B&quot;&gt;@total_lines&lt;/span&gt; += tmp_line&lt;tt&gt;
&lt;/tt&gt;          &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      puts &lt;span style=&quot;color:#33B&quot;&gt;@total_lines&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;details&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#33B&quot;&gt;@contents&lt;/span&gt;.each &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |key,value|&lt;tt&gt;
&lt;/tt&gt;      puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;key&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; file has lines of &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;value&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-10-08T09:15:41+08:00</created-at>
    <id type="integer">71</id>
    <title>&#39033;&#30446;&#25991;&#20214;&#34892;&#25968;&#35745;&#31639;</title>
    <updated-at type="datetime">2008-10-08T09:15:41+08:00</updated-at>
    <user-id type="integer">11</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>sanitizer = HTML::FullSanitizer.new
sanitizer.sanitize(&quot;&lt;p&gt;This &lt;u&gt;is&lt;u&gt; a &lt;a href='test.html'&gt;&lt;strong&gt;test&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;&quot;)

sanitizer = HTML::LinkSanitizer.new
sanitizer.sanitize(&quot;&lt;a href='almost'&gt;on my mind&lt;/a&gt;\n&lt;A href='almost'&gt;all day long&lt;/A&gt;&quot;)
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;sanitizer = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;HTML&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;FullSanitizer&lt;/span&gt;.new&lt;tt&gt;
&lt;/tt&gt;sanitizer.sanitize(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&amp;lt;p&amp;gt;This &amp;lt;u&amp;gt;is&amp;lt;u&amp;gt; a &amp;lt;a href='test.html'&amp;gt;&amp;lt;strong&amp;gt;test&amp;lt;/strong&amp;gt;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;sanitizer = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;HTML&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;LinkSanitizer&lt;/span&gt;.new&lt;tt&gt;
&lt;/tt&gt;sanitizer.sanitize(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&amp;lt;a href='almost'&amp;gt;on my mind&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&amp;lt;A href='almost'&amp;gt;all day long&amp;lt;/A&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-09-26T18:14:56+08:00</created-at>
    <id type="integer">70</id>
    <title>sanitizer html in controller</title>
    <updated-at type="datetime">2008-09-26T18:14:56+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&#25918;&#21040;routes.rb&#30340;&#26368;&#21518;</body>
    <category>ruby</category>
    <code>twitter&#39118;&#26684;&#30340;url, http://xxx.com/devon
map.connect ':name', :controller =&gt; 'user', :action =&gt; 'show'

route&#25152;&#26377;path&#21040;&#26576;&#19968;&#20010;action
map.connect '*path' , :controller =&gt; 'blog' , :action =&gt; 'unrecognized'</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;twitter&#39118;&#26684;&#30340;url, http&lt;span style=&quot;color:#A60&quot;&gt;:/&lt;/span&gt;/xxx.com/devon&lt;tt&gt;
&lt;/tt&gt;map.connect &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;:name&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:controller&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:action&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;show&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;route&#25152;&#26377;path&#21040;&#26576;&#19968;&#20010;action&lt;tt&gt;
&lt;/tt&gt;map.connect &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;*path&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; , &lt;span style=&quot;color:#A60&quot;&gt;:controller&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;blog&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; , &lt;span style=&quot;color:#A60&quot;&gt;:action&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;unrecognized&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-09-18T09:50:54+08:00</created-at>
    <id type="integer">69</id>
    <title>twitter&#39118;&#26684;&#30340;url</title>
    <updated-at type="datetime">2008-09-18T09:51:57+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&amp;lt;span style=&quot;position: absolute; border: 1px solid; width: 110px; background-color: #f8f8f8; right: 10px;&quot; id=&quot;score_&amp;lt;%= @exam_user.id -%&amp;gt;&quot;&amp;gt;&amp;lt;%= render :partial =&amp;gt; &quot;score&quot;, :object =&amp;gt; @exam_user %&amp;gt;&amp;lt;/span&amp;gt;

</body>
    <category>ruby</category>
    <code>function fixed_to_right(element, top) {
	this.move_score_show = function(){
		var arr = document.viewport.getScrollOffsets();
		var x = arr[0];
		var y = arr[1] + top;
		element.setStyle({top: y + &quot;px&quot;});
	}
	new PeriodicalExecuter(this.move_score_show, 0.1);
}</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;function fixed_to_right(element, top) {&lt;tt&gt;
&lt;/tt&gt;        this.move_score_show = function(){&lt;tt&gt;
&lt;/tt&gt;                var arr = document.viewport.getScrollOffsets();&lt;tt&gt;
&lt;/tt&gt;                var x = arr[&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;];&lt;tt&gt;
&lt;/tt&gt;                var y = arr[&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt;] + top;&lt;tt&gt;
&lt;/tt&gt;                element.setStyle({top: y + &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;});&lt;tt&gt;
&lt;/tt&gt;        }&lt;tt&gt;
&lt;/tt&gt;        new PeriodicalExecuter(this.move_score_show, &lt;span style=&quot;color:#60E; font-weight:bold&quot;&gt;0.1&lt;/span&gt;);&lt;tt&gt;
&lt;/tt&gt;}&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-09-16T02:10:16+08:00</created-at>
    <id type="integer">68</id>
    <title>&#23450;&#20301;&#22312;&#27983;&#35272;&#22120;&#31383;&#21475;&#21491;&#36793;</title>
    <updated-at type="datetime">2008-09-16T02:12:34+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>require 'xmpp4r'
   
class Messager
    
    def initialize
        puts 'initialize'
        #Jabber::debug = true
        jid = Jabber::JID.new('alexys.cn@gmail.com')
        @client = Jabber::Client.new(jid)
        @client.connect
        @client.auth('&#215;&#215;&#215;&#215;&#215;')
        @client.send(Jabber::Presence.new.set_show(:chat).set_status('Rails!'))
    end

    def send(addr ,msg)
        sendto = addr       
        #to = 'hlxwell@gmail.com'
        subject = &quot;Kuxue task&quot;
        msgbody = msg
        mail = Jabber::Message::new(sendto, msgbody).set_type(:normal).set_id('1').set_subject(subject)
        @client.send mail
    end

end
a=Messager.new()
a.send(&quot;xhan87@gmail.com&quot;,'hello ,I am the bot')</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;xmpp4r&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;Messager&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;initialize&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;initialize&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#888&quot;&gt;#Jabber::debug = true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        jid = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Jabber&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;JID&lt;/span&gt;.new(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;alexys.cn@gmail.com&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#33B&quot;&gt;@client&lt;/span&gt; = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Jabber&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Client&lt;/span&gt;.new(jid)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#33B&quot;&gt;@client&lt;/span&gt;.connect&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#33B&quot;&gt;@client&lt;/span&gt;.auth(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&#215;&#215;&#215;&#215;&#215;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#33B&quot;&gt;@client&lt;/span&gt;.send(&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Jabber&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Presence&lt;/span&gt;.new.set_show(&lt;span style=&quot;color:#A60&quot;&gt;:chat&lt;/span&gt;).set_status(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;Rails!&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;))&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;send&lt;/span&gt;(addr ,msg)&lt;tt&gt;
&lt;/tt&gt;        sendto = addr       &lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#888&quot;&gt;#to = 'hlxwell@gmail.com'&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        subject = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;Kuxue task&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        msgbody = msg&lt;tt&gt;
&lt;/tt&gt;        mail = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Jabber&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Message&lt;/span&gt;::new(sendto, msgbody).set_type(&lt;span style=&quot;color:#A60&quot;&gt;:normal&lt;/span&gt;).set_id(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).set_subject(subject)&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#33B&quot;&gt;@client&lt;/span&gt;.send mail&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;a=&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Messager&lt;/span&gt;.new()&lt;tt&gt;
&lt;/tt&gt;a.send(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;xhan87@gmail.com&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;hello ,I am the bot&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-08-26T14:54:32+08:00</created-at>
    <id type="integer">67</id>
    <title>ruby&#36890;&#36807;XMPP&#21457;&#36865;&#21450;&#26102;&#20449;&#24687;</title>
    <updated-at type="datetime">2008-08-26T14:54:32+08:00</updated-at>
    <user-id type="integer">11</user-id>
  </cookbook>
  <cookbook>
    <body>&#30452;&#23545;&#21333;&#20010;&#21518;&#32512;&#30340;&#25991;&#20214;&#26377;&#29992;&#65292;&#23545;xxx.tar.gz&#22411;&#25991;&#20214;&#21517;&#38656;&#35201;&#20462;&#25913;
name.gsub! /^[^\.]+/, 'customed filename'</body>
    <category>ruby</category>
    <code>class QuestionAttachment &lt; ActiveRecord::Base
  belongs_to :question

  has_attachment :content_type =&gt; :image,
  :storage =&gt; :file_system, 
  :path_prefix =&gt; 'public/question_files'

  def sanitize_filename(filename)
    return unless filename
    returning filename.strip do |name| 

      name.gsub! /^[^\.]+/, 'customed filename'
    end
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;QuestionAttachment&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  belongs_to &lt;span style=&quot;color:#A60&quot;&gt;:question&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  has_attachment &lt;span style=&quot;color:#A60&quot;&gt;:content_type&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#A60&quot;&gt;:image&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#A60&quot;&gt;:storage&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#A60&quot;&gt;:file_system&lt;/span&gt;, &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#A60&quot;&gt;:path_prefix&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;public/question_files&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;sanitize_filename&lt;/span&gt;(filename)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; filename&lt;tt&gt;
&lt;/tt&gt;    returning filename.strip &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |name| &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;      name.gsub! &lt;span style=&quot;background-color:#fff0ff&quot;&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;^[^&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\.&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;]+&lt;/span&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;customed filename&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-08-14T02:15:43+08:00</created-at>
    <id type="integer">66</id>
    <title>&#33258;&#23450;&#20041;attachment_fu&#25554;&#20214;&#19978;&#20256;&#30340;&#25991;&#20214;&#21517;</title>
    <updated-at type="datetime">2008-08-14T02:15:43+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body>&#27809;&#24590;&#20040;&#20005;&#26684;&#27979;&#35797;&#12290;&#22079;&#22079;</body>
    <category>ruby</category>
    <code>require 'find'
require 'fileutils'
   
#   usage:   dir_move target-path (,local-path )
#   it will creat a directory if target-path is empty
#   TODO&#65306; add a option for u to choose whether replace everyting 
#   if local and target has same name but not the same type(file,directory)

def dir_move( target,dirpath=Dir.pwd)
    ## check if path valid
    if !File.directory?(dirpath)  
        puts &quot;error first path&quot;
        return
    elsif File.file?(target)
        puts &quot;error :target is a file exist&quot;
        return
    end
    ###
    Dir.mkdir target unless File.exist? target
    Find.find dirpath do |path|
        path_lite=path.gsub(dirpath,'')
        target_path=target+path_lite
        begin
            if File.directory? path
               Dir.mkdir target_path
            else
                FileUtils.copy path,target_path
            end
        rescue
            if type(path) != type(target_path)
            puts &quot;waring: type unmatch, local=&gt;#{path} is a #{type(path)},target=&gt;#{target_path} is a #{type(target_path)}&quot;
            end
        end
    end
    puts &quot;everyting is ok&quot;
end

def type(file)
    return unless File.exist? file
    if File.file? file
        &quot;file&quot;
    else
        &quot;directory&quot;
    end
end
</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;35&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;45&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;fileutils&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;#   usage:   dir_move target-path (,local-path )&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;#   it will creat a directory if target-path is empty&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;#   TODO&#65306; add a option for u to choose whether replace everyting &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;#   if local and target has same name but not the same type(file,directory)&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;dir_move&lt;/span&gt;( target,dirpath=&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.pwd)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#888&quot;&gt;## check if path valid&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; !&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.directory?(dirpath)  &lt;tt&gt;
&lt;/tt&gt;        puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;error first path&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;elsif&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.file?(target)&lt;tt&gt;
&lt;/tt&gt;        puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;error :target is a file exist&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#888&quot;&gt;###&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.mkdir target &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exist? target&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Find&lt;/span&gt;.find dirpath &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |path|&lt;tt&gt;
&lt;/tt&gt;        path_lite=path.gsub(dirpath,&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;        target_path=target+path_lite&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.directory? path&lt;tt&gt;
&lt;/tt&gt;               &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.mkdir target_path&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;                &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;FileUtils&lt;/span&gt;.copy path,target_path&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;rescue&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; type(path) != type(target_path)&lt;tt&gt;
&lt;/tt&gt;            puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;waring: type unmatch, local=&amp;gt;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;path&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; is a &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;type(path)&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;,target=&amp;gt;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;target_path&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; is a &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;type(target_path)&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;            &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    puts &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;everyting is ok&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;type&lt;/span&gt;(file)&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exist? file&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.file? file&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;directory&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-08-13T17:56:53+08:00</created-at>
    <id type="integer">65</id>
    <title>RUBY&#20889;&#30340; &#30446;&#24405;&#21450;&#25991;&#20214;&#22797;&#21046;&#20195;&#30721;</title>
    <updated-at type="datetime">2008-08-13T17:56:53+08:00</updated-at>
    <user-id type="integer">11</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>&#22312;Application.rb&#20013;&#65306;

def rescue_action(exception) 
  exception.is_a?(ActiveRecord::RecordInvalid) ? render_invalid_record(exception.record)  
end 
def render_invalid_record(record) 
  @invalid_record = record 
  respond_to do |format| 
    format.html do 
      render :action =&gt; (record.new_record? ? 'new' : 'edit') 
    end 
    format.js do 
      render :update do |page| 
        page.alert @invalid_record.errors.full_messages.join(&quot;\n&quot;) 
      end 
    end 
  end 
end

&#22312;controller&#20013;&#65306;
def create 
  #... 
  @news.save! 
  redirect_to news_path(@news) 
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#F00; background-color:#FAA&quot;&gt;&#22312;&lt;/span&gt;&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Application&lt;/span&gt;.rb&#20013;&#65306;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;rescue_action&lt;/span&gt;(exception) &lt;tt&gt;
&lt;/tt&gt;  exception.is_a?(&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;RecordInvalid&lt;/span&gt;) ? render_invalid_record(exception.record)  &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;render_invalid_record&lt;/span&gt;(record) &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#33B&quot;&gt;@invalid_record&lt;/span&gt; = record &lt;tt&gt;
&lt;/tt&gt;  respond_to &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |format| &lt;tt&gt;
&lt;/tt&gt;    format.html &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;      render &lt;span style=&quot;color:#A60&quot;&gt;:action&lt;/span&gt; =&amp;gt; (record.new_record? ? &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; : &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;edit&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    format.js &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;      render &lt;span style=&quot;color:#A60&quot;&gt;:update&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |page| &lt;tt&gt;
&lt;/tt&gt;        page.alert &lt;span style=&quot;color:#33B&quot;&gt;@invalid_record&lt;/span&gt;.errors.full_messages.join(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#F00; background-color:#FAA&quot;&gt;&#22312;&lt;/span&gt;controller&#20013;&#65306;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;create&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#888&quot;&gt;#... &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#33B&quot;&gt;@news&lt;/span&gt;.save! &lt;tt&gt;
&lt;/tt&gt;  redirect_to news_path(&lt;span style=&quot;color:#33B&quot;&gt;@news&lt;/span&gt;) &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-07-28T09:04:40+08:00</created-at>
    <id type="integer">64</id>
    <title>&#20195;&#30721;&#39564;&#35777;</title>
    <updated-at type="datetime">2008-07-28T09:05:29+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>rhtml</category>
    <code>&lt;% if flash[:warning] or flash[:notice] %&gt;  
  &lt;div id=&quot;flash_message&quot; &lt;% if flash[:warning] %&gt;class=&quot;warning&quot;&lt;% elsif flash[:notice] %&gt;class='notice'&lt;% end %&gt; &gt;  
    &lt;%= flash[:warning] || flash[:notice] %&gt;  
  &lt;/div&gt;  
  &lt;script type=&quot;text/javascript&quot;&gt;  
    setTimeout(&quot;new Effect.Fade('flash_message');&quot;, 4000)  
  &lt;/script&gt;  
&lt;% end %&gt;  </code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; flash[&lt;span style=&quot;color:#A60&quot;&gt;:warning&lt;/span&gt;] &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;or&lt;/span&gt; flash[&lt;span style=&quot;color:#A60&quot;&gt;:notice&lt;/span&gt;] &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#070&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color:#007&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;flash_message&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; flash[&lt;span style=&quot;color:#A60&quot;&gt;:warning&lt;/span&gt;] &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#007&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;warning&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;elsif&lt;/span&gt; flash[&lt;span style=&quot;color:#A60&quot;&gt;:notice&lt;/span&gt;] &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#007&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;notice&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#070&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%=&lt;/span&gt; flash[&lt;span style=&quot;color:#A60&quot;&gt;:warning&lt;/span&gt;] || flash[&lt;span style=&quot;color:#A60&quot;&gt;:notice&lt;/span&gt;] &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#070&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#070&quot;&gt;&amp;lt;script&lt;/span&gt; &lt;span style=&quot;color:#007&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;text/javascript&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;    setTimeout(&amp;quot;new Effect.Fade('flash_message');&amp;quot;, 4000)  &lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#070&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;  &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;  &lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-07-25T17:10:02+08:00</created-at>
    <id type="integer">63</id>
    <title>flash&#28040;&#24687;&#65292;4&#31186;&#21518;&#28040;&#22833;</title>
    <updated-at type="datetime">2008-07-25T17:10:11+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>namespace 'views' do
  desc 'Renames all your rhtml views to erb'
  task 'rename' do
    Dir.glob('app/views/**/*.rhtml').each do |file|
      puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`
    end
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;namespace &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;views&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  desc &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;Renames all your rhtml views to erb&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  task &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;rename&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Dir&lt;/span&gt;.glob(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;app/views/**/*.rhtml&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).each &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |file|&lt;tt&gt;
&lt;/tt&gt;      puts &lt;span style=&quot;background-color:#f0fff0&quot;&gt;&lt;span style=&quot;color:#161&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color:#2B2&quot;&gt;svn mv &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;file&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#2B2&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;file.gsub(&lt;span style=&quot;background-color:#fff0ff&quot;&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#04D&quot;&gt;\.&lt;/span&gt;&lt;span style=&quot;color:#808&quot;&gt;rhtml$&lt;/span&gt;&lt;span style=&quot;color:#404&quot;&gt;/&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;.html.erb&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#161&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-07-13T00:23:32+08:00</created-at>
    <id type="integer">62</id>
    <title>rake task: &#26356;&#25913;rhtml&#20026;html.erb</title>
    <updated-at type="datetime">2008-07-13T00:23:32+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>require 'benchmark'
 
n = 100000
Benchmark.bm do |x|
   x.report('copy') { n.times do ; h = {}; h = h.merge({1 =&gt; 2}); end }
   x.report('no copy') { n.times do ; h = {}; h.merge!({1 =&gt; 2}); end }
end
 
#          user        system      total        real
# copy     0.460000   0.180000   0.640000 (  0.640692)
# no copy  0.340000   0.120000   0.460000 (  0.463339)</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;benchmark&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt; &lt;tt&gt;
&lt;/tt&gt;n = &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;100000&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Benchmark&lt;/span&gt;.bm &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; |x|&lt;tt&gt;
&lt;/tt&gt;   x.report(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;copy&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;) { n.times &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; ; h = {}; h = h.merge({&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;2&lt;/span&gt;}); &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; }&lt;tt&gt;
&lt;/tt&gt;   x.report(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;no copy&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;) { n.times &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;do&lt;/span&gt; ; h = {}; h.merge!({&lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;2&lt;/span&gt;}); &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt; }&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;#          user        system      total        real&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# copy     0.460000   0.180000   0.640000 (  0.640692)&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# no copy  0.340000   0.120000   0.460000 (  0.463339)&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-07-11T09:19:15+08:00</created-at>
    <id type="integer">61</id>
    <title>Benchmark &#20195;&#30721;&#25928;&#29575;</title>
    <updated-at type="datetime">2008-07-11T09:19:15+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>Exam.paginate :conditions=&gt; [&quot;users.id = ?&quot;, @user_id], :page =&gt; params[:page], :include =&gt; {:exam_users =&gt; :user}</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Exam&lt;/span&gt;.paginate &lt;span style=&quot;color:#A60&quot;&gt;:conditions&lt;/span&gt;=&amp;gt; [&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;users.id = ?&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#33B&quot;&gt;@user_id&lt;/span&gt;], &lt;span style=&quot;color:#A60&quot;&gt;:page&lt;/span&gt; =&amp;gt; params[&lt;span style=&quot;color:#A60&quot;&gt;:page&lt;/span&gt;], &lt;span style=&quot;color:#A60&quot;&gt;:include&lt;/span&gt; =&amp;gt; {&lt;span style=&quot;color:#A60&quot;&gt;:exam_users&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#A60&quot;&gt;:user&lt;/span&gt;}&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-28T16:01:43+08:00</created-at>
    <id type="integer">60</id>
    <title>include&#22810;&#23545;&#22810;&#20851;&#31995;</title>
    <updated-at type="datetime">2008-06-28T16:01:43+08:00</updated-at>
    <user-id type="integer">2</user-id>
  </cookbook>
  <cookbook>
    <body>/usr/local/lib/ruby/gems/1.8/gems/mongrel-x.x.x/bin/mongrel_rails</body>
    <category>ruby</category>
    <code>if File.exist? defaults[:pid_file]
  # mongrels that crash can leave stale PID files behind, and these
  # should not stop mongrel from being restarted by monitors...
  pid = File.new(defaults[:pid_file]).readline
  unless `ps -ef | grep #{pid} | grep -v grep`.length &gt; 0
    # use &quot;ps ax&quot; for freebsd 
    log &quot;!!! PID file #{defaults[:pid_file]} exists, but is stale, and will be deleted so that this mongrel can run.&quot;
    File.delete(defaults[:pid_file])
  else
    log &quot;!!! PID file #{defaults[:pid_file]} already exists and the process id referred to in it is running.  This mongrel is probably already running.  #{defaults[:log_file]} for errors.  EXITING.&quot;
    exit 1
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exist? defaults[&lt;span style=&quot;color:#A60&quot;&gt;:pid_file&lt;/span&gt;]&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#888&quot;&gt;# mongrels that crash can leave stale PID files behind, and these&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#888&quot;&gt;# should not stop mongrel from being restarted by monitors...&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  pid = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.new(defaults[&lt;span style=&quot;color:#A60&quot;&gt;:pid_file&lt;/span&gt;]).readline&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;background-color:#f0fff0&quot;&gt;&lt;span style=&quot;color:#161&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color:#2B2&quot;&gt;ps -ef | grep &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;pid&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#2B2&quot;&gt; | grep -v grep&lt;/span&gt;&lt;span style=&quot;color:#161&quot;&gt;`&lt;/span&gt;&lt;/span&gt;.length &amp;gt; &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#888&quot;&gt;# use &amp;quot;ps ax&amp;quot; for freebsd &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    log &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;!!! PID file &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;defaults[&lt;span style=&quot;color:#A60&quot;&gt;:pid_file&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; exists, but is stale, and will be deleted so that this mongrel can run.&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.delete(defaults[&lt;span style=&quot;color:#A60&quot;&gt;:pid_file&lt;/span&gt;])&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    log &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;!!! PID file &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;defaults[&lt;span style=&quot;color:#A60&quot;&gt;:pid_file&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; already exists and the process id referred to in it is running.  This mongrel is probably already running.  &lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;defaults[&lt;span style=&quot;color:#A60&quot;&gt;:log_file&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; for errors.  EXITING.&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    exit &lt;span style=&quot;color:#00D; font-weight:bold&quot;&gt;1&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-27T15:41:49+08:00</created-at>
    <id type="integer">59</id>
    <title>mongrel&#37325;&#21551;&#26102;&#28165;&#38500;&#36807;&#26399;&#30340;pid_file</title>
    <updated-at type="datetime">2008-06-27T15:41:49+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>class Account &lt; ActiveRecord::Base
  ReservedSubdomains = %w[admin blog dev ftp mail pop pop3 imap smtp stage stats status www]
  validates_exclusion_of :subdomain, :in =&gt; ReservedSubdomains, :message =&gt; 'is not allowed'
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;Account&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ReservedSubdomains&lt;/span&gt; = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;%w[&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;admin blog dev ftp mail pop pop3 imap smtp stage stats status www&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  validates_exclusion_of &lt;span style=&quot;color:#A60&quot;&gt;:subdomain&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:in&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ReservedSubdomains&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:message&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;is not allowed&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-25T09:51:27+08:00</created-at>
    <id type="integer">58</id>
    <title>&#20445;&#30041;&#20108;&#32423;&#22495;&#21517;</title>
    <updated-at type="datetime">2008-06-25T09:51:27+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&lt;%= will_paginate @photos, :renderer =&gt; 'RemoteLinkRenderer' %&gt;</body>
    <category>ruby</category>
    <code># helpers/remote_link_renderer.rb

class RemoteLinkRenderer &lt; WillPaginate::LinkRenderer
  def page_link_or_span(page, span_class = 'current', text = nil)
    text ||= page.to_s
    if page and page != current_page
      @template.link_to_remote text, :url =&gt; url_for(page), :method =&gt; :get
    else
      @template.content_tag :span, text, :class =&gt; span_class
    end
  end
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#888&quot;&gt;# helpers/remote_link_renderer.rb&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;RemoteLinkRenderer&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;WillPaginate&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;LinkRenderer&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;page_link_or_span&lt;/span&gt;(page, span_class = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;current&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, text = &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;nil&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    text ||= page.to_s&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; page &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;and&lt;/span&gt; page != current_page&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#33B&quot;&gt;@template&lt;/span&gt;.link_to_remote text, &lt;span style=&quot;color:#A60&quot;&gt;:url&lt;/span&gt; =&amp;gt; url_for(page), &lt;span style=&quot;color:#A60&quot;&gt;:method&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#A60&quot;&gt;:get&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span style=&quot;color:#33B&quot;&gt;@template&lt;/span&gt;.content_tag &lt;span style=&quot;color:#A60&quot;&gt;:span&lt;/span&gt;, text, &lt;span style=&quot;color:#A60&quot;&gt;:class&lt;/span&gt; =&amp;gt; span_class&lt;tt&gt;
&lt;/tt&gt;    &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-13T14:44:55+08:00</created-at>
    <id type="integer">57</id>
    <title>will_paginate with ajax</title>
    <updated-at type="datetime">2008-06-13T14:44:55+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&#28982;&#21518;&#65292;&#22312;config&#20013;&#22686;&#21152;application.yml&#65292;&#22312;&#37324;&#38754;&#20197;YML&#26041;&#24335;&#20889;&#20837;&#37197;&#32622;&#65292;&#27604;&#22914;&#65306;
hello: &#8216;world&#8217;

&#21017;&#65292;&#22312;&#31243;&#24207;&#20013;&#65292;&#21487;&#20197;&#30452;&#25509;&#24341;&#29992;&#65306; AppConfig.hello&#12290;&#20063;&#21487;&#20197;&#22312;&#31243;&#24207;&#20013;&#23545;&#37197;&#32622;&#39033;&#36171;&#20540;&#65292;&#27604;&#22914; AppConfig.hello = &#8216;cool&#8217;</body>
    <category>ruby</category>
    <code># &#22312;config/initializers&#20013;&#26032;&#22686;&#25991;&#20214; app_config.rb

module ApplicationConfiguration
  require 'ostruct'
  require 'yaml'
  if File.exists?( File.join(RAILS_ROOT, 'config', 'application.yml') )
    file = File.join(RAILS_ROOT, 'config', 'application.yml')
    users_app_config = YAML.load_file file
  end

  ::AppConfig = OpenStruct.new users_app_config
end</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#888&quot;&gt;# &#22312;config/initializers&#20013;&#26032;&#22686;&#25991;&#20214; app_config.rb&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;module&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;ApplicationConfiguration&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;ostruct&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;yaml&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.exists?( &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.join(&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;RAILS_ROOT&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;application.yml&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;) )&lt;tt&gt;
&lt;/tt&gt;    file = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;File&lt;/span&gt;.join(&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;RAILS_ROOT&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;config&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;application.yml&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    users_app_config = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;YAML&lt;/span&gt;.load_file file&lt;tt&gt;
&lt;/tt&gt;  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  ::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;AppConfig&lt;/span&gt; = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;OpenStruct&lt;/span&gt;.new users_app_config&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-12T14:07:04+08:00</created-at>
    <id type="integer">56</id>
    <title>Rails&#20013;&#29992;YML&#37197;&#32622;&#39033;&#30446;</title>
    <updated-at type="datetime">2008-06-12T14:07:04+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body></body>
    <category>ruby</category>
    <code>require 'uri'
require 'cgi'

foo = &quot;http://google.com?query=hello&quot;

uri_good = URI.escape(foo, Regexp.new(&quot;[^#{URI::PATTERN::UNRESERVED}]&quot;))
cgi_good = CGI.escape(foo)


&#25110;&#32773;

require 'uri'
foo = &quot;http://google.com?query=hello&quot;

bad = URI.escape(foo)
good = URI.escape(foo, Regexp.new(&quot;[^#{URI::PATTERN::UNRESERVED}]&quot;))

bad_uri = &quot;http://mysite.com?service=#{bad}&amp;bar=blah&quot;
good_uri = &quot;http://mysite.com?service=#{good}&amp;bar=blah&quot;

puts bad_uri
# outputs &quot;http://mysite.com?service=http://google.com?query=hello&amp;bar=blah&quot;

puts good_uri
# outputs &quot;http://mysite.com?service=http%3A%2F%2Fgoogle.com%3Fquery%3Dhello&amp;bar=blah&quot;</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;uri&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;cgi&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;foo = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;http://google.com?query=hello&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;uri_good = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;URI&lt;/span&gt;.escape(foo, &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Regexp&lt;/span&gt;.new(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;[^&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;URI&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;PATTERN&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;UNRESERVED&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;))&lt;tt&gt;
&lt;/tt&gt;cgi_good = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;CGI&lt;/span&gt;.escape(foo)&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#F00; background-color:#FAA&quot;&gt;&#25110;&lt;/span&gt;&lt;span style=&quot;color:#F00; background-color:#FAA&quot;&gt;&#32773;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;uri&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;foo = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;http://google.com?query=hello&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;bad = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;URI&lt;/span&gt;.escape(foo)&lt;tt&gt;
&lt;/tt&gt;good = &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;URI&lt;/span&gt;.escape(foo, &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;Regexp&lt;/span&gt;.new(&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;[^&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;URI&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;PATTERN&lt;/span&gt;::&lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;UNRESERVED&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;))&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;bad_uri = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;http://mysite.com?service=&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;bad&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&amp;amp;bar=blah&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;good_uri = &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;http://mysite.com?service=&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;good&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;&amp;amp;bar=blah&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;puts bad_uri&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# outputs &amp;quot;http://mysite.com?service=http://google.com?query=hello&amp;amp;bar=blah&amp;quot;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;puts good_uri&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;color:#888&quot;&gt;# outputs &amp;quot;http://mysite.com?service=http%3A%2F%2Fgoogle.com%3Fquery%3Dhello&amp;amp;bar=blah&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-06-11T12:45:43+08:00</created-at>
    <id type="integer">55</id>
    <title>url escape</title>
    <updated-at type="datetime">2008-06-11T12:45:43+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
  <cookbook>
    <body>&#20854;&#23427;&#26041;&#26696;&#65306;

http://d.hatena.ne.jp/zariganitosh/20070613

http://script.aculo.us/docs/Ajax.InPlaceEditor.html

http://seb.box.re/2008/2/3/patch-for-inplaceeditor-adding-editonblank-feature
</body>
    <category>rhtml</category>
    <code>&lt;span id=&quot;name_&lt;%= @student.id %&gt;&quot;&gt;Name:&lt;/span&gt;
&lt;%= in_place_editor_field :student, :name, {}, :external_control =&gt; &quot;name_#{@student.id}&quot; %&gt;</code>
    <code-html>&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td class=&quot;line_numbers&quot; title=&quot;click to toggle&quot; onclick=&quot;with (this.firstChild.style) { display = (display == '') ? 'none' : '' }&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre ondblclick=&quot;with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }&quot;&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;lt;span&lt;/span&gt; &lt;span style=&quot;color:#007&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;name_&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span style=&quot;color:#33B&quot;&gt;@student&lt;/span&gt;.id &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#070&quot;&gt;&amp;gt;&lt;/span&gt;Name:&lt;span style=&quot;color:#070&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;color:black&quot;&gt;&amp;lt;%=&lt;/span&gt; in_place_editor_field &lt;span style=&quot;color:#A60&quot;&gt;:student&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:name&lt;/span&gt;, {}, &lt;span style=&quot;color:#A60&quot;&gt;:external_control&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;name_&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;&lt;span style=&quot;color:#33B&quot;&gt;@student&lt;/span&gt;.id&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color:black&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code-html>
    <created-at type="datetime">2008-05-21T11:11:14+08:00</created-at>
    <id type="integer">53</id>
    <title>in_place_editor_field: &#31354;&#20540;&#26102;&#30340;&#22788;&#29702;&#26041;&#24335;&#20043;&#19968;</title>
    <updated-at type="datetime">2008-05-21T11:51:41+08:00</updated-at>
    <user-id type="integer">1</user-id>
  </cookbook>
</cookbooks>
