Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Site updated at 2012-10-07 16:14:01 UTC

  • Loading branch information...
commit 3df0da9a29eae71bf078cc52c8a6bf1d5ada0cb5 1 parent f529c7b
@yangchenyun authored
View
10 2011/08/tedxyouth-wesklake-speech/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, TEDx, TEDxYouth, TEDxWestlake, Hangzhou, Speech, Talk, Life changes">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Speech at TEDxYouth West Lake">
+ <meta name="keywords" content="TEDx, TEDxYouth, TEDxWestlake, Hangzhou, Speech, Talk, Life changes">
+ <meta name="description" content="Blog about hackings and development | Speech at TEDxYouth West Lake">
<title>Speech at TEDxYouth West Lake | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -73,11 +73,11 @@ <h2 id="what-holds-us-back-from-changes">What Holds Us Back from Changes</h2>
<h3>Recent Posts</h3>
<ul class="posts small">
- <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
- <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/annual-review/">Annual Review 2011 - A Turning in Life</a></li>
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
</ul>
</div>
View
10 2011/12/annual-review/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, annual review, 2012 review, life changes, ELEME, TEDxFivestarsquare, TEDxFSS, 饿了么, 年度小结, 个人总结">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Annual Review 2011 - A Turning in Life">
+ <meta name="keywords" content="annual review, 2012 review, life changes, ELEME, TEDxFivestarsquare, TEDxFSS, 饿了么, 年度小结, 个人总结">
+ <meta name="description" content="Blog about hackings and development | Annual Review 2011 - A Turning in Life">
<title>Annual Review 2011 - A Turning in Life | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -182,11 +182,11 @@ <h4 id="physical-training-and-health">Physical Training and Health</h4>
<h3>Recent Posts</h3>
<ul class="posts small">
- <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
- <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/lesson-learned/">Lesson Learned</a></li>
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
</ul>
</div>
View
10 2011/12/lesson-learned/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, lessons, sustain oneself, do boring work, distraction, focus, opportunity">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Lesson Learned">
+ <meta name="keywords" content="lessons, sustain oneself, do boring work, distraction, focus, opportunity">
+ <meta name="description" content="Blog about hackings and development | Lesson Learned">
<title>Lesson Learned | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -169,11 +169,11 @@ <h2 id="lesson-5-identify-the-opportunity">Lesson 5: Identify the “Opportunity
<h3>Recent Posts</h3>
<ul class="posts small">
- <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
- <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/annual-review/">Annual Review 2011 - A Turning in Life</a></li>
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
</ul>
</div>
View
10 2012/02/measure-network-performance/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, iperf, vnstat, ntop, traffic, LAN, bandwidth, network, speed, measurement">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. How to Measure and Monitor Network Performance">
+ <meta name="keywords" content="iperf, vnstat, ntop, traffic, LAN, bandwidth, network, speed, measurement">
+ <meta name="description" content="Blog about hackings and development | How to Measure and Monitor Network Performance">
<title>How to Measure and Monitor Network Performance | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -279,11 +279,11 @@ <h2 id="monitor-detailed-network-traffic-with-ntop">Monitor Detailed Network Tra
<h3>Recent Posts</h3>
<ul class="posts small">
- <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/annual-review/">Annual Review 2011 - A Turning in Life</a></li>
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/lesson-learned/">Lesson Learned</a></li>
+ <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
</ul>
</div>
View
10 2012/02/plans-for-2012/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, annual plans, web development, 2012, 年度计划">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Annual Plan 2012 - One Step Further">
+ <meta name="keywords" content="annual plans, web development, 2012, 年度计划">
+ <meta name="description" content="Blog about hackings and development | Annual Plan 2012 - One Step Further">
<title>Annual Plan 2012 - One Step Further | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -105,11 +105,11 @@ <h3 id="misc">Misc</h3>
<h3>Recent Posts</h3>
<ul class="posts small">
- <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/annual-review/">Annual Review 2011 - A Turning in Life</a></li>
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
- <li><span>31 Dec 2011</span> &raquo; <a href="/2011/12/lesson-learned/">Lesson Learned</a></li>
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
</ul>
</div>
View
217 2012/09/ack-a-better-way-to-search-in-files/index.html
@@ -0,0 +1,217 @@
+<!DOCTYPE html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta name="keywords" content="ack, grep">
+ <meta name="description" content="Blog about hackings and development | Ack - a better way to search in files">
+ <title>Ack - a better way to search in files | 杨晨昀 Steven Yang</title>
+ <link rel="stylesheet" href="/stylesheets/screen.css">
+ <!--[if lt IE 9]>
+ <script src="/javascripts/html5.js"></script>
+ <![endif]-->
+</head>
+
+<body>
+ <div class="wrap">
+ <div id="sidebar" class="side group clear">
+ <header>
+ <a href="/">Steven Yang</a>
+ </header>
+ <nav>
+ <ul>
+ <li><a href="/about/">About</a></li>
+ <li><a href="/contact/">Contact</a></li>
+ </ul>
+
+<!-- AddThis Button BEGIN -->
+<div class="addthis_toolbox addthis_default_style ">
+ <div>
+ <a class="addthis_button_facebook_like" fb:like:width="46px"></a>
+ <a class='addthis_button_google_plusone' g:plusone:size='small' g:plusone:annotation='none'></a>
+ <br class="clear">
+ </div>
+ <div>
+ <a class="addthis_button_douban"></a>
+ <a class="addthis_button_sinaweibo"></a>
+ <a class="addthis_button_twitter"></a>
+ <br class="clear">
+ </div>
+</div>
+<!-- AddThis Button END -->
+
+
+ </div>
+ <div class="content">
+ <article class="post">
+ <header id="post-title">
+ <h1>Ack - a better way to search in files</h1>
+ </header>
+ <div id="post-stats">
+ <p>Posted on September 2, 2012</p>
+ </div>
+ <div id="post-content">
+ <p>Recently, <a href="http://betterthangrep.com/">ack</a> became the replacement for <code>grep</code> when I need to spot editing point in my code bases. It wins over <code>grep</code> in terms of:</p>
+
+<ul>
+ <li>A better pattern match syntax with <a href="http://perldoc.perl.org/perlre.html">Perl regular expressions</a></li>
+ <li>Smarter to limit searches in directories or certain file types</li>
+ <li>Much prettier display of result</li>
+ <li>Config files to make customization permanent</li>
+</ul>
+
+<p>These advantages will be introduced in the the following sections and after reading it I hope you will be comfortable with it.</p>
+
+<p>Let’s start by installing <code>ack</code>:</p>
+
+<p>Mac OS X with homebrew:</p>
+
+<pre><code>brew install ack
+</code></pre>
+
+<p>Debian/Ubuntu</p>
+
+<pre><code>sudo apt-get install ack-grep; sudo ln -s $(which ack-grep) /usr/local/bin/ack
+</code></pre>
+
+<p>Then <code>git clone https://github.com/twitter/bootstrap</code> to get the directory used in following examples.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</a></li>
+ <li><a href="#limit-where-the-search-happens">Limit Where the Search Happens</a></li>
+ <li><a href="#add-files-to-be-searched">Add Files to be Searched</a></li>
+ <li><a href="#make-configuration-sticky">Make Configuration Sticky</a></li>
+ <li><a href="#more-magic-and-conclusion">More Magic and Conclusion</a></li>
+</ul>
+
+<h2 id="search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</h2>
+<p>Let’s start with a simple search <code>ack diff</code>.</p>
+
+<p>It prints out all the files whose lines contain the string <code>'diff'</code> within the current working directory.</p>
+
+<p>In fact <code>'diff'</code> could be any valid Perl Regular Expression include the <a href="http://www.regular-expressions.info/refadv.html">advanced regular expression syntax</a>, if you are familiar with regular expression in Ruby, Python, javaScript or Perl, you will be far more at home with the syntax than GNU Basic Regular Expression.</p>
+
+<p>For example, we could use <code>ack 'diff\(.+\)'</code> to detect a string as a function call such as <code>'diff(o, n)''</code> .</p>
+
+<p>It will be common that we will be more interested in <code>'diff'</code> as a word than a portion of string. In this case, we could use <code>ack '\bdiff\b'</code> but there is a handy option <code>-w</code> which force a pattern to match a complete word. So we could send our search result as <code>ack -w diff</code>.</p>
+
+<p>As in any regular expression flavors, to match character such as <code>$</code> or <code>.</code>, we need to escape them in the pattern as <code>'\$\.proxy'</code>. In this case, <code>ack</code> also comes with a handy way to treat the pattern as string literal. Use <code>ack -Q $.proxy</code> to match text against liternal <code>'$.proxy'</code>. It is useful to match IP addresses in log file such as <code>ack aa.bb.cc.dd access.log -Q</code>.</p>
+
+<h2 id="limit-where-the-search-happens">Limit Where the Search Happens</h2>
+<p>You might have already noticed that in the above example, <code>ack</code> automatically search under your current working directory.</p>
+
+<p>In order to alter this behavior, you could specify the file or directory to be searched in. <code>ack href js/bootstrap-alert.js</code> will only match pattern in the <code>js/bootstrap-alert.js</code> file. Similarly, if you specify a directory name as <code>ack proxy docs</code>, it will search in the <code>'docs'</code> directory recursively.</p>
+
+<p>To cancel the recursive behavior, pass in <code>-n</code> or <code>--no-recurce</code>. For example <code>ack post docs -n</code> will only match pattern in the <code>'docs'</code> directory but not its subdirectories.</p>
+
+<p>You can also ignore directory with <code>--ignore-dir=name</code> option, <code>ack post --ignore-dir=docs</code> will seek <code>'post'</code> in all directories other than <code>'docs'</code>.</p>
+
+<p>Sometimes the constrain is complicated, then the option <code>-f</code> will be helpful as it will print the files to be searched before performing the search. For example <code>ack --ignore-dir=docs -f</code> will print all the files <code>ack</code> will search in.</p>
+
+<p>Besides reading from arguments for files, <code>ack</code> could also reads from STDIN. This makes <code>ack</code> a nice candidate in unix pipeline. We could chain multiple <code>ack</code> together to zero in on what the text you really care about. For example <code>ack postError js | ack message</code> <strong>first</strong> find matches for <code>'postError'</code> in all <code>'js'</code> directory and <strong>within the result</strong> it find matches for <code>'message'</code>.</p>
+
+<h2 id="add-files-to-be-searched">Add Files to be Searched</h2>
+<p>Try <code>ack background less</code> to search files in the <code>less</code> directory. It doesn’t return the result we are looking for, the <code>.less</code> files are ignored by <code>ack</code>. There must be something wrong with <code>ack</code>, right?</p>
+
+<p>However, this behavior is not an error but is by design by its author Andy Lester:</p>
+
+<blockquote>
+ <p>… Most codebases have a lot files in them which aren’t source files, and grep wastes a lot of time searching through all of those as well and returning matches from those files. </p>
+</blockquote>
+
+<blockquote>
+ <p>That’s why ack’s behavior of not searching things it doesn’t recognize is one of its greatest strengths: the speed you get from only searching the things that you want to be looking at.</p>
+</blockquote>
+
+<p><code>ack</code> is designed to only search in file types it knows. The file types known by <code>ack</code> could be seen with <code>ack --help-types</code>. Through <code>ack --help-types | ack less</code> we found that, <code>*.less</code> is not known by <code>ack</code> and that’s the reason why they are ignored.</p>
+
+<p>To add more file types we use <code>--type-set</code> and <code>--type-add</code>. With <code>ack background less --type-set less=.less</code>, we succeeded in searching in the <code>*.less</code> files. </p>
+
+<p>Sometimes, we don’t care about file type and just want search in all files in the directory, in these cases, we use <code>--all-types</code> or <code>-a</code>. It will search in all files regardless of its type with one exception - the CVS directory such as <code>.git</code> or <code>.svn</code> is excluded. If we want to count them in, use the ultimate <code>--unrestricted</code> or <code>-u</code> options to search <strong>everything</strong> within a directory.</p>
+
+<h2 id="make-configuration-sticky">Make Configuration Sticky</h2>
+<p>In most cases, we want to limit our searches to certain types, then it will be tedious to type <code>--type-set</code> or <code>--type-add</code> every time we want to search beyond build-in file types. <code>~/.ackrc</code> comes into play in these case. This is the configuration file which will be loaded by <code>ack</code>. All the options we introduced above could be written to it to make it permanent.</p>
+
+<p>Take my configuration as an example:</p>
+
+<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="code"><pre><code class="bash"><span class="line"><span class="c"># ~/.ackrc ack configuration file</span>
+</span><span class="line">
+</span><span class="line"><span class="c"># Sort files by default</span>
+</span><span class="line">--sort-files
+</span><span class="line">
+</span><span class="line"><span class="c"># Use smart-case by default</span>
+</span><span class="line">--smart-case
+</span><span class="line">
+</span><span class="line"><span class="c"># Extended File Types</span>
+</span><span class="line">--type-add<span class="o">=</span><span class="nv">css</span><span class="o">=</span>.less,.scss,.sass
+</span><span class="line">--type-add<span class="o">=</span><span class="nv">ruby</span><span class="o">=</span>.haml
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">coffee</span><span class="o">=</span>.coffee
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">markdown</span><span class="o">=</span>.md,.markdown
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">json</span><span class="o">=</span>.json
+</span></code></pre></td></tr></table></div></figure></notextile></div>
+
+<p>One thing to be noticed, instead of use whitespace in <code>--type-add less=.less</code> use <code>=</code>. Also, line begins with <code>#</code> is ignored.</p>
+
+<p>After adding our own file types, we could use <code>--type less</code> / <code>--less</code> to limit searches in certain file types or <code>--type noless</code> or <code>--noless</code> to exclude them. </p>
+
+<h2 id="more-magic-and-conclusion">More Magic and Conclusion</h2>
+<p><code>ack</code> comes a lot options for the format of output, you could use <code>--pager=less -r</code> to use <code>less</code> as pager with color support, or use <code>-C</code> to display the lines above/below the matched line as well. For more information, check out <code>man ack</code>.</p>
+
+<p>This handy tool is smarter and faster than <code>grep</code> and I have been using it heavily in my workflow. Moreover, the coming <a href="http://stackoverflow.com/questions/9508431/ack-binding-an-actual-file-name-to-a-filetype#answer-9511450">ack2.0</a> is more powerful in terms of file type filtering and multiple config file support.</p>
+
+<p>Hope this introduction makes you comfortable with <code>ack</code>.</p>
+
+<p>Do you know other “improved” substitute for daily unix utility?</p>
+
+
+ </div>
+</article>
+<nav id="related">
+ <div class="related_left">
+ <h3>Recent Posts</h3>
+ <ul class="posts small">
+
+ <li><span>01 Oct 2012</span> &raquo; <a href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline</a></li>
+
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+
+ <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+
+ </ul>
+ </div>
+</nav>
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+ var disqus_shortname = 'yangchenyunblog'; // required: replace example with your forum shortname
+
+ /* * * DON'T EDIT BELOW THIS LINE * * */
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+
+
+ </div>
+ <br class="clear">
+ <footer>
+ <p>Powered by <a title="Don't worry, it's not the morally ambivalent doctor." href="http://github.com/mojombo/jekyll">Jekyll</a>.<span class="copyright">copyright 2011-2012&copy;Steven Yang</span></p>
+ <!-- <p>Also find me on <a href="http://stackoverflow.com/users/966437/steven-yang">stackoverflow</a> and <a href="http://delicious.com/chenyunyang">delicious</a>.</p> -->
+ </footer>
+ </div>
+</body>
+
+<!-- Add this script -->
+<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f01c8a46f097959"></script>
+<!-- Google Analytics Improved Version -->
+<script>var _gaq=[['_setAccount','UA-27986795-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'))
+</script>
+ <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
+ chromium.org/developers/how-tos/chrome-frame-getting-started -->
+ <!--[if lt IE 7 ]>
+ <script defer src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
+ <script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
+ <![endif]-->
+</html>
View
284 2012/10/understand-unix-pipeline/index.html
@@ -0,0 +1,284 @@
+<!DOCTYPE html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta name="keywords" content="unix, io, file, pipe, stream, process substitution">
+ <meta name="description" content="Blog about hackings and development | Understand Unix Pipeline">
+ <title>Understand Unix Pipeline | 杨晨昀 Steven Yang</title>
+ <link rel="stylesheet" href="/stylesheets/screen.css">
+ <!--[if lt IE 9]>
+ <script src="/javascripts/html5.js"></script>
+ <![endif]-->
+</head>
+
+<body>
+ <div class="wrap">
+ <div id="sidebar" class="side group clear">
+ <header>
+ <a href="/">Steven Yang</a>
+ </header>
+ <nav>
+ <ul>
+ <li><a href="/about/">About</a></li>
+ <li><a href="/contact/">Contact</a></li>
+ </ul>
+
+<!-- AddThis Button BEGIN -->
+<div class="addthis_toolbox addthis_default_style ">
+ <div>
+ <a class="addthis_button_facebook_like" fb:like:width="46px"></a>
+ <a class='addthis_button_google_plusone' g:plusone:size='small' g:plusone:annotation='none'></a>
+ <br class="clear">
+ </div>
+ <div>
+ <a class="addthis_button_douban"></a>
+ <a class="addthis_button_sinaweibo"></a>
+ <a class="addthis_button_twitter"></a>
+ <br class="clear">
+ </div>
+</div>
+<!-- AddThis Button END -->
+
+
+ </div>
+ <div class="content">
+ <article class="post">
+ <header id="post-title">
+ <h1>Understand Unix Pipeline</h1>
+ </header>
+ <div id="post-stats">
+ <p>Posted on October 1, 2012</p>
+ </div>
+ <div id="post-content">
+ <p>For linux beginners, these commands are powerful but confusing:</p>
+
+<pre><code>tail /var/log/nginx.log &gt; /tmp/recent.log
+node server.js 2&gt;&amp;1 &gt;/var/log/info.log
+ls -al | grep '/.rb' | wc -l
+tee &gt;(wc -l &gt;&amp;2) &lt; bigfile | gzip &gt; bigfile.gz
+</code></pre>
+
+<p>The shared syntaxes such as <code>&lt;</code>, <code>&gt;</code>, <code>&gt;&amp;1</code> or <code>|</code> indicates one of unix’s best features - standard IO streams. Standard IO streams has been introduced since <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">the early days of unix</a> and has formed a core part in <a href="http://www.faqs.org/docs/artu/ch01s06.html">unix philosophy</a>.</p>
+
+<blockquote>
+ <p>… Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.</p>
+</blockquote>
+
+<p>The following sections will explain IO streams of unix and their usage with programs. It will answer the following questions:
+- what is standard streams and how does it work with programs?
+- how to utilize standard streams in programs?
+- what is pipeline and how to use it?
+- how to make standard streams work with program arguments?</p>
+
+<p>If your are confused about unix streams, hope the following sections will help you understand the above commands; if you are already familiar with it, [references at the end][#references] might help you unleash more power of it.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#the-abstract-io-interface-for-program">The Abstract IO Interface for Program</a> <ul>
+ <li><a href="#example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</a></li>
+ </ul>
+ </li>
+ <li><a href="#io-redirections">IO Redirections</a></li>
+ <li><a href="#piping">Piping</a></li>
+ <li><a href="#pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</a> <ul>
+ <li><a href="#process-substitution">Process substitution</a></li>
+ <li><a href="#xargs"><code>xargs</code></a></li>
+ </ul>
+ </li>
+ <li><a href="#reference">Reference</a></li>
+</ul>
+
+<h2 id="the-abstract-io-interface-for-program">The Abstract IO Interface for Program</h2>
+<p>Computer programs need to talk with its environment. It needs to communicate with various hardware such as disk drive, disc, screen, keyboard, mouse, speaker, printer etc. </p>
+
+<p>In operating system predates Unix, program has to contain the ‘knowledge’ for specific devices. It need to know the right ways to talk to various devices. To build a program working with three types of different printers, it needs to contain the pieces to translate program instructions to each printer.</p>
+
+<p><img src="" alt="img of program talks to various devices" /></p>
+
+<p>This binding with devices makes program less portable.</p>
+
+<p>To solve this issue, unix invented the <strong>standard IO streams</strong></p>
+
+<p>Standard IO streams abstract the complexity of reading and writing to different devices with <strong>data stream</strong>. Data stream is merely an ordered sequence of data bytes. Any program could read data stream until the end of a file and it could write data stream without declare the size. This generic ways to read and write data enables program to read input from keyboard devices, files and write data to displays, files, printers etc. without knowing anything about these devices.</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>There are three kinds of standard IO streams including standard input, standard output and standard error. Standard input is the data going into a program. By default it is expected from keyboard. Standard output is the where program writes its data to and by default it is the terminal. Standard error is another output stream similar to standard output. It is typically used to output error messages or diagnostics.</p>
+
+<p>Standard streams follows the unix’s phisolophy that <a href="http://en.wikipedia.org/wiki/Everything_is_a_file">‘everything is a file’</a>. So from the program’s point of view, these three standard streams have no difference from normal files. As long as a program could read a file, it could read from standard input; as long as it could write a file, it could write the standard output.</p>
+
+<p>The actual actions of ‘writing to standard output’ is determined by unix itself. It could mean printing to terminal, recording a video tape, burning a disc, sending to printer etc. All of these are handled by the kernel of unix. This feature amplifies the composibility and portablity of a program</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>In conslusion, standard IO streams provide an unified input and output interfaces for the programs to communicate with various hardware devices without growing complexities. </p>
+
+<h3 id="example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</h3>
+<p>With the knowledge about the standard streams, let’s take a look at one program example.</p>
+
+<p>Type <code>cat</code> in the terminal and now the program will read the default standard input - keyboard. Type <code>first line</code> and <code>&lt;Enter&gt;</code>, it prints to string to the default standard output - the terminal.</p>
+
+<pre><code>$ cat
+first line
+&gt;first line
+</code></pre>
+
+<p><img src="" alt="img of command cat" /></p>
+
+<h2 id="io-redirections">IO Redirections</h2>
+<p>Sometimes we want to read data other than the keyboard or write data other than standard output. To alter the default stream source or destination is called <strong>IO Redirection</strong>. This could be archieved through <code>&lt;</code> or <code>&gt;</code>. Let’s first try <code>&gt;</code>:</p>
+
+<pre><code>$ ls -al &gt; /tmp/list.txt
+</code></pre>
+
+<p>It redirects the standard output to the file <code>/tmp/list.txt</code> instead of print to terminal.</p>
+
+<p><code>&gt;</code> has a sibling <code>&gt;&gt;</code> which will <strong>append</strong> data to file instead of writing it.</p>
+
+<pre><code>$ ls -al &gt;&gt; /tmp/list.txt
+</code></pre>
+
+<p>It appends the result to <code>/tmp/list.text</code> which should contain the same results twice. Let’s read this file now:</p>
+
+<pre><code>$ less &lt; /tmp/list.txt
+</code></pre>
+
+<p>It reads standard input from <code>/tmp/list.txt</code> instead of the keyboard.</p>
+
+<p><img src="" alt="img of IO Redirection" /></p>
+
+<p>How about redirect standard error? Use <code>2&gt;</code>:</p>
+
+<pre><code>$ find this-is-not-exist 2&gt; /tmp/error.txt
+</code></pre>
+
+<p>The error message is not displayed on the terminal but stored in the <code>/tmp/error.txt</code> file.</p>
+
+<p>The meaning of the <code>2</code> used in the above command is <strong>file descriptor</strong>, they are similar to file name which is used to access files in one system process.</p>
+
+<p>As standard streams don’t have file name, file descriptor is the usual way to access them. The file descriptors for standard input, standard output, standard error are 0, 1, and 2, respectively.</p>
+
+<p>So the above command means: execute the <code>find this-is-not-exist</code> command and redirect the file indicated by the file descriptor 2 (which is standard standard error) to <code>/tmp/error.txt</code>.</p>
+
+<p>File descriptor could also be used as redirection destination:</p>
+
+<pre><code>ls -al 2&gt;&amp;1 &gt;/tmp/result.txt
+</code></pre>
+
+<p>This means: execute <code>ls -al</code> and redirects file descriptor 2(standard error) to any destination file descriptor 1(standard output) points to and redirects standard output to file <code>/tmp/result.txt</code>. The <code>&amp;</code> used here is to distinguish between file name <code>1</code> and file descriptor <code>1</code>.</p>
+
+<p><img src="" alt="img of file descriptor cat" /></p>
+
+<h2 id="piping">Piping</h2>
+<p>Sometimes a program might write standard output data which might be read by another program as standard input. With the above knowledge it could be written by IO redirections:</p>
+
+<pre><code>ls -al ~ &gt; /tmp/list.tmp
+grep '\.sh' &lt; /tmp/list.tmp
+rm /tmp/list.tmp
+</code></pre>
+
+<p>But unix comes with a better method named pipeline which sends the standard output of one program to the standard input of another program. With pipeline the above example could be rewritten as <code>ls -al | grep '\.sh'</code>.</p>
+
+<p>With pipeline, it is possible to compose one giant pipeline to connect pieces of programs together to perform complex operations like <code>makewords sentence | lowercase | sort | unique | mismatch </code> in <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">this example(7:00)</a>.</p>
+
+<p>Another benefit of pipeline is that all the pieces of programs start execution as soon as data stream comes in. In the first example where a temporary file is created as a medium, <code>grep</code> is not executed until <code>ls -al</code> finishes and writes to the <code>/tmp/list.tmp</code>. In this case, if the temporary data is significantly big, <code>grep</code> needs to wait quitea while. However with pipeline, <code>grep</code> is executed once <code>ls -al</code> starts to send data through standard output. </p>
+
+<p>Pipeline takes less space of disk and memory but with faster processing as all the program runs in parellel to process the data stream.</p>
+
+<h2 id="pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</h2>
+<p>### Difference between standard streams and arguments
+Sometimes the program returns the same result when read from standard input or execute with an arguments.</p>
+
+<p><code>cat log</code> has the same result as <code>cat &lt; log</code>. But the mechanism is different.
+<code>cat file</code> pass the file name <code>log</code> as an argument to <code>cat</code> but <code>cat &lt; log</code> passes the content of the <code>log</code> file as standard input to <code>cat</code>.</p>
+
+<h3 id="process-substitution">Process substitution</h3>
+
+<pre><code>diff &lt;(sort file1) &lt;(sort file2)
+</code></pre>
+
+<h3 id="xargs"><code>xargs</code></h3>
+
+<pre><code>ls *.zip | xargs -n 1 -t unzip
+</code></pre>
+
+<h2 id="reference">Reference</h2>
+<p><a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">Wikipedia Pipepine</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Standard_streams">Wikipedia Standard Stream</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Process_substitution">Wikipedia Process Substitution</a></p>
+
+<p><a href="http://www.linfo.org/redirection.html">Redirection Definition</a></p>
+
+<p><a href="http://tldp.org/LDP/abs/html/io-redirection.html">I/O Redirection in Advanced Bash-Scripting Guide</a></p>
+
+<hr />
+
+<p>All the icons used in illustration are from The Noun Project.
+<a href="http://thenounproject.com/noun/hard-drive/#icon-No537">Hard Drive</a> and <a href="http://thenounproject.com/noun/computer/#icon-No115">Computer</a> is designed by annonymous designers.
+<a href="http://thenounproject.com/noun/computer-keyboard/#icon-No1807">Computer Keyboard</a> is designed by <a href="http://thenounproject.com/andrewforrester">Andrew Forrester</a>.
+<a href="http://thenounproject.com/noun/mouse/#icon-No890">Mouse</a> is designed by <a href="http://thenounproject.com/cbertoco">Camila Bertoco</a>.
+<a href="http://thenounproject.com/noun/floppy-disk/#icon-No2476">Floppy Disk</a> is designed by <a href="http://thenounproject.com/cortiemens">Cor Tiemens</a>.</p>
+
+<p><a href="http://thenounproject.com/noun/building-block/#icon-No5218" target="_blank">Building Block</a> designed by <a href="http://thenounproject.com/Mikhail1986" target="_blank">Michael Rowe</a> from The Noun Project
+<a href="http://thenounproject.com/noun/speaker/#icon-No4106" target="_blank">Speaker</a> designed by <a href="http://thenounproject.com/squintongreen" target="_blank">Samuel Q. Green</a> from The Noun Project
+<a href="http://thenounproject.com/noun/database/#icon-No4995" target="_blank">Database</a> designed by <a href="http://thenounproject.com/DmitryBaranovskiy" target="_blank">Dmitry Baranovskiy</a> from The Noun Project
+<a href="http://thenounproject.com/noun/document/#icon-No4769" target="_blank">Document</a> designed by <a href="http://thenounproject.com/mariavaragilal" target="_blank">Maria Varagilal</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No109" target="_blank">Printer</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No1235" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/johncaserta" target="_blank">John Caserta</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No3751" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/bitsnbobs" target="_blank">James Fenton</a> from The Noun Project
+<a href="http://thenounproject.com/noun/gears/#icon-No1870" target="_blank">Gears</a> designed by <a href="http://thenounproject.com/daria" target="_blank">Dasha Shevyrenkova</a> from The Noun Project
+<a href="http://thenounproject.com/noun/arrow/#icon-No2487" target="_blank">Arrow</a> designed by <a href="http://thenounproject.com/cortiemens" target="_blank">Cor Tiemens</a> from The Noun Project</p>
+
+ </div>
+</article>
+<nav id="related">
+ <div class="related_left">
+ <h3>Recent Posts</h3>
+ <ul class="posts small">
+
+ <li><span>02 Sep 2012</span> &raquo; <a href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files</a></li>
+
+ <li><span>17 Feb 2012</span> &raquo; <a href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance</a></li>
+
+ <li><span>16 Feb 2012</span> &raquo; <a href="/2012/02/plans-for-2012/">Annual Plan 2012 - One Step Further</a></li>
+
+ </ul>
+ </div>
+</nav>
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+ var disqus_shortname = 'yangchenyunblog'; // required: replace example with your forum shortname
+
+ /* * * DON'T EDIT BELOW THIS LINE * * */
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+
+
+ </div>
+ <br class="clear">
+ <footer>
+ <p>Powered by <a title="Don't worry, it's not the morally ambivalent doctor." href="http://github.com/mojombo/jekyll">Jekyll</a>.<span class="copyright">copyright 2011-2012&copy;Steven Yang</span></p>
+ <!-- <p>Also find me on <a href="http://stackoverflow.com/users/966437/steven-yang">stackoverflow</a> and <a href="http://delicious.com/chenyunyang">delicious</a>.</p> -->
+ </footer>
+ </div>
+</body>
+
+<!-- Add this script -->
+<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f01c8a46f097959"></script>
+<!-- Google Analytics Improved Version -->
+<script>var _gaq=[['_setAccount','UA-27986795-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'))
+</script>
+ <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
+ chromium.org/developers/how-tos/chrome-frame-getting-started -->
+ <!--[if lt IE 7 ]>
+ <script defer src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
+ <script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
+ <![endif]-->
+</html>
View
26 about/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, ">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. About me">
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | About me">
<title>About me | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -45,29 +45,17 @@
<h2 id="about-me">About me</h2>
<p><img src="/images/me.jpg" alt="self-potrait" class="right" />
- I am an self-taught craftman, I like build and design products with computers.</p>
+ I am an self-taught craftman, I like design and build stuff with computers.</p>
-<p>In 2011, I led the UI design and frontend development at a start-up(<a href="http://ele.me/at/entry/1">site</a>, <a href="http://ele.me/napos.php">webapp</a>).</p>
+<p>In 2011, I led the UI design and frontend development at <a href="http://ele.me/at/entry/1">eleme</a> and build a <a href="http://ele.me/napos.php">webapp</a> there. And currently I am starting up a <a href="http://zenhacks.org/">company</a> at Shanghai.</p>
-<p>I also collect <a href="http://quote.yangchenyun.com">inspiration</a> to keep myself motivated and volunteer to work at <a href="http://tedxfivestarsquare.com">TEDxFivestarsquare</a>.</p>
+<p>I am fluent in <code>javascript</code>/<code>coffeescript</code> and <code>Ruby</code>. I worked with <code>Symfony</code> and <code>Django</code> before. But now I am using <code>Rails</code> to create web application and <code>nodeJS</code> to do some cutting edge experiments. You could find me on <a href="https://github.com/yangchenyun">github</a> and <a href="http://stackoverflow.com/users/966437/steven-yang">stackoverflow</a>. I am also fascinated about <a href="http://www.faqs.org/docs/artu/ch01s06.html">Unix’s philosophy</a>.</p>
-<p>My toolkit consists of <code>javaScript</code>/<code>coffeescript</code>, <code>HTML5</code> and <code>CSS3</code>. I also use <code>Ruby</code> for scripting. For the backend, I have worked with projects based on <code>Rails</code>, <code>Django</code> and <code>Symfony</code>. I am also fascinated about Unix’s simplified philosophy after switching my workspace from the cumbersome Windows system.</p>
-
-<p>Currently, I am developing and organizing design and develop knowledge on the front-end side while digging more deeper into the details. Besides, I am also learning basic system administration, data abstraction and <code>Rails</code> to accomplish my personal projects. Because…</p>
-
-<blockquote>
- <p>Creating useful products with elegance is what drives me so far.</p>
-</blockquote>
+<p>Creating useful products with elegance is what drives me so far.</p>
<p>By the way, my name is Steven Yang graduated from Zhejiang University with a Bachelor degree in Economics.</p>
-<h2 id="about-the-site">About the Site</h2>
-
-<p>The site come to exist for selfish reasons.</p>
-
-<p>I need a place to organize the knowledge I acquired day in day out. The process to write a public article forces me to pay attention to details and think solutions in a structured way.</p>
-
-<p>Besides, I am learning <code>Ruby</code> and how the full web stack works, so I need a project to get my hands dirty.</p>
+<p>I’d love to collect <a href="http://quote.yangchenyun.com">inspiration</a> to keep myself motivated and volunteer to work at <a href="http://tedxfivestarsquare.com">TEDxFivestarsquare</a>.</p>
<p>This site is created with <a href="http://github.com/mojombo/jekyll">Jekyll</a> and hosted on <a href="http://github.com">github</a>.</p>
View
309 atom.xml
@@ -4,7 +4,7 @@
<title><![CDATA[Steven Yang's Blog | 杨晨昀]]></title>
<link href="http://blog.yangchenyun.com/atom.xml" rel="self"/>
<link href="http://blog.yangchenyun.com/"/>
- <updated>2012-08-07T22:48:15+08:00</updated>
+ <updated>2012-10-08T00:13:59+08:00</updated>
<id>http://blog.yangchenyun.com/</id>
<author>
<name><![CDATA[Steven Yang]]></name>
@@ -14,6 +14,313 @@
<entry>
+ <title type="html"><![CDATA[Understand Unix Pipeline]]></title>
+ <link href="http://blog.yangchenyun.com/2012/10/understand-unix-pipeline/"/>
+ <updated>2012-10-01T16:54:00+08:00</updated>
+ <id>http://blog.yangchenyun.com/2012/10/understand-unix-pipeline</id>
+ <content type="html"><![CDATA[<p>For linux beginners, these commands are powerful but confusing:</p>
+
+<pre><code>tail /var/log/nginx.log &gt; /tmp/recent.log
+node server.js 2&gt;&amp;1 &gt;/var/log/info.log
+ls -al | grep '/.rb' | wc -l
+tee &gt;(wc -l &gt;&amp;2) &lt; bigfile | gzip &gt; bigfile.gz
+</code></pre>
+
+<p>The shared syntaxes such as <code>&lt;</code>, <code>&gt;</code>, <code>&gt;&amp;1</code> or <code>|</code> indicates one of unix’s best features - standard IO streams. Standard IO streams has been introduced since <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">the early days of unix</a> and has formed a core part in <a href="http://www.faqs.org/docs/artu/ch01s06.html">unix philosophy</a>.</p>
+
+<blockquote>
+ <p>… Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.</p>
+</blockquote>
+
+<p>The following sections will explain IO streams of unix and their usage with programs. It will answer the following questions:
+- what is standard streams and how does it work with programs?
+- how to utilize standard streams in programs?
+- what is pipeline and how to use it?
+- how to make standard streams work with program arguments?</p>
+
+<p>If your are confused about unix streams, hope the following sections will help you understand the above commands; if you are already familiar with it, [references at the end][#references] might help you unleash more power of it.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#the-abstract-io-interface-for-program">The Abstract IO Interface for Program</a> <ul>
+ <li><a href="#example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</a></li>
+ </ul>
+ </li>
+ <li><a href="#io-redirections">IO Redirections</a></li>
+ <li><a href="#piping">Piping</a></li>
+ <li><a href="#pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</a> <ul>
+ <li><a href="#process-substitution">Process substitution</a></li>
+ <li><a href="#xargs"><code>xargs</code></a></li>
+ </ul>
+ </li>
+ <li><a href="#reference">Reference</a></li>
+</ul>
+
+<h2 id="the-abstract-io-interface-for-program">The Abstract IO Interface for Program</h2>
+<p>Computer programs need to talk with its environment. It needs to communicate with various hardware such as disk drive, disc, screen, keyboard, mouse, speaker, printer etc. </p>
+
+<p>In operating system predates Unix, program has to contain the ‘knowledge’ for specific devices. It need to know the right ways to talk to various devices. To build a program working with three types of different printers, it needs to contain the pieces to translate program instructions to each printer.</p>
+
+<p><img src="" alt="img of program talks to various devices" /></p>
+
+<p>This binding with devices makes program less portable.</p>
+
+<p>To solve this issue, unix invented the <strong>standard IO streams</strong></p>
+
+<p>Standard IO streams abstract the complexity of reading and writing to different devices with <strong>data stream</strong>. Data stream is merely an ordered sequence of data bytes. Any program could read data stream until the end of a file and it could write data stream without declare the size. This generic ways to read and write data enables program to read input from keyboard devices, files and write data to displays, files, printers etc. without knowing anything about these devices.</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>There are three kinds of standard IO streams including standard input, standard output and standard error. Standard input is the data going into a program. By default it is expected from keyboard. Standard output is the where program writes its data to and by default it is the terminal. Standard error is another output stream similar to standard output. It is typically used to output error messages or diagnostics.</p>
+
+<p>Standard streams follows the unix’s phisolophy that <a href="http://en.wikipedia.org/wiki/Everything_is_a_file">‘everything is a file’</a>. So from the program’s point of view, these three standard streams have no difference from normal files. As long as a program could read a file, it could read from standard input; as long as it could write a file, it could write the standard output.</p>
+
+<p>The actual actions of ‘writing to standard output’ is determined by unix itself. It could mean printing to terminal, recording a video tape, burning a disc, sending to printer etc. All of these are handled by the kernel of unix. This feature amplifies the composibility and portablity of a program</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>In conslusion, standard IO streams provide an unified input and output interfaces for the programs to communicate with various hardware devices without growing complexities. </p>
+
+<h3 id="example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</h3>
+<p>With the knowledge about the standard streams, let’s take a look at one program example.</p>
+
+<p>Type <code>cat</code> in the terminal and now the program will read the default standard input - keyboard. Type <code>first line</code> and <code>&lt;Enter&gt;</code>, it prints to string to the default standard output - the terminal.</p>
+
+<pre><code>$ cat
+first line
+&gt;first line
+</code></pre>
+
+<p><img src="" alt="img of command cat" /></p>
+
+<h2 id="io-redirections">IO Redirections</h2>
+<p>Sometimes we want to read data other than the keyboard or write data other than standard output. To alter the default stream source or destination is called <strong>IO Redirection</strong>. This could be archieved through <code>&lt;</code> or <code>&gt;</code>. Let’s first try <code>&gt;</code>:</p>
+
+<pre><code>$ ls -al &gt; /tmp/list.txt
+</code></pre>
+
+<p>It redirects the standard output to the file <code>/tmp/list.txt</code> instead of print to terminal.</p>
+
+<p><code>&gt;</code> has a sibling <code>&gt;&gt;</code> which will <strong>append</strong> data to file instead of writing it.</p>
+
+<pre><code>$ ls -al &gt;&gt; /tmp/list.txt
+</code></pre>
+
+<p>It appends the result to <code>/tmp/list.text</code> which should contain the same results twice. Let’s read this file now:</p>
+
+<pre><code>$ less &lt; /tmp/list.txt
+</code></pre>
+
+<p>It reads standard input from <code>/tmp/list.txt</code> instead of the keyboard.</p>
+
+<p><img src="" alt="img of IO Redirection" /></p>
+
+<p>How about redirect standard error? Use <code>2&gt;</code>:</p>
+
+<pre><code>$ find this-is-not-exist 2&gt; /tmp/error.txt
+</code></pre>
+
+<p>The error message is not displayed on the terminal but stored in the <code>/tmp/error.txt</code> file.</p>
+
+<p>The meaning of the <code>2</code> used in the above command is <strong>file descriptor</strong>, they are similar to file name which is used to access files in one system process.</p>
+
+<p>As standard streams don’t have file name, file descriptor is the usual way to access them. The file descriptors for standard input, standard output, standard error are 0, 1, and 2, respectively.</p>
+
+<p>So the above command means: execute the <code>find this-is-not-exist</code> command and redirect the file indicated by the file descriptor 2 (which is standard standard error) to <code>/tmp/error.txt</code>.</p>
+
+<p>File descriptor could also be used as redirection destination:</p>
+
+<pre><code>ls -al 2&gt;&amp;1 &gt;/tmp/result.txt
+</code></pre>
+
+<p>This means: execute <code>ls -al</code> and redirects file descriptor 2(standard error) to any destination file descriptor 1(standard output) points to and redirects standard output to file <code>/tmp/result.txt</code>. The <code>&amp;</code> used here is to distinguish between file name <code>1</code> and file descriptor <code>1</code>.</p>
+
+<p><img src="" alt="img of file descriptor cat" /></p>
+
+<h2 id="piping">Piping</h2>
+<p>Sometimes a program might write standard output data which might be read by another program as standard input. With the above knowledge it could be written by IO redirections:</p>
+
+<pre><code>ls -al ~ &gt; /tmp/list.tmp
+grep '\.sh' &lt; /tmp/list.tmp
+rm /tmp/list.tmp
+</code></pre>
+
+<p>But unix comes with a better method named pipeline which sends the standard output of one program to the standard input of another program. With pipeline the above example could be rewritten as <code>ls -al | grep '\.sh'</code>.</p>
+
+<p>With pipeline, it is possible to compose one giant pipeline to connect pieces of programs together to perform complex operations like <code>makewords sentence | lowercase | sort | unique | mismatch </code> in <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">this example(7:00)</a>.</p>
+
+<p>Another benefit of pipeline is that all the pieces of programs start execution as soon as data stream comes in. In the first example where a temporary file is created as a medium, <code>grep</code> is not executed until <code>ls -al</code> finishes and writes to the <code>/tmp/list.tmp</code>. In this case, if the temporary data is significantly big, <code>grep</code> needs to wait quitea while. However with pipeline, <code>grep</code> is executed once <code>ls -al</code> starts to send data through standard output. </p>
+
+<p>Pipeline takes less space of disk and memory but with faster processing as all the program runs in parellel to process the data stream.</p>
+
+<h2 id="pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</h2>
+<p>### Difference between standard streams and arguments
+Sometimes the program returns the same result when read from standard input or execute with an arguments.</p>
+
+<p><code>cat log</code> has the same result as <code>cat &lt; log</code>. But the mechanism is different.
+<code>cat file</code> pass the file name <code>log</code> as an argument to <code>cat</code> but <code>cat &lt; log</code> passes the content of the <code>log</code> file as standard input to <code>cat</code>.</p>
+
+<h3 id="process-substitution">Process substitution</h3>
+
+<pre><code>diff &lt;(sort file1) &lt;(sort file2)
+</code></pre>
+
+<h3 id="xargs"><code>xargs</code></h3>
+
+<pre><code>ls *.zip | xargs -n 1 -t unzip
+</code></pre>
+
+<h2 id="reference">Reference</h2>
+<p><a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">Wikipedia Pipepine</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Standard_streams">Wikipedia Standard Stream</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Process_substitution">Wikipedia Process Substitution</a></p>
+
+<p><a href="http://www.linfo.org/redirection.html">Redirection Definition</a></p>
+
+<p><a href="http://tldp.org/LDP/abs/html/io-redirection.html">I/O Redirection in Advanced Bash-Scripting Guide</a></p>
+
+<hr />
+
+<p>All the icons used in illustration are from The Noun Project.
+<a href="http://thenounproject.com/noun/hard-drive/#icon-No537">Hard Drive</a> and <a href="http://thenounproject.com/noun/computer/#icon-No115">Computer</a> is designed by annonymous designers.
+<a href="http://thenounproject.com/noun/computer-keyboard/#icon-No1807">Computer Keyboard</a> is designed by <a href="http://thenounproject.com/andrewforrester">Andrew Forrester</a>.
+<a href="http://thenounproject.com/noun/mouse/#icon-No890">Mouse</a> is designed by <a href="http://thenounproject.com/cbertoco">Camila Bertoco</a>.
+<a href="http://thenounproject.com/noun/floppy-disk/#icon-No2476">Floppy Disk</a> is designed by <a href="http://thenounproject.com/cortiemens">Cor Tiemens</a>.</p>
+
+<p><a href="http://thenounproject.com/noun/building-block/#icon-No5218" target="_blank">Building Block</a> designed by <a href="http://thenounproject.com/Mikhail1986" target="_blank">Michael Rowe</a> from The Noun Project
+<a href="http://thenounproject.com/noun/speaker/#icon-No4106" target="_blank">Speaker</a> designed by <a href="http://thenounproject.com/squintongreen" target="_blank">Samuel Q. Green</a> from The Noun Project
+<a href="http://thenounproject.com/noun/database/#icon-No4995" target="_blank">Database</a> designed by <a href="http://thenounproject.com/DmitryBaranovskiy" target="_blank">Dmitry Baranovskiy</a> from The Noun Project
+<a href="http://thenounproject.com/noun/document/#icon-No4769" target="_blank">Document</a> designed by <a href="http://thenounproject.com/mariavaragilal" target="_blank">Maria Varagilal</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No109" target="_blank">Printer</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No1235" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/johncaserta" target="_blank">John Caserta</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No3751" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/bitsnbobs" target="_blank">James Fenton</a> from The Noun Project
+<a href="http://thenounproject.com/noun/gears/#icon-No1870" target="_blank">Gears</a> designed by <a href="http://thenounproject.com/daria" target="_blank">Dasha Shevyrenkova</a> from The Noun Project
+<a href="http://thenounproject.com/noun/arrow/#icon-No2487" target="_blank">Arrow</a> designed by <a href="http://thenounproject.com/cortiemens" target="_blank">Cor Tiemens</a> from The Noun Project</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="html"><![CDATA[Ack - a better way to search in files]]></title>
+ <link href="http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files/"/>
+ <updated>2012-09-02T16:58:00+08:00</updated>
+ <id>http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files</id>
+ <content type="html"><![CDATA[<p>Recently, <a href="http://betterthangrep.com/">ack</a> became the replacement for <code>grep</code> when I need to spot editing point in my code bases. It wins over <code>grep</code> in terms of:</p>
+
+<ul>
+ <li>A better pattern match syntax with <a href="http://perldoc.perl.org/perlre.html">Perl regular expressions</a></li>
+ <li>Smarter to limit searches in directories or certain file types</li>
+ <li>Much prettier display of result</li>
+ <li>Config files to make customization permanent</li>
+</ul>
+
+<p>These advantages will be introduced in the the following sections and after reading it I hope you will be comfortable with it.</p>
+
+<p>Let’s start by installing <code>ack</code>:</p>
+
+<p>Mac OS X with homebrew:</p>
+
+<pre><code>brew install ack
+</code></pre>
+
+<p>Debian/Ubuntu</p>
+
+<pre><code>sudo apt-get install ack-grep; sudo ln -s $(which ack-grep) /usr/local/bin/ack
+</code></pre>
+
+<p>Then <code>git clone https://github.com/twitter/bootstrap</code> to get the directory used in following examples.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</a></li>
+ <li><a href="#limit-where-the-search-happens">Limit Where the Search Happens</a></li>
+ <li><a href="#add-files-to-be-searched">Add Files to be Searched</a></li>
+ <li><a href="#make-configuration-sticky">Make Configuration Sticky</a></li>
+ <li><a href="#more-magic-and-conclusion">More Magic and Conclusion</a></li>
+</ul>
+
+<h2 id="search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</h2>
+<p>Let’s start with a simple search <code>ack diff</code>.</p>
+
+<p>It prints out all the files whose lines contain the string <code>'diff'</code> within the current working directory.</p>
+
+<p>In fact <code>'diff'</code> could be any valid Perl Regular Expression include the <a href="http://www.regular-expressions.info/refadv.html">advanced regular expression syntax</a>, if you are familiar with regular expression in Ruby, Python, javaScript or Perl, you will be far more at home with the syntax than GNU Basic Regular Expression.</p>
+
+<p>For example, we could use <code>ack 'diff\(.+\)'</code> to detect a string as a function call such as <code>'diff(o, n)''</code> .</p>
+
+<p>It will be common that we will be more interested in <code>'diff'</code> as a word than a portion of string. In this case, we could use <code>ack '\bdiff\b'</code> but there is a handy option <code>-w</code> which force a pattern to match a complete word. So we could send our search result as <code>ack -w diff</code>.</p>
+
+<p>As in any regular expression flavors, to match character such as <code>$</code> or <code>.</code>, we need to escape them in the pattern as <code>'\$\.proxy'</code>. In this case, <code>ack</code> also comes with a handy way to treat the pattern as string literal. Use <code>ack -Q $.proxy</code> to match text against liternal <code>'$.proxy'</code>. It is useful to match IP addresses in log file such as <code>ack aa.bb.cc.dd access.log -Q</code>.</p>
+
+<h2 id="limit-where-the-search-happens">Limit Where the Search Happens</h2>
+<p>You might have already noticed that in the above example, <code>ack</code> automatically search under your current working directory.</p>
+
+<p>In order to alter this behavior, you could specify the file or directory to be searched in. <code>ack href js/bootstrap-alert.js</code> will only match pattern in the <code>js/bootstrap-alert.js</code> file. Similarly, if you specify a directory name as <code>ack proxy docs</code>, it will search in the <code>'docs'</code> directory recursively.</p>
+
+<p>To cancel the recursive behavior, pass in <code>-n</code> or <code>--no-recurce</code>. For example <code>ack post docs -n</code> will only match pattern in the <code>'docs'</code> directory but not its subdirectories.</p>
+
+<p>You can also ignore directory with <code>--ignore-dir=name</code> option, <code>ack post --ignore-dir=docs</code> will seek <code>'post'</code> in all directories other than <code>'docs'</code>.</p>
+
+<p>Sometimes the constrain is complicated, then the option <code>-f</code> will be helpful as it will print the files to be searched before performing the search. For example <code>ack --ignore-dir=docs -f</code> will print all the files <code>ack</code> will search in.</p>
+
+<p>Besides reading from arguments for files, <code>ack</code> could also reads from STDIN. This makes <code>ack</code> a nice candidate in unix pipeline. We could chain multiple <code>ack</code> together to zero in on what the text you really care about. For example <code>ack postError js | ack message</code> <strong>first</strong> find matches for <code>'postError'</code> in all <code>'js'</code> directory and <strong>within the result</strong> it find matches for <code>'message'</code>.</p>
+
+<h2 id="add-files-to-be-searched">Add Files to be Searched</h2>
+<p>Try <code>ack background less</code> to search files in the <code>less</code> directory. It doesn’t return the result we are looking for, the <code>.less</code> files are ignored by <code>ack</code>. There must be something wrong with <code>ack</code>, right?</p>
+
+<p>However, this behavior is not an error but is by design by its author Andy Lester:</p>
+
+<blockquote>
+ <p>… Most codebases have a lot files in them which aren’t source files, and grep wastes a lot of time searching through all of those as well and returning matches from those files. </p>
+</blockquote>
+
+<blockquote>
+ <p>That’s why ack’s behavior of not searching things it doesn’t recognize is one of its greatest strengths: the speed you get from only searching the things that you want to be looking at.</p>
+</blockquote>
+
+<p><code>ack</code> is designed to only search in file types it knows. The file types known by <code>ack</code> could be seen with <code>ack --help-types</code>. Through <code>ack --help-types | ack less</code> we found that, <code>*.less</code> is not known by <code>ack</code> and that’s the reason why they are ignored.</p>
+
+<p>To add more file types we use <code>--type-set</code> and <code>--type-add</code>. With <code>ack background less --type-set less=.less</code>, we succeeded in searching in the <code>*.less</code> files. </p>
+
+<p>Sometimes, we don’t care about file type and just want search in all files in the directory, in these cases, we use <code>--all-types</code> or <code>-a</code>. It will search in all files regardless of its type with one exception - the CVS directory such as <code>.git</code> or <code>.svn</code> is excluded. If we want to count them in, use the ultimate <code>--unrestricted</code> or <code>-u</code> options to search <strong>everything</strong> within a directory.</p>
+
+<h2 id="make-configuration-sticky">Make Configuration Sticky</h2>
+<p>In most cases, we want to limit our searches to certain types, then it will be tedious to type <code>--type-set</code> or <code>--type-add</code> every time we want to search beyond build-in file types. <code>~/.ackrc</code> comes into play in these case. This is the configuration file which will be loaded by <code>ack</code>. All the options we introduced above could be written to it to make it permanent.</p>
+
+<p>Take my configuration as an example:</p>
+
+<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="code"><pre><code class="bash"><span class="line"><span class="c"># ~/.ackrc ack configuration file</span>
+</span><span class="line">
+</span><span class="line"><span class="c"># Sort files by default</span>
+</span><span class="line">--sort-files
+</span><span class="line">
+</span><span class="line"><span class="c"># Use smart-case by default</span>
+</span><span class="line">--smart-case
+</span><span class="line">
+</span><span class="line"><span class="c"># Extended File Types</span>
+</span><span class="line">--type-add<span class="o">=</span><span class="nv">css</span><span class="o">=</span>.less,.scss,.sass
+</span><span class="line">--type-add<span class="o">=</span><span class="nv">ruby</span><span class="o">=</span>.haml
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">coffee</span><span class="o">=</span>.coffee
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">markdown</span><span class="o">=</span>.md,.markdown
+</span><span class="line">--type-set<span class="o">=</span><span class="nv">json</span><span class="o">=</span>.json
+</span></code></pre></td></tr></table></div></figure></notextile></div>
+
+<p>One thing to be noticed, instead of use whitespace in <code>--type-add less=.less</code> use <code>=</code>. Also, line begins with <code>#</code> is ignored.</p>
+
+<p>After adding our own file types, we could use <code>--type less</code> / <code>--less</code> to limit searches in certain file types or <code>--type noless</code> or <code>--noless</code> to exclude them. </p>
+
+<h2 id="more-magic-and-conclusion">More Magic and Conclusion</h2>
+<p><code>ack</code> comes a lot options for the format of output, you could use <code>--pager=less -r</code> to use <code>less</code> as pager with color support, or use <code>-C</code> to display the lines above/below the matched line as well. For more information, check out <code>man ack</code>.</p>
+
+<p>This handy tool is smarter and faster than <code>grep</code> and I have been using it heavily in my workflow. Moreover, the coming <a href="http://stackoverflow.com/questions/9508431/ack-binding-an-actual-file-name-to-a-filetype#answer-9511450">ack2.0</a> is more powerful in terms of file type filtering and multiple config file support.</p>
+
+<p>Hope this introduction makes you comfortable with <code>ack</code>.</p>
+
+<p>Do you know other “improved” substitute for daily unix utility?</p>
+
+]]></content>
+ </entry>
+
+ <entry>
<title type="html"><![CDATA[How to Measure and Monitor Network Performance]]></title>
<link href="http://blog.yangchenyun.com/2012/02/measure-network-performance/"/>
<updated>2012-02-17T15:54:00+08:00</updated>
View
142 blog/categories/tool/atom.xml
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title><![CDATA[Category: tool | Steven Yang's Blog | 杨晨昀]]></title>
+ <link href="http://blog.yangchenyun.com/blog/categories/tool/atom.xml" rel="self"/>
+ <link href="http://blog.yangchenyun.com/"/>
+ <updated>2012-10-08T00:13:59+08:00</updated>
+ <id>http://blog.yangchenyun.com/</id>
+ <author>
+ <name><![CDATA[Steven Yang]]></name>
+
+ </author>
+ <generator uri="http://octopress.org/">Octopress</generator>
+
+
+ <entry>
+ <title type="html"><![CDATA[Ack - a better way to search in files]]></title>
+ <link href="http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files/"/>
+ <updated>2012-09-02T16:58:00+08:00</updated>
+ <id>http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files</id>
+ <content type="html"><![CDATA[<p>Recently, <a href="http://betterthangrep.com/">ack</a> became the replacement for <code>grep</code> when I need to spot editing point in my code bases. It wins over <code>grep</code> in terms of:</p>
+
+<ul>
+ <li>A better pattern match syntax with <a href="http://perldoc.perl.org/perlre.html">Perl regular expressions</a></li>
+ <li>Smarter to limit searches in directories or certain file types</li>
+ <li>Much prettier display of result</li>
+ <li>Config files to make customization permanent</li>
+</ul>
+
+<p>These advantages will be introduced in the the following sections and after reading it I hope you will be comfortable with it.</p>
+
+<p>Let’s start by installing <code>ack</code>:</p>
+
+<p>Mac OS X with homebrew:</p>
+
+<pre><code>brew install ack
+</code></pre>
+
+<p>Debian/Ubuntu</p>
+
+<pre><code>sudo apt-get install ack-grep; sudo ln -s $(which ack-grep) /usr/local/bin/ack
+</code></pre>
+
+<p>Then <code>git clone https://github.com/twitter/bootstrap</code> to get the directory used in following examples.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</a></li>
+ <li><a href="#limit-where-the-search-happens">Limit Where the Search Happens</a></li>
+ <li><a href="#add-files-to-be-searched">Add Files to be Searched</a></li>
+ <li><a href="#make-configuration-sticky">Make Configuration Sticky</a></li>
+ <li><a href="#sort-files-by-default">Sort files by default</a></li>
+ <li><a href="#use-smart-case-by-default">Use smart-case by default</a></li>
+ <li><a href="#extended-file-types">Extended File Types</a> <ul>
+ <li><a href="#more-magic-and-conclusion">More Magic and Conclusion</a></li>
+ </ul>
+ </li>
+</ul>
+
+<h2 id="search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</h2>
+<p>Let’s start with a simple search <code>ack diff</code>.</p>
+
+<p>It prints out all the files whose lines contain the string <code>'diff'</code> within the current working directory.</p>
+
+<p>In fact <code>'diff'</code> could be any valid Perl Regular Expression include the <a href="http://www.regular-expressions.info/refadv.html">advanced regular expression syntax</a>, if you are familiar with regular expression in Ruby, Python, javaScript or Perl, you will be far more at home with the syntax than GNU Basic Regular Expression.</p>
+
+<p>For example, we could use <code>ack 'diff\(.+\)'</code> to detect a string as a function call such as <code>'diff(o, n)''</code> .</p>
+
+<p>It will be common that we will be more interested in <code>'diff'</code> as a word than a portion of string. In this case, we could use <code>ack '\bdiff\b'</code> but there is a handy option <code>-w</code> which force a pattern to match a complete word. So we could send our search result as <code>ack -w diff</code>.</p>
+
+<p>As in any regular expression flavors, to match character such as <code>$</code> or <code>.</code>, we need to escape them in the pattern as <code>'\$\.proxy'</code>. In this case, <code>ack</code> also comes with a handy way to treat the pattern as string literal. Use <code>ack -Q $.proxy</code> to match text against liternal <code>'$.proxy'</code>. It is useful to match IP addresses in log file such as <code>ack aa.bb.cc.dd access.log -Q</code>.</p>
+
+<h2 id="limit-where-the-search-happens">Limit Where the Search Happens</h2>
+<p>You might have already noticed that in the above example, <code>ack</code> automatically search under your current working directory.</p>
+
+<p>In order to alter this behavior, you could specify the file or directory to be searched in. <code>ack href js/bootstrap-alert.js</code> will only match pattern in the <code>js/bootstrap-alert.js</code> file. Similarly, if you specify a directory name as <code>ack proxy docs</code>, it will search in the <code>'docs'</code> directory recursively.</p>
+
+<p>To cancel the recursive behavior, pass in <code>-n</code> or <code>--no-recurce</code>. For example <code>ack post docs -n</code> will only match pattern in the <code>'docs'</code> directory but not its subdirectories.</p>
+
+<p>You can also ignore directory with <code>--ignore-dir=name</code> option, <code>ack post --ignore-dir=docs</code> will seek <code>'post'</code> in all directories other than <code>'docs'</code>.</p>
+
+<p>Sometimes the constrain is complicated, then the option <code>-f</code> will be helpful as it will print the files to be searched before performing the search. For example <code>ack --ignore-dir=docs -f</code> will print all the files <code>ack</code> will search in.</p>
+
+<p>Besides reading from arguments for files, <code>ack</code> could also reads from STDIN. This makes <code>ack</code> a nice candidate in unix pipeline. We could chain multiple <code>ack</code> together to zero in on what the text you really care about. For example <code>ack postError js | ack message</code> <strong>first</strong> find matches for <code>'postError'</code> in all <code>'js'</code> directory and <strong>within the result</strong> it find matches for <code>'message'</code>.</p>
+
+<h2 id="add-files-to-be-searched">Add Files to be Searched</h2>
+<p>Try <code>ack background less</code> to search files in the <code>less</code> directory. It doesn’t return the result we are looking for, the <code>.less</code> files are ignored by <code>ack</code>. There must be something wrong with <code>ack</code>, right?</p>
+
+<p>However, this behavior is not an error but is by design by its author Andy Lester:</p>
+
+<blockquote>
+ <p>… Most codebases have a lot files in them which aren’t source files, and grep wastes a lot of time searching through all of those as well and returning matches from those files. </p>
+</blockquote>
+
+<blockquote>
+ <p>That’s why ack’s behavior of not searching things it doesn’t recognize is one of its greatest strengths: the speed you get from only searching the things that you want to be looking at.</p>
+</blockquote>
+
+<p><code>ack</code> is designed to only search in file types it knows. The file types known by <code>ack</code> could be seen with <code>ack --help-types</code>. Through <code>ack --help-types | ack less</code> we found that, <code>*.less</code> is not known by <code>ack</code> and that’s the reason why they are ignored.</p>
+
+<p>To add more file types we use <code>--type-set</code> and <code>--type-add</code>. With <code>ack background less --type-set less=.less</code>, we succeeded in searching in the <code>*.less</code> files. </p>
+
+<p>Sometimes, we don’t care about file type and just want search in all files in the directory, in these cases, we use <code>--all-types</code> or <code>-a</code>. It will search in all files regardless of its type with one exception - the CVS directory such as <code>.git</code> or <code>.svn</code> is excluded. If we want to count them in, use the ultimate <code>--unrestricted</code> or <code>-u</code> options to search <strong>everything</strong> within a directory.</p>
+
+<h2 id="make-configuration-sticky">Make Configuration Sticky</h2>
+<p>In most cases, we want to limit our searches to certain types, then it will be tedious to type <code>--type-set</code> or <code>--type-add</code> every time we want to search beyond build-in file types. <code>~/.ackrc</code> comes into play in these case. This is the configuration file which will be loaded by <code>ack</code>. All the options we introduced above could be written to it to make it permanent.</p>
+
+<p>Take my configuration as an example:</p>
+
+<p>```bash
+# ~/.ackrc ack configuration file</p>
+
+<h1 id="sort-files-by-default">Sort files by default</h1>
+<p>–sort-files</p>
+
+<h1 id="use-smart-case-by-default">Use smart-case by default</h1>
+<p>–smart-case</p>
+
+<h1 id="extended-file-types">Extended File Types</h1>
+<p>–type-add=css=.less,.scss,.sass
+–type-add=ruby=.haml
+–type-set=coffee=.coffee
+–type-set=markdown=.md,.markdown
+–type-set=json=.json
+```</p>
+
+<p>One thing to be noticed, instead of use whitespace in <code>--type-add less=.less</code> use <code>=</code>. Also, line begins with <code>#</code> is ignored.</p>
+
+<p>After adding our own file types, we could use <code>--type less</code> / <code>--less</code> to limit searches in certain file types or <code>--type noless</code> or <code>--noless</code> to exclude them. </p>
+
+<h2 id="more-magic-and-conclusion">More Magic and Conclusion</h2>
+<p><code>ack</code> comes a lot options for the format of output, you could use <code>--pager=less -r</code> to use <code>less</code> as pager with color support, or use <code>-C</code> to display the lines above/below the matched line as well. For more information, check out <code>man ack</code>.</p>
+
+<p>This handy tool is smarter and faster than <code>grep</code> and I have been using it heavily in my workflow. Moreover, the coming <a href="http://stackoverflow.com/questions/9508431/ack-binding-an-actual-file-name-to-a-filetype#answer-9511450">ack2.0</a> is more powerful in terms of file type filtering and multiple config file support.</p>
+
+<p>Hope this introduction makes you comfortable with <code>ack</code>.</p>
+
+<p>Do you know other “improved” substitute for daily unix utility?</p>
+
+]]></content>
+ </entry>
+
+</feed>
View
39 blog/archives/index.html → blog/categories/tool/index.html
@@ -2,9 +2,9 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, ">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Blog Archive">
- <title>Blog Archive | 杨晨昀 Steven Yang</title>
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | Category: tool">
+ <title>Category: tool | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
<script src="/javascripts/html5.js"></script>
@@ -46,11 +46,11 @@
<article role="article">
<header>
- <h1 class="entry-title">Blog Archive</h1>
+ <h1 class="entry-title">Category: Tool</h1>
</header>
- <div id="blog-archives">
+ <div id="blog-archives" class="category">
@@ -58,34 +58,7 @@ <h1 class="entry-title">Blog Archive</h1>
<h2>2012</h2>
<article>
- Included file &#8216;archive_post.html&#8217; not found in _includes directory
-</article>
-
-
-
-<article>
- Included file &#8216;archive_post.html&#8217; not found in _includes directory
-</article>
-
-
-
-
- <h2>2011</h2>
-
-<article>
- Included file &#8216;archive_post.html&#8217; not found in _includes directory
-</article>
-
-
-
-<article>
- Included file &#8216;archive_post.html&#8217; not found in _includes directory
-</article>
-
-
-
-<article>
- Included file &#8216;archive_post.html&#8217; not found in _includes directory
+ Included file 'archive_post.html' not found in _includes directory
</article>
</div>
View
142 blog/categories/unix-/atom.xml
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title><![CDATA[Category: unix, | Steven Yang's Blog | 杨晨昀]]></title>
+ <link href="http://blog.yangchenyun.com/blog/categories/unix-/atom.xml" rel="self"/>
+ <link href="http://blog.yangchenyun.com/"/>
+ <updated>2012-10-08T00:13:59+08:00</updated>
+ <id>http://blog.yangchenyun.com/</id>
+ <author>
+ <name><![CDATA[Steven Yang]]></name>
+
+ </author>
+ <generator uri="http://octopress.org/">Octopress</generator>
+
+
+ <entry>
+ <title type="html"><![CDATA[Ack - a better way to search in files]]></title>
+ <link href="http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files/"/>
+ <updated>2012-09-02T16:58:00+08:00</updated>
+ <id>http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files</id>
+ <content type="html"><![CDATA[<p>Recently, <a href="http://betterthangrep.com/">ack</a> became the replacement for <code>grep</code> when I need to spot editing point in my code bases. It wins over <code>grep</code> in terms of:</p>
+
+<ul>
+ <li>A better pattern match syntax with <a href="http://perldoc.perl.org/perlre.html">Perl regular expressions</a></li>
+ <li>Smarter to limit searches in directories or certain file types</li>
+ <li>Much prettier display of result</li>
+ <li>Config files to make customization permanent</li>
+</ul>
+
+<p>These advantages will be introduced in the the following sections and after reading it I hope you will be comfortable with it.</p>
+
+<p>Let’s start by installing <code>ack</code>:</p>
+
+<p>Mac OS X with homebrew:</p>
+
+<pre><code>brew install ack
+</code></pre>
+
+<p>Debian/Ubuntu</p>
+
+<pre><code>sudo apt-get install ack-grep; sudo ln -s $(which ack-grep) /usr/local/bin/ack
+</code></pre>
+
+<p>Then <code>git clone https://github.com/twitter/bootstrap</code> to get the directory used in following examples.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</a></li>
+ <li><a href="#limit-where-the-search-happens">Limit Where the Search Happens</a></li>
+ <li><a href="#add-files-to-be-searched">Add Files to be Searched</a></li>
+ <li><a href="#make-configuration-sticky">Make Configuration Sticky</a></li>
+ <li><a href="#sort-files-by-default">Sort files by default</a></li>
+ <li><a href="#use-smart-case-by-default">Use smart-case by default</a></li>
+ <li><a href="#extended-file-types">Extended File Types</a> <ul>
+ <li><a href="#more-magic-and-conclusion">More Magic and Conclusion</a></li>
+ </ul>
+ </li>
+</ul>
+
+<h2 id="search-with-modern-regexp-pattern">Search with Modern Regexp Pattern</h2>
+<p>Let’s start with a simple search <code>ack diff</code>.</p>
+
+<p>It prints out all the files whose lines contain the string <code>'diff'</code> within the current working directory.</p>
+
+<p>In fact <code>'diff'</code> could be any valid Perl Regular Expression include the <a href="http://www.regular-expressions.info/refadv.html">advanced regular expression syntax</a>, if you are familiar with regular expression in Ruby, Python, javaScript or Perl, you will be far more at home with the syntax than GNU Basic Regular Expression.</p>
+
+<p>For example, we could use <code>ack 'diff\(.+\)'</code> to detect a string as a function call such as <code>'diff(o, n)''</code> .</p>
+
+<p>It will be common that we will be more interested in <code>'diff'</code> as a word than a portion of string. In this case, we could use <code>ack '\bdiff\b'</code> but there is a handy option <code>-w</code> which force a pattern to match a complete word. So we could send our search result as <code>ack -w diff</code>.</p>
+
+<p>As in any regular expression flavors, to match character such as <code>$</code> or <code>.</code>, we need to escape them in the pattern as <code>'\$\.proxy'</code>. In this case, <code>ack</code> also comes with a handy way to treat the pattern as string literal. Use <code>ack -Q $.proxy</code> to match text against liternal <code>'$.proxy'</code>. It is useful to match IP addresses in log file such as <code>ack aa.bb.cc.dd access.log -Q</code>.</p>
+
+<h2 id="limit-where-the-search-happens">Limit Where the Search Happens</h2>
+<p>You might have already noticed that in the above example, <code>ack</code> automatically search under your current working directory.</p>
+
+<p>In order to alter this behavior, you could specify the file or directory to be searched in. <code>ack href js/bootstrap-alert.js</code> will only match pattern in the <code>js/bootstrap-alert.js</code> file. Similarly, if you specify a directory name as <code>ack proxy docs</code>, it will search in the <code>'docs'</code> directory recursively.</p>
+
+<p>To cancel the recursive behavior, pass in <code>-n</code> or <code>--no-recurce</code>. For example <code>ack post docs -n</code> will only match pattern in the <code>'docs'</code> directory but not its subdirectories.</p>
+
+<p>You can also ignore directory with <code>--ignore-dir=name</code> option, <code>ack post --ignore-dir=docs</code> will seek <code>'post'</code> in all directories other than <code>'docs'</code>.</p>
+
+<p>Sometimes the constrain is complicated, then the option <code>-f</code> will be helpful as it will print the files to be searched before performing the search. For example <code>ack --ignore-dir=docs -f</code> will print all the files <code>ack</code> will search in.</p>
+
+<p>Besides reading from arguments for files, <code>ack</code> could also reads from STDIN. This makes <code>ack</code> a nice candidate in unix pipeline. We could chain multiple <code>ack</code> together to zero in on what the text you really care about. For example <code>ack postError js | ack message</code> <strong>first</strong> find matches for <code>'postError'</code> in all <code>'js'</code> directory and <strong>within the result</strong> it find matches for <code>'message'</code>.</p>
+
+<h2 id="add-files-to-be-searched">Add Files to be Searched</h2>
+<p>Try <code>ack background less</code> to search files in the <code>less</code> directory. It doesn’t return the result we are looking for, the <code>.less</code> files are ignored by <code>ack</code>. There must be something wrong with <code>ack</code>, right?</p>
+
+<p>However, this behavior is not an error but is by design by its author Andy Lester:</p>
+
+<blockquote>
+ <p>… Most codebases have a lot files in them which aren’t source files, and grep wastes a lot of time searching through all of those as well and returning matches from those files. </p>
+</blockquote>
+
+<blockquote>
+ <p>That’s why ack’s behavior of not searching things it doesn’t recognize is one of its greatest strengths: the speed you get from only searching the things that you want to be looking at.</p>
+</blockquote>
+
+<p><code>ack</code> is designed to only search in file types it knows. The file types known by <code>ack</code> could be seen with <code>ack --help-types</code>. Through <code>ack --help-types | ack less</code> we found that, <code>*.less</code> is not known by <code>ack</code> and that’s the reason why they are ignored.</p>
+
+<p>To add more file types we use <code>--type-set</code> and <code>--type-add</code>. With <code>ack background less --type-set less=.less</code>, we succeeded in searching in the <code>*.less</code> files. </p>
+
+<p>Sometimes, we don’t care about file type and just want search in all files in the directory, in these cases, we use <code>--all-types</code> or <code>-a</code>. It will search in all files regardless of its type with one exception - the CVS directory such as <code>.git</code> or <code>.svn</code> is excluded. If we want to count them in, use the ultimate <code>--unrestricted</code> or <code>-u</code> options to search <strong>everything</strong> within a directory.</p>
+
+<h2 id="make-configuration-sticky">Make Configuration Sticky</h2>
+<p>In most cases, we want to limit our searches to certain types, then it will be tedious to type <code>--type-set</code> or <code>--type-add</code> every time we want to search beyond build-in file types. <code>~/.ackrc</code> comes into play in these case. This is the configuration file which will be loaded by <code>ack</code>. All the options we introduced above could be written to it to make it permanent.</p>
+
+<p>Take my configuration as an example:</p>
+
+<p>```bash
+# ~/.ackrc ack configuration file</p>
+
+<h1 id="sort-files-by-default">Sort files by default</h1>
+<p>–sort-files</p>
+
+<h1 id="use-smart-case-by-default">Use smart-case by default</h1>
+<p>–smart-case</p>
+
+<h1 id="extended-file-types">Extended File Types</h1>
+<p>–type-add=css=.less,.scss,.sass
+–type-add=ruby=.haml
+–type-set=coffee=.coffee
+–type-set=markdown=.md,.markdown
+–type-set=json=.json
+```</p>
+
+<p>One thing to be noticed, instead of use whitespace in <code>--type-add less=.less</code> use <code>=</code>. Also, line begins with <code>#</code> is ignored.</p>
+
+<p>After adding our own file types, we could use <code>--type less</code> / <code>--less</code> to limit searches in certain file types or <code>--type noless</code> or <code>--noless</code> to exclude them. </p>
+
+<h2 id="more-magic-and-conclusion">More Magic and Conclusion</h2>
+<p><code>ack</code> comes a lot options for the format of output, you could use <code>--pager=less -r</code> to use <code>less</code> as pager with color support, or use <code>-C</code> to display the lines above/below the matched line as well. For more information, check out <code>man ack</code>.</p>
+
+<p>This handy tool is smarter and faster than <code>grep</code> and I have been using it heavily in my workflow. Moreover, the coming <a href="http://stackoverflow.com/questions/9508431/ack-binding-an-actual-file-name-to-a-filetype#answer-9511450">ack2.0</a> is more powerful in terms of file type filtering and multiple config file support.</p>
+
+<p>Hope this introduction makes you comfortable with <code>ack</code>.</p>
+
+<p>Do you know other “improved” substitute for daily unix utility?</p>
+
+]]></content>
+ </entry>
+
+</feed>
View
98 blog/categories/unix-/index.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | Category: unix,">
+ <title>Category: unix, | 杨晨昀 Steven Yang</title>
+ <link rel="stylesheet" href="/stylesheets/screen.css">
+ <!--[if lt IE 9]>
+ <script src="/javascripts/html5.js"></script>
+ <![endif]-->
+</head>
+
+<body>
+ <div class="wrap">
+ <div id="sidebar" class="side group clear">
+ <header>
+ <a href="/">Steven Yang</a>
+ </header>
+ <nav>
+ <ul>
+ <li><a href="/about/">About</a></li>
+ <li><a href="/contact/">Contact</a></li>
+ </ul>
+
+<!-- AddThis Button BEGIN -->
+<div class="addthis_toolbox addthis_default_style ">
+ <div>
+ <a class="addthis_button_facebook_like" fb:like:width="46px"></a>
+ <a class='addthis_button_google_plusone' g:plusone:size='small' g:plusone:annotation='none'></a>
+ <br class="clear">
+ </div>
+ <div>
+ <a class="addthis_button_douban"></a>
+ <a class="addthis_button_sinaweibo"></a>
+ <a class="addthis_button_twitter"></a>
+ <br class="clear">
+ </div>
+</div>
+<!-- AddThis Button END -->
+
+
+ </div>
+ <div class="content">
+ <div>
+<article role="article">
+
+ <header>
+ <h1 class="entry-title">Category: Unix,</h1>
+
+ </header>
+
+ <div id="blog-archives" class="category">
+
+
+
+
+ <h2>2012</h2>
+
+<article>
+ Included file 'archive_post.html' not found in _includes directory
+</article>
+
+</div>
+
+
+</article>
+
+</div>
+
+<aside class="sidebar">
+
+ Included file 'asides/recent_posts.html' not found in _includes directoryIncluded file 'asides/github.html' not found in _includes directoryIncluded file 'asides/twitter.html' not found in _includes directoryIncluded file 'asides/delicious.html' not found in _includes directoryIncluded file 'asides/pinboard.html' not found in _includes directoryIncluded file 'asides/googleplus.html' not found in _includes directory
+
+</aside>
+
+
+ </div>
+ <br class="clear">
+ <footer>
+ <p>Powered by <a title="Don't worry, it's not the morally ambivalent doctor." href="http://github.com/mojombo/jekyll">Jekyll</a>.<span class="copyright">copyright 2011-2012&copy;Steven Yang</span></p>
+ <!-- <p>Also find me on <a href="http://stackoverflow.com/users/966437/steven-yang">stackoverflow</a> and <a href="http://delicious.com/chenyunyang">delicious</a>.</p> -->
+ </footer>
+ </div>
+</body>
+
+<!-- Add this script -->
+<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f01c8a46f097959"></script>
+<!-- Google Analytics Improved Version -->
+<script>var _gaq=[['_setAccount','UA-27986795-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'))
+</script>
+ <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
+ chromium.org/developers/how-tos/chrome-frame-getting-started -->
+ <!--[if lt IE 7 ]>
+ <script defer src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
+ <script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
+ <![endif]-->
+</html>
View
203 blog/categories/unix/atom.xml
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title><![CDATA[Category: unix | Steven Yang's Blog | 杨晨昀]]></title>
+ <link href="http://blog.yangchenyun.com/blog/categories/unix/atom.xml" rel="self"/>
+ <link href="http://blog.yangchenyun.com/"/>
+ <updated>2012-10-08T00:13:59+08:00</updated>
+ <id>http://blog.yangchenyun.com/</id>
+ <author>
+ <name><![CDATA[Steven Yang]]></name>
+
+ </author>
+ <generator uri="http://octopress.org/">Octopress</generator>
+
+
+ <entry>
+ <title type="html"><![CDATA[Understand Unix Pipeline]]></title>
+ <link href="http://blog.yangchenyun.com/2012/10/understand-unix-pipeline/"/>
+ <updated>2012-10-01T16:54:00+08:00</updated>
+ <id>http://blog.yangchenyun.com/2012/10/understand-unix-pipeline</id>
+ <content type="html"><![CDATA[<p>For linux beginners, these commands are powerful but confusing:</p>
+
+<pre><code>tail /var/log/nginx.log &gt; /tmp/recent.log
+node server.js 2&gt;&amp;1 &gt;/var/log/info.log
+ls -al | grep '/.rb' | wc -l
+tee &gt;(wc -l &gt;&amp;2) &lt; bigfile | gzip &gt; bigfile.gz
+</code></pre>
+
+<p>The shared syntaxes such as <code>&lt;</code>, <code>&gt;</code>, <code>&gt;&amp;1</code> or <code>|</code> indicates one of unix’s best features - standard IO streams. Standard IO streams has been introduced since <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">the early days of unix</a> and has formed a core part in <a href="http://www.faqs.org/docs/artu/ch01s06.html">unix philosophy</a>.</p>
+
+<blockquote>
+ <p>… Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.</p>
+</blockquote>
+
+<p>The following sections will explain IO streams of unix and their usage with programs. It will answer the following questions:
+- what is standard streams and how does it work with programs?
+- how to utilize standard streams in programs?
+- what is pipeline and how to use it?
+- how to make standard streams work with program arguments?</p>
+
+<p>If your are confused about unix streams, hope the following sections will help you understand the above commands; if you are already familiar with it, [references at the end][#references] might help you unleash more power of it.</p>
+
+<ul id="markdown-toc">
+ <li><a href="#the-abstract-io-interface-for-program">The Abstract IO Interface for Program</a> <ul>
+ <li><a href="#example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</a></li>
+ </ul>
+ </li>
+ <li><a href="#io-redirections">IO Redirections</a></li>
+ <li><a href="#piping">Piping</a></li>
+ <li><a href="#pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</a> <ul>
+ <li><a href="#process-substitution">Process substitution</a></li>
+ <li><a href="#xargs"><code>xargs</code></a></li>
+ </ul>
+ </li>
+ <li><a href="#reference">Reference</a></li>
+</ul>
+
+<h2 id="the-abstract-io-interface-for-program">The Abstract IO Interface for Program</h2>
+<p>Computer programs need to talk with its environment. It needs to communicate with various hardware such as disk drive, disc, screen, keyboard, mouse, speaker, printer etc. </p>
+
+<p>In operating system predates Unix, program has to contain the ‘knowledge’ for specific devices. It need to know the right ways to talk to various devices. To build a program working with three types of different printers, it needs to contain the pieces to translate program instructions to each printer.</p>
+
+<p><img src="" alt="img of program talks to various devices" /></p>
+
+<p>This binding with devices makes program less portable.</p>
+
+<p>To solve this issue, unix invented the <strong>standard IO streams</strong></p>
+
+<p>Standard IO streams abstract the complexity of reading and writing to different devices with <strong>data stream</strong>. Data stream is merely an ordered sequence of data bytes. Any program could read data stream until the end of a file and it could write data stream without declare the size. This generic ways to read and write data enables program to read input from keyboard devices, files and write data to displays, files, printers etc. without knowing anything about these devices.</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>There are three kinds of standard IO streams including standard input, standard output and standard error. Standard input is the data going into a program. By default it is expected from keyboard. Standard output is the where program writes its data to and by default it is the terminal. Standard error is another output stream similar to standard output. It is typically used to output error messages or diagnostics.</p>
+
+<p>Standard streams follows the unix’s phisolophy that <a href="http://en.wikipedia.org/wiki/Everything_is_a_file">‘everything is a file’</a>. So from the program’s point of view, these three standard streams have no difference from normal files. As long as a program could read a file, it could read from standard input; as long as it could write a file, it could write the standard output.</p>
+
+<p>The actual actions of ‘writing to standard output’ is determined by unix itself. It could mean printing to terminal, recording a video tape, burning a disc, sending to printer etc. All of these are handled by the kernel of unix. This feature amplifies the composibility and portablity of a program</p>
+
+<p><img src="" alt="img of program talks to standard io" /></p>
+
+<p>In conslusion, standard IO streams provide an unified input and output interfaces for the programs to communicate with various hardware devices without growing complexities. </p>
+
+<h3 id="example-of-program-talks-with-standard-streams">Example of Program Talks with Standard Streams</h3>
+<p>With the knowledge about the standard streams, let’s take a look at one program example.</p>
+
+<p>Type <code>cat</code> in the terminal and now the program will read the default standard input - keyboard. Type <code>first line</code> and <code>&lt;Enter&gt;</code>, it prints to string to the default standard output - the terminal.</p>
+
+<pre><code>$ cat
+first line
+&gt;first line
+</code></pre>
+
+<p><img src="" alt="img of command cat" /></p>
+
+<h2 id="io-redirections">IO Redirections</h2>
+<p>Sometimes we want to read data other than the keyboard or write data other than standard output. To alter the default stream source or destination is called <strong>IO Redirection</strong>. This could be archieved through <code>&lt;</code> or <code>&gt;</code>. Let’s first try <code>&gt;</code>:</p>
+
+<pre><code>$ ls -al &gt; /tmp/list.txt
+</code></pre>
+
+<p>It redirects the standard output to the file <code>/tmp/list.txt</code> instead of print to terminal.</p>
+
+<p><code>&gt;</code> has a sibling <code>&gt;&gt;</code> which will <strong>append</strong> data to file instead of writing it.</p>
+
+<pre><code>$ ls -al &gt;&gt; /tmp/list.txt
+</code></pre>
+
+<p>It appends the result to <code>/tmp/list.text</code> which should contain the same results twice. Let’s read this file now:</p>
+
+<pre><code>$ less &lt; /tmp/list.txt
+</code></pre>
+
+<p>It reads standard input from <code>/tmp/list.txt</code> instead of the keyboard.</p>
+
+<p><img src="" alt="img of IO Redirection" /></p>
+
+<p>How about redirect standard error? Use <code>2&gt;</code>:</p>
+
+<pre><code>$ find this-is-not-exist 2&gt; /tmp/error.txt
+</code></pre>
+
+<p>The error message is not displayed on the terminal but stored in the <code>/tmp/error.txt</code> file.</p>
+
+<p>The meaning of the <code>2</code> used in the above command is <strong>file descriptor</strong>, they are similar to file name which is used to access files in one system process.</p>
+
+<p>As standard streams don’t have file name, file descriptor is the usual way to access them. The file descriptors for standard input, standard output, standard error are 0, 1, and 2, respectively.</p>
+
+<p>So the above command means: execute the <code>find this-is-not-exist</code> command and redirect the file indicated by the file descriptor 2 (which is standard standard error) to <code>/tmp/error.txt</code>.</p>
+
+<p>File descriptor could also be used as redirection destination:</p>
+
+<pre><code>ls -al 2&gt;&amp;1 &gt;/tmp/result.txt
+</code></pre>
+
+<p>This means: execute <code>ls -al</code> and redirects file descriptor 2(standard error) to any destination file descriptor 1(standard output) points to and redirects standard output to file <code>/tmp/result.txt</code>. The <code>&amp;</code> used here is to distinguish between file name <code>1</code> and file descriptor <code>1</code>.</p>
+
+<p><img src="" alt="img of file descriptor cat" /></p>
+
+<h2 id="piping">Piping</h2>
+<p>Sometimes a program might write standard output data which might be read by another program as standard input. With the above knowledge it could be written by IO redirections:</p>
+
+<pre><code>ls -al ~ &gt; /tmp/list.tmp
+grep '\.sh' &lt; /tmp/list.tmp
+rm /tmp/list.tmp
+</code></pre>
+
+<p>But unix comes with a better method named pipeline which sends the standard output of one program to the standard input of another program. With pipeline the above example could be rewritten as <code>ls -al | grep '\.sh'</code>.</p>
+
+<p>With pipeline, it is possible to compose one giant pipeline to connect pieces of programs together to perform complex operations like <code>makewords sentence | lowercase | sort | unique | mismatch </code> in <a href="http://www.youtube.com/watch?v=tc4ROCJYbm0">this example(7:00)</a>.</p>
+
+<p>Another benefit of pipeline is that all the pieces of programs start execution as soon as data stream comes in. In the first example where a temporary file is created as a medium, <code>grep</code> is not executed until <code>ls -al</code> finishes and writes to the <code>/tmp/list.tmp</code>. In this case, if the temporary data is significantly big, <code>grep</code> needs to wait quitea while. However with pipeline, <code>grep</code> is executed once <code>ls -al</code> starts to send data through standard output. </p>
+
+<p>Pipeline takes less space of disk and memory but with faster processing as all the program runs in parellel to process the data stream.</p>
+
+<h2 id="pipe-standard-input--output-as-arguments">Pipe Standard Input / Output as arguments</h2>
+<p>### Difference between standard streams and arguments
+Sometimes the program returns the same result when read from standard input or execute with an arguments.</p>
+
+<p><code>cat log</code> has the same result as <code>cat &lt; log</code>. But the mechanism is different.
+<code>cat file</code> pass the file name <code>log</code> as an argument to <code>cat</code> but <code>cat &lt; log</code> passes the content of the <code>log</code> file as standard input to <code>cat</code>.</p>
+
+<h3 id="process-substitution">Process substitution</h3>
+
+<pre><code>diff &lt;(sort file1) &lt;(sort file2)
+</code></pre>
+
+<h3 id="xargs"><code>xargs</code></h3>
+
+<pre><code>ls *.zip | xargs -n 1 -t unzip
+</code></pre>
+
+<h2 id="reference">Reference</h2>
+<p><a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">Wikipedia Pipepine</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Standard_streams">Wikipedia Standard Stream</a></p>
+
+<p><a href="http://en.wikipedia.org/wiki/Process_substitution">Wikipedia Process Substitution</a></p>
+
+<p><a href="http://www.linfo.org/redirection.html">Redirection Definition</a></p>
+
+<p><a href="http://tldp.org/LDP/abs/html/io-redirection.html">I/O Redirection in Advanced Bash-Scripting Guide</a></p>
+
+<hr />
+
+<p>All the icons used in illustration are from The Noun Project.
+<a href="http://thenounproject.com/noun/hard-drive/#icon-No537">Hard Drive</a> and <a href="http://thenounproject.com/noun/computer/#icon-No115">Computer</a> is designed by annonymous designers.
+<a href="http://thenounproject.com/noun/computer-keyboard/#icon-No1807">Computer Keyboard</a> is designed by <a href="http://thenounproject.com/andrewforrester">Andrew Forrester</a>.
+<a href="http://thenounproject.com/noun/mouse/#icon-No890">Mouse</a> is designed by <a href="http://thenounproject.com/cbertoco">Camila Bertoco</a>.
+<a href="http://thenounproject.com/noun/floppy-disk/#icon-No2476">Floppy Disk</a> is designed by <a href="http://thenounproject.com/cortiemens">Cor Tiemens</a>.</p>
+
+<p><a href="http://thenounproject.com/noun/building-block/#icon-No5218" target="_blank">Building Block</a> designed by <a href="http://thenounproject.com/Mikhail1986" target="_blank">Michael Rowe</a> from The Noun Project
+<a href="http://thenounproject.com/noun/speaker/#icon-No4106" target="_blank">Speaker</a> designed by <a href="http://thenounproject.com/squintongreen" target="_blank">Samuel Q. Green</a> from The Noun Project
+<a href="http://thenounproject.com/noun/database/#icon-No4995" target="_blank">Database</a> designed by <a href="http://thenounproject.com/DmitryBaranovskiy" target="_blank">Dmitry Baranovskiy</a> from The Noun Project
+<a href="http://thenounproject.com/noun/document/#icon-No4769" target="_blank">Document</a> designed by <a href="http://thenounproject.com/mariavaragilal" target="_blank">Maria Varagilal</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No109" target="_blank">Printer</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No1235" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/johncaserta" target="_blank">John Caserta</a> from The Noun Project
+<a href="http://thenounproject.com/noun/printer/#icon-No3751" target="_blank">Printer</a> designed by <a href="http://thenounproject.com/bitsnbobs" target="_blank">James Fenton</a> from The Noun Project
+<a href="http://thenounproject.com/noun/gears/#icon-No1870" target="_blank">Gears</a> designed by <a href="http://thenounproject.com/daria" target="_blank">Dasha Shevyrenkova</a> from The Noun Project
+<a href="http://thenounproject.com/noun/arrow/#icon-No2487" target="_blank">Arrow</a> designed by <a href="http://thenounproject.com/cortiemens" target="_blank">Cor Tiemens</a> from The Noun Project</p>
+]]></content>
+ </entry>
+
+</feed>
View
98 blog/categories/unix/index.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | Category: unix">
+ <title>Category: unix | 杨晨昀 Steven Yang</title>
+ <link rel="stylesheet" href="/stylesheets/screen.css">
+ <!--[if lt IE 9]>
+ <script src="/javascripts/html5.js"></script>
+ <![endif]-->
+</head>
+
+<body>
+ <div class="wrap">
+ <div id="sidebar" class="side group clear">
+ <header>
+ <a href="/">Steven Yang</a>
+ </header>
+ <nav>
+ <ul>
+ <li><a href="/about/">About</a></li>
+ <li><a href="/contact/">Contact</a></li>
+ </ul>
+
+<!-- AddThis Button BEGIN -->
+<div class="addthis_toolbox addthis_default_style ">
+ <div>
+ <a class="addthis_button_facebook_like" fb:like:width="46px"></a>
+ <a class='addthis_button_google_plusone' g:plusone:size='small' g:plusone:annotation='none'></a>
+ <br class="clear">
+ </div>
+ <div>
+ <a class="addthis_button_douban"></a>
+ <a class="addthis_button_sinaweibo"></a>
+ <a class="addthis_button_twitter"></a>
+ <br class="clear">
+ </div>
+</div>
+<!-- AddThis Button END -->
+
+
+ </div>
+ <div class="content">
+ <div>
+<article role="article">
+
+ <header>
+ <h1 class="entry-title">Category: Unix</h1>
+
+ </header>
+
+ <div id="blog-archives" class="category">
+
+
+
+
+ <h2>2012</h2>
+
+<article>
+ Included file 'archive_post.html' not found in _includes directory
+</article>
+
+</div>
+
+
+</article>
+
+</div>
+
+<aside class="sidebar">
+
+ Included file 'asides/recent_posts.html' not found in _includes directoryIncluded file 'asides/github.html' not found in _includes directoryIncluded file 'asides/twitter.html' not found in _includes directoryIncluded file 'asides/delicious.html' not found in _includes directoryIncluded file 'asides/pinboard.html' not found in _includes directoryIncluded file 'asides/googleplus.html' not found in _includes directory
+
+</aside>
+
+
+ </div>
+ <br class="clear">
+ <footer>
+ <p>Powered by <a title="Don't worry, it's not the morally ambivalent doctor." href="http://github.com/mojombo/jekyll">Jekyll</a>.<span class="copyright">copyright 2011-2012&copy;Steven Yang</span></p>
+ <!-- <p>Also find me on <a href="http://stackoverflow.com/users/966437/steven-yang">stackoverflow</a> and <a href="http://delicious.com/chenyunyang">delicious</a>.</p> -->
+ </footer>
+ </div>
+</body>
+
+<!-- Add this script -->
+<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f01c8a46f097959"></script>
+<!-- Google Analytics Improved Version -->
+<script>var _gaq=[['_setAccount','UA-27986795-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'))
+</script>
+ <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you want to support IE 6.
+ chromium.org/developers/how-tos/chrome-frame-getting-started -->
+ <!--[if lt IE 7 ]>
+ <script defer src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
+ <script defer>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
+ <![endif]-->
+</html>
View
4 contact/index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, ">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. About me">
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | About me">
<title>About me | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
View
10 index.html
@@ -2,8 +2,8 @@
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:g="urn:g">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="杨晨昀, 网站设计, 网站开发, Steven Yang, Chenyun, web designer, shanghai, beijing, china, ">
- <meta name="description" content="Steven Yang's Blog. I mainly write about personal development and frontend development. Home">
+ <meta name="keywords" content="">
+ <meta name="description" content="Blog about hackings and development | Home">
<title>Home | 杨晨昀 Steven Yang</title>
<link rel="stylesheet" href="/stylesheets/screen.css">
<!--[if lt IE 9]>
@@ -55,6 +55,12 @@
<h2>Recent Articles</h2>
<ul id="recent-list">
+ <li><p><a class="more" href="/2012/10/understand-unix-pipeline/">Understand Unix Pipeline &raquo;</a>
+ </p></li>
+
+ <li><p><a class="more" href="/2012/09/ack-a-better-way-to-search-in-files/">Ack - a better way to search in files &raquo;</a>
+ </p></li>
+
<li><p><a class="more" href="/2012/02/measure-network-performance/">How to Measure and Monitor Network Performance &raquo;</a>
</p></li>
View
26 sitemap.xml
@@ -2,38 +2,42 @@
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
<url>
<loc>http://blog.yangchenyun.com/2011/08/tedxyouth-wesklake-speech/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-09-02T23:34:40+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/2011/12/lesson-learned/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-09-02T23:34:40+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/2011/12/annual-review/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-09-02T23:34:40+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/2012/02/plans-for-2012/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-09-02T23:34:40+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/2012/02/measure-network-performance/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-10-01T18:31:21+08:00</lastmod>
</url>
<url>
- <loc>http://blog.yangchenyun.com/about/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <loc>http://blog.yangchenyun.com/2012/09/ack-a-better-way-to-search-in-files/</loc>
+ <lastmod>2012-10-01T18:31:46+08:00</lastmod>
+ </url>
+ <url>
+ <loc>http://blog.yangchenyun.com/2012/10/understand-unix-pipeline/</loc>
+ <lastmod>2012-10-07T01:19:19+08:00</lastmod>
</url>
<url>
- <loc>http://blog.yangchenyun.com/blog/archives/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <loc>http://blog.yangchenyun.com/about/</loc>
+ <lastmod>2012-10-08T00:13:30+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/contact/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-09-02T23:34:40+08:00</lastmod>
</url>
<url>
<loc>http://blog.yangchenyun.com/</loc>
- <lastmod>2012-07-30T01:01:10+08:00</lastmod>
+ <lastmod>2012-10-07T01:19:19+08:00</lastmod>
</url>
</urlset>
View
2  stylesheets/screen.css
@@ -1 +1 @@
-/* normalize.css 2011-11-04T15:38 UTC - http://github.com/necolas/normalize.css */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}[hidden]{display:none}html{font-size:100%;overflow-y:scroll;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}body,button,input,select,textarea{font-family:sans-serif}a:focus{outline:thin dotted}a:hover,a:active{outline:0}h1{font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}blockquote{margin:1em 40px}dfn{font-style:italic}mark{background:#ff0;color:#000}pre,code,kbd,samp{font-family:monospace, serif;_font-family:'courier new', monospace;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:none}q:before,q:after{content:'';content:none}small{font-size:75%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}ul,ol{margin-left:0;padding:0 0 0 40px}dd{margin:0 0 0 40px}nav ul,nav ol{list-style:none;list-style-image:none}img{border:0;-ms-interpolation-mode:bicubic}svg:not(:root){overflow:hidden}figure{margin:0}form{margin:0}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;*margin-left:-7px}button,input,select,textarea{font-size:100%;margin:0;vertical-align:baseline;*vertical-align:middle}button,input{line-height:normal}button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button;*overflow:visible}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0}@font-face{font-family:"Blooming Grove";src:url('/fonts/examples/bgrove.ttf') format('truetype'), url('/fonts/examples/bgrove.otf') format('opentype')}@font-face{font-family:'OFL Sorts Mill Goudy TT';font-style:normal;font-weight:normal;src:local("OFL Sorts Mill Goudy TT"),local("OFLGoudyStMTT"),url("http://themes.googleusercontent.com/static/fonts/oflsortsmillgoudytt/v3/9ZZVVBRCceNnPBXqWLH8IAznsJgBJReFlc4fyGg_5CcC1LhKU8qFLLahJuQDJSaO.woff") format("woff")}@font-face{font-family:'OFL Sorts Mill Goudy TT';font-style:italic;font-weight:normal;src:local("OFL Sorts Mill Goudy TT Italic"),local("OFLGoudyStMTT-Italic"),url("http://themes.googleusercontent.com/static/fonts/oflsortsmillgoudytt/v3/4zlbkWdiblhTyAxV3yYOK1Map0k-03pf3IKr-TpLv1-zty3XAGWFpfUour78S_ql.woff") format("woff")}@font-face{font-family:"/fonts/Latine";src:url("/fonts/Latine.eot?") format("eot"),url("/fonts/Latine.woff") format("woff"),url("/fonts/Latine.ttf") format("truetype"),url("/fonts/Latine.svg#/fonts/Latine") format("svg");font-weight:normal;font-style:normal}@font-face{font-family:"Droid Serif";src:url("/fonts/DroidSerif-Regular.eot?") format("eot"),url("/fonts/DroidSerif-Regular.woff") format("woff"),url("/fonts/DroidSerif-Regular.ttf") format("truetype"),url("/fonts/DroidSerif-Regular.svg#/fonts/DroidSerif") format("svg");font-weight:normal;font-style:normal}body code,body pre{font-family:Consolas, Menlo, "Courier New", monospace;font-size:14px}.highlight .code pre{font-family:Consolas, Menlo, "Courier New", monospace;font-size:16px;line-height:25px;overflow-x:auto;border:1px solid #d5d5d5;border-left:10px solid #d5d5d5;background-color:#fafafa;padding:11px 15px 12px}.highlight .code pre::-webkit-scrollbar{height:25px}.highlight .code pre::-webkit-scrollbar-button:start,.highlight .code pre::-webkit-scrollbar-button:end{display:none}.highlight .code pre::-webkit-scrollbar-track-piece{background-color:#eee}.highlight .code pre::-webkit-scrollbar-thumb{background-color:#bbb;border:7px solid #eee;-webkit-background-clip:padding-box;-webkit-border-radius:12px}body p code,body li code{border:1px solid #ccc;background-color:#fafafa;font-size:13px;padding:1px 3px;line-height:20px;margin:0;white-space:nowrap}.highlight .code{background:#ffffff}.highlight .code .c{color:#999988;font-style:italic}.highlight .code .err{color:#a61717;background-color:#e3d2d2}.highlight .code .k{color:#000000;font-weight:bold}.highlight .code .o{color:#000000;font-weight:bold}.highlight .code .cm{color:#999988;font-style:italic}.highlight .code .cp{color:#999999;font-weight:bold}.highlight .code .c1{color:#999988;font-style:italic}.highlight .code .cs{color:#999999;font-weight:bold;font-style:italic}.highlight .code .gd{color:#000000;background-color:#ffdddd}.highlight .code .gd .x{color:#000000;background-color:#ffaaaa}.highlight .code .ge{color:#000000;font-style:italic}.highlight .code .gr{color:#aa0000}.highlight .code .gh{color:#999999}.highlight .code .gi{color:#000000;background-color:#ddffdd}.highlight .code .gi .x{color:#000000;background-color:#aaffaa}.highlight .code .go{color:#888888}.highlight .code .gp{color:#555555}.highlight .code .gs{font-weight:bold}.highlight .code .gu{color:#aaaaaa}.highlight .code .gt{color:#aa0000}.highlight .code .kc{color:#000000;font-weight:bold}.highlight .code .kd{color:#000000;font-weight:bold}.highlight .code .kp{color:#000000;font-weight:bold}.highlight .code .kr{color:#000000;font-weight:bold}.highlight .code .kt{color:#445588;font-weight:bold}.highlight .code .m{color:#009999}.highlight .code .s{color:#d14}.highlight .code .na{color:#008080}.highlight .code .nb{color:#0086B3}.highlight .code .nc{color:#445588;font-weight:bold}.highlight .code .no{color:#008080}.highlight .code .ni{color:#800080}.highlight .code .ne{color:#990000;font-weight:bold}.highlight .code .nf{color:#990000;font-weight:bold}.highlight .code .nn{color:#555555}.highlight .code .nt{color:#000080}.highlight .code .nv{color:#008080}.highlight .code .ow{color:#000000;font-weight:bold}.highlight .code .w{color:#bbbbbb}.highlight .code .mf{color:#009999}.highlight .code .mh{color:#009999}.highlight .code .mi{color:#009999}.highlight .code .mo{color:#009999}.highlight .code .sb{color:#d14}.highlight .code .sc{color:#d14}.highlight .code .sd{color:#d14}.highlight .code .s2{color:#d14}.highlight .code .se{color:#d14}.highlight .code .sh{color:#d14}.highlight .code .si{color:#d14}.highlight .code .sx{color:#d14}.highlight .code .sr{color:#009926}.highlight .code .s1{color:#d14}.highlight .code .ss{color:#990073}.highlight .code .bp{color:#999999}.highlight .code .vc{color:#008080}.highlight .code .vg{color:#008080}.highlight .code .vi{color:#008080}.highlight .code .il{color:#009999}html{overflow-y:scroll}body{color:#222;position:relative;background:#e7e8e8 url(/images/noise.jpg);font:normal 18px/25px Palatino,"Palatino Linotype",serif;line-height:25px}p,h1,h2,h3,h4,h5,h6{margin:0;padding:0}.clear{clear:both}body a,body a:visited{text-decoration:none;color:#e11d30}body a:hover{text-decoration:underline}body p{margin-bottom:1em}h1,h2,h3,h4,h5,h6{font-family:"Droid Serif",Palatino,"Palatino Linotype",sans-serif;font-weight:normal}h1{font-size:45px;line-height:50px;margin:25px 0}h2{font-size:32px;line-height:50px;margin:25px 0}h3{font-size:23px;line-height:25px;margin:25px 0}h4{font-size:18px;line-height:25px;margin:25px 0}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:#222}h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color:#e11d30;text-decoration:none}h1 .amp,h2 .amp,h3 .amp,h4 .amp,h5 .amp,h6 .amp{font-style:italic}.wrap{width:900px;margin:0 auto;position:relative}.wrap .content{width:680px;margin-left:220px;border-left:2px solid whiteSmoke;padding-left:20px}.wrap .side{width:200px;position:fixed;text-align:right}.wrap .side header{font-family:"Droid Serif",Palatino,"Palatino Linotype",sans-serif;font-size:23px;line-height:50px;text-transform:lowercase;padding-left:2px}.wrap .side header .amp{font-style:italic}.wrap .side header a{font-size:30px;text-transform:capitalize;color:#222;-webkit-transition-property:color;-moz-transition-property:color;-ms-transition-property:color;-o-transition-property:color;transition-property:color;-webkit-transition-duration:0.5s;-moz-transition-duration:0.5s;-ms-transition-duration:0.5s;-o-transition-duration:0.5s;transition-duration:0.5s;-webkit-transition-timing-function:ease-out;-moz-transition-timing-function:ease-out;-ms-transition-timing-function:ease-out;-o-transition-timing-function:ease-out;transition-timing-function:ease-out}.wrap .side header a:hover{color:#e11d30}.wrap .side nav{font:normal 18px/50px "Droid Serif",Palatino,"Palatino Linotype",sans-serif;text-align:right;text-transform:lowercase;padding-right:2px;line-height:30px}.wrap .side nav a{text-transform:capitalize}.wrap .side nav .sep{padding:0 4px;color:#666}.wrap footer{font-size:14px;font-style:italic;line-height:35px;text-align:center}.wrap footer .copyright{position:absolute;right:0;color:#aaa}blockquote{font-size:22px;line-height:26px;font-style:italic;margin:1em 2em}blockquote p{quotes:"\201c" "\201d"}blockquote p:first-of-type{text-indent:0}blockquote p::before{content:open-quote}blockquote p::after{content:no-close-quote}blockquote p:last-of-type::after{content:close-quote}blockquote p:last-child{margin-bottom:0}#post-stats p{color:#666;margin-top:-22px;margin-bottom:22px}body embed{-webkit-box-shadow:#777 1px 2px 7px;-moz-box-shadow:#777 1px 2px 7px;box-shadow:#777 1px 2px 7px;margin:30px auto;display:block}body img{-webkit-box-shadow:#777 1px 2px 7px;-moz-box-shadow:#777 1px 2px 7px;box-shadow:#777 1px 2px 7px}body img.left,body img.right{border:none;background:none;padding:none}body img.left{float:left;margin:0 15px 15px 0}body img.right{float:right;margin:0 0 15px 15px}body img.center{display:block;margin:0 auto}#post-content .gallery img{background:none;padding:0;border:none;display:inline;margin-bottom:25px;margin-right:25px}#post-content #markdown-toc{list-style:none}#post-content #markdown-toc ul{list-style:none}#post-content #markdown-toc ul:first-child>li{margin-left:0em}#post-content.with-diagrams img{display:block;margin:25px auto;padding:0;background:none;border:none}#related{margin:1em 0 2em 0}#related li{color:#666}.print-links{display:none}img.self{border:none;padding:0;margin:0;margin-right:-108px;margin-top:-15px;margin-left:30px;margin-bottom:20px}#scrolling-header{color:#999;font-size:23px;font-style:italic;font:italic 23px "Droid Serif",Palatino,"Palatino Linotype",sans-serif;line-height:30px;position:fixed;top:75px;text-align:right;width:180px}.addthis_toolbox{line-height:40px}.addthis_default_style>div>a{float:right !important}.fb_iframe_widget iframe{width:46px !important}
+/* normalize.css 2011-11-04T15:38 UTC - http://github.com/necolas/normalize.css */article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none}[hidden]{display:none}html{font-size:100%;overflow-y:scroll;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}body,button,input,select,textarea{font-family:sans-serif}a:focus{outline:thin dotted}a:hover,a:active{outline:0}h1{font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}blockquote{margin:1em 40px}dfn{font-style:italic}mark{background:#ff0;color:#000}pre,code,kbd,samp{font-family:monospace, serif;_font-family:'courier new', monospace;font-size:1em}pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word}q{quotes:none}q:before,q:after{content:'';content:none}small{font-size:75%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}ul,ol{margin-left:0;padding:0 0 0 40px}dd{margin:0 0 0 40px}nav ul,nav ol{list-style:none;list-style-image:none}img{border:0;-ms-interpolation-mode:bicubic}svg:not(:root){overflow:hidden}figure{margin:0}form{margin:0}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;*margin-left:-7px}button,input,select,textarea{font-size:100%;margin:0;vertical-align:baseline;*vertical-align:middle}button,input{line-height:normal}button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button;*overflow:visible}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0}@font-face{font-family:"Blooming Grove";src:url('/fonts/examples/bgrove.ttf') format('truetype'), url('/fonts/examples/bgrove.otf') format('opentype')}@font-face{font-family:'OFL Sorts Mill Goudy TT';font-style:normal;font-weight:normal;src:local("OFL Sorts Mill Goudy TT"),local("OFLGoudyStMTT"),url("http://themes.googleusercontent.com/static/fonts/oflsortsmillgoudytt/v3/9ZZVVBRCceNnPBXqWLH8IAznsJgBJReFlc4fyGg_5CcC1LhKU8qFLLahJuQDJSaO.woff") format("woff")}@font-face{font-family:'OFL Sorts Mill Goudy TT';font-style:italic;font-weight:normal;src:local("OFL Sorts Mill Goudy TT Italic"),local("OFLGoudyStMTT-Italic"),url("http://themes.googleusercontent.com/static/fonts/oflsortsmillgoudytt/v3/4zlbkWdiblhTyAxV3yYOK1Map0k-03pf3IKr-TpLv1-zty3XAGWFpfUour78S_ql.woff") format("woff")}@font-face{font-family:"/fonts/Latine";src:url("/fonts/Latine.eot?") format("eot"),url("/fonts/Latine.woff") format("woff"),url("/fonts/Latine.ttf") format("truetype"),url("/fonts/Latine.svg#/fonts/Latine") format("svg");font-weight:normal;font-style:normal}@font-face{font-family:"Droid Serif";src:url("/fonts/DroidSerif-Regular.eot?") format("eot"),url("/fonts/DroidSerif-Regular.woff") format("woff"),url("/fonts/DroidSerif-Regular.ttf") format("truetype"),url("/fonts/DroidSerif-Regular.svg#/fonts/DroidSerif") format("svg");font-weight:normal;font-style:normal}body code,body pre{font-family:Consolas, Menlo, "Courier New", monospace;font-size:14px}.highlight .code pre{font-family:Consolas, Menlo, "Courier New", monospace;font-size:16px;line-height:25px;overflow-x:auto;border:1px solid #d5d5d5;border-left:10px solid #d5d5d5;background-color:#fafafa;padding:11px 15px 12px}.highlight .code pre::-webkit-scrollbar{height:25px}.highlight .code pre::-webkit-scrollbar-button:start,.highlight .code pre::-webkit-scrollbar-button:end{display:none}.highlight .code pre::-webkit-scrollbar-track-piece{background-color:#eee}.highlight .code pre::-webkit-scrollbar-thumb{background-color:#bbb;border:7px solid #eee;-webkit-background-clip:padding-box;-webkit-border-radius:12px}body p code,body li code{border:1px solid #ccc;background-color:#fafafa;font-size:13px;padding:1px 3px;line-height:20px;margin:0;white-space:nowrap}.highlight .code{background:#ffffff}.highlight .code .c{color:#999988;font-style:italic}.highlight .code .err{color:#a61717;background-color:#e3d2d2}.highlight .code .k{color:#000000;font-weight:bold}.highlight .code .o{color:#000000;font-weight:bold}.highlight .code .cm{color:#999988;font-style:italic}.highlight .code .cp{color:#999999;font-weight:bold}.highlight .code .c1{color:#999988;font-style:italic}.highlight .code .cs{color:#999999;font-weight:bold;font-style:italic}.highlight .code .gd{color:#000000;background-color:#ffdddd}.highlight .code .gd .x{color:#000000;background-color:#ffaaaa}.highlight .code .ge{color:#000000;font-style:italic}.highlight .code .gr{color:#aa0000}.highlight .code .gh{color:#999999}.highlight .code .gi{color:#000000;background-color:#ddffdd}.highlight .code .gi .x{color:#000000;background-color:#aaffaa}.highlight .code .go{color:#888888}.highlight .code .gp{color:#555555}.highlight .code .gs{font-weight:bold}.highlight .code .gu{color:#aaaaaa}.highlight .code .gt{color:#aa0000}.highlight .code .kc{color:#000000;font-weight:bold}.highlight .code .kd{color:#000000;font-weight:bold}.highlight .code .kp{color:#000000;font-weight:bold}.highlight .code .kr{color:#000000;font-weight:bold}.highlight .code .kt{color:#445588;font-weight:bold}.highlight .code .m{color:#009999}.highlight .code .s{color:#d14}.highlight .code .na{color:#008080}.highlight .code .nb{color:#0086B3}.highlight .code .nc{color:#445588;font-weight:bold}.highlight .code .no{color:#008080}.highlight .code .ni{color:#800080}.highlight .code .ne{color:#990000;font-weight:bold}.highlight .code .nf{color:#990000;font-weight:bold}.highlight .code .nn{color:#555555}.highlight .code .nt{color:#000080}.highlight .code .nv{color:#008080}.highlight .code .ow{color:#000000;font-weight:bold}.highlight .code .w{color:#bbbbbb}.highlight .code .mf{color:#009999}.highlight .code .mh{color:#009999}.highlight .code .mi{color:#009999}.highlight .code .mo{color:#009999}.highlight .code .sb{color:#d14}.highlight .code .sc{color:#d14}.highlight .code .sd{color:#d14}.highlight .code .s2{color:#d14}.highlight .code .se{color:#d14}.highlight .code .sh{color:#d14}.highlight .code .si{color:#d14}.highlight .code .sx{color:#d14}.highlight .code .sr{color:#009926}.highlight .code .s1{color:#d14}.highlight .code .ss{color:#990073}.highlight .code .bp{color:#999999}.highlight .code .vc{color:#008080}.highlight .code .vg{color:#008080}.highlight .code .vi{color:#008080}.highlight .code .il{color:#009999}html{overflow-y:scroll}body{color:#222;position:relative;background:#e7e8e8 url(/images/noise.jpg);font:normal 18px/25px Palatino,"Palatino Linotype",serif;line-height:25px}p,h1,h2,h3,h4,h5,h6{margin:0;padding:0}.clear{clear:both}body a,body a:visited{text-decoration:none;color:#e11d30}body a:hover{text-decoration:underline}body p{margin-bottom:1em}h1,h2,h3,h4,h5,h6{font-family:"Droid Serif",Palatino,"Palatino Linotype",sans-serif;font-weight:normal}h1{font-size:35px;line-height:50px;margin:25px 0}h2{font-size:32px;line-height:50px;margin:25px 0}h3{font-size:23px;line-height:25px;margin:25px 0}h4{font-size:18px;line-height:25px;margin:25px 0}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color:#222}h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color:#e11d30;text-decoration:none}h1 .amp,h2 .amp,h3 .amp,h4 .amp,h5 .amp,h6 .amp{font-style:italic}.wrap{width:900px;margin:0 auto;position:relative}.wrap .content{width:680px;margin-left:220px;border-left:2px solid whiteSmoke;padding-left:20px}.wrap .side{width:200px;position:fixed;text-align:right}.wrap .side header{font-family:"Droid Serif",Palatino,"Palatino Linotype",sans-serif;font-size:23px;line-height:50px;text-transform:lowercase;padding-left:2px}.wrap .side header .amp{font-style:italic}.wrap .side header a{font-size:30px;text-transform:capitalize;color:#222;-webkit-transition-property:color;-moz-transition-property:color;-ms-transition-property:color;-o-transition-property:color;transition-property:color;-webkit-transition-duration:0.5s;-moz-transition-duration:0.5s;-ms-transition-duration:0.5s;-o-transition-duration:0.5s;transition-duration:0.5s;-webkit-transition-timing-function:ease-out;-moz-transition-timing-function:ease-out;-ms-transition-timing-function:ease-out;-o-transition-timing-function:ease-out;transition-timing-function:ease-out}.wrap .side header a:hover{color:#e11d30}.wrap .side nav{font:normal 18px/50px "Droid Serif",Palatino,"Palatino Linotype",sans-serif;text-align:right;text-transform:lowercase;padding-right:2px;line-height:30px}.wrap .side nav a{text-transform:capitalize}.wrap .side nav .sep{padding:0 4px;color:#666}.wrap footer{font-size:14px;font-style:italic;line-height:35px;text-align:center}.wrap footer .copyright{position:absolute;right:0;color:#aaa}blockquote{font-size:22px;line-height:26px;font-style:italic;margin:1em 2em}blockquote p{quotes:"\201c" "\201d"}blockquote p:first-of-type{text-indent:0}blockquote p::before{content:open-quote}blockquote p::after{content:no-close-quote}blockquote p:last-of-type::after{content:close-quote}blockquote p:last-child{margin-bottom:0}#post-stats p{color:#666;margin-top:-22px;margin-bottom:22px}body embed{-webkit-box-shadow:#777 1px 2px 7px;-moz-box-shadow:#777 1px 2px 7px;box-shadow:#777 1px 2px 7px;margin:30px auto;display:block}body img{-webkit-box-shadow:#777 1px 2px 7px;-moz-box-shadow:#777 1px 2px 7px;box-shadow:#777 1px 2px 7px}body img.left,body img.right{border:none;background:none;padding:none}body img.left{float:left;margin:0 15px 15px 0}body img.right{float:right;margin:0 0 15px 15px}body img.center{display:block;margin:0 auto}#post-content .gallery img{background:none;padding:0;border:none;display:inline;margin-bottom:25px;margin-right:25px}#post-content #markdown-toc{list-style:none}#post-content #markdown-toc ul{list-style:none}#post-content #markdown-toc ul:first-child>li{margin-left:0em}#post-content.with-diagrams img{display:block;margin:25px auto;padding:0;background:none;border:none}#related{margin:1em 0 2em 0}#related li{color:#666}.print-links{display:none}img.self{border:none;padding:0;margin:0;margin-right:-108px;margin-top:-15px;margin-left:30px;margin-bottom:20px}#scrolling-header{color:#999;font-size:23px;font-style:italic;font:italic 23px "Droid Serif",Palatino,"Palatino Linotype",sans-serif;line-height:30px;position:fixed;top:75px;text-align:right;width:180px}.addthis_toolbox{line-height:40px}.addthis_default_style>div>a{float:right !important}.fb_iframe_widget iframe{width:46px !important}
Please sign in to comment.
Something went wrong with that request. Please try again.