<rss version="2.0">
<channel>
  <title>zouchao</title>
  <link>http://zouchao.me</link>
  
  <item>
    <title>记录一次mysql升级之后rails遇到的问题</title>
    <description>&lt;p&gt;mysql升级之后数据文件夹共用, 但是无法使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db:migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;错误信息大致如下：&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2019&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;02&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;T11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;06&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;23.650106&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#68912] ERROR -- : Mysql2::Error: Table 'performance_schema.session_variables' doesn't exist: SHOW VARIABLES LIKE 'character_set_database'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rake&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aborted!&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;StatementInvalid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mysql2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Table&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'performance_schema.session_variables'&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;doesn&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'t exist: SHOW VARIABLES LIKE '&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;character_set_database&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;解决方式：&lt;/p&gt;
&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mysql_upgrade &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; 用户名 &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;然后一定记得重启mysql服务&lt;/p&gt;
</description>
    <published>2019-02-14T11:14:12+00:00</published>
    <link>http://zouchao.me/2019/02/14/record-the-mysql-upgrade</link>
  </item>
  
  <item>
    <title>给终端设置代理</title>
    <description>&lt;p&gt;如下是初级工程师Bob和老程序员Bill的又一个故事。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Bob：我这&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;golang&lt;/code&gt;装个包太困难了。动不动就&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;time out&lt;/code&gt;&lt;br /&gt;
Bill：开代理啊&lt;br /&gt;
Bob：开了，我有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shadowsocks&lt;/code&gt;, 而且我开了全局代理.&lt;br /&gt;
Bill: 那你一定是没有给你的终端设置&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http&lt;/code&gt;代理。ss设置的系统代理是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;socks5&lt;/code&gt;代理, 给你一个教程吧!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;教程&quot;&gt;教程&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;首先找到ss里面的HTTP Proxy Preference, 如下图：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fvmpbmzbm5j207l0dldgk.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;然后查看你的端口：&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fvmpcgrot0j20hu0ietax.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.bashrc&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.zshrc&lt;/code&gt;中加入如下代码:
    &lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# alias for proxy&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;alias &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;proxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;export http_proxy=http://127.0.0.1:1087 &amp;amp;&amp;amp; export https_proxy=http://127.0.0.1:1087&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;alias &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;unproxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;unset http_proxy &amp;amp;&amp;amp; unset https_proxy&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;alias &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ip&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;curl https://ip.cn&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;检查是否使用代理&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fvmw5i1ngnj20hy0833zh.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
</description>
    <published>2018-09-25T09:45:08+00:00</published>
    <link>http://zouchao.me/2018/09/25/set-proxy-for-iterm</link>
  </item>
  
  <item>
    <title>Go语言如何实现单例模式</title>
    <description>&lt;p&gt;单例模式是常见的设计模式，被广泛用于创建数据库，redis等单实例。作用在于可以控制实例个数节省系统资源&lt;/p&gt;

&lt;h2 id=&quot;特点&quot;&gt;特点：&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;保证调用多次，只会产生单个实例&lt;/li&gt;
  &lt;li&gt;全局访问&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;单例的分类&quot;&gt;单例的分类&lt;/h2&gt;
&lt;p&gt;单例模式大致分为2大类:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;懒汉式: 指全局的单例实例在第一次被使用时构建。&lt;/li&gt;
  &lt;li&gt;饿汉式: 指全局的单例实例在类装载时构建。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;synconce&quot;&gt;sync.Once&lt;/h2&gt;
