<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rico&#039;s Tech Memo</title>
	<atom:link href="http://ricochen.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ricochen.wordpress.com</link>
	<description>about programming, computer &#38; stuff</description>
	<lastBuildDate>Sun, 29 Jan 2012 16:47:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ricochen.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rico&#039;s Tech Memo</title>
		<link>http://ricochen.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ricochen.wordpress.com/osd.xml" title="Rico&#039;s Tech Memo" />
	<atom:link rel='hub' href='http://ricochen.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Javascript OOP design pattern</title>
		<link>http://ricochen.wordpress.com/2012/01/29/javascript-oop-design-pattern/</link>
		<comments>http://ricochen.wordpress.com/2012/01/29/javascript-oop-design-pattern/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 16:40:41 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1099</guid>
		<description><![CDATA[I&#8217;ve been using the following programming pattern whenever I need to write some client-side javascript: In the above example I create a Foo object and expose one function some_pub_func, which can be invoked by calling Foo.some_pub_func(). Enclosure is used to avoid name-space conflicts. It&#8217;s worth noting that the some_priv_func can not be accessed from outside [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1099&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the following programming pattern whenever I need to write some client-side javascript:<br />
<pre class="brush: jscript;">
( function() {
    if(!window.Foo) window.Foo={};
    function some_priv_func() {
        // define a private function (not accessible from
        // outside of the enclosure)
        alert('this is a private function');
    }
    function some_pub_func() {
        // calling some_priv_func()
        some_private_func();
    }
    window.Foo.some_pub_func=some_pub_func;
} )();
</pre><br />
In the above example I create a Foo object and expose one function <strong>some_pub_fun</strong>c, which can be invoked by calling <strong>Foo.some_pub_func()</strong>. Enclosure is used to avoid name-space conflicts. It&#8217;s worth noting that the <strong>some_priv_func</strong> can not be accessed from outside of the enclosure.</p>
<p>I recently discovered a better way to program the OOP way in Jtavascript through <a href="http://nodetuts.com/handson-nodejs-book.html" target="_blank">Hands-on Node.js</a> (page 100) and I would like to share with you this technique. Let&#8217;s look at code:<br />
<pre class="brush: jscript;">
( function() {
    if(!window.Foo2) {
        window.Foo2=function(options) {
            // to avoid getting confused when using
            // 'this' in member functions
            var self=this;
            self.options=options;
            function some_priv_func() {
                // define a private function (not accessible from
                // outside of the enclosure)
                alert('this is a private function');
            }
            self.some_pub_func=function() {
                // calling some_priv_func()
                some_priv_func();
            }
        };
        window.Foo2.create=function(options) {
            return new Foo2(options);
        }
    }
} )();
</pre></p>
<p>Foo2.create() is made so one can initialise a Foo2 instance without using the &#8220;new&#8221; keyword. You can use Foo2 in ways like the following:<br />
<pre class="brush: jscript;">
var f2=new Foo2( { name: 'the new guy' } ); // as if Foo2.create doesn't exist
</pre><br />
or<br />
<pre class="brush: jscript;">
var f2=Foo2.create( { name: 'the new guy' } );
</pre><br />
For demonstration purpose I also expose the member options to the public allowing it be accessed and changed. A better way to handle this is to use the jQuery extend function. (Assuming jQuery is being used)<br />
<pre class="brush: jscript;">
            ...
            var self=this;
            var defaults={
                name: 'no name'
            };
            // merge settings in options to defaults
            $.extend(defaults, options);
            function some_priv_func() {
            ...
</pre></p>
<p>So if one initialises Foo2 without any options ( <strong>var f2=Foo2.create()</strong> ), defaults will have its default value <strong>{name: &#8216;no name&#8217;}</strong>. Or it can be overwritten by providing a parameter.<br />
The benefit of this is the exposing of member options (using defaults instead, which is not accessible outside of Foo2) is avoided.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1099/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1099/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1099/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1099&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/29/javascript-oop-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>Print color in shell terminal</title>
		<link>http://ricochen.wordpress.com/2012/01/25/print-color-in-shell-terminal/</link>
		<comments>http://ricochen.wordpress.com/2012/01/25/print-color-in-shell-terminal/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 03:01:03 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1091</guid>
		<description><![CDATA[Sometimes you might want to print something with color in a text terminal (by color I mean something other than the default text color). Put the following shell function to your ~/.bash_profile and you are go to good. Some examples: The above commands should output something like this ($TERM setting xterm-256color, tested on both OS [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1091&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes you might want to print something with color in a text terminal (by color I mean something other than the default text color). Put the following shell function to your ~/.bash_profile and you are go to good.</p>
<p><pre class="brush: bash;">
cecho() {
    case $2 in
        red) code=31;;
        blue) code=34;;
        green) code=32;;
        cyan) code=36;;
        purple) code=35;;
        brown) code=33;;
        white) code=37;;
        *) code=30;;
    esac
    printf &quot;\e[01;${code}m$1\e[0m\n&quot;
}
</pre></p>
<p>Some examples:<br />
<pre class="brush: bash;">
cecho hello cyan
cecho &quot;something needs your attention&quot; brown
cecho &quot;there's something terribly wrong, have to abort now&quot; red
cecho &quot;this looks so pale&quot; white
cecho &quot;will purple work too?&quot; purple
cecho goodbye blue
</pre></p>
<p>The above commands should output something like this ($TERM setting xterm-256color, tested on both OS X 10.7.2 and Ubuntu 11.10 64bit Server):<br />
<a href="http://ricochen.files.wordpress.com/2012/01/screen-shot-2012-01-24-at-9-51-51-pm.png"><img src="http://ricochen.files.wordpress.com/2012/01/screen-shot-2012-01-24-at-9-51-51-pm.png?w=600&#038;h=197" alt="" title="cecho - color print in shell terminal" width="600" height="197" class="alignleft size-full wp-image-1092" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1091/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1091/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1091/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1091&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/25/print-color-in-shell-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>

		<media:content url="http://ricochen.files.wordpress.com/2012/01/screen-shot-2012-01-24-at-9-51-51-pm.png" medium="image">
			<media:title type="html">cecho - color print in shell terminal</media:title>
		</media:content>
	</item>
		<item>
		<title>Open a new tab (or window) in Mac OSX Terminal and run command</title>
		<link>http://ricochen.wordpress.com/2012/01/25/open-a-new-tab-or-window-in-mac-osx-terminal-and-run-command/</link>
		<comments>http://ricochen.wordpress.com/2012/01/25/open-a-new-tab-or-window-in-mac-osx-terminal-and-run-command/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 02:01:30 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[mac osx]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1087</guid>
		<description><![CDATA[[ UPDATE ] After implementing the ruby code by user tig I was like, did I just make things more complicated than they should be? I was surprised that I didn&#8217;t first think about using the following applescript instead. put the following codes in ~/.bash_profile All I need to do then is to run either [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1087&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>[ <strong>UPDATE</strong> ]<br />
After implementing the ruby code by user tig I was like, did I just make things more complicated than they should be? I was surprised that I didn&#8217;t first think about using the following applescript instead.</p>
<p>put the following codes in ~/.bash_profile<br />
<pre class="brush: bash;">
comm_tw() {
        [ $# -lt 2 ] &amp;&amp; return
        osascript -e &quot;
                tell application \&quot;System Events\&quot; to tell process \&quot;Terminal\&quot; to keystroke \&quot;$1\&quot; using command down
                tell application \&quot;Terminal\&quot; to do script \&quot;$2\&quot; in selected tab of the front window
        &quot; &gt; /dev/null 2&gt;&amp;1
}
newt() {
	comm_tw t &quot;$1&quot;
}
neww() {
	comm_tw n &quot;$1&quot;
}
</pre><br />
All I need to do then is to run either newt (to open a new tab or neww (to open a new window) and run command(s) in it. For example:<br />
<pre class="brush: bash;">
newt &quot;ls -l ~; uptime&quot;
neww &quot;date; who am i&quot;
</pre><br />
It&#8217;s worth noting that commands separated by semi-colon are allowed.</p>
<p>[ <strong>Initial Edit</strong> ]<br />
I was looking for a solution to open a new tab (or window) and run a command (ssh for example) as sometimes I need to ssh to a number of hosts at once. I found the answer <a href="http://superuser.com/questions/174576/opening-a-new-terminal-from-the-command-line-and-running-a-command-on-mac-os-x" target="_blank">here</a>. It&#8217;s almost what I needed for the tab part. I decided to change the ruby code (by sueruser.com user <a href="http://superuser.com/users/22584/tig">tig</a>) a bit so I can use an option [ which is -w ] to run command in a new window. I am gonna post the code below. You can also <a href="https://github.com/midnightcodr/term_runner">fork me on github</a>.</p>
<p><pre class="brush: ruby;">
#!/usr/bin/env ruby
# A ruby script to open a new tab (or a new window) and run command in it on Mac OS X
# Modified based on the answer from tig regarding question posted at
# http://superuser.com/questions/174576/opening-a-new-terminal-from-the-command-line-and-running-a-command-on-mac-os-x
# Expands its feature a bit by allowing -w option top run command in a new window
# Usage Example:
#   ./dt ls -l
#   ./dt -w top
#
# Tested with Ruby 1.8.7

require 'rubygems'
require 'shellwords'
require 'appscript'

class Terminal
  include Appscript
  attr_reader :terminal, :current_window
  def initialize
    @terminal = app('Terminal')
    @current_window = terminal.windows.first
    yield self
  end

  def tab(dir, command = nil, mode = 't')
    app('System Events').application_processes['Terminal.app'].keystroke(mode, :using =&gt; :command_down)
    cd_and_run dir, command
  end

  def cd_and_run(dir, command = nil)
    run &quot;clear; cd #{dir.shellescape}&quot;
    run command
  end

  def run(command)
    command = command.shelljoin if command.is_a?(Array)
    if command &amp;&amp; !command.empty?
      terminal.do_script(command, :in =&gt; current_window.tabs.last)
    end
  end
end

Terminal.new do |t|
  if ARGV.length&gt;=1 &amp;&amp; ARGV.first == '-w'
    t.tab(Dir.pwd, ARGV[1, ARGV.length], 'n')
  else
    t.tab(Dir.pwd, ARGV)
  end
end
</pre></p>
<p>As a side note, tmux can also be used for this kind of tasks with better scripting support. The only problem I <a href="http://ricochen.wordpress.com/2011/06/08/how-to-get-out-from-tmux-session-inside-a-tmux-window/" target="_blank">might run into</a> is hot key conflicts between local and remote hosts as most of the hosts I need to access are using tmux.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1087/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1087&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/25/open-a-new-tab-or-window-in-mac-osx-terminal-and-run-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>A real-time app made with node.js, socket.io, express &#8230;</title>
		<link>http://ricochen.wordpress.com/2012/01/19/a-real-time-app-made-with-node-js-socket-io-express/</link>
		<comments>http://ricochen.wordpress.com/2012/01/19/a-real-time-app-made-with-node-js-socket-io-express/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 01:55:25 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[node.js]]></category>
		<category><![CDATA[socket.io]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1081</guid>
		<description><![CDATA[This past weekend I decided to work on a pet project &#8211; build a real-time app using node.js. Modules used: socket.io, express, jade, sqlite3. Still screenshot: Checkout the source codes at: https://github.com/midnightcodr/news_board Video demo is available here (audio-less). Have fun.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1081&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This past weekend I decided to work on a pet project &#8211; build a real-time app using node.js. </p>
<p>Modules used: socket.io, express, jade, sqlite3.</p>
<p>Still screenshot:<br />
<div id="attachment_1080" class="wp-caption alignleft" style="width: 610px"><a href="http://ricochen.files.wordpress.com/2012/01/news_board_demo_still.png"><img src="http://ricochen.files.wordpress.com/2012/01/news_board_demo_still.png?w=600&#038;h=455" alt="News Board still image" title="news_board_demo_still" width="600" height="455" class="size-full wp-image-1080" /></a><p class="wp-caption-text">News Board 3 clients on the left, admin UI on the right</p></div></p>
<p>Checkout the source codes at:<br />
<a href="https://github.com/midnightcodr/news_board">https://github.com/midnightcodr/news_board</a></p>
<p>Video demo is available <a href="http://dl.dropbox.com/u/16020214/news_board_demo.mov" title="News Board in action" target="_blank">here</a> (audio-less).</p>
<p>Have fun.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1081/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1081&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/19/a-real-time-app-made-with-node-js-socket-io-express/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://dl.dropbox.com/u/16020214/news_board_demo.mov" length="4430872" type="video/quicktime" />
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>

		<media:content url="http://ricochen.files.wordpress.com/2012/01/news_board_demo_still.png" medium="image">
			<media:title type="html">news_board_demo_still</media:title>
		</media:content>
	</item>
		<item>
		<title>[Fresh] Install node.js on Ubuntu server 11.10 (x64) via nvm step by step guide</title>
		<link>http://ricochen.wordpress.com/2012/01/08/fresh-install-node-js-on-ubuntu-server-11-10-x64-via-nvm-step-by-step-guide/</link>
		<comments>http://ricochen.wordpress.com/2012/01/08/fresh-install-node-js-on-ubuntu-server-11-10-x64-via-nvm-step-by-step-guide/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 18:00:35 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[node.js]]></category>
		<category><![CDATA[nvm]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1072</guid>
		<description><![CDATA[Note: It&#8217;s better to put the source command (. ~/nvm/nvm.sh) into your ~/.bashrc since the nvm command might get used quite often: If anything goes wrong during nvm install (for example, complaining certain library is not installed, I found the easiest way to re-start the install process is to install the missing library, followed by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1072&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><pre class="brush: bash;">
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install curl git
cd ~
git clone git://github.com/creationix/nvm.git
. ~/nvm/nvm.sh
nvm install v0.6.7     # Current version as of this writing
nvm use v0.6.7
curl http://npmjs.org/install.sh | sh      # Optional to install npm but recommended
</pre></p>
<p><strong>Note:</strong> </p>
<ul>
<li>It&#8217;s better to put the source command (<strong>. ~/nvm/nvm.sh</strong>) into your <strong>~/.bashrc</strong> since the <strong>nvm</strong> command might get used quite often:<br />
<pre class="brush: bash;">
if [ -f ~/nvm/nvm.sh ]; then
    . ~/nvm/nvm.sh
fi
</pre>
        </li>
<li>If anything goes wrong during nvm install (for example, complaining certain library is not installed, I found the easiest way to re-start the install process is to install the missing library, followed by the removal of installation directory, ~/nvm/src/node-v0.6.7, for example</li>
<li>On my ubuntu vm running off an i3 laptop, it took 7 minutes to install node.js v0.6.7, YMMV</li>
<li>If you find yourself stuck inside node console, type command <strong>process.exit()</strong> to get out, solution found from <a href="http://www.hacksparrow.com/node-js-how-to-exit-from-the-node-console.html" target="_blank">here</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1072/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1072&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/08/fresh-install-node-js-on-ubuntu-server-11-10-x64-via-nvm-step-by-step-guide/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>Change git origin</title>
		<link>http://ricochen.wordpress.com/2012/01/07/change-git-origin/</link>
		<comments>http://ricochen.wordpress.com/2012/01/07/change-git-origin/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 18:35:04 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1065</guid>
		<description><![CDATA[Scenario: you checkout a remote github repo as read-only: After you work on the local working directory for a while you decide that you would want to be able to push the changes back to github. The easiest way is to either: 1) run the follow command on the root of the working directory: 2) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1065&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Scenario: </strong><br />
you checkout a remote github repo as read-only:<br />
<pre class="brush: bash;">
git clone git://github.com/yourusername/oneofyourrepo
</pre></p>
<p>After you work on the local working directory for a while you decide that you would want to be able to push the changes back to github.</p>
<p><strong>The easiest way is to either:</strong><br />
1) run the follow command on the root of the working directory:<br />
<pre class="brush: bash;">
git config remote.origin.url git@github.com:yourusername/oneofyourrepo
</pre><br />
2) edit <strong>.git/config</strong>, look for section <strong>[remote "origin"] </strong>and change the url to<br />
<strong>git@github.com:yourusername/oneofyourrepo</strong></p>
<p>If you have already added the ssh public key of the host that you are working on to github.com, you should now be able to push the changes.</p>
<p>Credit goes to: <a href="http://stackoverflow.com/questions/3011402/leaving-github-how-to-change-the-origin-of-a-git-repo" target="_blank">http://stackoverflow.com/questions/3011402/leaving-github-how-to-change-the-origin-of-a-git-repo</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1065/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1065/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1065/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1065&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/07/change-git-origin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>Build a simple PHP template with str_replace()</title>
		<link>http://ricochen.wordpress.com/2012/01/05/build-a-simple-php-template-with-str_replace/</link>
		<comments>http://ricochen.wordpress.com/2012/01/05/build-a-simple-php-template-with-str_replace/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 04:44:27 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1052</guid>
		<description><![CDATA[You are given a task to notify a list of customers regarding their pin setting changes through their email address on file. There are many ways to accomplish this in PHP. One way I found quite interesting is through a simple php function str_replace. Let me demo through the following example (only showing how the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1052&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You are given a task to notify a list of customers regarding their pin setting changes through their email address on file. There are many ways to accomplish this in PHP. One way I found quite interesting is through a simple php function <strong><a href="http://php.net/manual/en/function.str-replace.php" target="_blank">str_replace</a></strong>. Let me demo through the following example (only showing how the message body is constructed, the email address part should be easy to take care of):<br />
<pre class="brush: php;">
&lt;?php
        /* main.php */
        function build_key($key) {
                return '{{'.$key.'}}';
        }

        function gen_msg($format_str, $arr) {
                $keys=array_map(build_key, array_keys($arr));
                // $keys can also be generated by using the following code
                // but I found using array_map is more elegant and fun
                // $keys=array();
                // foreach(array_keys($arr) as $k) {
                //      array_push($keys, '{{'.$k.'}}');
                // }

                return str_replace( $keys, array_values($arr), $format_str);
        }

        // here's the template
        $template=&quot;Dear {{user}}, your pin number has been changed to {{pin}}.&quot;;

        // here's the data, hard-coded in this example but it can be pulled from external sources as well
        $data=array(
                array( 'user'=&gt;'John Smith', 'pin'=&gt;'1234' ),
                array( 'user'=&gt;'Mr. S', 'pin'=&gt;'9999' ),
                array( 'user'=&gt;'Customer', 'pin'=&gt;'****' )
        );

        foreach($data as $d) {
                printf(&quot;%s\n&quot;, gen_msg($template, $d));
        }
</pre></p>
<p>Run the above code through php (cli) will output the following:</p>
<p><code>Dear John Smith, your pin number has been changed to 1234.<br />
Dear Mr. S, your pin number has been changed to 9999.<br />
Dear Customer, your pin number has been changed to ****.</code></p>
<p>[ Update ] I also added an OOP implementation of the above code, if you are interested you can checkout <a href="https://github.com/midnightcodr/simple_php_template/tree/master/OOP" target="_blank">my code</a> on github.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1052/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1052/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1052/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1052&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/05/build-a-simple-php-template-with-str_replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>Combine regular expression and conditional statements in BASH</title>
		<link>http://ricochen.wordpress.com/2012/01/01/combine-regular-expression-and-conditional-statements-in-bash/</link>
		<comments>http://ricochen.wordpress.com/2012/01/01/combine-regular-expression-and-conditional-statements-in-bash/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 06:08:08 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1038</guid>
		<description><![CDATA[As we all know we can use conditional statements in BASH. For example, show usage if number of arguments is 0: We might also want to use regular expression to test if $1 is start, stop or restart if $# is no longer 0: But wouldn&#8217;t it be nice if the tests can be combined [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1038&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As we all know we can use conditional statements in BASH. For example, show usage if number of arguments is 0:<br />
<pre class="brush: bash;">
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
    echo &quot;Usage: $0 start|stop|restart&quot;
    exit 0
fi
echo &quot;going to run with \$1=$1&quot;
</pre></p>
<p>We might also want to use regular expression to test if $1 is <strong>start</strong>, <strong>stop</strong> or <strong>restart</strong> if $# is no longer 0:<br />
<pre class="brush: bash;">
#!/usr/bin/env bash
function usage() {
    echo &quot;Usage: $0 start|stop|restart&quot;
}
if [ $# -eq 0 ]; then
    usage
    exit 0
fi

if [[ ! $1 =~ ^(start|stop|restart)$ ]]; then
    usage
    exit 0
fi
echo &quot;going to run with \$1=$1&quot;
</pre></p>
<p>But wouldn&#8217;t it be nice if the tests can be combined together. With bash operator || the above code can be written as:<pre class="brush: bash;">
#!/usr/bin/env bash
function usage() {
    echo &quot;Usage: $0 start|stop|restart&quot;
}   
if [ $# -eq 0 ] || [[ ! $1 =~ ^(start|stop|restart)$ ]]; then
    usage
    exit 0
fi  
echo &quot;going to run with \$1=$1&quot;
</pre></p>
<p>One more example using operator &amp;&amp; instead:<br />
<pre class="brush: bash;">
#!/usr/bin/env bash
if [ -d ~/a_folder ] &amp;&amp; [[ $1 =~ ^(install|remove)$ ]]; then
    echo &quot;going to $1 something&quot; 
else
    echo &quot;Folder ~/a_folder doesn't exist or you specified the wrong parameter:&quot;
    echo &quot;Usage: $0 install|remove&quot; 
    exit 0
fi  
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1038/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1038&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2012/01/01/combine-regular-expression-and-conditional-statements-in-bash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>MySQL: select data whose certain column contains the specified values only</title>
		<link>http://ricochen.wordpress.com/2011/12/23/mysql-select-data-whose-certain-column-contains-the-specified-values-only/</link>
		<comments>http://ricochen.wordpress.com/2011/12/23/mysql-select-data-whose-certain-column-contains-the-specified-values-only/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 03:25:41 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1023</guid>
		<description><![CDATA[This problem could be best described by an example as below: k, v are both char(10), not null. I want to find out records whose v column is either 1 or 3 [and only 1 or 3, therefore in the above example the only qualified records are ('B', '1') and ('B', '3')]. This is just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1023&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This problem could be best described by an example as below:</p>
<p><pre class="brush: plain;">select * from mytbl;
+------+------+
| k    | v    |
+------+------+
| A    | 1    |
| A    | 2    |
| A    | 3    |
| B    | 1    |
| B    | 3    |
| C    | 1    |
| C    | 3    |
| C    | 4    |
| E    | 2    |
| E    | 1    |
| F    | 5    |
+------+------+
</pre></p>
<p>k, v are both char(10), not null.</p>
<p>I want to find out records whose v column is either 1 or 3 [and only 1 or 3, therefore in the above example the only qualified records are ('B', '1') and ('B', '3')]. This is just a simplified version of the problem I faced at work recently and I did find someone posting the similar question on Internet but I forgot to bookmark the url and I didn&#8217;t find its solutions interesting hence I pulled my hair a bit and came up with the following solution using <strong>group_concat</strong> and <strong>regexp</strong>:<br />
<pre class="brush: plain;">
select k, group_concat(distinct v order by v) as g from mytbl group by k having g regexp '^(1,?)?(3)?$';
+------+------+
| k    | g    |
+------+------+
| B    | 1,3  |
+------+------+
</pre></p>
<p>If the requirement becomes v is either 1, 3 or 4 (again, 1, 3 or 4 only), </p>
<p><pre class="brush: plain;">
select k, group_concat(distinct v order by v) as g from mytbl group by k having g regexp '^(1,?)?(3,?)?(4)?$';
+------+-------+
| k    | g     |
+------+-------+
| B    | 1,3   |
| C    | 1,3,4 |
+------+-------+
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1023/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1023&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2011/12/23/mysql-select-data-whose-certain-column-contains-the-specified-values-only/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
		<item>
		<title>git branching by example</title>
		<link>http://ricochen.wordpress.com/2011/12/11/git-branching-by-example/</link>
		<comments>http://ricochen.wordpress.com/2011/12/11/git-branching-by-example/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 16:37:23 +0000</pubDate>
		<dc:creator>ricoch3n</dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://ricochen.wordpress.com/?p=1014</guid>
		<description><![CDATA[In this post I am going to demonstrate how to use git to apply a bug fix from the master branch to a feature branch that has already committed a new feature. Example: fork a branch, add some new features to it. In the meanwhile add a bug fix to the master branch. We want [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1014&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I am going to demonstrate how to use git to apply a bug fix from the master branch to a feature branch that has already committed a new feature.</p>
<p><strong>Example</strong>: fork a branch, add some new features to it. In the meanwhile add a bug fix to the master branch. We want to apply the bug fix to the feature branch while working on it but we decide it&#8217;s not time yet to add the new feature to the master branch. The simplest way I found (so far) is to create a temporary branch (and switch to it) on top of the master branch with the bug-fix commit, merge from feature branch, then switch to feature branch, merge changes from combined.<br />
<pre class="brush: bash;">
mkdir demo_proj
cd demo_proj
vi func.php
</pre><br />
Put the following code into func.php and save.<br />
<pre class="brush: php;">
&lt;?php
    function do_something() {
        echo &quot;hello\n&quot;;
        return &quot;wrong value&quot;;
    }
</pre></p>
<p><pre class="brush: bash;">
git add .
git commit -a -m &quot;added function do_something in func.php&quot;
git checkout -b feature
vi func.php
</pre><br />
Add a new function new_feature() to func.php<br />
<pre class="brush: php;">
&lt;?php
    function do_something() {
        echo &quot;hello\n&quot;;
        return &quot;wrong value&quot;;
    }


    function new_feature() {
        return 999;
    }
</pre><br />
<pre class="brush: bash;">
git checkout master
vi func.php
</pre><br />
Change word &#8220;wrong&#8221; to &#8220;right&#8221;:<br />
<pre class="brush: php;">
&lt;?php
	function do_something() {
		echo &quot;hello\n&quot;;
		return &quot;right value&quot;;
	}
</pre><br />
<pre class="brush: bash;">
git commit -a -m &quot;fixed a bug in do_something()&quot;
git checkout -b combined
git merge feature
git checkout feature
git merge combined
git branch -d combined
</pre></p>
<p>After &#8220;git merge combined&#8221; the feature branch has the bug-fix from master branch while maintaining its own new_feature() function. Branch <strong>combined</strong> has accomplished its goal hence it&#8217;s OK to remove it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ricochen.wordpress.com/1014/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ricochen.wordpress.com/1014/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ricochen.wordpress.com/1014/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ricochen.wordpress.com&amp;blog=7838515&amp;post=1014&amp;subd=ricochen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ricochen.wordpress.com/2011/12/11/git-branching-by-example/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/feb5d9348c13cd4df5f9cb84ad78593a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricoch3n</media:title>
		</media:content>
	</item>
	</channel>
</rss>
