<?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/"
	>

<channel>
	<title>Shiqi's careless whisper</title>
	<atom:link href="http://shiqiyang.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://shiqiyang.com/blog</link>
	<description>世琦的无心快语</description>
	<lastBuildDate>Sat, 13 Aug 2011 08:14:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Great land of Africa here I come!</title>
		<link>http://shiqiyang.com/blog/?p=273</link>
		<comments>http://shiqiyang.com/blog/?p=273#comments</comments>
		<pubDate>Sat, 13 Aug 2011 08:13:37 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[travel]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=273</guid>
		<description><![CDATA[Going on vacation tomorrow, finally got a chance to do a 9 day safari trip in Kenya with some friends and then stop over at Switzerland for another 4 days on the way back to Bay area. Still packing at last minute but I&#8217;m so excited!]]></description>
			<content:encoded><![CDATA[<p>Going on vacation tomorrow, finally got a chance to do a 9 day safari trip in Kenya with some friends and then stop over at Switzerland for another 4 days on the way back to Bay area. Still packing at last minute but I&#8217;m so excited! </p>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=273"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;count=none&amp;text=Great%20land%20of%20Africa%20here%20I%20come%21" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;count=none&amp;text=Great%20land%20of%20Africa%20here%20I%20come%21" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;linkname=Great%20land%20of%20Africa%20here%20I%20come%21" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D273&amp;title=Great%20land%20of%20Africa%20here%20I%20come%21" id="wpa2a_2"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=273</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cars 2 is out this weekend</title>
		<link>http://shiqiyang.com/blog/?p=257</link>
		<comments>http://shiqiyang.com/blog/?p=257#comments</comments>
		<pubDate>Thu, 23 Jun 2011 09:33:21 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=257</guid>
		<description><![CDATA[Be sure to check it out in theater, my friend, although it is not so much favored by movie critics, mostly due to not having as deep of emotional storyline as last year&#8217;s toy story 3, I think it is still a solid, entertaining family film. And kids would like it for sure. Also be [...]]]></description>
			<content:encoded><![CDATA[<p>Be sure to check it out in theater, my friend, although it is not so much favored by movie critics, mostly due to not having as deep of emotional storyline as last year&#8217;s toy story 3,<br />
I think it is still a solid, entertaining family film. And kids would like it for sure.</p>
<p><a href="http://shiqiyang.com/blog/wp-content/uploads/2011/06/cars-2-630.jpg"><img class="alignnone size-full wp-image-258" title="cars-2-630" src="http://shiqiyang.com/blog/wp-content/uploads/2011/06/cars-2-630.jpg" alt="" width="630" height="376" /></a></p>
<p>Also be sure to check out the teaser of our next year&#8217;s &#8216;Brave&#8217;.  My colleagues and I have spent years on the new software platform<br />
and &#8216;Brave&#8217; is the first one that uses it.</p>
<p><a href="http://shiqiyang.com/blog/wp-content/uploads/2011/06/BraveTease.jpg"><img class="alignnone size-full wp-image-259" title="BraveTease" src="http://shiqiyang.com/blog/wp-content/uploads/2011/06/BraveTease.jpg" alt="" width="510" height="756" /></a></p>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=257"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;count=none&amp;text=Cars%202%20is%20out%20this%20weekend" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;count=none&amp;text=Cars%202%20is%20out%20this%20weekend" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;linkname=Cars%202%20is%20out%20this%20weekend" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D257&amp;title=Cars%202%20is%20out%20this%20weekend" id="wpa2a_4"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=257</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Ruby 1.9.2 and Rails 3 on Ubuntu 11.04</title>
		<link>http://shiqiyang.com/blog/?p=237</link>
		<comments>http://shiqiyang.com/blog/?p=237#comments</comments>
		<pubDate>Fri, 10 Jun 2011 07:19:12 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=237</guid>
		<description><![CDATA[It seems apt-get hasn&#8217;t updated with ruby 1.9.2 and rails 3, so apt-get install ruby/rails won&#8217;t get ruby 1.9.2 and rails 3 (at least not for me at the moment). But I really want to explore the world of rails 3, especially I&#8217;ve heard a lot has been changed since rails 2, which was the [...]]]></description>
			<content:encoded><![CDATA[<p>It seems apt-get hasn&#8217;t updated with ruby 1.9.2 and rails 3, so apt-get install ruby/rails won&#8217;t get ruby 1.9.2 and rails 3 (at least not for me at the moment).<br />
But I really want to explore the world of rails 3, especially I&#8217;ve heard a lot has been changed since rails 2, which was the version last time I touched it while I was at CMU.<br />
I was going to build from source but luckily I found <a href="http://stuffingabout.blogspot.com/2011/04/installing-rails-3-on-ubuntu-1104.html"> this blog post </a> which saved me quite a bit of time and effort.<br />
However, I did encounter some problems by following the steps from that post, so I&#8217;m posting my steps here hopefully this could be useful to some else.</p>
<p>first you need to install bunch of packages via apt-get if you haven&#8217;t already:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> curl git-core build-essential <span style="color: #c20cb9; font-weight: bold;">bison</span> openssl libreadline5 libreadline5-dev zlib1g zlib1g-dev libssl-dev libsqlite3-<span style="color: #000000;">0</span> libsqlite3-dev sqlite3 libxml2-dev libmysqlclient-dev mysql-client mysql-server <span style="color: #c20cb9; font-weight: bold;">autoconf</span></pre></td></tr></table></div>

<p>then you need install rvm, which is a great tool to manage your ruby version (I guess it&#8217;s like python_select in ruby world)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-s</span> https:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>install<span style="color: #000000; font-weight: bold;">/</span>rvm</pre></td></tr></table></div>

<p>add the following line to your .bashrc</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> . <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span>  <span style="color: #666666; font-style: italic;"># This loads RVM into a shell session.</span></pre></td></tr></table></div>

<p>source it so rvm is available in your shell session, I think the original post didn&#8217;t mention this step so if you follow it strictly like I did you will get an error like svmsudo command not found in further steps.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm</pre></td></tr></table></div>

<p>then install ruby and rails</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2
rvm use 1.9.2 <span style="color: #660033;">--default</span>
rvm 1.9.2 <span style="color: #660033;">--passenger</span>
rvm 1.9.2
gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libcurl4-openssl-dev
rvmsudo passenger-install-nginx-module
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</pre></td></tr></table></div>

<p>you should be able to use rails now:</p>
<pre>
shiqi@ubuntu:~$ which ruby
/home/shiqi/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
shiqi@ubuntu:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
shiqi@ubuntu:~$ which rails
/home/shiqi/.rvm/gems/ruby-1.9.2-p180/bin/rails
shiqi@ubuntu:~$ rails -v
Rails 3.0.8
</pre>
<p>easy, huh?</p>
<p>kudos to the author of the following references:<br />
1. <a href="http://stuffingabout.blogspot.com/2011/04/installing-rails-3-on-ubuntu-1104.html">http://stuffingabout.blogspot.com/2011/04/installing-rails-3-on-ubuntu-1104.html</a><br />
2. <a href="http://thekindofme.wordpress.com/2010/10/24/rails-3-on-ubuntu-10-10-with-rvm-passenger-and-nginx/">http://thekindofme.wordpress.com/2010/10/24/rails-3-on-ubuntu-10-10-with-rvm-passenger-and-nginx/</a><br />
3. <a href="https://rvm.beginrescueend.com/rvm/install/">https://rvm.beginrescueend.com/rvm/install/</a></p>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=237"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;count=none&amp;text=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;count=none&amp;text=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;linkname=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D237&amp;title=Install%20Ruby%201.9.2%20and%20Rails%203%20on%20Ubuntu%2011.04" id="wpa2a_6"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=237</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My new toy arrived</title>
		<link>http://shiqiyang.com/blog/?p=230</link>
		<comments>http://shiqiyang.com/blog/?p=230#comments</comments>
		<pubDate>Thu, 09 Jun 2011 09:34:29 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[gigs]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=230</guid>
		<description><![CDATA[Dell XPS 8300 desktop to replace my old (yet still robust) Lenovo T60p laptop (for the past 2 years I&#8217;ve been using it as a desktop). the newbie comes with i5 processor and 6G RAM, and I just put ubuntu 11.04 and fedora 15 on it, plus the existing Windows 7, it is really hard [...]]]></description>
			<content:encoded><![CDATA[<p>Dell XPS 8300 desktop to replace my old (yet still robust) Lenovo T60p laptop (for the past 2 years I&#8217;ve been using it as a desktop).<br />
the newbie comes with i5 processor and 6G RAM, and I just put ubuntu 11.04 and fedora 15 on it, plus the existing Windows 7, it is really hard to decide which linux I should boot with <img src='http://shiqiyang.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
It will take me some time to install all the things I need, but nagios should be relatively easy, was trying to install that on my Macbook Pro with Macport, such a nightmare.<br />
I spent 2 days trying to figure out the usage of gcc &#8211;arch flags and still have no clue how to fix that. decided to give up on that.<br />
So far everything went pretty smooth, found <a href="http://stuffingabout.blogspot.com/2011/04/installing-rails-3-on-ubuntu-1104.html">this blog post</a> to help with install rails 3 on ubuntu 11.04 but still having some minor troubles with rvm. Also the dual screen setting doesn&#8217;t look very easy to deal with in Ubuntu (my machine comes with only one HDMI plug and I had to use a Diamond BUV195 USB to DVI adapter to extend the screen). Fedora 15 meanwhile is giving me a hard time on the wireless adapter. I have to say under windows 7 those were handled much better (mostly because some of the drivers are only available for windows). All my wacky devices are recognized and installed, no question asked.<br />
Looks I just found some gigs for the weekend to figure out, can&#8217;t wait! <img src='http://shiqiyang.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
<a href="http://shiqiyang.com/blog/wp-content/uploads/2011/06/TS307_555pxBLOG.jpg"><img src="http://shiqiyang.com/blog/wp-content/uploads/2011/06/TS307_555pxBLOG.jpg" alt="" title="new toys!" width="555" height="311" class="alignnone size-full wp-image-231" /></a></p>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=230"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;count=none&amp;text=My%20new%20toy%20arrived" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;count=none&amp;text=My%20new%20toy%20arrived" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;linkname=My%20new%20toy%20arrived" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D230&amp;title=My%20new%20toy%20arrived" id="wpa2a_8"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=230</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sqlalchemy: merge on duplicates, primary key, unique and python class</title>
		<link>http://shiqiyang.com/blog/?p=192</link>
		<comments>http://shiqiyang.com/blog/?p=192#comments</comments>
		<pubDate>Sun, 05 Jun 2011 02:48:25 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=192</guid>
		<description><![CDATA[For a pythonista an amateur python code writer like me to work with sql, especially mysql there used to be very limited choices and I remember the days I used MySQLdb module with raw SQL statement string all over the place in my python code. My code looked so tedious that I had to quit my job [...]]]></description>
			<content:encoded><![CDATA[<p>For <del datetime="2011-06-03T07:55:01+00:00">a pythonista</del> an amateur python code writer like me to work with sql, especially mysql there used to be very limited choices and I remember the days I used MySQLdb module with raw SQL statement string all over the place in my python code. My code looked so tedious that I had to quit my job at yahoo to stay away from it. OK that wasn&#8217;t the reason why I quit, but the code I wrote for that tool to query bugzilla database was pretty lame indeed. I even had a class dedicated to generate sql statements based on different parameters passed in, and as expected I spent shit load of time maintaining and refactoring that class. Alright, in all fairness I have to admit that I shouldn&#8217;t attribute my horrible experiences solely to MySQLdb, it is a fantastic base data access layer implementation between python and mysql, lots of amazing tools/modules are based on it, my unpleasantness was actually almost entirely due to my bad sense of design pattern and refactoring.</p>
<p>So anyways, as history moves on and human nature of life keeps getting better and better, people, great and smart people created SqlAlchemy. The great thing (maybe just for me) is that it comes with data abstraction layer ORM. and suddenly I can access my data in an elegant, object-oriented way. I like it so much that I can dedicate a whole blog just talk about how it helped me become a better person and thus changed my life completely, Not.</p>
<p>But like all other powerful things SqlAlchemy has its Achilles&#8217; Heel&#8230;&#8230; well, I&#8217;m not going to talk about that here, LOL. What I want to talk about is just something I always feel inconvenient and really wish they could make it part of the SqlAlchmey library. So the here is the task I&#8217;m facing more often than not, in a nutshell: So I have two tables users and addresses, and users have a foreign key constrain to addresses, which means multiple users can share one address, but not vise versa. So the my db will look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">        <span style="color: #dc143c;">user</span> = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">'user'</span>, metadata,
            Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'id'</span>, Integer, primary_key = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
            Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span>, String<span style="color: black;">&#40;</span><span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
            Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'addr_id'</span>, Integer, ForeignKey<span style="color: black;">&#40;</span><span style="color: #483d8b;">'addr.id'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#41;</span>
&nbsp;
        addr = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">'addr'</span>, metadata,
            Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'id'</span>, Integer, primary_key = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
            Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'addr_info'</span>, String<span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>, unique=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>and of course my table classes will look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> User<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__repr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">','</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">name</span>,
                         <span style="color: #008000;">self</span>.<span style="color: black;">addr_id</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Addr<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, addr_info=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">addr_info</span> = addr_info
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__repr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">addr_info</span></pre></td></tr></table></div>

<p>and of course the mappers:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">mapper<span style="color: black;">&#40;</span>User, <span style="color: #dc143c;">user</span>, properties=<span style="color: black;">&#123;</span><span style="color: #483d8b;">'addr'</span>: relation<span style="color: black;">&#40;</span>Addr<span style="color: black;">&#41;</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
mapper<span style="color: black;">&#40;</span>Addr, addr<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>now I&#8217;m reading my data from a file, with each line describing a resident and an address, my code is supposed to read this file and put them into the database. The logic is fairly simple here, just parse the file, initialize my data class instance with data, then put them into the database. </p>
<p>However, the insertion process needs special attention here: if the address you parsed already exist in the db, you don&#8217;t want to insert another row in the address table to create a duplicate record, you really just want to update your foreign key and only insert your new resident here to avoid redundant insertion in the address table. The operation sounds very generic and I was so certain that SqlAlchemy would have something magical I can use to make this &#8220;update if exist&#8221; happen automatically. And Session.merge() at some point was so close to the pony in my dream until I found it only checks on primary key (<a href="http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg22204.html">see discussion here</a>). So my first and brutal force solution was always do a query first to query out the address id of existing record (None if not) and then assign the id explicitly to the foreign key for resident. Then my first cut looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">        <span style="color: #dc143c;">user</span>, addr = <span style="color: #008000;">self</span>.<span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_data</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
        known_addr = <span style="color: #008000;">self</span>.<span style="color: black;">session</span>.<span style="color: black;">query</span><span style="color: black;">&#40;</span>Addr<span style="color: black;">&#41;</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Addr.<span style="color: black;">addr_info</span>==addr.<span style="color: black;">addr_info</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> known_addr:
            addr = <span style="color: #008000;">self</span>.<span style="color: black;">session</span>.<span style="color: black;">merge</span><span style="color: black;">&#40;</span>known_addr<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">session</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span>addr<span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">user</span>.<span style="color: black;">addr</span> = addr</pre></td></tr></table></div>

<p>While this is essentially what needs to be done on logical level (unfortunately there are no magical APIs to handle this situation from SqlAlchemy, due to performance reasons, <a href="http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg22206.html">more details here</a>), it really makes the code long and hard to maintain. without putting this logic into some code block, almost every data insertion would require this kind of query/validation first. So what would be the best way to refactor this?</p>
<p>the first thing came up in my mind was to put this in my utility/helper class for database, the function could be shortened like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">        <span style="color: #dc143c;">user</span>, addr = <span style="color: #008000;">self</span>.<span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_data</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span>
        addr = db_helper.<span style="color: black;">sync_with_db</span><span style="color: black;">&#40;</span>addr<span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;">#all query_check_merge biz goes here</span>
        <span style="color: #dc143c;">user</span>.<span style="color: black;">addr</span> = addr</pre></td></tr></table></div>

<p>I&#8217;m not really in favor of this solution because I still need to remember to call the helper function from my utility/helper class after I parse my data. plus if I have more tables like address with slightly different logic I would ended up writing functions for each of them in my db_helper, and I have to remember to call all of them as well, it could get very ugly with a super long list of function calling.<br />
Generally speaking, the duplication check is really the business of a table itself since different table has different column names, types and requirements built around them, so it feels natural to build this logic into the table class. Is there a way to embed this into my table class so the duplication check is performed when my instance is formed? There are some smart solutions I found online and my favorite one is to utilize the __new__ class method to check the duplication during class instantiation. Follow <a href="http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject">this recipe</a> I could make my case work as simple as the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Addr<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, addr_info<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">addr_info</span> =addr_info
&nbsp;
mapper<span style="color: black;">&#40;</span>Addr, addr<span style="color: black;">&#41;</span>
Addr = unique_constructor<span style="color: black;">&#40;</span>Session, 
            <span style="color: #ff7700;font-weight:bold;">lambda</span> addr_info:addr_info, 
            <span style="color: #ff7700;font-weight:bold;">lambda</span> query, name:query.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Addr.<span style="color: black;">addr_info</span>==addr_info<span style="color: black;">&#41;</span>
<span style="color: black;">&#41;</span><span style="color: black;">&#40;</span>Addr<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>with declarative this could be simpler even more, as indicated on the recipe page above. </p>
<p>after that the call of</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">Addr<span style="color: black;">&#40;</span><span style="color: #483d8b;">'blah'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>will grant me a instance representing either an existing row or a new record. No more clumsy query_first_and_then_add business.</p>
<p>I was trying to customized it to make it look simpler and only work the class I created, until I realized how silly that is, it&#8217;s like changing the super key to 1000 doors to make it a normal key to only open 1. I&#8217;m glad I stopped myself before I face another door and start to miss the super key. </p>
<p>but to keep the record of my stupidity and help me learn, here is my super hacky class, it passed my test of 3 line of data so I&#8217;m sure it is useful to someone out there, LOL:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Addr<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, addr_info<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">addr_info</span> = addr_info
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__repr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">addr_info</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot; &quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__new__</span><span style="color: black;">&#40;</span>cls, addr=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        known_addr = sessionmaker<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">query</span><span style="color: black;">&#40;</span>cls<span style="color: black;">&#41;</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>Addr.<span style="color: black;">addr_info</span>==addr<span style="color: black;">&#41;</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> known_addr:
            <span style="color: #ff7700;font-weight:bold;">return</span> known_addr<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">object</span>.<span style="color: #0000cd;">__new__</span><span style="color: black;">&#40;</span>cls<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=192"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;count=none&amp;text=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;count=none&amp;text=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;linkname=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D192&amp;title=Sqlalchemy%3A%20merge%20on%20duplicates%2C%20primary%20key%2C%20unique%20and%20python%20class" id="wpa2a_10"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=192</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>making hooq work with pyQt and Qt4.7</title>
		<link>http://shiqiyang.com/blog/?p=195</link>
		<comments>http://shiqiyang.com/blog/?p=195#comments</comments>
		<pubDate>Fri, 03 Jun 2011 02:46:45 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[hooq]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=195</guid>
		<description><![CDATA[GUI automation test for desktop apps with Qt could be a PIA, not only because GUI automation is simply a PIA in general, but there are just not that much free open source tools you can make use of for Qt. Or I should say at least for me it is not easy to find [...]]]></description>
			<content:encoded><![CDATA[<p>GUI automation test for desktop apps with Qt could be a PIA, not only because GUI automation is simply a PIA in general,<br />
but there are just not that much free open source tools you can make use of for Qt. Or I should say at least for me it is not easy to find any.<br />
Almost all tools I found online are heavy weight commercial software<br />
that have this long and fancy feature set that I have to buy as a whole, out of which most I may never touch.</p>
<p>Luckily I found <a href="http://www.fredemmott.co.uk/blog/2010/01/18/Qt4%20GUI%20Testing%20with%20Hooq">hooq</a>, a free, open source tool to help recording qt events<br />
and replay them (which is exactly what I need, for now). Like all other free lunches it does take me some effort to make it useful for me. And kudos to my genius coworker Leaf<br />
who figured out how to build all the packages hooq requires to make this happen. It seems most people got stuck on this very first step.</p>
<p>But then I got stuck on another problem:<br />
although hooq can be executed fine and it can launch my app correctly, it won&#8217;t record any of my actions.<br />
All I got was requireHooqScriptVersion(2);<br />
I spent a whole day digging into this and it seems to be a timing issue.<br />
fundamentally hooq uses gdb to track all the qt events by inserting breaks on all QCoreApplication::exec<br />
and sometimes (I&#8217;m not sure if this is a system thing) the timing of loading the shared libraries could be different<br />
and that will cause the breaks failed to be set, thus the recording won&#8217;t take effect</p>
<p>after trying different combinations, I modify void GdbInjector::startProcess() in GdbInjecter.cpp into the following<br />
and this seem to work for me:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> GdbInjector<span style="color: #008080;">::</span><span style="color: #007788;">startProcess</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
        QString argumentsString<span style="color: #008080;">;</span>
        Q_FOREACH<span style="color: #008000;">&#40;</span>QString argument, m_applicationArguments<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
         	argument.<span style="color: #007788;">replace</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">'&quot;'</span>, <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                argumentsString.<span style="color: #007788;">append</span><span style="color: #008000;">&#40;</span>QString<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot; <span style="color: #000099; font-weight: bold;">\&quot;</span>%1<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">arg</span><span style="color: #008000;">&#40;</span>argument<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
        Q_ASSERT<span style="color: #008000;">&#40;</span>m_gdb<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>state<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> QProcess<span style="color: #008080;">::</span><span style="color: #007788;">Running</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Q_ASSERT<span style="color: #008000;">&#40;</span>m_gdb<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>isWritable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        m_gdbStream.<span style="color: #007788;">setDevice</span><span style="color: #008000;">&#40;</span>m_gdb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;set breakpoint pending on&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;set auto-solib-add off&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// avoid loading symbols for shared libraries                                                                                                         </span>
                                                         <span style="color: #666666;">// that we do not need to interact with from GDB                                                                                                      </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;break _start&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// C entry point - after main libraries have been loaded                                                                                                        </span>
	m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;set args&quot;</span> <span style="color: #000080;">&lt;&lt;</span> argumentsString <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;run&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// run until we hit it, and therefore Qt shared libraries are loaded                                                                                                     </span>
&nbsp;
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;sharedlibrary libdl&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load the libdl library so that we can call __dlopen()                                                                                                 </span>
	m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;sharedlibrary libc&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>  <span style="color: #666666;">// load the libc library so that we can call __dlopen()                                                                                                  </span>
        <span style="color: #666666;">//m_gdbStream &lt;&lt; QString(&quot;call dlopen(\&quot;/usr/lib64/libQtCore.so.4\&quot;,%1)&quot;).arg(QString::number(RTLD_NOW)) &lt;&lt; endl;                                                                                      </span>
        <span style="color: #666666;">// Newer systems                                                                                                                                                                                       </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> QString<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;call dlopen(<span style="color: #000099; font-weight: bold;">\&quot;</span>%1<span style="color: #000099; font-weight: bold;">\&quot;</span>, %2)&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">arg</span><span style="color: #008000;">&#40;</span>libraryPath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">arg</span><span style="color: #008000;">&#40;</span>QString<span style="color: #008080;">::</span><span style="color: #007788;">number</span><span style="color: #008000;">&#40;</span>RTLD_NOW<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load our library                                                                       </span>
	<span style="color: #666666;">// Older systems                                                                                                                                                                                       </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> QString<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;call __dlopen(<span style="color: #000099; font-weight: bold;">\&quot;</span>%1<span style="color: #000099; font-weight: bold;">\&quot;</span>, %2)&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">arg</span><span style="color: #008000;">&#40;</span>libraryPath<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">arg</span><span style="color: #008000;">&#40;</span>QString<span style="color: #008080;">::</span><span style="color: #007788;">number</span><span style="color: #008000;">&#40;</span>RTLD_NOW<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load our library                                                                     </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;sharedlibrary libQtCore&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load QtCore for breaking on QCoreApplication::exec()                                                                                              </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;sharedlibrary libQtGui&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load QtCore for breaking on QCoreApplication::exec()                                                                                               </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;break QCoreApplication::exec&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// now, we can set this breakpoint...                                                                                                           </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;continue&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;sharedlibrary injectedHooq&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// load the hooq injector library so that we can call startHooq()                                                                                 </span>
&nbsp;
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;call startHooq()&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// install our plugin (which required QCoreApplication setup)                                                                                               </span>
	m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;continue&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// run the app                                                                                                                                                      </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;backtrace&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// just in case (use with --spam)                                                                                                                                  </span>
        m_gdbStream <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;quit&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// after the application has exited, quit gdb                                                                                                                           </span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=195"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;count=none&amp;text=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;count=none&amp;text=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;linkname=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D195&amp;title=making%20hooq%20work%20with%20pyQt%20and%20Qt4.7" id="wpa2a_12"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=195</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Playing with wordpress plugins</title>
		<link>http://shiqiyang.com/blog/?p=185</link>
		<comments>http://shiqiyang.com/blog/?p=185#comments</comments>
		<pubDate>Sun, 29 May 2011 09:03:44 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=185</guid>
		<description><![CDATA[I spent some time tonight playing with some of the wordpress plugins, one of them is &#8216;Facebook comments for wordpress&#8217;. Works great except I had a hard time to adjust the width of the comment box. I spent quite some time and still couldn&#8217;t figured out why the width is always set to 300px, firebug told [...]]]></description>
			<content:encoded><![CDATA[<p>I spent some time tonight playing with some of the wordpress plugins, one of them is <a href="http://wordpress.org/extend/plugins/facebook-comments-for-wordpress/">&#8216;Facebook comments for wordpress&#8217;</a>. Works great except I had a hard time to adjust the width of the comment box. I spent quite some time and still couldn&#8217;t figured out why the width is always set to 300px, firebug told me it is not set explicitly in any css file and there seems no good way to find how this number is calculated. well, my hacky solution for now is to add the following css definition to my  <strong>facebook-comments-widgets.css</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.fb_ltr</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.fb_iframe_widget</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">610px</span><span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/*this is according to my theme layout setup*/</span></pre></td></tr></table></div>

<p>would be nice to get to the bottom of it but it works fine for now.</p>
<p>Other plugins works great after installation.<br />
I really like the charming new look <a href="http://wordpress.org/extend/plugins/wptouch/">WPtouch</a> gave under iphone/itouch<br />
and the many share buttons by <a href="http://www.addtoany.com">AddtoAny</a></p>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=185"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;count=none&amp;text=Playing%20with%20wordpress%20plugins" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;count=none&amp;text=Playing%20with%20wordpress%20plugins" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;linkname=Playing%20with%20wordpress%20plugins" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D185&amp;title=Playing%20with%20wordpress%20plugins" id="wpa2a_14"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding the continuous sequence that has largest sum from a list of integers(or floats)</title>
		<link>http://shiqiyang.com/blog/?p=162</link>
		<comments>http://shiqiyang.com/blog/?p=162#comments</comments>
		<pubDate>Sat, 28 May 2011 23:54:26 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[algorithm]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=162</guid>
		<description><![CDATA[Long weekend could be boring, especially when you are just 3 weeks out of a major (relatively) surgery and can&#8217;t do serious outdoor activities. So I decided to dive into some of the basic algorithms and implement them in python. I used to just look at the pseudo code and thought &#8220;this is easy&#8221;. but [...]]]></description>
			<content:encoded><![CDATA[<p>Long weekend could be boring, especially when you are just 3 weeks out of a major (relatively) surgery and can&#8217;t do serious outdoor activities. So I decided to dive into some of the basic algorithms and implement them in python. I used to just look at the pseudo code and thought &#8220;this is easy&#8221;. but for the past week I&#8217;ve been struggling to implement another problem (post in draft now) which really made me realize it could be much harder said than done. Admittedly some of those problems are really fundamental and most of the times people won&#8217;t bother to implement them because there are various libs to take advantage of (plus implementing your own version of same functionality from standard lib is really not a very good practice anyways). However, it is fun and really kills time. Besides, my biggest fear never is to be dumb but to be dumb without realizing it and the will the change it, struggling with those problems really help me to remind myself how bad of a coder I am and inspire me to improve it everyday.</p>
<p>So here is today&#8217;s problem:</p>
<p>Finding the continuous sequence that has largest sum from a list of integers(or floats)</p>
<p>The algorithm itself is pretty obvious: keep track of your sum, if it is below 0 then it won&#8217;t contribute to the max,</p>
<p>at that point keep what you have and then start a new iteration on the rest of the list.</p>
<p>My first implementation was to return the whole list, then I realized that the result will always be a subset of the original list</p>
<p>so just return the start and end index should be enough, it would save some space in this way.</p>
<p>Now it is arguable how to handle the situation when the max you can find is negative, which means you have nothing but negative numbers</p>
<p>in your list. I took a short cut here by returning an empty list in this case, my idea is that by returning an empty list I&#8217;m sending the message saying that you best choice in this situation is to not have anything from this list. An alternative could be scan the whole list once and initialize</p>
<p>the max_sum with the biggest element in the list. This won&#8217;t do harm to the O(n) time complexity.</p>
<p><span style="color: #ffff00;"><strong>Update: the wordpress coding syntax plugin reminds me that sum is a preserved keyword in python for sum function (shame on me that I even called that function in my code below for printing out without realizing it). Ahh, isn&#8217;t the highlighting nice? LOL</strong></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> largest_sum<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, list_of_int<span style="color: black;">&#41;</span>:
	max_sum = <span style="color: #ff4500;">0</span>
	<span style="color: #008000;">sum</span> = <span style="color: #ff4500;">0</span>
	i_max_start = <span style="color: #ff4500;">0</span>
	i_max_end = -<span style="color: #ff4500;">1</span>
	current_start = <span style="color: #ff4500;">0</span>		
	<span style="color: #ff7700;font-weight:bold;">if</span> list_of_int <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>list_of_int<span style="color: black;">&#41;</span>==<span style="color: #008000;">type</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
		list_size = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>list_of_int<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">for</span> index, item <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>list_of_int<span style="color: black;">&#41;</span>:
			<span style="color: #008000;">sum</span> += item
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">sum</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
				<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">sum</span> <span style="color: #66cc66;">&gt;</span> max_sum:
					max_sum = <span style="color: #008000;">sum</span>
					i_max_end = index
					i_max_start = current_start				
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				<span style="color: #008000;">sum</span> = <span style="color: #ff4500;">0</span>
				<span style="color: #ff7700;font-weight:bold;">if</span> index <span style="color: #66cc66;">&lt;</span> list_size-<span style="color: #ff4500;">1</span>:
					current_start = index +<span style="color: #ff4500;">1</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> i_max_start, i_max_end				
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> test_largest_sum<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
	data = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,-<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">5</span>,-<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">20</span>,<span style="color: #ff4500;">6</span>,<span style="color: #ff4500;">2</span>,-<span style="color: #ff4500;">6</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,-<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,-<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">1</span>,-<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">20</span>,<span style="color: #ff4500;">6</span>,<span style="color: #ff4500;">2</span>,-<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">7</span>,-<span style="color: #ff4500;">1</span>,-<span style="color: #ff4500;">7</span>,-<span style="color: #ff4500;">20</span>,<span style="color: #ff4500;">6</span>,<span style="color: #ff4500;">2</span>,-<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">7</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">10</span><span style="color: black;">&#93;</span>,
			<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>,-<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>,
			<span style="color: #483d8b;">'test'</span>,
			<span style="color: #008000;">None</span><span style="color: black;">&#93;</span>
	result = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>start, end<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>start, end<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">largest_sum</span>, data<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">for</span> index, d <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>:
		start, end = result<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> end<span style="color: #66cc66;">&gt;</span>=<span style="color: #ff4500;">0</span>:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>d<span style="color: black;">&#91;</span>start:end+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, d<span style="color: black;">&#91;</span>start:end+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">None</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>and here are the output:</p>
<pre>28 [20, 6, 2]
None []
1 [1]
31 [20, 6, 2, -1, 4]
11 [6, 2, -1, 4]
3 [3]
None []
10 [10]
5 [3, -2, 4]
None []
None []</pre>
<p>Something I thought about that could be interesting extension on this but yet have time to implement it or think it though:</p>
<li>1. find all sequences with largest sum if there are more than one sequence with that sum</li>
<li>2. find the longest/shortest one among the result from the result of 1 above (I <del datetime="2011-05-29T00:06:44+00:00">feel that doesn&#8217;t mean</del> don&#8217;t know if this necessarily means that I have to get the result from 1.  Update: I probably still do. won&#8217;t know the largest sum if I don&#8217;t go thru them all)</li>
<li>3. turn this question around: given the largest and smallest sum and the elements (unordered), construct the list (the answer <del datetime="2011-05-29T00:06:44+00:00">of course won&#8217;t</del> may not be unique)</li>
<li>4. same as above, but construct the list so that the list has longest/shortest sequence with largest sum (first impression: separate the positive and negative value into two lists, sort them and then intersect them might be enough to achieve this&#8230; but again, &#8216;easier said than done&#8217; LOL)</li>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=162"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;count=none&amp;text=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;count=none&amp;text=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;linkname=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D162&amp;title=Finding%20the%20continuous%20sequence%20that%20has%20largest%20sum%20from%20a%20list%20of%20integers%28or%20floats%29" id="wpa2a_16"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=162</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the largest possible number of people in circus tower</title>
		<link>http://shiqiyang.com/blog/?p=148</link>
		<comments>http://shiqiyang.com/blog/?p=148#comments</comments>
		<pubDate>Tue, 24 May 2011 05:33:32 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[lambda function]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=148</guid>
		<description><![CDATA[A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number [...]]]></description>
			<content:encoded><![CDATA[<p>A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.</p>
<pre>
EXAMPLE:
Input:
        (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom:
        (56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)
</pre>
<p>I really love one of the solutions I found online.<br />
It took several advantages of python language:</p>
<p>1.lambda function<br />
2.bisect<br />
3.how python compare iterables like list and tuple by default<br />
(compare the first element and it is recursive!)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">bisect</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> circus<span style="color: black;">&#40;</span>input_set<span style="color: black;">&#41;</span>:
        input_set_by_y_order = <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>input_set, key=<span style="color: #ff7700;font-weight:bold;">lambda</span> item:item<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        result_set = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> input_item <span style="color: #ff7700;font-weight:bold;">in</span> input_set_by_y_order:
                new_guy = <span style="color: black;">&#91;</span>input_item<span style="color: black;">&#93;</span>
                i = <span style="color: #dc143c;">bisect</span>.<span style="color: black;">bisect_left</span><span style="color: black;">&#40;</span>result_set, new_guy<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> i <span style="color: #66cc66;">!</span>= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>result_set<span style="color: black;">&#41;</span>:
                    result_set<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,new_guy<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                    result_set.<span style="color: black;">append</span><span style="color: black;">&#40;</span>new_guy<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>result_set<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_circus<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        data_set = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">65</span>,<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">70</span>,<span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">56</span>,<span style="color: #ff4500;">90</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">75</span>,<span style="color: #ff4500;">190</span><span style="color: black;">&#41;</span>, <span style="color: black;">&#40;</span><span style="color: #ff4500;">60</span>,<span style="color: #ff4500;">95</span><span style="color: black;">&#41;</span>,
                    <span style="color: black;">&#40;</span><span style="color: #ff4500;">68</span>,<span style="color: #ff4500;">110</span><span style="color: black;">&#41;</span>,<span style="color: black;">&#40;</span><span style="color: #ff4500;">62</span>,<span style="color: #ff4500;">144</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> circus<span style="color: black;">&#40;</span>data_set<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=148"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;count=none&amp;text=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;count=none&amp;text=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;linkname=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D148&amp;title=Find%20the%20largest%20possible%20number%20of%20people%20in%20circus%20tower" id="wpa2a_18"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=148</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My weight loss trend</title>
		<link>http://shiqiyang.com/blog/?p=138</link>
		<comments>http://shiqiyang.com/blog/?p=138#comments</comments>
		<pubDate>Sun, 22 May 2011 06:55:25 +0000</pubDate>
		<dc:creator>shiqiyang</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[diet]]></category>
		<category><![CDATA[weightloss]]></category>

		<guid isPermaLink="false">http://shiqiyang.com/blog/?p=138</guid>
		<description><![CDATA[There is really no secret on this: exercise and diet are your best friend. I&#8217;m heading toward my 100 lb weight loss goal now and I&#8217;m very close.]]></description>
			<content:encoded><![CDATA[<p>There is really no secret on this: exercise and diet are your best friend. </p>
<p>I&#8217;m heading toward my 100 lb weight loss goal now and I&#8217;m very close.</p>

<div id="easyChartDiv4b938001" style='width:100%;'  style='text-align:center;' align='center'>
<!-- Easy Chart Builder by dyerware -->
<img id="easyChartDiv4b938001_img" style='text-align:center;float:center;' alt='dyerware.com' title=''  align='center' border='0' />
<br/><br/><INPUT type='button' value='Show/Hide Table Data' onclick='wpEasyChartToggle("easyChartDiv4b938001_data");' style='text-align:center;' align='center' ><br/><div class='easyChartBuilder' id="easyChartDiv4b938001_data" style='text-align:center;display:none;' align='center'></div>
</div>
<script type="text/javascript">
//<![CDATA[
wpEasyChart.wpNewChart("easyChartDiv4b938001", {"type":"line","width":"350","height":"300","title":"Shiqi's weight loss trend","minaxis":"","groupnames":"lb","groupcolors":"0070C0,FFFF00,FF0000,00CC00,A3A3A3,007070,00FFFF,CC7000,00CC70,CC0070,7000CC,A370CC","valuenames":"2008\/7, 2009\/1, 2009\/7, 2010\/1, 2010\/7, 2011\/1, 2011\/5","group1values":"258, 215, 201, 204, 190, 182, 165","group2values":"0,0,0","group3values":"0,0,0","group4values":"0,0,0","group5values":"0,0,0","group6values":"0,0,0","group7values":"0,0,0","group8values":"0,0,0","group9values":"0,0,0","group10values":"0,0,0","group11values":"0,0,0","group12values":"0,0,0","group1markers":"","group2markers":"","group3markers":"","group4markers":"","group5markers":"","group6markers":"","group7markers":"","group8markers":"","group9markers":"","group10markers":"","group11markers":"","group12markers":"","markercolor":"FFFF00","imagealtattr":"dyerware.com","imagetitleattr":"","hidechartdata":false,"chartcolor":"FFFFFF","chartfadecolor":"DDDDDD","datatablecss":"hentry easyChartDataTable","imgstyle":"text-align:center;float:center;","watermark":"","watermarkvert":"","watermarkcolor":"A0BAE9","currency":"","precision":"","grid":false,"axis":"both"});
//]]&gt;
</script>
<div class="plus-one-wrap"><g:plusone href="http://shiqiyang.com/blog/?p=138"></g:plusone></div><p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;count=none&amp;text=My%20weight%20loss%20trend" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;counturl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;count=none&amp;text=My%20weight%20loss%20trend" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_email" href="http://www.addtoany.com/add_to/email?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Email" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/email.png" width="16" height="16" alt="Email"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Digg" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Facebook" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Delicious" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Twitter" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_tumblr" href="http://www.addtoany.com/add_to/tumblr?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Tumblr" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/tumblr.png" width="16" height="16" alt="Tumblr"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_button_google_reader" href="http://www.addtoany.com/add_to/google_reader?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Google Reader" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reader.png" width="16" height="16" alt="Google Reader"/></a><a class="a2a_button_sina_weibo" href="http://www.addtoany.com/add_to/sina_weibo?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Sina Weibo" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/sina_weibo.png" width="16" height="16" alt="Sina Weibo"/></a><a class="a2a_button_box_net" href="http://www.addtoany.com/add_to/box_net?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Box.net" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/box.png" width="16" height="16" alt="Box.net"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Evernote" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_friendfeed" href="http://www.addtoany.com/add_to/friendfeed?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="FriendFeed" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/friendfeed.png" width="16" height="16" alt="FriendFeed"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Hotmail" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_livejournal" href="http://www.addtoany.com/add_to/livejournal?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="LiveJournal" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/livejournal.png" width="16" height="16" alt="LiveJournal"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a href="javascript:print()" title="Print" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/print.png" width="16" height="16" alt="Print"/></a><a class="a2a_button_printfriendly" href="http://www.addtoany.com/add_to/printfriendly?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="PrintFriendly" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/printfriendly.png" width="16" height="16" alt="PrintFriendly"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Reddit" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="Slashdot" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;linkname=My%20weight%20loss%20trend" title="WordPress" rel="nofollow" target="_blank"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fshiqiyang.com%2Fblog%2F%3Fp%3D138&amp;title=My%20weight%20loss%20trend" id="wpa2a_20"><img src="http://shiqiyang.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://shiqiyang.com/blog/?feed=rss2&#038;p=138</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