&lt;p&gt;这里我们不做一步一步的演进，哪种好，哪种不好见仁见智。我们来看看golang中如何实现单例模式:&lt;/p&gt;
&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;once&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sync&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Once&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetIns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;once&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ins&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ins&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;synconce源码解读&quot;&gt;sync.Once源码解读&lt;/h2&gt;
&lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sync&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Once&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Mutex&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;done&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;uint32&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Once&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomic&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LoadUint32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 	&lt;span class=&quot;c&quot;&gt;// 保证原子性操作，加载标记，如果存在直接返回&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// Slow-path.&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Lock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 					&lt;span class=&quot;c&quot;&gt;// 加锁进一步保证f()方法只能被执行一次&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Unlock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;done&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;defer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomic&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StoreUint32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 	&lt;span class=&quot;c&quot;&gt;// 设置标志&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;					&lt;span class=&quot;c&quot;&gt;// 注意：如果f()内部报错，sync.Once仍然不会执行第二次&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <published>2018-04-11T14:11:35+00:00</published>
    <link>http://zouchao.me/2018/04/11/golang-singleton</link>
  </item>
  
  <item>
    <title>Go语言学习笔记</title>
    <description>&lt;h3 id=&quot;golang基础&quot;&gt;Golang基础&lt;/h3&gt;

&lt;h4 id=&quot;一-变量常量&quot;&gt;一. 变量、常量&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;内置支持utf8编码
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, world or 你好，世界 or καλημ ́ρα κóσμ or こんにちはせかい&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_&lt;/code&gt;下划线是个特殊的变量名，任何赋予它的值都会被丢弃。
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;34&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;35&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;在方法 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;func&lt;/code&gt; 内申明的变量必须使用，全局变量则不用，但是尽量不要定义不使用的变量&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;常量的定义最好都大写，虽然不做强制要求，但保持好的习惯&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;常量声明省略值时，默认和之前一个值的字面相同。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;分组申明常量时&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iota&lt;/code&gt;，的值表示为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const的行数的值,从0开始&lt;/code&gt;
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt;             &lt;span class=&quot;c&quot;&gt;//a=0&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;B&quot;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt;             &lt;span class=&quot;c&quot;&gt;//c=2&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;//d=3,e=3,f=3&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;iota&lt;/span&gt;             &lt;span class=&quot;c&quot;&gt;//g = 4&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;二-内置基础类型&quot;&gt;二. 内置基础类型&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;整数类型有无符号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint&lt;/code&gt;和带符号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;两种。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rune&lt;/code&gt;是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int32&lt;/code&gt;的别称，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byte&lt;/code&gt;是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uint8&lt;/code&gt;的别称。&lt;/li&gt;
  &lt;li&gt;整数类型位数对应表
    &lt;blockquote&gt;
      &lt;table&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th&gt;类型名称&lt;/th&gt;
            &lt;th&gt;有无符号&lt;/th&gt;
            &lt;th&gt;bit数&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
          &lt;tr&gt;
            &lt;td&gt;int8&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;8&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;int16&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;16&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;int32&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;32&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;int64&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;64&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uint8&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;8&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uint16&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;16&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uint32&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;32&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uint64&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;64&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;int&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;等于cpu位数&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uint&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;等于cpu位数&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;rune&lt;/td&gt;
            &lt;td&gt;Yes&lt;/td&gt;
            &lt;td&gt;与 int32 等价&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;byte&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;与 uint8 等价&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;uintptr&lt;/td&gt;
            &lt;td&gt;No&lt;/td&gt;
            &lt;td&gt;-&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;不同类型的变量之间不允许互相赋值或操作
    &lt;blockquote&gt;

      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int8&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int32&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
      &lt;p&gt;另外，尽管int的长度是32 bit, 但int 与 int32并不可以互用。&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;字符串不允许使用单引号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;在Go中字符串是不可以直接修改的
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;hello&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'c'&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;// 报错: cannot assign to s[0]&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;// 如果硬要修改可如下方式：&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;// 1. 将字符串 s 转换为 []byte 类型&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;'c'&lt;/span&gt;                 &lt;span class=&quot;c&quot;&gt;// 或者c[0] = 99, 单引号 == ASCII码值&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;            &lt;span class=&quot;c&quot;&gt;// 再转换回 string 类型&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;     &lt;span class=&quot;c&quot;&gt;// cello&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;// 2. 通过+号连接2个字符串&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;c&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;            &lt;span class=&quot;c&quot;&gt;// 字符串虽不能更改，但可进行切片操作&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;      &lt;span class=&quot;c&quot;&gt;// cello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;`&lt;/code&gt; 括起的字符串为Raw字符串，即字符串在代码中的形式就是打印时的形式，它没有字符转义，换行也将原样输出。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;数组的长度是固定的，不可改变
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;// 声明了一个长度为3的int数组&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;数组作为参数传递的时候是传递的副本，而不是它的指针, 而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;slice&lt;/code&gt;可以传递指针&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;array[i:j]&lt;/code&gt;的长度是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;j - i&lt;/code&gt;
    &lt;blockquote&gt;
      &lt;div class=&quot;language-go highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;// 声明一个含有10个元素元素类型为byte的数组&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;f&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;g&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;h&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;i&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;j&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;// 声明两个含有byte的slice&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;// a指向数组的第3个元素开始，并到第五个元素结束，&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;//现在a含有的元素: ar[2]、ar[3]和ar[4]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;// output: [c d e]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;slice&lt;/code&gt;总是指向一个底层&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;array&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt;和其他基本型别不同，它不是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;thread-safe&lt;/code&gt;，在多个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go-routine&lt;/code&gt;存取时，必须使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mutex lock&lt;/code&gt;机制&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;用于内建类型（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;slice&lt;/code&gt; 和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;channel&lt;/code&gt;）的内存分配。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;用于各种类型的内存分配。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt;返回指针&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;返回初始化后的（非零）值&lt;/li&gt;
