<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[帐前卒专栏]]></title>
  <link href="http://chilly.github.com/atom.xml" rel="self"/>
  <link href="http://chilly.github.com/"/>
  <updated>2012-05-17T00:40:11+08:00</updated>
  <id>http://chilly.github.com/</id>
  <author>
    <name><![CDATA[chillycreator]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[上传大文件]]></title>
    <link href="http://chilly.github.com/blog/2012/05/16/shang-chuan-da-wen-jian/"/>
    <updated>2012-05-16T23:45:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/05/16/shang-chuan-da-wen-jian</id>
    <content type="html"><![CDATA[<p>今天解决了上传大文件问题。这个问题对于简单的web程序基本是不用关注的。不过需要考虑http超时和socket超时等情况。对于nginx代理跳转的web程序，需要在nginx中设置client_max_body_size 和 proxy_read_timeout这两个地方。前一个参数是http body size,例如你要上传10M的文件，你这里需要设置11M或者更大，因为http body中不光有文件的二进制信息。后者是设置proxy server与后端server的连接后等待返回的时间。例如后面使用的是JBoss那就是与JBOSS的连接。</p>

<p>确定问题比较容易。如果一个请求发生，但是后端Server没有打印access log.那就说明请求还没有到后端server，需要检查代理服务器的设置。如果请求写入access log,但是没有被server后端的webapp打印出log,一般说明在后端的server处挂掉，需要检查后端server的相应配置。当然也可能是webapp自己直接做了限制，例如设置如下类的参数</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>org.springframework.web.multipart.commons.CommonsMultipartResolver</span></code></pre></td></tr></table></div></figure>


<p>这里设置后会导致在<code>doFilter()</code>之后parseRequest时挂掉。如果看到报类似SizeLimit exception或者 max upload file exception,大概就是这里的问题。</p>

<p>最后要检测app代码中是否也有这些限制。以及检查client端socket timeout等情况。以下代码是针对client socket提前超时设置的。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>HttpParams params = new BasicHttpParams();
</span><span class='line'>HttpConnectionHttpParams.setConnectionTimeout(params,60000); // 连接超时1分钟
</span><span class='line'>HttpConnectionHttpParams.setSoTimeout(params, 60000); // socket 读取写入超时
</span><span class='line'>DefaultHttpClient client = new DefaultHttpClient(params);</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[cookie]]></title>
    <link href="http://chilly.github.com/blog/2012/05/11/cookie/"/>
    <updated>2012-05-11T01:26:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/05/11/cookie</id>
    <content type="html"><![CDATA[<p>Cookie的特性：</p>

<ul>
<li>首先分为3种cookie:

<ol>
<li>持久化cookie(persist cookie), 这种cookie有过期时间, 关掉浏览器还存在。</li>
<li>会话cookie(session cookie), 这种cookie没有过期时间，关掉浏览器就消失。</li>
<li>要被删除的cookie(deleted cookie). 这种cookie到达请求方就立即失效了。不会再带回服务器端。</li>
</ol>
</li>
<li>Cookie的domain一定要对。例如发送给note.youdao.com的cookie, domain可以是.note.youdao.com, 可以是.youdao.com.但是最好是.note.youdao.com, 否则有可能给其他的应用带去不必要的cookie, 增大传输量。</li>
<li>Cookie的path一定要对，如果在生成cookie时没有指明，那就是那个页面的当前路径。例如note.youdao.com/web/x.html 生成了cookie, 那路径就是/web, 再访问note.youdao.com/时，这个cookie不会被带上。只有/web以及/web的子路径可以得到该cookie.所以一般cookie的path设置为&#8221;/&#8221;.</li>
<li>Cookie是否是HTTP ONLY.这个对JS很重要。其实就是SET-COOKIE: header中加入了httponly的字段。但是HttpOnly的cookie, JS是拿不到的。在一定程度上保证安全。</li>
<li>永久cookie是跨进程的。当然chrome做到session cookie也跨进程(跨chrome进程)。永久cookie可以跨所有的进程。例如客户端用A帐号访问，web端用B帐号访问。客户端的永久cookie会带到web访问中。</li>
<li>JAVA的HttpClient或者其他httpClient库发送cookie到server时不会带上HTTPOnly或者domain信息，因为他们只有对的domain才会发送cookie. 但是如果server要做抹除客户端cookie的事情，那就必须在返回消息中发送除cookie value和过期时间不一致，其他都要一致的cookie才行。否则达不到抹除的目的。</li>
</ul>


<p> 就先写到这里。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[server 1.6 上线]]></title>
    <link href="http://chilly.github.com/blog/2012/05/11/server-1-dot-6-shang-xian/"/>
    <updated>2012-05-11T00:30:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/05/11/server-1-dot-6-shang-xian</id>
    <content type="html"><![CDATA[<p>今天server端上线，自己负责的两个server上线，一个更新了依赖，另外一个FIX了一个稳定性问题。当然变化最大的server很快就会上线。话说本产品的最大竞争对手入住中国，本以为有啥大事发生，后来发现只改了个名字。搞出一个中国公司这事情还要瞒着zzzz</p>

<p>然后今天晚上发现微博里好多活动的人。都有做server的潜质呀。</p>

<p>个人感觉还是不要加什么硬类型，什么硬编码，什么字段。map存储是扩展王道。当然弱类型肯定速度慢，但如果这里速度慢不是瓶颈，那不算什么问题。</p>

<p>这周解决的问题颇多，后来发现是自己遗留下的问题颇多。当初的设计想想都是很奇葩的。现在只能愈加奇葩。下个版本重构一下，遗留的能fix的就fix吧。</p>

<p>答辩终于结束，心里压力顿时小许多。filter呀filter, 整合入common吧～</p>

<p>明早倒休&#8230;.要睡到中午~~~~</p>

<p>好吧，有空出篇技术贴，现在写blog太水了。</p>

<p>Server上线还是没有一次成功。又出了各种小问题。这次主要是由于配置文件线上和milestone不同。以后要diff一下milestone的配置文件和online的配置文件。确认后再上线。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[新浪Oauth认证又改出bug...mismatch url]]></title>
    <link href="http://chilly.github.com/blog/2012/04/26/sina-oauth2/"/>
    <updated>2012-04-26T22:18:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/04/26/sina-oauth2</id>
    <content type="html"><![CDATA[<p>万恶的新浪呀～～～今天本来事情多，结果新浪Oauth2.0接口突然有变化。导致新浪用户无法使用有道云笔记登录，登录就会有mismatch url error。于是今天做hot fix. 一时找不出问题时，客户端登录不上去，但是web可以正常使用。然后经大师兄点拨，对比了一下两个访问新浪的url,终于发现了不同。原因在于某个新浪小白程序猿写程序出了bug。我的callback地址是四级域名（xx.xx.youdao.com）而新浪现在的接口即使绑定了域名，还是只支持三级域名(xx.youdao.com). 以前新浪的小白程序猿还写出来仅接受一个url参数的神奇程序，当然出现这个情况也在意料之中。我时常在想写新浪微博和写新浪微博openAPI的一定不是同一批人。最主要的是新浪更新或者新浪自己挂掉从来不通知开发者。这让人相当费解。只有不要传播谣言啥的专门给开发者发信&#8230;他们真有趣。</p>

<p>知道了原因，首先做hot fix.让新浪那边改，那难比登天呀。做第三方这事情还是QQ做得好些。Hot fix比较恶心，不推荐大家学习。虽然只改了一句code，但是是硬编码。Hot Fix之后，所有的客户端就能正常登录了。但是有道云笔记的页面会最终说..其实你没有认证成功的&#8230;.但是客户端的确是活着好好的。这是为啥&#8230;上了趟厕所，灵感来了。有道server完成了跳转，但是因为cookie的domain和callback的域名不一致。所以那个最终页面看到没有带来cookie呀，那肯定登录失败了。但是cookie被client端很好接收。所以也就可以完成登录和获取数据。这就是为啥登录失败了，但是客户端还活着好好的。</p>

<p>然后继续做Hot FIX.后来发现自己编来编去，还是太丑陋。直接叫运维做了一个跳转&#8230;然后客户端就活得好好的了。也不会出现登录失败页了。</p>

<p>今天大事小事都赶到一起了。做了一个TTT，本以为写得概括大家就都能听懂，结果大家都听得很朦胧。以后写ppt还是要写细致一些，还要写挑战和为什么要做这件事。嗯嗯，下次会更好..这又让我想到写论文&#8230;话说敏姐的致谢中大部分都是在赞美导师&#8230;这一定是怕不让毕业&#8230;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[svn diff]]></title>
    <link href="http://chilly.github.com/blog/2012/03/21/svn-diff/"/>
    <updated>2012-03-21T21:21:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/03/21/svn-diff</id>
    <content type="html"><![CDATA[<p>最近碰到了<code>svn merge</code>之后，再使用<code>svn diff</code>产生出来的patch中缺少某些文件的信息。后来发现了原因。使用<code>svn st</code>查看那些文件信息，类似于:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>A       src/aa.c
</span><span class='line'>A   +   src/bb.c
</span><span class='line'>M       src/cc.c</span></code></pre></td></tr></table></div></figure>


<p>这样输出的patch中，aa.c是信息是都有的。cc.c也是有的。但是bb.c的信息不存在。主要是存在那个<code>+</code>. <code>+</code>的意思是这些文件存在于提交历史中，所以该文件不能再次被diff.但是为什么会存在于提交历史中，这个我就不知道了。   <br/>
下面是教你如何去掉<code>+</code>.
使用下面的脚本会方便的去掉各个文件的<code>+</code>,对于目录的<code>+</code>是不能去掉的.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>#!/bin/sh
</span><span class='line'>plus_file=`svn st | grep "^A" | grep "+" | cut -d" " -f6`
</span><span class='line'>for i in $plus_file; do
</span><span class='line'>        if [ -d $i ]; then
</span><span class='line'>                echo "skip $i"
</span><span class='line'>        else
</span><span class='line'>                cp ${i} ${i}.back;
</span><span class='line'>                echo $i;
</span><span class='line'>                svn revert $i;
</span><span class='line'>                mv ${i}.back ${i};
</span><span class='line'>                svn add $i;
</span><span class='line'>        fi
</span><span class='line'>
</span><span class='line'>done;</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>上面脚本的工作原理是:
</span><span class='line'>cp src/bb.c src/bb.c.back
</span><span class='line'>svn revert src/bb.c
</span><span class='line'>mv src/bb.c.back src/bb.c
</span><span class='line'>svn add src/bb.c</span></code></pre></td></tr></table></div></figure>


<p>这样所有的<code>A +</code>状态就变为了<code>A</code>。这样再使用<code>svn diff</code>就可以得到完整的diff信息。如果有想法还可以处理一下文件夹。不过review code时，文件夹的意义并不大，所以就没有处理。这里顺便感谢下巧大牛。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[有道云笔记1.5正式版上线]]></title>
    <link href="http://chilly.github.com/blog/2012/02/23/you-dao-yun-bi-ji-1-dot-5zheng-shi-ban-shang-xian/"/>
    <updated>2012-02-23T02:08:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/23/you-dao-yun-bi-ji-1-dot-5zheng-shi-ban-shang-xian</id>
    <content type="html"><![CDATA[<p>今天晚上..或者说今天早上。反正是跨天的.有道云笔记1.5版本正式上线。开始时数据转换花了很长时间。后面基本没有出现什么大问题，主要是id不统一。整到两点钟才算正式搞好。明天早上就不准备去上班了.困&#8230;还是把这篇blog写完吧。</p>

<h4>问题：</h4>

<ol>
<li>其实测试环境下，还是不能测试出所有到问题。因为和线上的配置不一样。</li>
<li>其实组内改动什么设计问题，可能牵扯到几个人，但是做设计或者真正写代码的时候，其实不知道牵扯到谁。</li>
<li>web页面的文字链.其实没有提前做好。不知道为什么UI总是在临上线的时候才有。</li>
<li>技术先导的project,再让PM来设计.真的是比较痛苦。</li>
</ol>


<h4>新的功能：</h4>

<ol>
<li>客户端新浪微博帐号登录。其实根据现在的涉及还是有些bug的。比如打开两个授权页面，第一个页面其实已经不能再用来登录了。但是用户输入用户名密码还是会授权成功。至于为什么..我不告诉你～</li>
<li>锁屏&#8230;离线登录态&#8230;.还有啥就不知道了。</li>
<li>server端的设计有改动。</li>
<li>。。。。。</li>
</ol>


<h4>好了..该去睡觉了。</h4>

<p>另外今天上线的是有道云笔记1.5正式版&#8230;..比官方稿件快7-8个小时&#8230;
另外地址是<a href="http://note.youdao.com">有道云笔记1.5</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[windows c++程序迁移到linux]]></title>
    <link href="http://chilly.github.com/blog/2012/02/21/windows-c-plus-plus-cheng-xu-qian-yi-dao-linux/"/>
    <updated>2012-02-21T20:16:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/21/windows-c-plus-plus-cheng-xu-qian-yi-dao-linux</id>
    <content type="html"><![CDATA[<p>今天把程序从windows上迁移到了linux上。主要遇到到问题是: makeFile, lib库, compile error, 编码 encoding.</p>

<h4>make file</h4>

<p>这里其实可以使用eclipse中到cdt插件，然后就可以从eclipse中写c++。挺方便的，同时也解决了make file的问题。因为创建一个c++ 或者 c project，eclipse会自动创建一系列的makefile文件。所以让make file步骤简单无比。</p>

<h4>lib库和include库</h4>

<p>这里真的要注意/usr/include和/usr/lib中是否有你想要到文件。当然如果你是纯c++代码，可以尝试下只使用/usr/include/c++. 当如除了-L libpath, 还有-llibname, 这里的libname其实是libXXXX.so中的XXXX. 不过如果不会写，这里还是会费些劲。还有include路径要使用<code>-I</code>,每一个路径前都要有一个<code>-I</code>. 另外还要在eclipse run configurate中的environment中填入LD_LIBRARY_PATH,这个是你要调用的lib库（这个lib库如果不在/usr/lib中，那么就要手工将路径填入到LD_LIBRARY_PATH变量里）。并且在.bashrc中写：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:your_lib_path</span></code></pre></td></tr></table></div></figure>


<p></p>

<h4>编码</h4>

<p>因为windows上最常用到中文编码是GBK,而文件编码最常用到是utf-16el.这里最有可能会出错。在eclipse中或者gcc直接编译，都最好转换为UTF-8编码。文件也需要是UTF-8的编码。否则就会报&#8221;程序有游离的XXX, 忽略空字符&#8221;等诡异的错误。<a href="http://chillyc.info/blog/2012/02/20/jie-jue-cheng-xu-zhong-you-you-chi-de-slash-xxx-hu-lue-kong-zi-fu/">详见解决方法</a></p>

<h4>compile error</h4>

<p>这个可能就多种多样了。不过有c/c++基础的，应该大部分都可以搞定了。</p>

<p>如果使用eclipse, 直接build project就可以编译成功。然后找到main函数run就可以了。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[octopress error, rake generate]]></title>
    <link href="http://chilly.github.com/blog/2012/02/21/octopress-error/"/>
    <updated>2012-02-21T20:00:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/21/octopress-error</id>
    <content type="html"><![CDATA[<p>Today, I met the following problem. I wrote an article, and use <code>rake generate</code> to generate the site. Then the console reports:</p>

<blockquote><p>/home/chico/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse&#8217;: couldn&#8217;t parse YAML at line 3 column 17 (Psych::SyntaxError)</p></blockquote>


<p>why?   <br/>
Then I found the reason:</p>

<blockquote><p>&#8220;&#92;&#8221; should not be written in title of your article. If you really want to write it, use &#8220;&#92;&#92;&#8221;</p></blockquote>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[程序中有游离的\x,忽略空字符]]></title>
    <link href="http://chilly.github.com/blog/2012/02/20/jie-jue-cheng-xu-zhong-you-you-chi-de-slash-xxx-hu-lue-kong-zi-fu/"/>
    <updated>2012-02-20T13:32:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/20/jie-jue-cheng-xu-zhong-you-you-chi-de-slash-xxx-hu-lue-kong-zi-fu</id>
    <content type="html"><![CDATA[<p>今天解决了linux 环境中编译c++或者c文件时产生的错误。</p>

<blockquote><p>程序中有游离的&#8221;\xxx&#8221;<br/>忽略空字符</p></blockquote>


<p>以上两个错误，产生的原因和字符编码有关系。一般是文件从windows转移到linux下，然后使用c或者cc或者g++编译。产生了一系列的报警和错误信息。
解决方法如下：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>1. 使用vi打开报错的文件
</span><span class='line'>2. 查看其文件编码. 也就是用vi 查看encoding变量。":set fileencoding?" 
</span><span class='line'>3. 如果编码不是utf-8则转换为utf-8. 使用":set fileencoding=utf-8"
</span><span class='line'>4. 保存文件</span></code></pre></td></tr></table></div></figure>


<p>当然产生这种错误的原因还有可能是由于在代码里输入了全角字符引起的。如果上面的方法不对，还需要再进一步排查<code>cat -A filename</code>。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[xrange and range in python]]></title>
    <link href="http://chilly.github.com/blog/2012/02/13/xrange-and-range-in-python/"/>
    <updated>2012-02-13T20:14:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/13/xrange-and-range-in-python</id>
    <content type="html"><![CDATA[<h4>简单来说</h4>

<p>python range会生成一个list对象，然后返回list中的内容，而xrange不会生成list对象。所以xrange相对与range来说更省空间，并且速度较快。</p>

<p>在英文中的官方解释是：</p>

<blockquote><p>class xrange(object)<br/> |  xrange([start,] stop[, step]) -> xrange object<br/> |  <br/> |  Like range(), but instead of returning a list, returns an object that<br/> |  generates the numbers in the range on demand.  For looping, this is <br/> |  slightly faster than range() and more memory efficient.</p></blockquote>


<p>ok. Do you understand?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[build website in ubuntu]]></title>
    <link href="http://chilly.github.com/blog/2012/02/11/build-website-in-ubuntu/"/>
    <updated>2012-02-11T14:31:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/11/build-website-in-ubuntu</id>
    <content type="html"><![CDATA[<p>This article will tell you how to build a website in ubuntu system. First you should install apache and php. These two tools can help you to build a small website, like &#8220;hello world&#8221; websit:D</p>

<blockquote><p>// run the following commands<br/>sudo apt-get install apache2 php5 libapache2-mod-php5<br/>/etc/init.d/apache2 restart</p></blockquote>


<h4>important path</h4>

<p>Then you should remember the following paths:</p>

<blockquote><p>* /etc/init.d/apache2 <br/> * /var/www <br/> * /etc/apache2/apache2.conf<br/> * /etc/apache2/conf.d<br/> * /etc/apache2/sites-enabled</p></blockquote>


<p>  Apache&#8217;s default document root is /var/www on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d</p>

<h4>Test your php</h4>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>vi /var/www/hello.php</span></code></pre></td></tr></table></div></figure>


<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;?php
</span><span class='line'>phpinfo();
</span><span class='line'>?&gt;</span></code></pre></td></tr></table></div></figure>


<p>Then call this file in browser (http://localhost/hello.php)
DONE:D</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[machine learning]]></title>
    <link href="http://chilly.github.com/blog/2012/02/06/machine-learning/"/>
    <updated>2012-02-06T14:06:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/06/machine-learning</id>
    <content type="html"><![CDATA[<p>概率，贝叶斯，熵，条件熵。互信息<code>I(X,Y)=H(Y)-H(Y|X)</code>，两个变量之间的依赖度。
今天接触了一个新的概念：学习的本质是压缩。化为经典就是<code>大道至简</code>。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[jstack jmap resin]]></title>
    <link href="http://chilly.github.com/blog/2012/02/01/jstack-jmap-resin/"/>
    <updated>2012-02-01T20:41:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/02/01/jstack-jmap-resin</id>
    <content type="html"><![CDATA[<p>Today, I use <code>jstack</code>, <code>jmap</code>, and <code>resin</code> to look up why my server is deading in stress test. And I also find printing information into log is useful. You can print log in entrance of function and exit of function. <br/>
jstack is a tool which is looked up stack of system, specailly in threads. It is mainly for looking up dead lock and some functions which are executed too slowly.  <br/>
jmap is a tool which is looked up current memory of system or some memery jvm can not delete immediately.
You can use jstack like this:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>jstack -l [pid]</span></code></pre></td></tr></table></div></figure>


<p>If you know pid of the process, you can see what&#8217;s the situation of stacks in process. If you want to see the detail, looking at those stacks. <br/>
jmap is used like this:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>jmap -heap [pid]</span></code></pre></td></tr></table></div></figure>


<p>Today, Big niu Qiao tells me about JVM GC policy. <br/>
There are New Generation, Old Generate and Perm Generation in JVM. You can find them in jmap command. And New Generation are new objects. And Old Generation are old objects which are still be refered. Eden Space stores new generate objects. And From Space stores still alive objects after gc once. To space stores objects which are not refered and in From space before gc once. If an objects is in From Space many times, it will be moved to Old Generation by JVM. Perm Generation are static objects and Classes. <br/>
By the way, if your application runs in resin, you should look up those logs of resin, for example, jvm-default.log. The log file contains GC log information. If GC throws overMemory exception, you should modify your configuration of resin (resin.xml in resin4.0+). Modify or add:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;jvm-arg&gt;-Xmx1024&lt;/jvm-arg&gt;</span></code></pre></td></tr></table></div></figure>


<p>
This means set JVM heap space to 1G.</p>

<!-- more -->


<p>
今天使用了一下jstack, jmap来查看系统为啥在压力测试中缓慢的挂掉。我发现还是很有用的还有就是打log.函数入口和函数出口都打log。  <br/>
jstack是查看系统现在卡在那里，特别是各个线程在哪里，主要是排查死锁或者运行相当缓慢的函数。jmap是为了看系统的内存。当前使用的内存，以及jvm想删除却很久都没有删除的内存。  <br/>
jstack的使用方法如下</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>jstack -l [pid]</span></code></pre></td></tr></table></div></figure>


<p>只要知道pid,就能知道该进程现在的stack情况。具体排查就是看那些stack&#8230;</p>

<p>jmap的使用基本一致</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>jmap -heap [pid]</span></code></pre></td></tr></table></div></figure>


<p>今天继续听巧大牛讲JVM GC策略。
jmap中有New Generation 和Old Generation. 分别对应新生成的和很久都没有被释放的。Eden Space就是新生成的对象。而From Space是以前曾经存活的对象（一次GC之后，Eden区的对象都会转换为From区）。To Space是以前曾经存活的对象但是现在已经没有引用了（一次GC过后, Eden区全部对象和From区尚有引用的对象回全部放入到To区）。而对象如果一直在From区，就会被jvm放入到Old Generation中。
Old Generation是扫描一边标记，再扫一边回收，另外涉及到内存压缩云云。
Perm Generation是static对象和class  <br/>
另外如果运行在resin中，还是看看resin的各个log.例如jvm-default.log.这个log中有关于GC的信息。如果GC已经OverMemery了.那就不用找了，直接在resin的conf中的resin.xml中找到jvm参数修改-Xmx的值即可。例如改为<code>-Xmx1024</code>即为java将使用内存1G.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[git alias]]></title>
    <link href="http://chilly.github.com/blog/2012/01/31/git-alias/"/>
    <updated>2012-01-31T19:57:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/31/git-alias</id>
    <content type="html"><![CDATA[<p>今天唐大牛教了些git的命令。顺便把他的git别名也发给我了。啥叫别名，就是</p>

<blockquote><p>git br<br/>==><br/>git branch</p></blockquote>


<p>只需要在home目录下的.gitconfig文件中添加：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[alias]
</span><span class='line'>  st = status -s
</span><span class='line'>  ci = commit
</span><span class='line'>  l = log --oneline --decorate -13
</span><span class='line'>  ll = log --oneline --decorate
</span><span class='line'>  co = checkout
</span><span class='line'>  br = branch
</span><span class='line'>  rb = rebase
</span><span class='line'>  dci = dcommit</span></code></pre></td></tr></table></div></figure>


<p>以后就可以使用别名了。</p>

<!-- more -->


<p>Today, big tang teaches me some git commands. And he gives me his alias of git commands to me. What&#8217;s alias? That&#8217;s</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>git br
</span><span class='line'>==&gt;
</span><span class='line'>git branch
</span></code></pre></td></tr></table></div></figure>


<p>only write the following code in <code>~/.gitconfig</code> file.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[alias]
</span><span class='line'>  st = status -s
</span><span class='line'>  ci = commit
</span><span class='line'>  l = log --oneline --decorate -13
</span><span class='line'>  ll = log --oneline --decorate
</span><span class='line'>  co = checkout
</span><span class='line'>  br = branch
</span><span class='line'>  rb = rebase
</span><span class='line'>  dci = dcommit
</span></code></pre></td></tr></table></div></figure>


<p>And now you can use alias of git commands. Try <code>git br</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[孔府，孔庙，孔林]]></title>
    <link href="http://chilly.github.com/blog/2012/01/26/kong-fu-kong-miao-kong-lin/"/>
    <updated>2012-01-26T19:41:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/26/kong-fu-kong-miao-kong-lin</id>
    <content type="html"><![CDATA[<p>今天跟姐和姐夫逛了下曲阜。三孔很小的时候去过，现在基本什么记忆都没有了。当年好像破破烂烂。现在好像好一点了。很多翻修的痕迹，如果过去不砸，也就不用修了。跟着导游看了看，貌似只有题字有看的必要。翻修的有些差，就如同翻修的长城。    <br/>
在孔林里听说只要姓孔就可以埋到孔林里。孔老师看来很有希望&#8230;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[octopress deploy]]></title>
    <link href="http://chilly.github.com/blog/2012/01/25/octopress-deploy/"/>
    <updated>2012-01-25T23:23:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/25/octopress-deploy</id>
    <content type="html"><![CDATA[<p>octopress这东西还是很难弄的。这几天发生了各种git的异常。也不知道是怎么发生的。亦难解决。这stack overflow中查到都是中看不中用的东西。最后只好从github上再次clone下来。然后<code>git init</code>.这里要注意的是，octopress的home目录中其实是ignore <code>_deploy</code> 文件夹的。home 对应的是自己的source分支。而<code>_deploy</code>中才是master分支。    <br/>
<code>rake deploy</code> 其实是调用的<code>rake push</code>。其实是将<code>_public</code>中的内容copy到<code>_deploy</code>中。然后</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>cd _deploy
</span><span class='line'>git init
</span><span class='line'>git add .
</span><span class='line'>git add -u
</span><span class='line'>git commit -m "some time"
</span><span class='line'>git push -u origin master</span></code></pre></td></tr></table></div></figure>


<p>所以还是多看看octopress的内部实现比较好。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[octopress bugs]]></title>
    <link href="http://chilly.github.com/blog/2012/01/21/octopress-bugs/"/>
    <updated>2012-01-21T21:19:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/21/octopress-bugs</id>
    <content type="html"><![CDATA[<p><meta name="Keywords" content="octopress,bug,solve"/>
<meta name="Description" content="The page will show many octopress bugs. And tell you how to solve it."></p>

<p>Today, I have met a bug of octopress. When you write your blog with number in categories, like &#8220;cattegories: [some keyword, 2012]&#8221;.</p>

<p>When you type  <code>rake generate</code>. The command will report:</p>

<blockquote><p>/plugins/category_generator.rb:109:in `block in write_category_indexes`;: undefined method `gsub`; for 2012:Fixnum (NoMethodError)</p></blockquote>


<p> <br/>
It is caused by your number <code>2012</code>.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>vi plugins/category_generator.rb</span></code></pre></td></tr></table></div></figure>


<p>Go to line <code>109</code>. and add a line code:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>category = category.to_s</span></code></pre></td></tr></table></div></figure>


<p>Now, type <code>rake generate</code> again. It will be fine.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[back home]]></title>
    <link href="http://chilly.github.com/blog/2012/01/21/back-home/"/>
    <updated>2012-01-21T21:11:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/21/back-home</id>
    <content type="html"><![CDATA[<p>今天终于到家了。卧了一夜到火车。在六点多睡势良好的情况下被列车猿唤醒换票。另外卧铺车厢开灯太早了，并且关灯太晚了。 <br/>
回到家中吃吃喝喝，洗澡理发，不知不觉就到中午了。下午实在困，睡了一下午。晚上的时候家人一起玩玩UNO.感觉很好。教会了爸妈。UNO还是适合各种人群的。 <br/>
公司发的扑克牌，貌似只对懂外语的年轻人有效。对爸妈一点杀伤力都没有。下午还看了一下holmes.剧情还不错，根据现代场景改变的历史剧还是很有看头。 <br/>
晚上再研究一下wordpress导入。自己改的脚本还是多多少少有些问题。导致解析不成功。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[新浪Oauth]]></title>
    <link href="http://chilly.github.com/blog/2012/01/17/xin-lang-oauth/"/>
    <updated>2012-01-17T00:11:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/17/xin-lang-oauth</id>
    <content type="html"><![CDATA[<p><meta name="description" content="这篇文章是关于新浪Oauth认证上的一些经验">
新浪Oauth好像是上Oauth2.0了。不过也支持OAuth 1.0a.但是新浪的OAuth 1.0a是冒牌的。也就是说，应该是1.0～1.0a或者是真正到1.0 alpha.
因为这个Oauth不支持oauth_callback_confirm参数，也就是在request_token之后就仅仅返回oauth_token和oauth_secret.因为没有这个oauth_call_confirm,
也就无法区分Oauth到底是1.0的还是1.0a的。另外如果你真的照着OAuth1.0a的流程与新浪的接口整合。就会发现在获取authorized_token，还是要传给新浪
oauth_callback,否则新浪真的不知道callback到哪里去，于是新浪就展示给你获取oauth_verifier到页面,也就是授权码页面。</p>

<p><span class='pullquote-right' data-pullquote='所以请记住：国内就真的没有什么Oauth1.0a. '>
另外如果你真的加了oauth_callback,加入你的callback中没有参数，那谢天谢地，你的程序可以跑得很好。如果你的callback中有一个参数，那也谢天谢地，
你的程序可以跑得良好。如果你的callback中有更多到参数，那就别想跑得好了。因为新浪在某些情况下会丢参数。即使你将oauth_callback中的值整个用urlEncode编码一下（再使用替换个别字符转为Oauth特殊编码），也是有可能给你丢参数的。  <br/>
所以请记住：国内就真的没有什么Oauth1.0a.
另外传说腾讯Oauth的oauth_callback的特殊值不是oob, 而是null.  <br/>
所以最简单有效到方法是将oauth_callback值中的&#8217;&amp;&#8217;替换为&#8217;||&#8217;，将&#8217;=&#8217;替换为&#8217;|&#8217;.然后在callback之后的页面进行反编码。就可以得到自己想要到参数了。
新浪是从Oauth1.0进行改版到Oauth1.0a的。其实就仅仅做了oauth_verifier的生成。然后就真的啥事请都没有做。<br/>
</span></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[temp file, just test]]></title>
    <link href="http://chilly.github.com/blog/2012/01/16/test/"/>
    <updated>2012-01-16T20:43:00+08:00</updated>
    <id>http://chilly.github.com/blog/2012/01/16/test</id>
    <content type="html"><![CDATA[<p>This blog is just for octopress test. Not use <code>rake new_post</code>, just <code>vi source/_post/2012-01-16-test.markdown</code>. I want to see whether it works. <br/>
En, it works.</p>
]]></content>
  </entry>
  
</feed>

