<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7338042968667045216</id><updated>2011-11-28T01:23:20.293-08:00</updated><category term='Python'/><category term='Developer'/><category term='Blogger Tool'/><category term='Ubuntu'/><category term='Java'/><category term='Interview'/><category term='Linux'/><category term='Windows Tool'/><category term='Mysql'/><title type='text'>Chu-Cheng's Public Note</title><subtitle type='html'>This blog intends to document all computer science problems I encountered and my solutions/comments to them.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>31</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-3650239906428093306</id><published>2011-11-18T02:39:00.000-08:00</published><updated>2011-11-18T03:02:22.240-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Interview'/><title type='text'>Find all possible ways of representing a number n</title><content type='html'>During one of my recent interview with a giant software company, I was asked this question: &lt;br /&gt;&lt;br /&gt;&lt;blockquote class="tr_bq"&gt;&lt;b&gt;Given an array of numbers, find all possible ways of representing a number n. &lt;/b&gt;For example, let's assume we have [2, 3, 5] in an array, and the target number is 10.&lt;/blockquote&gt;Well... I fail this interview in that I'm trying to work out a iterative solution given the stressful condition. I went home and I suddenly realize this is a manageable problem as long as I'm not greedy.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Tip 1: for all "combination" / "subset" questions, you should always start with hacking a recursive solution, because it's the most intuitive one.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Tip 2: never try to provide the "best" answer to your interviewer. Don't worry, they will challenge you and ask you to propose a better answer later.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;Some people might argue that tip 2 looks stupid, especially if you know that recursive is usually awful in terms of space complexity. Don't get me wrong here, the time complexity for a permutation style question is O(N!), factorial, and for a subset style question is O(2^N), exponential. But hey...this is not the side effect of recursive, but it is the nature that the space you have to search !! Yes, the space complexity is awful, and you may fix by Dynamic Programming or Iterative solution. However, what you need in the interview is not a perfect answer, but is to show you ability of coding, and analyzing complexity. And don't worry, if you get this simple answer quickly, they will ask you to improve it. That's the time for "iterative" solution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the simple way of doing it:&lt;br /&gt;&lt;pre&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Arrays;&lt;br /&gt;&lt;br /&gt;public class FindAllComb {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        int[] ar = {3,5, 2};&lt;br /&gt;        printCombForN(ar,10,0, new ArrayList&lt;integer&gt;());&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    //try = 0, meaning we start from the first element in the array&lt;br /&gt;    public static boolean printCombForN(int[] ar, int target, int idx, ArrayList&lt;integer&gt; buffer){&lt;br /&gt;        //base case: if no more choice&lt;br /&gt;        if(target == 0) {&lt;br /&gt;            return true;&lt;br /&gt;        }&lt;br /&gt;        else if (target &amp;lt; 0) {&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // for all possible choice&lt;br /&gt;        for(int i=idx; i &amp;lt; ar.length; i++){&lt;br /&gt;            //make a choice&lt;br /&gt;            buffer.add(ar[i]);&lt;br /&gt;            target-=ar[i];&lt;br /&gt;            if (printCombForN(ar, target, i, buffer)){&lt;br /&gt;                //print buffer&lt;br /&gt;                System.out.println(Arrays.toString(buffer.toArray()));&lt;br /&gt;            }&lt;br /&gt;            //unmake the choice&lt;br /&gt;            buffer.remove(buffer.size() -1);&lt;br /&gt;            target += ar[i];&lt;br /&gt;        }&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/integer&gt;&lt;/integer&gt;&lt;/pre&gt;It may looks hard at its first glance but essentially this is a simple back-tracking problem. For back-tracking problem, here is the template I follow: &lt;br /&gt;&lt;pre&gt;bool Solve(configuration conf) //Credit: Zelenski, Julie&lt;br /&gt;{&lt;br /&gt;    if (no more choices) // BASE CASE&lt;br /&gt;        return (conf is goal state);&lt;br /&gt;&lt;br /&gt;    for (all available choices) {&lt;br /&gt;        try one choice c;&lt;br /&gt;        // solve from here, if works out, you're done&lt;br /&gt;        if (Solve(conf with choice c made)) return true;&lt;br /&gt;        unmake choice c;&lt;br /&gt;    }&lt;br /&gt;    return false; //tried all choices, no soln found&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Can we do better?&lt;br /&gt;&lt;br /&gt;Yes, with the help of DP.&lt;br /&gt;The idea is that we can "memorize" things we did before.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example, if we know th only possible choice of making 5 are (2,3) or (5), we can simple save it in a HashMap so that we don't have to go over same path again.&lt;br /&gt;&lt;br /&gt;So let's slightly change the problem, what if we don't need you to print all possible combination, but we just want you to return number of possible combinations?&lt;br /&gt;&lt;br /&gt;The idea here is Num(array, 10) = the sum of the following&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Num(array, 8)&amp;nbsp; + 1 (we deal with 2)&lt;/li&gt;&lt;li&gt;Num(array, 7)&amp;nbsp; + 1 (we deal with 3)&lt;/li&gt;&lt;li&gt;Num(array, 5)&amp;nbsp; + 1 (we deal with 5)&lt;/li&gt;&lt;/ol&gt;So you get the big picture now, if we have an array that index is the "target", which is the remainder after we recursively call the function , and the value is the "# of possible combinations" we already know. We can simple sum them up.&lt;br /&gt;&lt;br /&gt;I will add answer later, but one thing you should keep in mind is that &lt;b&gt;to make things faster, often times the price is space.&lt;/b&gt; In this example, we need extra space for tracking counts. Though, here (the revised question) the cost is acceptable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note that all back-tracking problem can be accelerated by some heuristic pruning. That is, you may "return false" earlier if you know there's no way you can get a goal state along the path.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-3650239906428093306?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/3650239906428093306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/11/find-all-possible-ways-of-representing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3650239906428093306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3650239906428093306'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/11/find-all-possible-ways-of-representing.html' title='Find all possible ways of representing a number n'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-4851406394411698564</id><published>2011-08-17T20:34:00.000-07:00</published><updated>2011-11-10T02:54:02.307-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Log (logging) in Python</title><content type='html'>Logging is always an important topic when you try to develop a "real-world" app.&amp;nbsp;I once wrote my own logging system, but apparently the best practice is to use something provided by Python Standard&amp;nbsp;Library, not to reinvent the wheel.&lt;br /&gt;&lt;br /&gt;Here, I have no intent to write a complete tutorial of teaching the&amp;nbsp;&lt;a href="http://docs.python.org/library/logging.html"&gt;python's logging framework&lt;/a&gt;. I extract the most useful/simple part(s) of logging from my viewpoints, which I believe it solves 90% cases I(you) need.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Firstly, you should try to build a customized logger. It is&amp;nbsp;impractical&amp;nbsp;to use &lt;a href="http://docs.python.org/howto/logging.html#a-simple-example"&gt;the logging&lt;/a&gt;&amp;nbsp;module directly via changing basicConfig() because you cannot tell where the log comes from if you have multiple modules in your app. This is one of the reason why I write this article.&lt;br /&gt;&lt;br /&gt;To get a "customized" logger, firstly you should assign a name to it.&lt;br /&gt;&lt;pre class="brush:python; gutter: false;"&gt;mlogging = logging.getLogger("test_log") #Get a logging for this module&lt;/pre&gt;&lt;br /&gt;If you would like to have some beautiful format on logging records,&amp;nbsp;&lt;b&gt;logging.Formatter&lt;/b&gt;&amp;nbsp;is something you need to set it up. Sure you should do it because the default one seems to be a little clumsy. To change the date format (that is, &lt;b&gt;%(asctime)s&lt;/b&gt;), please refer to things used in&amp;nbsp;&lt;a href="http://docs.python.org/library/time.html#time.strftime"&gt;time.strftime()&lt;/a&gt;.&amp;nbsp;And to create a format for a record, the related variables can be found in &lt;a href="http://docs.python.org/library/logging.html#logrecord-attributes"&gt;attributes of LogRecord&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:python; gutter: false;"&gt;# -- Set up Formatter --&lt;br /&gt;log_format = '%(asctime)s(%(name)s--%(levelname)s):%(message)s'&lt;br /&gt;log_date_format = '[%m/%d/%y %H:%M:%S]'&lt;br /&gt;uniform_fmt = logging.Formatter(fmt=log_format, datefmt=log_date_format)&lt;/pre&gt;&lt;br /&gt;Mostly, we store logs in a file, so you need a file handler.&lt;br /&gt;&lt;pre class="brush:python; gutter: false;"&gt;# -- Log to File --&lt;br /&gt;hdlr = logging.FileHandler('OnlyOneFile.log') &amp;nbsp; # or "mlogger.name + 'log' if you would like to separate logs&lt;br /&gt;hdlr.setFormatter(uniform_fmt)&lt;/pre&gt;&lt;br /&gt;If you would like to see log in your screen, say, for debugging, you have to link it to STDOUT.&lt;br /&gt;&lt;pre class="brush:python; gutter: false;"&gt;# -- Log to Console --&lt;br /&gt;hdlrConsole = logging.StreamHandler(sys.__stdout__)&lt;br /&gt;hdlrConsole.setFormatter(uniform_fmt)&lt;/pre&gt;&lt;br /&gt;Do not forget to link your handler with your logger.&lt;br /&gt;&lt;pre class="brush:python; gutter: false;"&gt;mlogging.addHandler(hdlr)&lt;br /&gt;mlogging.addHandler(hdlrConsole)&lt;/pre&gt;&lt;br /&gt;Finally, you have to assign a log level so that you can get all the details. Otherwise,&amp;nbsp;The default level is WARNING. (&lt;a href="http://docs.python.org/howto/logging.html"&gt;All default levels&lt;/a&gt;)&lt;br /&gt;&lt;pre class="brush:python;"&gt;mlogging.setLevel(logging.DEBUG) #this is the most detailed level&lt;/pre&gt;&lt;br /&gt;Putting all together, here is an example:&lt;br /&gt;&lt;pre class="brush:python;"&gt;import sys&lt;br /&gt;import logging&lt;br /&gt;&lt;br /&gt;mlogging = logging.getLogger("test_log") #Get a logging for this module&lt;br /&gt;"""&lt;br /&gt;logging.basicConfig(&lt;br /&gt;&amp;nbsp; &amp;nbsp; #filename=mlogging.name + '.log', #Use the name of logger as log file name&lt;br /&gt;&amp;nbsp; &amp;nbsp; filename='onefile.log', #Use the name of logger as log file name&lt;br /&gt;&amp;nbsp; &amp;nbsp; level=logging.DEBUG,&lt;br /&gt;&amp;nbsp; &amp;nbsp; format='%(asctime)s(%(name)s--%(levelname)s):%(message)s',&lt;br /&gt;&amp;nbsp; &amp;nbsp; datefmt='[%m/%d/%y %H:%M:%S]'&lt;br /&gt;"""&lt;br /&gt;&lt;br /&gt;# -- Set up Formatter --&lt;br /&gt;log_format = '%(asctime)s(%(name)s--%(levelname)s):%(message)s'&lt;br /&gt;log_date_format = '[%m/%d/%y %H:%M:%S]'&lt;br /&gt;uniform_fmt = logging.Formatter(fmt=log_format, datefmt=log_date_format)&lt;br /&gt;&lt;br /&gt;# -- Log to File --&lt;br /&gt;hdlr = logging.FileHandler('OnlyOneFile.log')&lt;br /&gt;hdlr.setFormatter(uniform_fmt)&lt;br /&gt;&lt;br /&gt;# -- Log to Console --&lt;br /&gt;hdlrConsole = logging.StreamHandler(sys.__stdout__)&lt;br /&gt;hdlrConsole.setFormatter(uniform_fmt)&lt;br /&gt;&lt;br /&gt;mlogging.addHandler(hdlr)&lt;br /&gt;mlogging.addHandler(hdlrConsole)&lt;br /&gt;mlogging.setLevel(logging.DEBUG)&lt;br /&gt;&lt;br /&gt;mlogging.debug('This is debug msg')&lt;br /&gt;mlogging.info('Ok~ info now')&lt;br /&gt;mlogging.warning('Warning here')&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;&amp;nbsp; &amp;nbsp; x = 4/0&lt;br /&gt;except Exception as e:&lt;br /&gt;&amp;nbsp; &amp;nbsp; mlogging.exception(e)&lt;/pre&gt;&lt;br /&gt;Before we leave the discussion, you should pay attention to &lt;code&gt;mlogging.exception(e)&lt;/code&gt;. This is the way we log an exception, including its trace-back information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-4851406394411698564?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/4851406394411698564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/08/log-logging-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4851406394411698564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4851406394411698564'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/08/log-logging-in-python.html' title='Log (logging) in Python'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-8743567329092147596</id><published>2011-07-12T11:19:00.000-07:00</published><updated>2011-11-09T13:01:16.741-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Developer'/><title type='text'>Git Version Control Resource</title><content type='html'>I'm a heavily Subversion (SVN) developer. Recently, I join several projects that use git as their version control frameworks. Thus, I document some useful resource as follows:&lt;br /&gt;&lt;br /&gt;* &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html"&gt; A quick tutorial&lt;/a&gt;&lt;br /&gt;* &lt;a href="http://progit.org/book/"&gt; A detail, through introduction: Git Book &lt;/a&gt;Recently, I happens to notice another good website:* &lt;a href="http://www-cs-students.stanford.edu/~blynn/gitmagic/"&gt;Git Magic&lt;/a&gt;: This site is hosted in Stanford.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-8743567329092147596?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/8743567329092147596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/07/git-version-control-resource.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/8743567329092147596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/8743567329092147596'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/07/git-version-control-resource.html' title='Git Version Control Resource'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-3820750528586870228</id><published>2011-07-12T10:27:00.000-07:00</published><updated>2011-07-12T10:34:00.987-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Firefox 5 on ubuntu 10.04 LTS</title><content type='html'>For people who are using ubuntu 10.04, the default version of Firefox is 3.6. (Seriously?) It's suggested that you update to the latest stable version of ubuntu. &lt;br /&gt;&lt;br /&gt;To install the latest "stable" version of ubuntu, add the following ppa repository:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;sudo add-apt-repository ppa:mozillateam/firefox-stable&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is nothing more than add a &lt;span style="font-weight:bold;"&gt;mozillateam-firefox-stable-lucid.list&lt;/span&gt; to "/etc/apt/sources.list.d".&lt;br /&gt;&lt;br /&gt;Than, do "sudo apt-get update &amp;&amp; sudo apt-get upgrade" and you are done.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-3820750528586870228?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/3820750528586870228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/07/firefox-5-on-ubuntu-1004-lts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3820750528586870228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3820750528586870228'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/07/firefox-5-on-ubuntu-1004-lts.html' title='Firefox 5 on ubuntu 10.04 LTS'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-4737296886683345609</id><published>2011-03-08T18:59:00.000-08:00</published><updated>2011-03-08T19:12:39.810-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>MySQL Remote Access</title><content type='html'>By default, the mysql (5.x) allows login within localhost. What if you need to access a MySQL database from another computer?&lt;br /&gt;&lt;br /&gt;I found this tutorial is quite helpful:&lt;br /&gt;&lt;a href="http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html"&gt; how-do-i-enable-remote-access-to-mysql-database-server &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Unfortunately, I still get the following errors&lt;br /&gt;&lt;pre&gt;chucheng@laptop:~$ mysql -ufoo -pcrap mysql.ucla.edu&lt;br /&gt;ERROR 1044 (42000): Access denied for user 'foo'@'laptop' to...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After trying several solution, I finally realized that in the statement &lt;code&gt;GRANT ALL ON db_name.* TO foo@'%' IDENTIFIED BY 'PASSWORD';&lt;/code&gt; you cannot skip "IDENTIFIED BY password".&lt;br /&gt;&lt;br /&gt;It turns out that you will "override" existing passwords with an empty password if you did not provide corresponding inputs.&lt;br /&gt;&lt;br /&gt;Just in case that you still have problems:&lt;br /&gt;Please make sure that &lt;br /&gt;(1) Your bind-address in /etc/mysql/my.cnf has been changed to "real" IP.&lt;br /&gt;(2) your port is listening&lt;br /&gt;&lt;code&gt;netstat -an | grep 3306  &lt;/code&gt; &lt;br /&gt;(3) You grant remote access permission to the user accounts.&lt;br /&gt;p.s if you encounter any problems when login from localhost, instead of granting foo@'%', please grant foo@'localhost' as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-4737296886683345609?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/4737296886683345609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/03/mysql-remote-access.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4737296886683345609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4737296886683345609'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/03/mysql-remote-access.html' title='MySQL Remote Access'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-3623849102423133523</id><published>2011-02-04T09:54:00.000-08:00</published><updated>2011-02-04T09:58:34.370-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Ubuntu Application</title><content type='html'>I would like to document several apps that, I believe, are very useful as follows. Though there are many choices in WWW. The followings are really handy ones.&lt;br /&gt;&lt;br /&gt;Programming Tools:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;WingIDE (Python)&lt;/li&gt;&lt;li&gt;IntelliJ IDEA (Java)&lt;/li&gt;&lt;li&gt;Eclipse (C++/Java)&lt;/li&gt;&lt;li&gt;Rabbit VCS (Version Control)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;MISC:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Mendeley&lt;/li&gt;&lt;li&gt;Stardict (Dictionary)&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-3623849102423133523?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/3623849102423133523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/02/ubuntu-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3623849102423133523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3623849102423133523'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/02/ubuntu-application.html' title='Ubuntu Application'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-9177037336650711586</id><published>2011-02-01T17:16:00.000-08:00</published><updated>2011-02-01T17:19:25.683-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Brightness Control on T410 (T410s)</title><content type='html'>I find the brightness control seems to be not working after installing ubuntu 10.04 on my Thinkpad T410s.&lt;br /&gt;&lt;br /&gt;Here are two solutions:&lt;br /&gt;&lt;br /&gt;(1) Switch to console (CTRL+ALT+F2) and adjust the brightness. Then switch back to GNOME (CTRL+ALT+F7)&lt;br /&gt;&lt;br /&gt;(2) Edit /etc/X11/xorg.conf&lt;br /&gt;Under the "DEVICE" section, add the following OPTION&lt;br /&gt;&lt;pre&gt;Option "RegistryDwords" "EnableBrightnessControl=1"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Done! Enjoy it!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-9177037336650711586?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/9177037336650711586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/02/brightness-control-on-t410-t410s.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/9177037336650711586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/9177037336650711586'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/02/brightness-control-on-t410-t410s.html' title='Brightness Control on T410 (T410s)'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-6263501717154494696</id><published>2011-01-25T23:35:00.000-08:00</published><updated>2011-01-25T23:39:52.962-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Install Sun Java SDK 6 on Ubutnu 10.04</title><content type='html'>Since Ubuntu 10.04, Sun(Oracle?) SDK is not existed in multiverse anymore. &lt;br /&gt;&lt;br /&gt;If you would like to install Sun Java SDK, you have to use "partner" repository.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"&lt;br /&gt;sudo apt-get update&lt;br /&gt;sudo apt-get install sun-java6-jdk&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Is that all? Not quitely.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Choosing the default Java to use&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;Just installing new Java flavours does not change the default Java pointed to by /usr/bin/java. You must explicitly set this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    * Open a Terminal window&lt;br /&gt;    * Run sudo update-java-alternatives -l to see the current configuration and possibilities.&lt;br /&gt;    * Run sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun&lt;br /&gt;    * Run java -version to ensure that the correct version is being called. &lt;br /&gt;&lt;br /&gt;You can also use the following command to interactively make the change;&lt;br /&gt;&lt;br /&gt;    * Open a Terminal window&lt;br /&gt;    * Run sudo update-alternatives --config java&lt;br /&gt;    * Follow the onscreen prompt &lt;br /&gt;&lt;br /&gt;Ref: https://help.ubuntu.com/community/Java&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-6263501717154494696?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/6263501717154494696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/01/install-sun-java-sdk-6-on-ubutnu-1004.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/6263501717154494696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/6263501717154494696'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2011/01/install-sun-java-sdk-6-on-ubutnu-1004.html' title='Install Sun Java SDK 6 on Ubutnu 10.04'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1019937794002016640</id><published>2010-12-01T22:15:00.000-08:00</published><updated>2010-12-01T22:24:11.270-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Windows 7 HotKey in Ubuntu</title><content type='html'>As a bi-OS user, I am always confused with the hot-key setting while I switch between Operating System. No offense, while I said bi-OS user, I refer to Windows 7 and Ubuntu Lucid. (Not Mac OS).&lt;br /&gt;&lt;br /&gt;Some hotkeys introduced in Windows 7 are very userful for myself. For example, Windows + Left / Right / Up / Down&lt;br /&gt;&lt;br /&gt;If you never try above hotkeys, try it on a Windows O/S, and you will know what would happen.&lt;br /&gt;Long story short, I would like to resize my windows the the left/right window. What should I do?&lt;br /&gt;&lt;br /&gt;(1) You have to install &lt;span style="font-weight:bold;"&gt;wmctrl&lt;/span&gt; package&lt;br /&gt;&lt;pre&gt; sudo apt-get install wmctrl&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;(2) Open "System"--&gt;"Preference"--&gt;"Keyboard Shortcuts".&lt;br /&gt;Bound Windows + Left to    ==&gt;  wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz;wmctrl -r :ACTIVE: -e 0,0,20,1920,1150&lt;br /&gt;Bound Windows + Right to   ==&gt;  wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz;wmctrl -r :ACTIVE: -e 0,960,20,960,1150&lt;br /&gt;&lt;br /&gt;To Maximize a windows: &lt;br /&gt;Bound Windows + Up to      ==&gt; wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz;wmctrl -r :ACTIVE: -e 0,0,20,1925,1150&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Would you like to learn more?&lt;br /&gt;Read here: &lt;a href="http://spiralofhope.wordpress.com/2010/02/03/wmctrl-user-documentation/"&gt;wmctrl tutorial&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1019937794002016640?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1019937794002016640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/12/windows-7-hotkey-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1019937794002016640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1019937794002016640'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/12/windows-7-hotkey-in-ubuntu.html' title='Windows 7 HotKey in Ubuntu'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-5632381807442083594</id><published>2010-11-23T11:27:00.000-08:00</published><updated>2010-11-23T11:30:21.178-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Where is my "Ctrl + Alt + Backspace" ?</title><content type='html'>After installing ubuntu 10.04, I quickly realized that CRTL-ALT-F1 (for opening a terminal) and CRTL-ALT-BACKSPACE (for killing X-server) are gone. Luckily, here is the solution I found:&lt;br /&gt;&lt;br /&gt;Enabling Ctrl-Alt-Backspace for Ubuntu 10.04&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Select “System”-&gt;”Preferences”-&gt;”Keyboard”&lt;/li&gt;&lt;li&gt;Select the “Layouts” tab and click on the “Layout Options” button.&lt;/li&gt;&lt;li&gt;Select “Key sequence to kill the X server” and enable “Control + Alt + Backspace”&lt;/li&gt;&lt;/ol&gt;Enjoy your hot keys :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-5632381807442083594?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/5632381807442083594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/11/where-is-by-ctrl-alt-backspace.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5632381807442083594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5632381807442083594'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/11/where-is-by-ctrl-alt-backspace.html' title='Where is my &quot;Ctrl + Alt + Backspace&quot; ?'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-7319523428551795951</id><published>2010-10-14T00:00:00.001-07:00</published><updated>2011-01-24T23:46:37.879-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Move window buttons (Min, Max, Close) back to right in ubuntu 10.04</title><content type='html'>One of the most controversial change in ubuntu 10.04 is to have window buttons on the left side. Although this change favors many mac(apple) users. As a user worked in dual O/S, windows 7 and ubuntu, the change is somehow inconvenient. Here I explain how to move them back. (The min, max, and close button)&lt;br /&gt;&lt;br /&gt;1. Open the configuration editor of gnome.&lt;br /&gt;&lt;pre&gt;gconf-editor&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. Click on the + button next to the “apps” folder, then click “metacity” in the list of folders expanded for apps, and then click on the “general” category. The button layout can be now changed by editing the “button_layout” key.&lt;br /&gt;&lt;br /&gt;3. Change it to:&lt;br /&gt;&lt;pre&gt;menu:minimize,maximize,close&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Save, close, and you are done. (Restart X Window to take effect)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-7319523428551795951?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/7319523428551795951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/10/move-window-buttons-min-max-close-back.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7319523428551795951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7319523428551795951'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/10/move-window-buttons-min-max-close-back.html' title='Move window buttons (Min, Max, Close) back to right in ubuntu 10.04'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-7490770705106690430</id><published>2010-08-24T13:50:00.000-07:00</published><updated>2010-08-24T15:07:47.820-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Weired ssh-agent error in Ubuntu</title><content type='html'>To protect your private key, one might add a long pass-phrase for avoiding the burglary. However, somehow I see the following error while trying to add my private key to ssh-agent.&lt;br /&gt;&lt;pre&gt;chucheng@ubuntuVM:~$ ssh-add&lt;br /&gt;Could not open a connection to your authentication agent.&lt;/pre&gt;&lt;br /&gt;Here is the solution:&lt;br /&gt;&lt;code&gt;exec ssh-agent bash&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Don't know why, but it just works :)&lt;br /&gt;&lt;br /&gt;Results:&lt;br /&gt;&lt;pre&gt;chucheng@ubuntuVM:~$ ssh-add&lt;br /&gt;Enter passphrase for /home/chucheng/.ssh/id_rsa:&lt;br /&gt;Identity added: /home/chucheng/.ssh/id_rsa (/home/chucheng/.ssh/id_rsa)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-7490770705106690430?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/7490770705106690430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/08/weired-ssh-agent-error-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7490770705106690430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7490770705106690430'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/08/weired-ssh-agent-error-in-ubuntu.html' title='Weired ssh-agent error in Ubuntu'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1536149413392902648</id><published>2010-07-06T20:31:00.000-07:00</published><updated>2010-07-06T20:34:49.140-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Rename mutliple files at once in ubuntu / linux</title><content type='html'>I would like to rename multiple files at once in my Ubuntu 10.04.&lt;br /&gt;I google around and I found people suggest the following command:&lt;br /&gt;&lt;pre&gt;rename .bak .new *.bak&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;However, this magic does not work in my Ubuntu. &lt;br /&gt;To rename a batch of files with their extension, the following syntax works:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;rename 's/\.bak$/\.csv/' *.bak&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above command would rename all files with the extension ".bak" to the new extension ".csv".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1536149413392902648?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1536149413392902648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/07/rename-mutliple-files-at-once-in-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1536149413392902648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1536149413392902648'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/07/rename-mutliple-files-at-once-in-ubuntu.html' title='Rename mutliple files at once in ubuntu / linux'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1659669058444380228</id><published>2010-06-22T15:43:00.000-07:00</published><updated>2011-01-03T12:40:48.035-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Ubuntu 10.04 hang after login</title><content type='html'>For some unknown reason(s), my newly install Ubuntu 10.04 went panic last Friday. Simply put, the ubuntu 10.04 hang after entering login information. I spend lost of hours on finding the problem. However, I still cannot see why it happens. It turns out that some package contains bugs and cause the o/s crashed after login.&lt;br /&gt;&lt;br /&gt;I have tried the following means and none of them works:&lt;br /&gt;- &lt;code&gt;sudo apt-get install --reinstall ubuntu-desktop&lt;/code&gt;&lt;br /&gt;- Update every package installed in the system&lt;br /&gt;- Use the default xorg.conf setting (Without Xinerma)&lt;br /&gt;- ... rm -rf home directory ...&lt;br /&gt;&lt;br /&gt;Anyway, after keep trial and errors, here explains how I solve the problem.&lt;br /&gt;&lt;br /&gt;1. Reboot to &lt;strong&gt;Recovery Model&lt;/strong&gt;&lt;br /&gt;It's a little tricky in Ubuntu 10.04 because by default the grub2 won't show up a start menu for you. The "default" in Ubuntu 10.04 always try to select the default booting item after power on the system. In addition, there's no more &lt;span style="font-weight: bold;"&gt;/boot/grub/menu.lst&lt;/span&gt; in ubuntu 10.04.&lt;br /&gt;&lt;br /&gt;Here are solutions:&lt;br /&gt; (1) Comment out "#GRUB_HIDDEN_TIMEOUT=0" through editing &lt;span style="font-weight:bold;"&gt;/etc/default/grub&lt;/span&gt;&lt;br /&gt; (2) Run &lt;code&gt;update-grub&lt;/code&gt; (or update-grub2 ?)&lt;br /&gt; (3) Reboot and you will see the grub menu. Select the recovery mode and you are done.&lt;br /&gt;&lt;br /&gt;2. Installed the following two package&lt;br /&gt;&lt;pre&gt;sudo aptitude install libpam-gnome-keyring=2.92.92.is.2.30.0-0ubuntu3&lt;br /&gt;sudo aptitude install gnome-keyring=2.92.92.is.2.30.0-0ubuntu3&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If it works for you as well, please simply leave a comment here :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1659669058444380228?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1659669058444380228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/06/ubuntu-1004-hang-after-login.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1659669058444380228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1659669058444380228'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2010/06/ubuntu-1004-hang-after-login.html' title='Ubuntu 10.04 hang after login'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-3142704713519537493</id><published>2009-11-18T20:36:00.000-08:00</published><updated>2009-11-23T02:59:16.889-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Upgrade Debian 3.1(sarge) to 4.0(etch)</title><content type='html'>&lt;p&gt;It look like that to upgrade from Debian 3.1 to 4.0 should be fairly easy; however, the truth is that you will somehow trap by "libc6" loop. Here is a note to solve the problem.&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt; Update 3.1 as best as possible. Modified the /etc/apt/sources.list&lt;br /&gt;    &lt;pre&gt;#OldStable&lt;br /&gt;#deb http://security.debian.org/ lenny/updates main contrib non-free&lt;br /&gt;#deb http://ftp.us.debian.org/debian/ oldstable main contrib non-free&lt;/pre&gt;&lt;br /&gt;    &lt;code&gt;sudo apt-get update&lt;/code&gt;&lt;br/&gt;&lt;br /&gt;    &lt;code&gt;sudo apt-get upgrade&lt;/code&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Switch to the etch sources, and update the kernel.&lt;br /&gt;    &lt;pre&gt;#etch&lt;br /&gt;deb http://security.debian.org/ etch/updates main contrib non-free&lt;br /&gt;deb http://ftp.us.debian.org/debian/ etch main contrib non-free&lt;/pre&gt;&lt;br /&gt;    &lt;code&gt;sudo apt-get update&lt;/code&gt;&lt;br/&gt;&lt;br /&gt;    &lt;code&gt;sudo apt-get install linux-image-2.6.18-6-686&lt;/code&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Pre-Processing&lt;br /&gt;    &lt;code&gt;apt-get install locales&lt;/code&gt;&lt;br/&gt;&lt;br /&gt;    Make sure we handle all the dependency issue:&lt;br /&gt;    &lt;code&gt;apt-get install -f&lt;/code&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Install the kernel.&lt;br/&gt;&lt;br /&gt;    &lt;code&gt;sudo apt-get install linux-image...&lt;/code&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Update Grub by running: &lt;code&gt;update-grub&lt;/code&gt;&lt;br/&gt;&lt;br /&gt;       Edit /boot/grub/menu.lst, set the Default to correct kernel&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;  &lt;li&gt; Edit the tow links to the right kernel:&lt;pre&gt;/boot/initrd.img initrd.img -&gt; initrd.img-2.6.8-3-686-smp&lt;br /&gt;/boot/vmlinuz  -&gt; vmlinuz-2.6.8-3-686-smp&lt;/pre&gt;, and then Reboot &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-3142704713519537493?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/3142704713519537493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/upgrade-debian-31sarge-to-40etch.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3142704713519537493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3142704713519537493'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/upgrade-debian-31sarge-to-40etch.html' title='Upgrade Debian 3.1(sarge) to 4.0(etch)'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-5421196181987256741</id><published>2009-11-10T01:30:00.000-08:00</published><updated>2009-11-10T02:37:31.505-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Install Postfix on Ubuntu</title><content type='html'>A step by step instruction to install a postfix server on ubuntu 8.10:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;    &lt;li&gt;Install package. &lt;br /&gt;        &lt;code&gt;sudo apt-get install postfix&lt;/code&gt;&lt;br /&gt;    &lt;ol&gt;&lt;br /&gt;        &lt;li&gt;type of mail configuration: Internet Site&lt;/li&gt;&lt;br /&gt;        &lt;li&gt;enter your domain name: e.g. not.exist.edu (You have to register a domain name first) &lt;a href="http://www.no-ip.org/"&gt;Free Register&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;    &lt;/ol&gt;&lt;br /&gt;    &lt;/li&gt;&lt;br /&gt;    &lt;li&gt;Install mail utilities if you want to send a email through command line.&lt;br /&gt;      &lt;code&gt;sudo apt-get install mailutils&lt;/code&gt;&lt;br /&gt;    &lt;/li&gt;&lt;br /&gt;    &lt;li&gt;Write a testing email.&lt;br /&gt;      &lt;code&gt;echo testing_message | mail -s Subject_Not_Important youremail@some.domain.name&lt;/code&gt;&lt;br /&gt;      You should get your email in a second. If not, check your &lt;strong&gt;SPAM&lt;/strong&gt; filter/box.&lt;br /&gt;    &lt;/li&gt;&lt;br /&gt;    &lt;li&gt;By default, the log files locate at /var/log&lt;br /&gt;      &lt;code&gt;ls -l /var/log | grep mail&lt;/code&gt;&lt;br /&gt;      Check log files if you encounter any errors.&lt;br /&gt;    &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-5421196181987256741?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/5421196181987256741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/install-postfix-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5421196181987256741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5421196181987256741'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/install-postfix-on-ubuntu.html' title='Install Postfix on Ubuntu'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1524401990882107315</id><published>2009-11-09T16:55:00.000-08:00</published><updated>2009-11-09T17:32:59.823-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>How to move mysql datadir to new location</title><content type='html'>&lt;p&gt; By default the mysql install the datadir at /var/lib/mysql. Unfortunately, people usually did partition their hard disk, or buy a new hard drive later. In such a case, you would like to move the *huge* datadir to another disk to both boost the speed by parallel in I/O and utilize space smartly. Here's what you should do:&lt;br /&gt;   &lt;ol&gt;&lt;br /&gt;      &lt;li&gt;Stop your mysql service.&lt;br /&gt;         &lt;code&gt;sudo /etc/init.d/mysql stop&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;Copying all files from old location to new location and preserver the ownership and timestamp information.&lt;br /&gt;         &lt;code&gt;sudo cp -r -p /var/lib/mysql /newlocation/&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;Update your mysql configuration file:&lt;br /&gt;         &lt;code&gt;sudo vim /etc/mysql/my.cnf&lt;br /&gt;         &lt;pre&gt;datadir     = /newlocation/mysql &lt;span class="cdcmt"&gt;#old: /var/lib/mysql&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;Update the second configuration file for apparmor:&lt;br /&gt;         &lt;pre&gt;  /newlocation/mysql/ r, #/var/lib/mysql/ r,&lt;br /&gt;  /newlocation/mysql/** rwk, #/var/lib/mysql/** rwk,&lt;/pre&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;(Optional) Rename the old folder to prevent confusing.&lt;br /&gt;         &lt;code&gt;sudo mv /var/lib/mysql /var/lib/mysql.bak&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;Restart your apparmor &amp; mysql service.&lt;br /&gt;         &lt;code&gt;sudo /etc/init.d/apparmor reload&lt;/code&gt;&lt;br /&gt;         &lt;code&gt;sudo /etc/init.d/mysql start&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;      &lt;li&gt;Delete the old location&lt;br /&gt;         &lt;code&gt;sudo rm -rf /var/lib/mysql.bak&lt;/code&gt;&lt;/li&gt;&lt;br /&gt;   &lt;/ol&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1524401990882107315?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1524401990882107315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/how-to-move-mysql-datadir-to-new.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1524401990882107315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1524401990882107315'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/11/how-to-move-mysql-datadir-to-new.html' title='How to move mysql datadir to new location'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-5691668224657169920</id><published>2009-09-29T21:22:00.000-07:00</published><updated>2009-09-29T21:24:51.976-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Recursively download entire website from a ftp</title><content type='html'>&lt;p&gt;The easiest way is the following command:&lt;br /&gt;&lt;code&gt;wget -r ftp://user:password @domain.name here&lt;/code&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;The only problem is that this method doesn't support "resume" function :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-5691668224657169920?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/5691668224657169920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/09/recursively-download-entire-website.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5691668224657169920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/5691668224657169920'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/09/recursively-download-entire-website.html' title='Recursively download entire website from a ftp'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-6888788382128262288</id><published>2009-09-25T13:03:00.000-07:00</published><updated>2009-11-24T02:16:26.728-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Intall Python 3 on Ubuntu</title><content type='html'>0. Install related packages:&lt;br /&gt;   &lt;code&gt;sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libbz2-dev libc6-dev libsqlite3-dev tk-dev g++ gcc &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;1. Download the file to /tmp:&lt;br /&gt;   &lt;code&gt;cd /tmp&lt;/code&gt;&lt;br /&gt;   &lt;code&gt;wget http://www.python.org/ftp/python/3.1.1/Python-3.1.1.tgz&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;2. Unzip the tar zip file:&lt;br /&gt;   &lt;code&gt;tar xzvf Python-3.1.1.tgz&lt;/code&gt; &lt;br /&gt;&lt;br /&gt;3. Run configuration command &lt;code&gt;./configure&lt;/code&gt;&lt;br /&gt;   * In case you encounter some problem, install build-essential&lt;br /&gt;&lt;br /&gt;4. make (optional)&lt;br /&gt;&lt;br /&gt;5. Install the program to system:&lt;br /&gt;   &lt;code&gt;sudo make install&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-6888788382128262288?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/6888788382128262288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/09/intall-python-3-on-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/6888788382128262288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/6888788382128262288'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/09/intall-python-3-on-ubuntu.html' title='Intall Python 3 on Ubuntu'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-7207052506858785945</id><published>2009-08-17T13:50:00.000-07:00</published><updated>2009-08-17T13:56:12.973-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Appending to Your Python Path</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;h4&gt;Question:&lt;/h4&gt;How do you append directories to your Python path?&lt;br /&gt;&lt;h4&gt;Answer:&lt;/h4&gt;Your path (i.e. the list of directories Python goes through to search for modules and files) is stored in the path attribute of the sys module. Since path is a list, you can use the append method to add new directories to the path.&lt;br /&gt;&lt;br /&gt;For instance, to add the directory /home/me/mypy to the path, just do:&lt;br /&gt;&lt;pre&gt;    import sys&lt;br /&gt;    sys.path.append("/home/me/mypy") &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;src: &lt;a href="http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html"&gt;Here&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-7207052506858785945?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/7207052506858785945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/appending-to-your-python-path.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7207052506858785945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7207052506858785945'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/appending-to-your-python-path.html' title='Appending to Your Python Path'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-3795399731900611737</id><published>2009-08-13T15:11:00.000-07:00</published><updated>2009-08-17T13:57:03.922-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>wget with proxy</title><content type='html'>&lt;p&gt;As a researcher, we often need to crawl the web pages and save a dump in local disk for future use. However, sometimes we use a proxy to connect a specific website for security concerns or performance issue. There are two ways to assign this job, the first method:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;   &lt;li&gt;Create a &lt;strong&gt;~/.wgetrc&lt;/strong&gt; file: This file can be used as a configuration file for wget command.&lt;br/&gt;&lt;pre&gt;http_proxy=&amp;lt;your http proxy&amp;gt;&lt;/pre&gt;&lt;br /&gt;Reference: &lt;a href="http://www.delorie.com/gnu/docs/wget/wget_34.html"&gt;wget manual &lt;/a&gt;&lt;br /&gt;   &lt;/li&gt;&lt;br /&gt;   &lt;li&gt;Add a environment variable to your &lt;strong&gt;~/.bashrc&lt;/strong&gt;. &lt;pre&gt;export http_proxy="...url..."&lt;/pre&gt;&lt;br /&gt;   &lt;/il&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Either way works well, but how about a proxy through socks proxy?&lt;br/&gt;&lt;br /&gt;sorry... I cannot find a solution yet&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-3795399731900611737?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/3795399731900611737/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/wget-with-proxy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3795399731900611737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/3795399731900611737'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/wget-with-proxy.html' title='wget with proxy'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1525496122554174324</id><published>2009-08-10T16:48:00.000-07:00</published><updated>2009-08-10T17:22:27.846-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Set password protection for you web pages</title><content type='html'>&lt;p&gt;&lt;br /&gt;Here is an simple scenario that comes to my mind. I created a website but I would like to protect some sub-directories from viewing by anonymous users. For example, you might created web pages to store all your bookmarks but you don't want to share it to the public but only limit to some close friends. Or, you are a instructor and you would like to share course website only to the students who attend the class. Okay... the solution is simple, you would like to create a password-protect directory through http server. &lt;br/&gt;&lt;br /&gt;You will need two files to achieve this goal. First, you need a file, &lt;strong&gt;.htaccess&lt;/strong&gt; to store the user name and authentication type. Secondly, you need a file, &lt;strong&gt;.htpasswd&lt;/strong&gt;, to store the password of the user you created in &lt;strong&gt;.htaccess&lt;/strong&gt; file. &lt;br/&gt;&lt;br /&gt;Filename:&lt;strong&gt;.htaccess&lt;/strong&gt;&lt;pre&gt;AuthType Basic&lt;br /&gt;&lt;span class="cdcmt"&gt;# You can customized your authentication name&lt;/span&gt;&lt;br /&gt;AuthName "Chucheng's Research Authentication"&lt;br /&gt;&lt;span class="cdcmt"&gt;# Where the &lt;strong&gt;.htpasswd&lt;/strong&gt; located&lt;/span&gt;&lt;br /&gt;AuthUserFile /home/chucheng/www/Research/.htpasswd&lt;br /&gt;&lt;span class="cdcmt"&gt;# Assign user name here&lt;/span&gt;&lt;br /&gt;Require user chucheng&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can then generate the &lt;strong&gt;.htpasswd&lt;/strong&gt; by typing the following code:&lt;br /&gt;&lt;pre&gt;&lt;span class="cdcmt"&gt;# The same username you used in &lt;strong&gt;.htaccess&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;$ htpasswd -c /home/chucheng/www/Research/.htpasswd chucheng&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can update the &lt;strong&gt;.htpasswd&lt;/strong&gt; by typing the following code:&lt;br /&gt;&lt;pre&gt;&lt;span class="cdcmt"&gt;# The same username you used in &lt;strong&gt;.htaccess&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;$ htpasswd /home/chucheng/www/Research/.htpasswd-users chucheng&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You are done! Enjoy your password-protected website :)&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Dv9_chr-A10/SoC5sh_aIFI/AAAAAAAAABU/G3qq3opHi7s/s1600-h/htaccess_demo.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 233px;" src="http://3.bp.blogspot.com/_Dv9_chr-A10/SoC5sh_aIFI/AAAAAAAAABU/G3qq3opHi7s/s400/htaccess_demo.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5368494930515337298" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1525496122554174324?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1525496122554174324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/set-password-protection-for-you-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1525496122554174324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1525496122554174324'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/set-password-protection-for-you-web.html' title='Set password protection for you web pages'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_Dv9_chr-A10/SoC5sh_aIFI/AAAAAAAAABU/G3qq3opHi7s/s72-c/htaccess_demo.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-468140575333905498</id><published>2009-08-10T13:00:00.000-07:00</published><updated>2009-08-10T13:16:54.675-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Tool'/><title type='text'>VirtuaWin - The Virtual Desktop Manager</title><content type='html'>&lt;p&gt;Those of you who had ever been Ubuntu must remember the multi-desktop support on GNOME. Unfortunately, neither Windows XP or Vista support this function by default. As an indulgent user of Windows, I soon understand that this function is a great plus to increase my working performance. After googling around, I found this open source project work almost perfect to meet my needs (with very light loading). Try it if you do need a multi-desktops working environment in Windows. Hopefully, Windows 7 can made this function built-in.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Official Site: &lt;a href="http://virtuawin.sourceforge.net/"&gt;VirtuaWin Official Site&lt;/a&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Dv9_chr-A10/SoB-ydpRKoI/AAAAAAAAAA8/mk3J2EM6Jtc/s1600-h/screen_1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 208px; height: 212px;" src="http://1.bp.blogspot.com/_Dv9_chr-A10/SoB-ydpRKoI/AAAAAAAAAA8/mk3J2EM6Jtc/s320/screen_1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5368430161241909890" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Dv9_chr-A10/SoB-2gkSpqI/AAAAAAAAABE/a7A7EvuU7yw/s1600-h/screen_2.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 208px; height: 212px;" src="http://3.bp.blogspot.com/_Dv9_chr-A10/SoB-2gkSpqI/AAAAAAAAABE/a7A7EvuU7yw/s320/screen_2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5368430230745818786" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Dv9_chr-A10/SoB-6yYi33I/AAAAAAAAABM/lRGdSVEvAz8/s1600-h/screen_3.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 208px; height: 212px;" src="http://4.bp.blogspot.com/_Dv9_chr-A10/SoB-6yYi33I/AAAAAAAAABM/lRGdSVEvAz8/s320/screen_3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5368430304247865202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Copyrights of above pictures belong to the official website&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-468140575333905498?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/468140575333905498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/virtuawin-virtual-desktop-manager.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/468140575333905498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/468140575333905498'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/virtuawin-virtual-desktop-manager.html' title='VirtuaWin - The Virtual Desktop Manager'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_Dv9_chr-A10/SoB-ydpRKoI/AAAAAAAAAA8/mk3J2EM6Jtc/s72-c/screen_1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-8443234575898716278</id><published>2009-08-04T18:00:00.000-07:00</published><updated>2009-08-04T18:10:07.226-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Free Python 3.x Tutorial</title><content type='html'>&lt;p&gt;This article shall be constantly updated to collect useful resource for learning python 3.x .&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;   &lt;li&gt;&lt;a href="http://diveintopython3.org/"&gt;Dive into Python 3&lt;/a&gt;&lt;br/&gt;&lt;br /&gt;   I didn't buy this book because while I start this article, it hasn't be published yet, but definitely this is a very very good book. It's much better than the book I bought from amazon, &lt;a href="http://www.amazon.com/Programming-Python-Complete-Introduction-Developers/dp/0137129297/"&gt;Programming in Python 3 by Mark Summerfield&lt;/a&gt;. The book I bought is too difficult to understand, and the only reason I bought it is that it's one of the earliest book published for python 3.x. I'm still waiting for the publication of the Dive into Python 3, and I believe this book is better than the one I owned now.&lt;br /&gt;   &lt;/li&gt;&lt;br /&gt;   &lt;li&gt;&lt;a href="http://docs.python.org/3.1/"&gt;Official Python v3.1 documentation&lt;/a&gt;&lt;br/&gt;&lt;br /&gt;   I believe that you can find all the update information from here. Anyway, it's something that you would always check for answers.&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-8443234575898716278?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/8443234575898716278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/free-python-3x-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/8443234575898716278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/8443234575898716278'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/free-python-3x-tutorial.html' title='Free Python 3.x Tutorial'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-7243830425389235375</id><published>2009-08-04T17:52:00.000-07:00</published><updated>2009-08-04T18:00:12.400-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Make vim easy to use</title><content type='html'>&lt;p&gt;These are common VIM setting I use to make vim more easy to use. &lt;br /&gt;&lt;br /&gt;The following lines should be inserted to ~/.vimrc&lt;br /&gt;&lt;pre&gt;&lt;span class="cdcmt"&gt;#This can make the comment color become lighter (easy to read)&lt;/span&gt;&lt;br /&gt;set bg=dark&lt;br /&gt;&lt;br /&gt;&lt;span class="cdcmt"&gt;#Smartindent is very helpful if you use vim for coding purpose&lt;/span&gt;&lt;br /&gt;set smartindent&lt;br /&gt;&lt;br /&gt;&lt;span class="cdcmt"&gt;#4 spaces = 1 tab&lt;/span&gt;&lt;br /&gt;set tabstop=4&lt;br /&gt;set shiftwidth=4&lt;br /&gt;set expandtab&lt;br /&gt;&lt;br /&gt;&lt;span class="cdcmt"&gt;#Press F5 to enable spell check&lt;/span&gt;&lt;br /&gt;map &lt;F5&gt; :setlocal spell! spelllang=en_us&lt;CR&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-7243830425389235375?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/7243830425389235375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/make-vim-easy-to-use.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7243830425389235375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7243830425389235375'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/make-vim-easy-to-use.html' title='Make vim easy to use'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-9089084156172417925</id><published>2009-08-04T17:46:00.000-07:00</published><updated>2009-08-04T17:58:41.759-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Make the "ls --color" lighter and more readable</title><content type='html'>In some Linux distribution, the default color skim is quite annoying. The "blue" is too dark of "ls --color" command, and it is almost invisible. Here is one tip to resolve the problem:&lt;br/&gt;&lt;br /&gt;open ~/.bashrc and insert the following line:&lt;br /&gt;&lt;pre&gt;&lt;span class="cdcmt"&gt;#This works for BASH shell&lt;/span&gt;&lt;br /&gt;export LS_COLORS="no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;00:cd=40;33;00:or=00;05;37;41:mi=00;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:"&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-9089084156172417925?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/9089084156172417925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/make-ls-color-lighter.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/9089084156172417925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/9089084156172417925'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/08/make-ls-color-lighter.html' title='Make the &quot;ls --color&quot; lighter and more readable'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-7826535539451885094</id><published>2009-07-31T16:06:00.000-07:00</published><updated>2009-07-31T16:11:43.556-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Collection Types in Python 3</title><content type='html'>I would like to document some useful snippet for handling collections in Python 3.x.&lt;br /&gt;&lt;strong&gt;set:&lt;/strong&gt;&lt;br /&gt;&lt;p&gt; To add item to a set:&lt;br /&gt;&lt;pre&gt;s.add(x)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; To check whether item is in a set:&lt;br /&gt;&lt;pre&gt;x in s &lt;span class="cdcmt"&gt;#return True if set s contains item x&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; To remove item from a set:&lt;br /&gt;&lt;pre&gt;s.remove(x)&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-7826535539451885094?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/7826535539451885094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/collection-types-in-python-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7826535539451885094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/7826535539451885094'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/collection-types-in-python-3.html' title='Collection Types in Python 3'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-4660060101913202281</id><published>2009-07-31T14:36:00.000-07:00</published><updated>2009-08-18T17:04:08.053-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Awk Command in Linux</title><content type='html'>&lt;span style="font-weight:bold;"&gt;awk&lt;/span&gt; is a very useful command. I would document some very simple but useful example here. As a rule of thumb: we use "condition {expression}" in awk.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span class="cdcmt"&gt;#Extract first column while the lines are comma seperated&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;awk '{FS=","}{print $1}'&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span class="cdcmt"&gt;#Check whether second column is "Artists", if so, print first and second columns.&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;awk '{FS="\t"} $2 = "Artists" {print $1 "\t" $2}'&lt;/pre&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-4660060101913202281?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/4660060101913202281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/useful-awk-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4660060101913202281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/4660060101913202281'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/useful-awk-command.html' title='Awk Command in Linux'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-532173417985696937</id><published>2009-07-31T14:20:00.000-07:00</published><updated>2009-07-31T14:42:08.886-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Randomly picks n lines in a text file</title><content type='html'>I try to google, but I cannot find the easy way to do this in command. Often times, I would like to randomly sample (without duplicate) lines in a text file. Here is my python code.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span class="cdcmt"&gt;#!/bin/python3&lt;br /&gt;# The goal of this script is to randomly choose n lines from a text files by line without duplicate&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;import sys, os, pdb, random&lt;br /&gt;&lt;br /&gt;&lt;span class="cdcmt"&gt;#The prefix will add to the front of each line&lt;/span&gt;&lt;br /&gt;prefix = ""&lt;br /&gt;&lt;br /&gt;if len(sys.argv) != 3 and len(sys.argv) != 4:&lt;br /&gt;    print("syntax: randomlines.py &amp;lt;input_file&amp;gt; &amp;lt;num_of_sample&amp;gt;")&lt;br /&gt;    sys.exit()&lt;br /&gt;else:&lt;br /&gt;    input_file = sys.argv[1]&lt;br /&gt;    num_of_sample = int(sys.argv[2])&lt;br /&gt;&lt;br /&gt;if len(sys.argv) == 4:&lt;br /&gt;    prefix = sys.argv[3]&lt;br /&gt;&lt;br /&gt;&lt;span class="cdcmt"&gt;#pdb.set_trace()&lt;/span&gt;&lt;br /&gt;lines = open(input_file, "r").read().splitlines()&lt;br /&gt;if len(lines) &lt; num_of_sample:&lt;br /&gt;    print("The number of random lines you asked for is larger than the lines in the target file.\n" +&lt;br /&gt;        "Shrink it to lines of target file automatically.\n" +&lt;br /&gt;        "-----------------------------------------------\n")&lt;br /&gt;    num_of_sample = len(lines)&lt;br /&gt;&lt;br /&gt;chosen_lines_num = random.sample(range(0,len(lines)), num_of_sample)   #range(0,3) only generate 0,1,2&lt;br /&gt;for i in chosen_lines_num:&lt;br /&gt;    print(prefix + lines[i])&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-532173417985696937?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/532173417985696937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/randomly-picks-n-lines-in-text-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/532173417985696937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/532173417985696937'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/randomly-picks-n-lines-in-text-file.html' title='Randomly picks n lines in a text file'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-1953366356940407354</id><published>2009-07-29T18:18:00.001-07:00</published><updated>2009-07-29T18:31:33.305-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Blogger Tool'/><title type='text'>Enable Latex support in blogspot</title><content type='html'>Here is an example:&lt;br /&gt;$$\pi = \int_{0}^{1} \frac{4}{1+x^{2}}$$&lt;br /&gt;becomes:&lt;br /&gt;&amp;lt;a latex equation in pic&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://wolverinex02.googlepages.com/emoticonsforblogger2"&gt;Here&lt;/a&gt; explains all the details you need.&lt;br /&gt;&lt;br /&gt;*Update*: The previous method doesn't work because the http://www.forkosh.dreamhost.com refuse to service other public website :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-1953366356940407354?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/1953366356940407354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/enable-latex-support-in-blogspot.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1953366356940407354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/1953366356940407354'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/enable-latex-support-in-blogspot.html' title='Enable Latex support in blogspot'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7338042968667045216.post-240776275438975386</id><published>2009-07-29T17:39:00.000-07:00</published><updated>2009-07-29T19:06:23.000-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Sorting Python Dictionary by Value</title><content type='html'>This is a slower version:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;sorted(adict.items(), key=lambda (k,v): v)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is a faster version:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;from operator import itemgetter&lt;br /&gt;sorted(d.items(), key=itemgetter(1))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;source: &lt;a href="http://blog.client9.com/2008/09/sorting-python-dictionary-by-value-take.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;However, what if value is a list, and we would like to sort by the items inside the list?&lt;br /&gt;&lt;br /&gt;For example, we have a dictionary variable x:&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; x&lt;br /&gt;{'a': [1, 2, 3], 'b': [0, 3, 1]}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can sort them by the following command&lt;br /&gt;&lt;pre&gt;&gt;&gt;&gt; sorted(x.items(), key = (lambda k: k[0])) #sort by key&lt;br /&gt;[('a', [1, 2, 3]), ('b', [0, 3, 1])]&lt;br /&gt;&gt;&gt;&gt; sorted(x.items(), key = (lambda k: k[1])) #sort by value&lt;br /&gt;[('b', [0, 3, 1]), ('a', [1, 2, 3])]&lt;br /&gt;&gt;&gt;&gt; sorted(x.items(), key = (lambda k: k[1][0])) #sort by first item in value(a list)&lt;br /&gt;[('b', [0, 3, 1]), ('a', [1, 2, 3])]&lt;br /&gt;&gt;&gt;&gt; sorted(x.items(), key = (lambda k: k[1][1])) #sort by second item in value(a list)&lt;br /&gt;[('a', [1, 2, 3]), ('b', [0, 3, 1])]&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7338042968667045216-240776275438975386?l=chuchenghsieh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chuchenghsieh.blogspot.com/feeds/240776275438975386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/sorting-python-dictionary-by-value.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/240776275438975386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7338042968667045216/posts/default/240776275438975386'/><link rel='alternate' type='text/html' href='http://chuchenghsieh.blogspot.com/2009/07/sorting-python-dictionary-by-value.html' title='Sorting Python Dictionary by Value'/><author><name>Chu-Cheng Hsieh</name><uri>http://www.blogger.com/profile/14567883291644265206</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_Dv9_chr-A10/SnDwJrv0jzI/AAAAAAAAAAM/v8i97X9qHgk/s1600-R/MyPic.jpg'/></author><thr:total>0</thr:total></entry></feed>