&lt;/ol&gt;
</description>
    <published>2018-03-14T11:00:12+00:00</published>
    <link>http://zouchao.me/2018/03/14/Golang-study-notes</link>
  </item>
  
  <item>
    <title>如何使用Visual Studio Code调试Golang程序</title>
    <description>&lt;p&gt;最近想玩玩golang，同事安利了一个编辑器&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Visual Studio Code&lt;/code&gt;, 是用nodejs开发的，用起来十分趁手,如何配置golang的环境就不表了，网上帖子一大把，自行查阅。&lt;/p&gt;

&lt;p&gt;今天只说说如何用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VSCode&lt;/code&gt;的debug模式调试&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Golang&lt;/code&gt;：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;在VSCode中打开你的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package main&lt;/code&gt;的文件&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(Shift) ⇧ + (Command) ⌘ + D&lt;/code&gt;呼出&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debug&lt;/code&gt;侧边栏&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;点击绿色三角形符号的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Start Debugging&lt;/code&gt;按钮&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;第一次使用VSCode会自动判断你的语言类型，生产如下的一个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;launch.josn&lt;/code&gt;文件
&lt;img src=&quot;https://ww1.sinaimg.cn/large/6a629b92gy1fluf8ejfztj21r41asan3.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;成功之后会在你所在的项目目录下生产如下2个文件
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;debug
.vscode/launch.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git status&lt;/code&gt;也能看到他们，所以别忘了把他们加到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.gitignore&lt;/code&gt;文件中去哦
&lt;img src=&quot;https://ww1.sinaimg.cn/large/6a629b92gy1flufndpw0fj211w0vcag6.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;当然你也有可能和我一样遇到如下问题&quot;&gt;当然你也有可能和我一样遇到如下问题：&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2017/11/24 15:34:15 server.go:73: Using API v1
2017/11/24 15:34:15 debugger.go:96: launching process with args: [/Users/sean/Code/Go/src/go_bms_web/debug]
could not launch process: exec: &quot;lldb-server&quot;: executable file not found in $PATH
Process exiting with code: 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;没关系，在terminal中执行如下语句，就可以了&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;xcode-select --install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <published>2017-11-23T11:00:12+00:00</published>
    <link>http://zouchao.me/2017/11/23/Golang-debug-mode-for-Visual-Studio-Code</link>
  </item>
  
  <item>
    <title>after_save和after_commit使用的误区</title>
    <description>&lt;blockquote&gt;
  &lt;p&gt;Callbacks are methods that get called at certain moments of an object’s life cycle. With callbacks it is possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;以上是&lt;a href=&quot;http://guides.rubyonrails.org/active_record_callbacks.html&quot;&gt;RailsGuides&lt;/a&gt;对&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActiveRecord&lt;/code&gt;的回调的解释，大致意思是：&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;回调是在对象生命周期的特定时刻执行的方法。回调方法可以在 Active Record 对象创建、保存、更新、删除、验证或从数据库中读出时执行。&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;我们有很多场景都会用到，但是某些情况你可能会发现其实他们也没有你想象中那么好用，比如说，你有一个问答网站，并希望所有的问题都能被搜索到，为了搜索的效率你又引入了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ElasticSearch&lt;/code&gt;，es的数据需要索引，而为了构建索引的效率以及实时性，你又引入了sidekiq。听起来很复杂，其实这种比你想象中要常见的多。&lt;/p&gt;

