<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coder Santa</title>
	<atom:link href="http://www.contrib.andrew.cmu.edu/~hanlai/index.php?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.contrib.andrew.cmu.edu/~hanlai</link>
	<description>EvilSanta&#039;s first website</description>
	<lastBuildDate>Tue, 30 Apr 2013 19:13:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Malloc and free.  C programming tips</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=241&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=malloc-and-free-c-programming-tips</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=241#comments</comments>
		<pubDate>Tue, 30 Apr 2013 19:13:50 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Other language tips]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[free error]]></category>
		<category><![CDATA[free()]]></category>
		<category><![CDATA[invalid address]]></category>
		<category><![CDATA[invalid pointer]]></category>
		<category><![CDATA[malloc error]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/~hanlai/?p=241</guid>
		<description><![CDATA[In C programming, we usually have to define a lot of customized structs, they work similar to classes but without the methods. Usually to construct a struct, we have the following struct xyz { int a; int b; .... } Then when you use it, you have to do struct xyz * apointer= malloc(sizeof(struct xyz)); [...]]]></description>
				<content:encoded><![CDATA[<p>In C programming, we usually have to define a lot of customized structs, they work similar to classes but without the methods.</p>
<p>Usually to construct a struct, we have the following</p>
<p><code> struct xyz {<br />
int a;<br />
int b;<br />
....<br />
}</code></p>
<p>Then when you use it, you have to do</p>
<p><code> struct xyz * apointer= malloc(sizeof(struct xyz));</code></p>
<p>To simplify the code, we use</p>
<p><code> typedef struct xyz * xyz</code></p>
<p>This way, we don't have to type "struct xyz *" every time, but simply use a "xyz".</p>
<p>Problem usually happen when you try to free the memory. After you are done with this struct.<br />
Then you free the memory that "apointer" points to by using <code> free(apointer)</code></p>
<p>Many times people will get a "invalid size", or "invalid address" error when they try to free the memory and get very confused. I found it very often that this happens very often with one case. So I point it out to remind myself.<br />
<code> xyz curPointer=malloc(sizeof(xyz));</code><br />
<strong>THIS IS VERY WRONG!!!</strong></p>
<p>This means you are only malloc enough space for a xyz pointer!, which is only 8 byte( or 4 byte). You should use<br />
<code> xyz curPointer=malloc(sizeof(struct xyz));</code></p>
<p>This is very important!<br />
If you did not "malloc" enough space for one struct and write more bytes into the space. You'll overwrite the memory space adjacent to it. (C does not check for this when it writes to this location exceed the malloc space). When you try to free the next memory block, it will not understand what to free, because this block was overwritten.</p>
<p>Suppose you have block A and B adjacent to each other. A is 8 byte, B is also 8 byte.</p>
<p>Then you write 9 bytes to A, and then try to free B. You'll get the error I was talking about.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=241</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java practices</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=221&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-practices</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=221#comments</comments>
		<pubDate>Mon, 18 Feb 2013 20:37:03 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[hints]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/~hanlai/?p=221</guid>
		<description><![CDATA[Just found this website that got so many interesting and fun java techniques. I think any new java learner, even some professionals will find this site very useful. http://www.javapractices.com/ Cheers.]]></description>
				<content:encoded><![CDATA[<p>Just found this website that got so many interesting and fun java techniques. I think any new java learner, even some professionals will find this site very useful. </p>
<p>http://www.javapractices.com/</p>
<p>Cheers. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=221</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is Random</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=173&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-is-random</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=173#comments</comments>
		<pubDate>Thu, 15 Nov 2012 21:33:51 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[deterministic]]></category>
		<category><![CDATA[factors]]></category>
		<category><![CDATA[flip coin]]></category>
		<category><![CDATA[measure]]></category>
		<category><![CDATA[probablistic]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[roll dice]]></category>
		<category><![CDATA[statistic]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=173</guid>
		<description><![CDATA[A big concept in statistics is randomness. Rolling a fair dice, or throwing a quarter, picking a sample from a population, sampling from some distribution. These behaviors all involved some randomness. Very often, you can see a question like this: what's the probability of throwing a fair (50/50) quarter and you get heads? This is [...]]]></description>
				<content:encoded><![CDATA[<p>A big concept in statistics is randomness. Rolling a fair dice, or throwing a quarter, picking a sample from a population, sampling from some distribution. These behaviors all involved some randomness.</p>
<p>Very often, you can see a question like this: what's the probability of throwing a fair (50/50) quarter and you get heads? This is based on the assumption that throwing this quarter, this quarter will land randomly.</p>
<p>However, it is very tricky to think about this concept. Why would there be random? If you think really deep( not saying I can think deeper than you), every random behavior can be explained to be a deterministic behavior, and can be monitored and predicted, if, the power of computing is good enough, and power of measuring is accurate enough.</p>
<p>For example, throwing a quarter. There are many factors that involved with the quarter show head or tail after it land, such as: air flow speed, direction, landing angle, throwing angle, landing material, and so on. These things can all affect the result.</p>
<p>However, can we actually measure the air flow, throwing angle, and all these factors? This answer is quite difficult. Let's imagine that the air flow direction is the only factor affect result, the air is left and right.(which obviously is not the case), then when we throw quarter 100 times and 50 heads. It does not mean the coin itself is a fair coin, it can also be explained as the coin is not a fair coin, but the air flow direction somehow&nbsp;compensated&nbsp;the bias.</p>
<p>Therefore, I believe that in a reduced factor scenario, where there is no air and the quarter is dropped the same way many times, then every time the quarter should show the same side.</p>
<p>I believe it is very important to realize that everything in the world is in fact deterministic, we use probabilistic models is because there are so many factors that we have no idea how to capture. And remember "air flow direction" when you make a statement of a quarter's fairness.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=173</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tree and Tree node implementation</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=163&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tree-and-tree-node-implementation</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=163#comments</comments>
		<pubDate>Thu, 13 Sep 2012 21:57:56 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[implement]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[java tree]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[Tree]]></category>
		<category><![CDATA[tree class]]></category>
		<category><![CDATA[tree implementation]]></category>
		<category><![CDATA[tree node]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=163</guid>
		<description><![CDATA[A tree is a very useful structure, many people like to use class TreeNode{ E nodeData; TreeNode child1; TreeNode child2; ... } to represent nodes in a tree, I find it complicated and hoping to get create a way such that tree nodes can be any class that implement a TreeNode class. For example, anytime [...]]]></description>
				<content:encoded><![CDATA[<p>A tree is a very useful structure, many people like to use</p>
<p><code> class TreeNode{<br />
E nodeData;<br />
TreeNode child1;<br />
TreeNode child2;<br />
...<br />
} </code><br />
to represent nodes in a tree, I find it complicated and hoping to get create a way such that tree nodes can be any class that <strong>implement </strong>a TreeNode class. For example, anytime you try to get the child or parent, you'll have to throw away this wrapper of TreeNode. The code in my mind to use the node would be as easy as<br />
<code> class employee implements TreeNode{<br />
...<br />
}<br />
</code> Then we can use<br />
<code> employee e1= new employee();<br />
employee e2= new employee();<br />
e2.addChild(e1);<br />
</code><br />
But this bring up a problem. The tree node function such as, getChildren, getParent, getDecendants, they should be inherited instead of re-declared in each of the subclass that implements TreeNode.<br />
So a better way is to use <strong>abstract class</strong> instead of <strong>interface</strong>.<br />
<code>public abstract class Treenode&lt;T extends Treenode&lt;T&gt;&gt; {<br />
T next;<br />
T myself=(T) this;<br />
T parent;<br />
public void addChild(T node) {<br />
next=node;<br />
node.parent=myself;<br />
}<br />
public T getChild() {<br />
return next;<br />
}<br />
public T getParent(){<br />
return parent;<br />
}</code></p>
<p>}<br />
The logic here is that any class that extends this Treenode class will automatically get the following functions without reprogramming them. The ugly part of this snippet is the <code>T myself=(T) this;</code>. Here the "this" is considered to be any Treenode, but myself is considered to be the subclass that extends it. This have to be a cast, but I can't see any reason such a cast could fail. Unless<br />
<code> class class1 extends Treenode{};<br />
class class2 extends Treenode{};<br />
</code><br />
Then for some reason you want<br />
<code><br />
class1 c=new class1();<br />
c.add(new class2());<br />
</code><br />
This should not happen as a strongly typed programming practice. Period.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=163</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>why we need interface</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=160&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-we-need-interface</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=160#comments</comments>
		<pubDate>Thu, 13 Sep 2012 19:05:17 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[implement]]></category>
		<category><![CDATA[interface]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=160</guid>
		<description><![CDATA[Come across with this article, I think it is a must read for all new programmers. http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=1]]></description>
				<content:encoded><![CDATA[<p>Come across with this article, I think it is a must read for all new programmers.</p>
<p><a href="http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=1">http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=160</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Service Start up</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=157&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=windows-service-start-up</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=157#comments</comments>
		<pubDate>Fri, 01 Jun 2012 19:38:56 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Visual Studio C#]]></category>
		<category><![CDATA[C sharp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[On Continue]]></category>
		<category><![CDATA[Onstart]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=157</guid>
		<description><![CDATA[Visual Studio 2010 has a very nice template for creating a windows service. It's fairly simple to just create it. Click here to see tutorial on how to create and install a windows service. Because a windows service cannot be running inside visual studio, it has to be running in a windows service management, therefore [...]]]></description>
				<content:encoded><![CDATA[<p>Visual Studio 2010 has a very nice template for creating a windows service. It's fairly simple to just create it.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/zt39148a.aspx">Click here</a> to see tutorial on how to create and install a windows service.</p>
<p>Because a windows service cannot be running inside visual studio, it has to be running in a windows service management, therefore the service cannot be debugged in Visual Studio. The alternative option here is to attach a debugger on the service that is running.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.80).aspx">Click here</a> to see tutorial on how to attach a debugger on the service.</p>
<p>Few things to note is: The service is not viewable in the processes dialog box if it is not started. Which means you cannot attach your debugger unless you started the service. When the service start, it executes the Onstart() method. Once it started executing that method, you can see it in the process dialog box and attach debugger.</p>
<p>But what if you want to debug the Onstart() method?</p>
<p>You can use System.Threading, and use the static method Thread.sleep(x milisec); Make the service start wait for 1o sec, and attach the debugger during that 10 sec. But here comes another trick, the service management only gives arround 30-40 sec for the Onstart() to execute. If Onstart() takes too long, then error message appears saying your service is not responding. So the longer  you wait, the less time you give Onstart() to execute.</p>
<p>OnContinue()</p>
<p>This method does NOT mean after Onstart(), it will be executed. This method is only called after the service is paused and resumed.</p>
<p>A general structure of a service should be,</p>
<p>Onstart: Use threading, generate thread to start any processes. Do not put the process here, Onstart has very limited time to start!</p>
<p>OnStop: interrupt the thread, disable any thread, or timer. and dispose.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=157</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pre-phase What is statistics</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=150&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pre-phase-what-is-statistics</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=150#comments</comments>
		<pubDate>Wed, 30 May 2012 19:11:20 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[101]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[estimate]]></category>
		<category><![CDATA[estimator]]></category>
		<category><![CDATA[guarantee]]></category>
		<category><![CDATA[learning statistics]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[variance]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=150</guid>
		<description><![CDATA[In my opinion, statistic is ALL about estimation. Estimating the probability of some events that happen over the universe of all events. Test of significance When people first learn about statistics, they are probably learned from stats 101, where the professor told them how to do a t-test, or chi-square-test where they can decide a [...]]]></description>
				<content:encoded><![CDATA[<p>In my opinion, statistic is ALL about estimation. Estimating the probability of some events that happen over the universe of all events.</p>
<p>Test of significance</p>
<p>When people first learn about statistics, they are probably learned from stats 101, where the professor told them how to do a t-test, or chi-square-test where they can decide a certain judgement is significant or not. &nbsp;Well, this is an estimation too, in fact, these tests are estimating the probability of you making a mistake by saying the judgement is significant. &nbsp;For example, if you are doing a t-test of two samples, and the p-value is 0.01, that is saying if you say these two samples are significant, the probability that you are incorrect is 0.001. It's pretty much means that you are almost correct.</p>
<p>Then why is there a whole area of statistics if the only goal of statistics is to estimate?</p>
<p>It's because there are so many models, that each have its own strength when estimating a probability. There's parametric, non-parametric to estimate a probability distribution over continuous, or discrete interval. There's also graphical models, multivariate models if the dataset you have got more than one variables, and you want to estimate conditional probability.</p>
<p>When you are estimating something, there are also many measurements of how good the estimator is. There are always trade-off between properties of an estimator, if your estimator is unbiased, it's probably going to have high variance.</p>
<p>There are many questions to ask when you want to estimate something.</p>
<p>Would you like an estimator that is generally good, but can make is very bad mistake or you'd like an estimator that is not as good, but is&nbsp;guaranteed&nbsp;to not make a very bad mistake?</p>
<p>Would you like an estimator that is unbiased when sample size is infinity with high variance or you'd like an estimator that is little biased but with very small variance?</p>
<p>etc.</p>
<p>So before you get into the field of statistics, &nbsp;these questions are definitely important to keep in mind, and when you use statistics to solve problems in research, you'll always have to state how/why you chose such estimator.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=150</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matlab: Double precision problem</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=136&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-double-precision-problem</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=136#comments</comments>
		<pubDate>Mon, 07 May 2012 21:04:49 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Matlab]]></category>
		<category><![CDATA[==]]></category>
		<category><![CDATA[== not work]]></category>
		<category><![CDATA[double]]></category>
		<category><![CDATA[double equal bug]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://hanlai.bio.cmu.edu/?p=136</guid>
		<description><![CDATA[In matlab, Sometimes when you try to compare two numbers, they don't usually gives you the answer you excepted. When you compare two integers, a=1; b=1; a==b will gives you 1. but when you compare double, sometimes it doesn't work. Simple cases that if you do a=0.001; b=0.001; a==b will give you 1 still. But [...]]]></description>
				<content:encoded><![CDATA[<p>In matlab, Sometimes when you try to compare two numbers, they don't usually gives you the answer you excepted. When you compare two integers,</p>
<p><code>a=1;<br />
b=1;<br />
a==b<br />
</code><br />
will gives you 1.</p>
<p>but when you compare double, sometimes it doesn't work. Simple cases that if you do</p>
<p><code> a=0.001;<br />
b=0.001;<br />
a==b</code></p>
<p>will give you 1 still. But if you save a into a file, and use <code> textread(filename)</code> to get the value, the value may still look like 0.001, but if you do</p>
<p><code> a==0.001</code></p>
<p>It might give you 0 because the a was read from a file and it was in some weird format. This might be a bug. Some people fix it by doing</p>
<p><code> abs(a-0.001)&lt;0.000001</code></p>
<p>it basically means if a and 0.001 is very close, then they are equal.</p>
<p>I personally have a quicker fix.</p>
<p><code> a+1==0.001+1</code>.</p>
<p>For some reason, after any operation on the variable, the value no long have anything weird going on inside.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=136</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: read table with empty elements.</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=133&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-read-table-with-empty-elements</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=133#comments</comments>
		<pubDate>Mon, 30 Apr 2012 19:49:48 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[I/O hints]]></category>
		<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[comma]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[empty emelent]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[read table]]></category>
		<category><![CDATA[split]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tokenizer]]></category>

		<guid isPermaLink="false">http://hanlai.bio.cmu.edu/?p=133</guid>
		<description><![CDATA[Suppose you have a table, tab or "," delimited. Look like this: element1,element2,element3,element4 element21,,,element24 If you read each line and do split(","); The result will be a 2 element String[] for 2nd line. Because java will ignore the repeated ",". The solution to this is to do split(",",-1);]]></description>
				<content:encoded><![CDATA[<p>Suppose you have a table, tab or "," delimited. Look like this:</p>
<blockquote><p>element1,element2,element3,element4<strong></strong></p>
<p>element21,,,element24</p></blockquote>
<p>If you read each line and do<br />
<code>split(",");</code></p>
<p>The result will be a 2 element String[] for 2nd line. Because java will ignore the repeated ",".</p>
<p>The solution to this is to do <code>split(",",-1);</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=133</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips: cookies in different browsers, why sometimes saved cookie does not load</title>
		<link>http://www.contrib.andrew.cmu.edu/~hanlai/?p=109&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tips-cookies-in-different-browsers-why-sometimes-saved-cookie-does-not-load</link>
		<comments>http://www.contrib.andrew.cmu.edu/~hanlai/?p=109#comments</comments>
		<pubDate>Fri, 23 Mar 2012 21:32:05 +0000</pubDate>
		<dc:creator>Han Lai</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[cannot log in]]></category>
		<category><![CDATA[cannot set cookie]]></category>
		<category><![CDATA[cookie problem]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[not load]]></category>

		<guid isPermaLink="false">http://www.contrib.andrew.cmu.edu/%7Ehanlai/?p=109</guid>
		<description><![CDATA[This post is demonstrated using php. I presume in other language it's the same. The cookies are small files saved in client computers when visiting web server. information like username and password can be saved in cookie, so the next time you visit the website, you don't have to reenter, it automatically log you in. [...]]]></description>
				<content:encoded><![CDATA[<p>This post is demonstrated using php. I presume in other language it's the same.</p>
<p>The cookies are small files saved in client computers when visiting web server. information like username and password can be saved in cookie, so the next time you visit the website, you don't have to reenter, it automatically log you in.</p>
<p>Of course people can make programs that stole your information from cookie. (but cookies are usually encrypted and secured,unless you didn't save it correctly).</p>
<p>Today I found a very interesting bug, well, an observation.<br />
in php, the syntax is</p>
<p><code>setcookie(key,value,expiration time,path,domain,...);</code></p>
<p>One thing to note for the path is: if the path contain special characters. such as '~', then it behaves differently in different browsers.</p>
<p>suppose you have to save a cookie</p>
<p><code>setcookie("name","foo",0,"/~bar/","www.domain.com")</code></p>
<p>Then when you visit http://www.domain.com/~bar/ you should be able to retrieve the cookie. This is generally true.</p>
<p>BUT, for security reasons, many people like to url encode the path to prevent the site from XXS attacks in other places and forgot to decode it. (It encodes special characters to other formats.) if you do url encoding on '~', it's %7E.</p>
<p>Then when you set the cookie, you actually doing</p>
<p><code>setcookie("name","foo",0,"/%7Ebar/","www.domain.com");</code></p>
<p>This cookie can be loaded in FireFox, but NOT GOOGLE CHROME!!!!. CHROME will not load this cookie, and it will appear that you are not logged in.</p>
<p>I am not sure if this is a bug in browser, or they did this for a reason. So be sure that you url decoded the PATH variable when you set cookies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.contrib.andrew.cmu.edu/~hanlai/?feed=rss2&#038;p=109</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
