<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>phun</title>
    <link>https://ruby-china.org/phun</link>
    <description>Do Fun!</description>
    <language>en-us</language>
    <item>
      <title>leet gem —— 程序员的黑话</title>
      <description>&lt;p&gt;程序员的黑话，把字母转成象形的，挺有意思的～&lt;/p&gt;

&lt;p&gt;leet 很好实现，但是 unleet 有些像 hash 的逆向，不知道能做到 100% 不？&lt;/p&gt;
&lt;h2 id="leet gem"&gt;&lt;a href="https://github.com/astonfu/leet" rel="nofollow" target="_blank" title=""&gt;leet gem&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A ruby gem that convert string to leet or unleet it.&lt;/p&gt;

&lt;p&gt;Every leet code only has a source char for unleet.&lt;/p&gt;

&lt;p&gt;Thanks to the leet table &lt;a href="https://zh.wikipedia.org/wiki/Leet" rel="nofollow" target="_blank" title=""&gt;on wikipedia&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="usage"&gt;usage&lt;/h2&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install leet
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="bin"&gt;bin&lt;/h2&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;leet &lt;span class="s2"&gt;"I Love Ruby!"&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;3y3 &lt;span class="o"&gt;[&lt;/span&gt;_&amp;lt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\|&lt;/span&gt;&amp;amp; /2&lt;span class="o"&gt;(&lt;/span&gt;_&lt;span class="o"&gt;)&lt;/span&gt;13&lt;span class="se"&gt;\|&lt;/span&gt;/!

&lt;span class="nv"&gt;$ &lt;/span&gt;leet &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="s1"&gt;'3y3 [_&amp;lt;&amp;gt;\|&amp;amp; /2(_)13\|/!'&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;i lovg rubwi
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="code"&gt;code&lt;/h2&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'leet'&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I Love Ruby!"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;leet&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; j 1_p\/|=- .-L|/3`/!&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"j 1_p&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="s2"&gt;|=- .-L|/3`/!"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unleet&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; i lo rubyi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="TODO"&gt;TODO&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;unleet 100% (Maybe it cannot be 100% for it like hash reverse.)&lt;/li&gt;
&lt;li&gt;han pinyin&lt;/li&gt;
&lt;/ul&gt;</description>
      <author>phun</author>
      <pubDate>Wed, 30 Dec 2015 11:38:09 +0800</pubDate>
      <link>https://ruby-china.org/topics/28567</link>
      <guid>https://ruby-china.org/topics/28567</guid>
    </item>
    <item>
      <title>关于"a=a+1"的思考</title>
      <description>&lt;h2 id="a = a + 1"&gt;a = a + 1&lt;/h2&gt;
&lt;p&gt;如上，在 irb 上中就执行上面的代码，那么结果是什么呢？&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;首先，a 被赋值为 nil。&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;然后，报错：&lt;strong&gt;NoMethodError: undefined method `+' for nil:NilClass&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;而我期望的是它会报&lt;strong&gt;NameError: undefined local variable or method `a' for main:Object&lt;/strong&gt;这样的错，然后停止对 a 赋值。&lt;/p&gt;

&lt;p&gt;我没有看过 ruby 代码，猜想当代码执行到那一句时，先是解释"a="，没有 a 这个变量，于是乎创建一个 a 并赋值 nil，然后在"a+1"时 a 就是 nil。&lt;/p&gt;

&lt;p&gt;上面的想法可以通过执行&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;nil?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;来验证，会返回 true。&lt;/p&gt;

&lt;p&gt;那么它带来的问题是当我在一个类中，想对一个方法的返回值进行处理然后赋值给同名的变量时，就会报错了。&lt;/p&gt;

&lt;p&gt;有点儿绕口，看代码：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;C&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_wrong&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_right&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;a&lt;/span&gt;          &lt;span class="c1"&gt;#=&amp;gt; 1&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_wrong&lt;/span&gt;  &lt;span class="c1"&gt;#=&amp;gt; NoMethodError: undefined method `+' for nil:NilClass&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_right&lt;/span&gt;  &lt;span class="c1"&gt;#=&amp;gt; 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;摘自：&lt;a href="http://fuhao.im/2014/05/08/ruby-tips.html" rel="nofollow" target="_blank" title=""&gt;http://fuhao.im/2014/05/08/ruby-tips.html&lt;/a&gt;.&lt;/p&gt;</description>
      <author>phun</author>
      <pubDate>Fri, 05 Jun 2015 16:53:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/25902</link>
      <guid>https://ruby-china.org/topics/25902</guid>
    </item>
    <item>
      <title>CStock：一个抓取股票交易信息的 gem</title>
      <description>&lt;p&gt;最近股票比较热，之前写的一个 gem，拿来分享，还不太成熟但是 it works，源码在&lt;a href="https://github.com/astonfu/cstock" rel="nofollow" target="_blank" title=""&gt;https://github.com/astonfu/cstock&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="cstock"&gt;cstock&lt;/h2&gt;
&lt;p&gt;Quote chinese stock infomation.&lt;/p&gt;

&lt;p&gt;It crawl infomation from "hq.sinajs.cn/list=", and include the below info:&lt;/p&gt;

&lt;p&gt;股票代码 股票名 开盘价 昨日收盘价 当前价 今日最高 今日最低 买一价 卖一价 成交量 成交额&lt;/p&gt;

&lt;p&gt;买一挂单 买一价 买二挂单 买二价 买三挂单 买三价 买四挂单 买四价 买五挂单 买五价&lt;/p&gt;

&lt;p&gt;卖一挂单 卖一价 卖二挂单 卖二价 卖三挂单 卖三价 卖四挂单 卖四价 卖五挂单 卖五价&lt;/p&gt;

&lt;p&gt;日期 时间&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;as&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;code name open_price yesterday_close_price current_price high_price low_price bid_price ask_price volume turnover&lt;/p&gt;

&lt;p&gt;bid_volume_1 bid_price_1 bid_volume_2 bid_price_2 bid_volume_3 bid_price_3 bid_volume_4 bid_price_4 bid_volume_5 bid_price_5&lt;/p&gt;

&lt;p&gt;ask_volume_1 ask_price_1 ask_volume_2 ask_price_2 ask_volume_3 ask_price_3 ask_volume_4 ask_price_4 ask_volume_5 ask_price_5&lt;/p&gt;

&lt;p&gt;date time&lt;/p&gt;
&lt;h2 id="usage"&gt;usage&lt;/h2&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;cstock&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'cstock'&lt;/span&gt;

&lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CStock&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'600000'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;  &lt;span class="c1"&gt;#=&amp;gt; 浦发银行&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;股票名&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; 浦发银行&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;open_price&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; 16.00&lt;/span&gt;

&lt;span class="c1"&gt;# wrong stock code, its attrs will be nil&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CStock&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'错误的'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;   &lt;span class="c1"&gt;#=&amp;gt; nil&lt;/span&gt;

&lt;span class="c1"&gt;# refresh data&lt;/span&gt;
&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh&lt;/span&gt;

&lt;span class="c1"&gt;# refresh multi stocks at one quote&lt;/span&gt;
&lt;span class="no"&gt;CStock&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;stock1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stock2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Read spec for more usage.&lt;/p&gt;
&lt;h2 id="in terminal"&gt;in terminal&lt;/h2&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;% cstock 600000

股票代码 : 600000
股票名 : 浦发银行
开盘价 : 16.00
收盘价 : 16.18
当前价 : 16.20
今日最高 : 16.29
今日最低 : 15.93
买一价 : 16.20
卖一价 : 16.21
成交量 : 320361507
成交额 : 5171219071
买一挂单 : 12400
买一价 : 16.20
买二挂单 : 532100
买二价 : 16.19
买三挂单 : 815459
买三价 : 16.18
买四挂单 : 574500
买四价 : 16.17
买五挂单 : 358300
买五价 : 16.16
卖一挂单 : 773560
卖一价 : 16.21
卖二挂单 : 1226841
卖二价 : 16.22
卖三挂单 : 1063620
卖三价 : 16.23
卖四挂单 : 1037567
卖四价 : 16.24
卖五挂单 : 2292649
卖五价 : 16.25
日期 : 2015-04-03
时间 : 15:04:04
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>phun</author>
      <pubDate>Wed, 03 Jun 2015 15:35:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/25867</link>
      <guid>https://ruby-china.org/topics/25867</guid>
    </item>
    <item>
      <title>部署后 gem 不能使用，但本地正常 (已解决)</title>
      <description>&lt;p&gt;环境：ubuntu + nginx + unicron + rbenv，用 capistrano2 部署。
在 Gemfile 里添加 gem "chartkick"后，在本地一切正常，可部署到服务器，访问页面就报 500 错误，看 log 显示：&lt;/p&gt;

&lt;p&gt;ActionView::Template::Error (undefined method `line_chart' for #&amp;lt;&lt;a rel="nofollow" target="_blank"&gt;Class:0x007fd31f771f88&lt;/a&gt;:0x007fd3223b0c48&amp;gt;):&lt;/p&gt;

&lt;p&gt;就是那个 gem 里的方法不能使用，但是在 server 下用 bundle show 能看到那个 gem。
 bundle install，rbenv rehash 也不行。
经测试新加入的 gem 都不能在 server 上使用，旧的都 ok。
请教是怎么回事？谢谢！&lt;/p&gt;</description>
      <author>phun</author>
      <pubDate>Sun, 05 Jan 2014 02:00:19 +0800</pubDate>
      <link>https://ruby-china.org/topics/16631</link>
      <guid>https://ruby-china.org/topics/16631</guid>
    </item>
  </channel>
</rss>