&lt;p&gt;而此时视乎是使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_save&lt;/code&gt;的绝佳时机，因此，在你的模型中，你大概会这样写：&lt;/p&gt;

&lt;div class=&quot;file_title&quot;&gt;
  app/models/question.rb
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
class Question &amp;lt; ActiveRecord::Base
  after_save :index_for_search

  # ...

  private

  def index_for_search
    QuestionIndexerJob.perform_later(self)
  end
end
&lt;/pre&gt;
&lt;div class=&quot;file_title&quot;&gt;
app/jobs/question_indexer_job.rb
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
class QuestionIndexerJob &amp;lt; ActiveJob::Base
  queue_as :default

  def perform(question)
    # ... index the question ...
  end
end
&lt;/pre&gt;
&lt;p&gt;到这看起来似乎都是完美的。直到你查看你的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq&lt;/code&gt;日志，看到这些错误显示：&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-log&quot;&gt;2015-03-10T05:29:02.881Z 52530 TID-oupf889w4 WARN: Error while trying to deserialize arguments: Couldn't find Question with 'id'=3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;当然&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq&lt;/code&gt;里面可以使用重试机制，让索引构建成功，但是发生这样的错误还是很怪异，对吧？&lt;/p&gt;

&lt;h4 id=&quot;多线程和多进程的错&quot;&gt;多线程和多进程的错&lt;/h4&gt;
&lt;p&gt;其实此处的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq&lt;/code&gt;相当于形成了一个多进程来执行查询，是的sidekiq是单独的进程在运行。而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_save&lt;/code&gt;执行回调时，事物并没有提交。此时在另一个进程中运行的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq&lt;/code&gt;自然也就查询不到数据。&lt;/p&gt;

&lt;p&gt;是的，我们自然而然的应该想到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActiveRecord&lt;/code&gt;的另外一个关于事物的回调&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_commit&lt;/code&gt;，修改模型：&lt;/p&gt;
&lt;div class=&quot;file_title&quot;&gt;
  app/models/question.rb
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
class Question &amp;lt; ActiveRecord::Base
  after_commit :index_for_search, on: [:create, :update]

  # ...
end
&lt;/pre&gt;

&lt;p&gt;再观察&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sidekiq&lt;/code&gt;日志，发现问题确实解决了。完美&lt;/p&gt;

&lt;h3 id=&quot;高兴太早还有一个问题&quot;&gt;高兴太早，还有一个问题&lt;/h3&gt;

&lt;p&gt;当你是用了一堆&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_commit&lt;/code&gt;来替换&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_save&lt;/code&gt;之后，接下来我们运行一下测试：&lt;/p&gt;

&lt;div class=&quot;file_title&quot;&gt;
  test/models/question_test.rb
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
require 'test_helper'

class QuestionTest &amp;lt; ActiveSupport::TestCase
  test &quot;A saved question is queued for indexing&quot; do
    assert_enqueued_with(job: QuestionIndexerJob) do
      Question.create(title: &quot;Is it legal to kill a zombie?&quot;)
    end
  end
end
&lt;/pre&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; Failure:
QuestionTest#test_A_saved_question_is_queued_for_indexing &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;/Users/jweiss/Source/testapps/after_commit/test/models/question_test.rb:7]:
No enqueued job found with &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;:job&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;QuestionIndexerJob&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;哎哟，什么情况？不是只换了一个回调方法嘛，而且作用都差不多。发生了什么？&lt;/p&gt;

&lt;p&gt;默认情况下，rails的测试是每个测试用例使用 ** 一个事物 ** 包裹,这确实对测试效率提升很大。只需一个指令即可撤销在该测试用例中执行的所有数据库操作。因此你的数据在保存的时候并没有事物提交，so你的after_commit也根本不会执行。&lt;/p&gt;

&lt;p&gt;其实这个问题也有一个比较简单的方式来解决，那就是引入一个叫&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test_after_commit&lt;/code&gt;的gem包：&lt;/p&gt;

&lt;div class=&quot;file_title&quot;&gt;
Gemfile
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
group :test do
  gem &quot;test_after_commit&quot;
end
&lt;/pre&gt;
&lt;p&gt;这样有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;after_commit&lt;/code&gt;的回调就能在测试中再加一层事物, 得到我们想要的效果。但是也许你还是会觉得别扭，为毛我要为这事儿单独去加载一个gem？你是对的，这非常别扭。但是这事也不会持续太久了，因为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rails5&lt;/code&gt;中已经修复了这个问题：&lt;a href=&quot;https://github.com/rails/rails/pull/18458&quot;&gt;https://github.com/rails/rails/pull/18458&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt; 本文译自： &lt;a href=&quot;http://www.justinweiss.com/articles/a-couple-callback-gotchas-and-a-rails-5-fix/&quot; title=&quot;A Couple of Callback Gotchas (and a Rails 5 Fix)&quot;&gt;A Couple of Callback Gotchas (and a Rails 5 Fix) | Justin Weiss's blog&lt;/a&gt;&lt;/pre&gt;

</description>
    <published>2015-10-31T10:00:00+00:00</published>
    <link>http://zouchao.me/2015/10/31/after_save-callback-sidekiq-find-data</link>
  </item>
  
  <item>
    <title>安装Laravel Homestead遇到的坑</title>
    <description>&lt;h4 id=&quot;一安装条件&quot;&gt;一、安装条件&lt;/h4&gt;
&lt;p&gt;由于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VMWare&lt;/code&gt;需要收费，本章只介绍安装&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Vagrant&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VirtualBox&lt;/code&gt;所遇到的麻烦，首先请在如下&lt;br /&gt;
网站下载和自己系统匹配的安装包，并完成安装&lt;/p&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;VirtualBox： &lt;a href=&quot;https://www.virtualbox.org/wiki/Downloads&quot;&gt;https://www.virtualbox.org/wiki/Downloads&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;Vagrant： &lt;a href=&quot;https://www.vagrantup.com/downloads.html&quot;&gt;https://www.vagrantup.com/downloads.html&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;然后&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
vagrant box add laravel/Homestead
&lt;/pre&gt;
&lt;h4 id=&quot;二安装中断没法继续&quot;&gt;二、安装中断，没法继续？&lt;/h4&gt;
&lt;p&gt;兴高采烈安Homestead，网速太渣报错误：
&lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fqh64k1hhcj20u008vju4.jpg&quot; alt=&quot;SSL read: error:00000000:lib(0):func(0):reason(0), errno 54&quot; title=&quot;SSL read: error:00000000:lib(0):func(0):reason(0), errno 54&quot; /&gt;
无奈又来第二次，结果始终报如下错误:
&lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fqh65po22qj20u00ajjue.jpg&quot; alt=&quot;HTTP server doesn't seem to support byte ranges. Cannot resume.&quot; title=&quot;HTTP server doesn't seem to support byte ranges. Cannot resume.&quot; /&gt;
解决办法：&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
rm ~/.vagrant.d/tmp/*
&lt;/pre&gt;

&lt;h4 id=&quot;三更好的方式&quot;&gt;三、更好的方式&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;更好的方式还是直接下载下来文件,但是用p2p工具的同学千万记住不要用离线下载, 也千万不要用高速通道，就是这么残忍，坑在这里：&lt;br /&gt;
 &lt;img src=&quot;https://ws1.sinaimg.cn/large/6a629b92gy1fqh672m9urj20mn04n0ty.jpg&quot; alt=&quot;bsdtar: Error opening archive: gzip decompression failed&quot; title=&quot;bsdtar: Error opening archive: gzip decompression failed&quot; /&gt;&lt;br /&gt;
 没错 当你下载的文件名叫&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;virtualbox.box&lt;/code&gt;那么你很可能已经陷入这个深坑了，正确的文件名大致是这样的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hc-download&lt;/code&gt;，下载完毕了再修改文件名后缀&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;貌似还有一种方式：&lt;/p&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;
 vagrant box add laravel/Homestead -c &lt;/pre&gt;
    &lt;p&gt;加&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c&lt;/code&gt;参数，作用是断点续传，但是我亲试之后还是有问题的，只怪我网络环境特别不好，一、两次可以，多几次之后并没有断点续传。不知道是不是我的问题。大家可以试试，成功的话，希望评论告知，感激&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;四福利始终在最后&quot;&gt;四、福利始终在最后&lt;/h4&gt;
&lt;p&gt;提供的版本&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;homesteam0.3.0_virtualbox.box&lt;/code&gt;
百度云盘下载链接: &lt;a href=&quot;http://pan.baidu.com/s/1jGfIahw&quot;&gt;http://pan.baidu.com/s/1jGfIahw&lt;/a&gt; 密码: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;9xbp&lt;/code&gt;&lt;/p&gt;

</description>
    <published>2015-10-27T14:00:00+00:00</published>
    <link>http://zouchao.me/2015/10/27/vagrant-box-add-laravel-homestead</link>
  </item>
  
  <item>
    <title>苹果优惠及选购</title>
    <description>&lt;h4 id=&quot;思想针扎&quot;&gt;思想针扎：&lt;/h4&gt;

&lt;p&gt;最近在公司猴群的怂恿和嘲笑下确实考虑入手一台mac book pro了，都说mac能给程序猿幸福感带来值的提升，加之朕的虚拟机惊吓了寡人。遂思虑再三决定把跟了自己三年的T430放进书包做为珍藏了。主要的针扎点还是穷……(┬＿┬)&lt;/p&gt;

&lt;h4 id=&quot;金牛座本质暴露&quot;&gt;金牛座本质暴露：&lt;/h4&gt;

&lt;p&gt;去了官网看了下价格，品质要求(其实因为穷，想买了多用几年)，因此决定选顶配。在15inch和13inch间纠结了良久15inch有显卡，13inch外观美观性价比高。据说金牛座是对价格和质量皆有要求的纠结奇葩星座。最后女朋友帮忙拿定了注意要13inch。也好，打消了玩游戏的念头再看13inch各种好。轻便，美观，而且带有新配Force Touch 触控板。。。嘎嘎，下单， 点了分期，阿西吧。。。免息呢？居然没有了。。。各种犹豫啊。。。&lt;/p&gt;

&lt;h4 id=&quot;福利&quot;&gt;福利：&lt;/h4&gt;
&lt;p&gt;福利来了，在多番尝试，搜索下以及果粉群分享。得知Apple免息还是存在的并且得到了具体的链接，感谢google，感谢强大的果粉，感谢金牛座的视钱如命。接下来放出链接来和大家分享，有钱人请绕道。。。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;默认进入商店是cn没有免息:&lt;a href=&quot;http://store.apple.com/cn/buy-mac/macbook-pro&quot;&gt; http://store.apple.com/cn/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;cn-k12是教育优惠不免息: &lt;a href=&quot;http://store.apple.com/cn-k12/buy-mac/macbook-pro&quot;&gt;http://store.apple.com/cn-k12/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;cn_cmb是招行12期免息: &lt;a href=&quot;http://store.apple.com/cn_cmb/buy-mac/macbook-pro&quot;&gt;http://store.apple.com/cn_cmb/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;cn_cmb_edu是招行教育优惠+12期免息: &lt;a href=&quot;http://store.apple.com/cn_cmb_edu/buy-mac/macbook-pro&quot;&gt;http://store.apple.com/cn_cmb_edu/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;cn_icbc是工行12期免息: &lt;a href=&quot;http://store.apple.com/cn_icbc/buy-mac/macbook-pro&quot;&gt;http://store.apple.com/cn_icbc/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;cn_icbc_edu是工行教育优惠+12期免息: &lt;a href=&quot;http://store.apple.com/cn_icbc_edu/buy-mac/macbook-pro&quot;&gt;http://store.apple.com/cn_icbc_edu/buy-mac/macbook-pro&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;还有一个网站要推荐：&lt;a href=&quot;http://buyersguide.macrumors.com/&quot;&gt;http://buyersguide.macrumors.com&lt;/a&gt;，这个网站会根据苹果产品发布周期，以及确切新闻，和mac各产品新增配置给出一些建议现在是否合适购买各个产品，看完之后再次确定13inch是我的最佳选择啊。o(∩_∩)o 哈哈&lt;/p&gt;

</description>
    <published>2015-06-07T20:46:53+00:00</published>
    <link>http://zouchao.me/2015/06/07/apple-store-interest-free</link>
  </item>
  
  <item>
    <title>VirtualBox无法启动报错</title>
    <description>&lt;p&gt;由于本屌穷且爱折腾，因此目前大多数时候的工作环境都是在linux虚拟机下面。虽然有备份但是一般也是几个月的周期才备份一次（原谅我是个懒人）&lt;/p&gt;

&lt;p&gt;但是就在今天来公司我发现我的虚拟机居然神奇般的打不开了&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;不能为虚拟电脑 Centos 打开一个新任务.&lt;br /&gt;
VM cannot start because the saved state file &lt;br /&gt;
‘F:\VirtualBox VMs\Centos\Snapshots\2015-06-03T02-43-10-456513000Z.sav’ is invalid (VERR_FILE_NOT_FOUND)&lt;br /&gt;
Delete the saved state prior to starting the VM. &lt;br /&gt;
返回 代码:VBOX_E_FILE_ERROR (0x80BB0004) 组件:Console 界面:IConsole {db7ab4ca-2a3f-4183-9243-c1208da92392}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这个可给我吓出一身冷汗啊，今天还必须的完成一个重要的项目呢。&lt;/p&gt;

&lt;p&gt;不过还好感谢万能的GOOGLE，查到了解决办法，因此留文存档，用以警示自己帮助他人。&lt;/p&gt;

&lt;h4 id=&quot;解决办法本方案只针对virtual-box&quot;&gt;解决办法(本方案只针对virtual box):&lt;/h4&gt;

&lt;p&gt;打开Oracle VM VirtualBox管理器主界面（GUI） - 控制 - 清除保存的状态（I）&lt;/p&gt;

</description>
    <published>2015-06-03T12:36:33+00:00</published>
    <link>http://zouchao.me/2015/06/03/virtual-box-error</link>
  </item>
  
  <item>
    <title>Vundle管理vim插件</title>
    <description>&lt;h3 id=&quot;使用vundle管理安装vim插件&quot;&gt;使用Vundle管理安装vim插件&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;再在vimrc加类似如下配置:&lt;/p&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'gmarik/vundle'
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
.
# 此处放置你需要安装的插件
.

call vundle#end()
filetype plugin indent on     &quot; required!
&lt;/pre&gt;

&lt;p&gt;然随意打开一个vim窗口&lt;/p&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
$ vim
:PluginInstall
&lt;/pre&gt;

&lt;h3 id=&quot;我的vimrc&quot;&gt;我的vimrc:&lt;/h3&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;
if has('gui_running')
  &quot; set background=light
  set background=dark
else
  set background=dark
endif
let g:solarized_termcolors=256
set tabstop=2
set shiftwidth=2
set laststatus=2
&quot; set dictionary+=$HOME/.mydict
&quot; set dictionary+=/usr/share/dict/words
set isk+=- &quot;把-分割的单词视为一个整体
&quot; set mouse=nv
set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936
set autoindent
set cindent
set sw=2
set ts=2
set expandtab
set number                     &quot; 行号
syntax on                      &quot; 语法高亮
syntax enable

autocmd FileType php setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=79

nnoremap &amp;lt; v&amp;lt;
nnoremap &amp;gt; v&amp;gt;
vnoremap &amp;lt; &lt;gv vnoremap=&quot;&quot;&gt; &amp;gt;gv

let mapleader = &quot;,&quot;
map &lt;F3&gt; :%s/\s*$//g&lt;CR&gt;:noh&lt;CR&gt;   &quot;移除行尾空格
nmap &lt;F2&gt; :NERDTreeToggle &lt;CR&gt;
nmap ff :NERDTreeFind &lt;CR&gt;
nmap gb :Gblame &lt;CR&gt;
imap zsj &lt;c-r&gt;=strftime(&quot;%F %T&quot;)&lt;CR&gt;
&quot;set cursorline &quot;高亮光标所在行
let Tlist_Use_Right_Window=1 &quot;方法列表放在屏幕的右侧

set list
set listchars=tab:,.,trail:.,extends:#,nbsp:.
let g:vim_markdown_folding_disabled=1


set guifont=Monaco:h15
set nocompatible               &quot; be iMproved
filetype off                   &quot; required!
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

&quot; let Vundle manage Vundle
&quot; &quot; required!
Plugin 'gmarik/Vundle.vim'

&quot; My Plugins here:
&quot;
&quot; original repos on github
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'tpope/vim-rails.git'

Plugin 'L9'
Plugin 'FuzzyFinder'
Plugin 'kien/ctrlp.vim'
&quot; Plugin 'vim-scripts/snipMate'
Plugin 'mattn/emmet-vim'
Plugin 'scrooloose/nerdtree'
Plugin 'groenewege/vim-less'
Plugin 'kchmck/vim-coffee-script'
Plugin 'slim-template/vim-slim'
Plugin 'yaymukund/vim-rabl'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
Plugin 'eikenberry/acp'
Plugin 'airblade/vim-gitgutter'
Plugin 'honza/vim-snippets'
Plugin 'altercation/vim-colors-solarized'

call vundle#end()
filetype plugin indent on     &quot; required!

colorscheme solarized
&quot;
&quot; Brief help
&quot; :PluginList          - list configured bundles
&quot; :PluginInstall(!)    - install(update) bundles
&quot; :PluginSearch(!) foo - search(or refresh cache first) for foo
&quot; :PluginClean(!)      - confirm(or auto-approve) removal of unused bundles
&quot;
&quot; see :h vundle for more details or wiki for FAQ
&quot; NOTE: comments after Plugin command are not allowed..

&amp;lt;/pre&amp;gt;
&lt;/CR&gt;&lt;/c-r&gt;&lt;/CR&gt;&lt;/CR&gt;&lt;/CR&gt;&lt;/F2&gt;&lt;/CR&gt;&lt;/CR&gt;&lt;/F3&gt;&lt;/gv&gt;&lt;/pre&gt;
</description>
    <published>2015-03-23T10:59:10+00:00</published>
    <link>http://zouchao.me/2015/03/23/save-my-vimrc</link>
  </item>
  
</channel>
</rss>
