<?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>Tonny Xu &#187; My Blog</title>
	<atom:link href="http://www.totodotnet.net/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.totodotnet.net</link>
	<description>Life is like a box of chocolates...</description>
	<lastBuildDate>Thu, 02 Feb 2012 00:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CoreData with NSOrderedSet does not work well on insertion</title>
		<link>http://www.totodotnet.net/2012/02/02/coredata-with-nsorderedset-does-not-work-well-on-insertion/</link>
		<comments>http://www.totodotnet.net/2012/02/02/coredata-with-nsorderedset-does-not-work-well-on-insertion/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 00:44:54 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[iPhone Dev]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/?p=852</guid>
		<description><![CDATA[Usually, we generate an entity class with Editor-&#62;Create NSManagedOBject Subclass... For example we created a subclass of NSManagedObject Xcode generates the .h file like this: @interface MyEntity : NSManagedObject @property (nonatomic, retain) NSOrderedSet manySubs; //... some methods generated by Xcode - (void)addManySubsObject:(MySubEntity*)value; //... some other methods generated by Xcode @end and the .m file like &#8230; <a href="http://www.totodotnet.net/2012/02/02/coredata-with-nsorderedset-does-not-work-well-on-insertion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Usually, we generate an entity class with <code>Editor-&gt;Create NSManagedOBject Subclass...</code>
For example we created a subclass of NSManagedObject</p>

<p>Xcode generates the <code>.h</code> file like this:</p>

<pre><code>@interface MyEntity : NSManagedObject

@property (nonatomic, retain) NSOrderedSet manySubs;

//... some methods generated by Xcode
- (void)addManySubsObject:(MySubEntity*)value;
//... some other methods generated by Xcode

@end
</code></pre>

<p>and the <code>.m</code> file like this:</p>

<pre><code>@implement MyEntity

@dynamic manySubs;

@end
</code></pre>

<p>If you use <code>MyEntity</code> just like this, you will get an error when you try to insert a new <code>MySubEntity</code> class by calling <code>[myEntityObj addManySubsObject:aSubEntityObj];</code>.</p>

<p>The error reads:</p>

<blockquote>
  <p><code>*** -[NSSet intersectsSet:]: set argument is not an NSSet</code></p>
</blockquote>

<p>This is a bug Apple hasn&#8217;t resolved yet, but you can work around this bug by adding the following method to <code>.m</code> file.</p>

<pre><code>- (void)addManySubsObject:(MySubEntity*)value{
    [self willChangeValueForKey:@"manySubs"];
    NSMutableOrderedSet *tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.manySubs];
    [tempSet addObject: value];
    self.manySubs = tempSet;
    [self didChangeValueForKey:@"manySubs"];
}
</code></pre>

<p>Be careful</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2012/02/02/coredata-with-nsorderedset-does-not-work-well-on-insertion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Updated]Billboard problem Resolved &#8211; Facebook Hacker Cup 2012</title>
		<link>http://www.totodotnet.net/2012/01/24/billboard-problem-resolved-facebook-hacker-cup-2012/</link>
		<comments>http://www.totodotnet.net/2012/01/24/billboard-problem-resolved-facebook-hacker-cup-2012/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 07:39:31 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/?p=843</guid>
		<description><![CDATA[[Update@2012-01-24] I made a little mistake in a if...else... statement. Facebook started Facebook Hacker Cup 2012 from January 20 at 4:00pm PST, and until January 23 at 4:00pm PST, the event is closed to receive submission. There are three questions, when I learned the event, the event is already started and left me only near &#8230; <a href="http://www.totodotnet.net/2012/01/24/billboard-problem-resolved-facebook-hacker-cup-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>[Update@2012-01-24] I made a little mistake in a <code>if...else...</code> statement.</p>

<p>Facebook started <strong>Facebook Hacker Cup 2012</strong> from January 20 at 4:00pm PST, and until January 23 at 4:00pm PST, the event is closed to receive submission.</p>

<p>There are three questions, when I learned the event, the event is already started and left me only near 16 hours to take some challenge.</p>

<p>I picked &#8220;Billboard problem&#8221;.</p>

<h2>The original question</h2>

<blockquote>
  <h3>Billboards</h3>
  
  <p>We are starting preparations for Hacker Cup 2013 really early. Our first step is to prepare billboards to advertise the contest. We have text for hundreds of billboards, but we need your help to design them.</p>
  
  <p>The billboards are of different sizes, but are all rectangular. The billboard widths and heights are all integers. We will supply you with the size in inches and the text we want printed. We want you to tell us how large we can print the text, such that it fits on the billboard without splitting any words across lines. Since this is to attract hackers like yourself, we will use a monospace font, meaning that all characters are of the same width (e.g.. &#8216;l&#8217; and &#8216;m&#8217; take up the same horizontal space, as do space characters). The characters in our font are of equal width and height, and there will be no additional spacing between adjacent characters or adjacent rows. If you print a word on one line and print the next word on the next line, you do not need to print a space between them.</p>
  
  <p>Let&#8217;s say we want to print the text &#8220;Facebook Hacker Cup 2013&#8243; on a 350&#215;100&#8243; billboard. If we use a font size of 33&#8243; per character, then we can print &#8220;Facebook&#8221; on the first line, &#8220;Hacker Cup&#8221; on the second and &#8220;2013&#8243; on the third. The widest of the three lines is &#8220;Hacker Cup&#8221;, which is 330&#8243; wide. There are three lines, so the total height is 99&#8243;. We cannot go any larger.</p>
  
  <h3>Input</h3>
  
  <p>The first line of the input file contains a single integer T: the number of test cases. <code>T</code> lines follow, each representing a single test case in the form &#8220;W H S&#8221;. <code>W</code> and <code>H</code> are the width and height in inches of the available space. <code>S</code> is the text to be written.</p>
  
  <h3>Output</h3>
  
  <p>Output <code>T</code> lines, one for each test case. For each case, output &#8220;Case #t: s&#8221;, where t is the test case number (starting from 1) and s is the maximum font size, in inches per character, we can use. The size must be an integral number of inches. If the text does not fit when printed at a size of 1&#8243;, then output 0.</p>
  
  <h3>Constraints</h3>
  
  <ul>
  <li><code>1 ≤ T ≤ 20</code></li>
  <li><code>1 ≤ W, H ≤ 1000</code></li>
  </ul>
  
  <p>The text will contain only lower-case letters a-z, upper-case letters A-Z, digits 0-9 and the space character. The text will not start or end with the space character, and will never contain two adjacent space characters. The text in each case contains at most 1000 characters</p>
  
  <h3>Example input</h3>

<pre><code>5
20 6 hacker cup
100 20 hacker cup 2013
10 20 MUST BE ABLE TO HACK
55 25 Can you hack
100 20 Hack your way to the cup
</code></pre>
  
  <h3>Example output</h3>

<pre><code>Case #1: 3
Case #2: 10
Case #3: 2
Case #4: 8
Case #5: 7
</code></pre>
</blockquote>

<h2>My Solution</h2>

<p>I used Objective-C to resolve this problem. I created a Mac app project. Later I think it&#8217;s completely unnecessary. I will try to use maybe pure <code>C</code> or <code>Cocoa Console</code> later.</p>

<p>Here is the my solution on <a href="https://github.com/TonnyXu/BillboardProblem-FacebookHackerCup2012">github</a></p>

<p>The key idea behind my solution is <a href="http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm">divide and conquer</a>.</p>

<h3>1. Find the possible max font size</h3>

<ol>
<li>Assume the billboard only show one line or one column, the <code>MIN(width, height)</code> will give the first guess of the max font size.</li>
<li>Assume all the characters without space will be layout on the billboard one by one, the biggest font to whole all characters will be our <strong>possible max font size</strong>. Because if we add any space or non-hyphenation constraints to layout, we must shrink the font to hold these extra constraints.</li>
</ol>

<p>Here I used the D&amp;C to find the possible max font size:</p>

<pre><code>- (NSInteger)maxFontSizeForText:(NSString *)text 
                withTextInArray:(NSArray *)textInArray 
               constraintToArea:(NSInteger)rectArea 
                     withBounds:(NSDictionary *)bounds
{
  NSParameterAssert(text);
  NSParameterAssert(textInArray);
  NSParameterAssert(bounds);

  NSInteger upperSize = [[bounds objectForKey:UPPER_BOUND_KEY] integerValue];
  NSInteger lowerSize = [[bounds objectForKey:LOWER_BOUND_KEY] integerValue];
//  NSLog(@"*** finding max size between %4ld...%ld", lowerSize, upperSize);

  NSInteger upperArea = upperSize * upperSize * ([text length] - ([textInArray count] - 1));
  NSInteger lowerArea = lowerSize * ([text length] - ([textInArray count] - 1));

  // No need to go further, there will be one size suitable for rectArea
  if (1 &gt;= (upperSize - lowerSize)) { // there could be a case of 0
    if (upperArea &lt;= rectArea) {
      return upperSize;
    }else if (lowerArea &lt;= rectArea){
      return lowerSize;
    }else {
      return 0;
    }
  }

  // Otherwise, we need to go recursive routine to find the max size in lower...upper
  NSInteger middleSize = lowerSize + ((upperSize - lowerSize) &gt;&gt; 1);
  NSInteger middleArea = middleSize * middleSize * ([text length] - ([textInArray count] - 1));
  if (middleArea &gt; rectArea) {
    NSDictionary *boundsDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                [bounds objectForKey:LOWER_BOUND_KEY], LOWER_BOUND_KEY,
                                [NSNumber numberWithInteger:middleSize], UPPER_BOUND_KEY,
                                nil];
    return [self maxFontSizeForText:text withTextInArray:textInArray constraintToArea:rectArea withBounds:boundsDict];
  }else {
    NSDictionary *boundsDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithInteger:middleSize], LOWER_BOUND_KEY,
                                [bounds objectForKey:UPPER_BOUND_KEY], UPPER_BOUND_KEY,
                                nil];
    return [self maxFontSizeForText:text withTextInArray:textInArray constraintToArea:rectArea withBounds:boundsDict];
  }
}
</code></pre>

<h3>2. Find the correct max font size</h3>

<p>Try to fit the text start with <code>possible max font</code>, then shrink the font size to meet the constraints.</p>

<p>This is simple but have some complex <code>if...else...</code> statements.</p>

<blockquote>
  <p>[Update 2012-01-24] Thanks to Chong, the following algorithm failed to find the correct font size for Case #7, it should be <code>9</code> instead of <code>8</code>, to fix this, I need to modify 2 places, change <code>realFontSize = width/[aWord length];</code> to <code>realFontSize--;</code> and change <code>realFontSize = height/(currentLineIndex + 1);</code> to <code>realFontSize--;</code></p>
</blockquote>

<pre><code>// Another core algorithm that will try and shrink the font size to fit the billboard
- (NSInteger)correctMaxFontSizeForNoHyphenationFor:(NSArray *)textInArray 
                                      constraintTo:(NSInteger)possibleMaxFontSize 
                                        boardWidth:(NSInteger)width 
                                       boardHeight:(NSInteger)height
{
  NSParameterAssert(textInArray);

  if (possibleMaxFontSize == 0) {
    return 0;
  }

  NSInteger realFontSize = possibleMaxFontSize;
  BOOL finished = NO;
  do {
    NSInteger currentLineWidth = 0;
    NSInteger currentLineIndex = 0;

    for (int idx= 0; idx &lt; [textInArray count]; idx++) {
      NSString *aWord = [textInArray objectAtIndex:idx];
      NSInteger wordLengthAppliedFontSize = [aWord length]*realFontSize;
      // width is not enough for a single word
      if (wordLengthAppliedFontSize &gt; width) {
        realFontSize = width/[aWord length];
        currentLineIndex = 0;
        currentLineWidth = 0;
        break;
      }

      // current word is safe for at least one line, see if it is safe to add to current line.
      if (currentLineWidth + wordLengthAppliedFontSize &gt; width) {
        // need a new line
        currentLineIndex++;
        currentLineWidth = wordLengthAppliedFontSize;

      }else{
        currentLineWidth += wordLengthAppliedFontSize;
      }

      if (currentLineWidth + realFontSize &lt; width) {
        // current line is safe for one more space.
        currentLineWidth += realFontSize;
      //}else{   //&lt;- Here cause the case #1 failed
      }else if (idx != ([textInArray count] -1)){
        // need a new line
        currentLineIndex++;
        currentLineWidth = 0;
      }

      // height is not enough for the whole text
      if ((currentLineIndex + 1) * realFontSize &gt; height){
        realFontSize = height/(currentLineIndex + 1);
        currentLineIndex = 0;
        currentLineWidth = 0;
        break;
      }
      // done.
      if (idx == [textInArray count] -1) {
        // last line
        finished = YES;
      }

    }

  } while (realFontSize &gt; 0 &amp;&amp; !finished);

  return realFontSize;
}
</code></pre>

<h3>3. Verify it</h3>

<p>I created some test cases to test on it. It includes some extra test cases that need to be omitted when read in the file.</p>

<p><a href="https://raw.github.com/TonnyXu/BillboardProblem-FacebookHackerCup2012/master/facebook-hackercup-billboard.input">Download my test cases</a></p>

<p>Meanwhile, Facebook has an <a href="https://raw.github.com/TonnyXu/BillboardProblem-FacebookHackerCup2012/master/billboards.txt">input file</a>, you can also download it.</p>

<h2>Output</h2>

<p>Here is my output, what&#8217;s yours? Whose one is correct?</p>

<pre><code>Case #1: 30 //&lt;- Wrong, should be 60
Case #2: 5
Case #3: 31
Case #4: 6
Case #5: 30
Case #6: 83
Case #7: 8      //&lt;- Wrong, should be 9
Case #8: 80
Case #9: 21
Case #10: 4
Case #11: 31
Case #12: 21
Case #13: 30
Case #14: 21
Case #15: 30
Case #16: 21
Case #17: 4
Case #18: 21
Case #19: 4
Case #20: 4
</code></pre>

<hr />

<p>After modified step2, I think the following result is correct:</p>

<pre><code>Case #1: 60 
Case #2: 5 
Case #3: 31 
Case #4: 6 
Case #5: 30 
Case #6: 83 
Case #7: 9 
Case #8: 80 
Case #9: 21 
Case #10: 4 
Case #11: 31 
Case #12: 21 
Case #13: 30 
Case #14: 21 
Case #15: 30 
Case #16: 21 
Case #17: 4 
Case #18: 21 
Case #19: 4 
Case #20: 4 
</code></pre>

<p>It&#8217;s fun, <strong>I&#8217;m no longer qualified for next round now, good luck, my friends.</strong> <em>(hope I can enter the qualification round. And so do you.)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2012/01/24/billboard-problem-resolved-facebook-hacker-cup-2012/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Transparent view vs. hidden view in iOS</title>
		<link>http://www.totodotnet.net/2012/01/22/transparent-view-vs-hidden-view-in-ios/</link>
		<comments>http://www.totodotnet.net/2012/01/22/transparent-view-vs-hidden-view-in-ios/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 13:54:08 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[iPhone Dev]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/?p=835</guid>
		<description><![CDATA[Rise the question Here comes the question, how to create a transparent view without any contents? Wow, the answer looks so easy to get! Almost every iOS developer has created one or even more &#8216;transparent view&#8217;s. Let&#8217;s take a look at those solutions. We have 2 solutions. Solutions #1 Create a view with alpha=0.f. take &#8230; <a href="http://www.totodotnet.net/2012/01/22/transparent-view-vs-hidden-view-in-ios/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Rise the question</h2>
<p>Here comes the question,</p>
<blockquote>
<p><strong>how to create a transparent view without any contents</strong>?</p>
</blockquote>
<p>Wow, the answer looks so easy to get! Almost every iOS developer has created one or even more &#8216;transparent view&#8217;s. Let&#8217;s take a look at those solutions. We have 2 solutions.</p>
<h3>Solutions #1</h3>
<p>Create a view with <code>alpha=0.f</code>. take a look at the code below</p>
<pre><code>UIView *transparentView1 = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 460.f)];
transparentView1.alpha = 0.f;
[self.view addSubview:transparentView1];
[transparentView1 release];
</code></pre>
<p>It&#8217;s simple and straight forward. Hum? Let&#8217;s take a look at another solution.</p>
<h3>Solution #2</h3>
<p>Create a view with <code>backgroundColor=[UIColor clearColor]</code>.</p>
<pre><code>UIView *transparentView2 = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 460.f)];
transparentView2.backgroundColor = [UIColor clearColor];
[self.view addSubview:transparentView2];
[transparentView2 release];
</code></pre>
<p>This is also very simple.</p>
<p>So, what&#8217;s the difference between these 2 solutions?</p>
<h2>The difference on surface</h2>
<p>Before we talking about the difference, we need to review some basic yet <strong>key</strong> properties provided by iOS</p>
<ol>
<li><strong>hidden</strong>: set this property to <code>YES</code> will cause the view invisible. default is <code>NO</code>;</li>
<li><strong>alpha</strong>: this property affect all the contents of the view, including drawing and subviews. <strong>animatable</strong>;</li>
<li><strong>backgroundColor</strong>: this only affect the background color, not affect the drawing and subviews of the view. <strong>animatable</strong>;</li>
<li><strong>opaque</strong>: set this property to <code>YES</code>, will gain some performance boost on UI rendering. But need to full fill the rectangle of the view. <em>If <code>opaque</code> is set to <code>YES</code> and the view has full or partial transparent content, the behavior is not define</em>.</li>
</ol>
<blockquote>
<p>Visit apple&#8217;s <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html">document for UIView</a> for detail information.</p>
</blockquote>
<p>With these basic knowledge, we can easily tell the difference between these 2 solutions.</p>
<ul>
<li>Solution #1 uses <code>alpha</code> property to make the view transparent, in another word, it&#8217;s invisible because the view is <strong>hidden</strong>.</li>
<li>Solution #2 sets <code>backgroundColor</code> to transparent color to make it invisible.</li>
<li>Solution #2 only set the background to transparent, if you draw anything on the view, or add some subviews to the view, they are still visible, and solution #1 will make everything in the view invisible, including the custom drawings and all the subviews.</li>
<li>If the view is a clean view without any custom drawings and  subviews, the result of these 2 solutions look the same.</li>
</ul>
<p>They look the same? But actually not the same? Yes, they just look the same, but not exactly the same, so what&#8217;s the real difference?</p>
<h2>Look the same, but…</h2>
<p>There is always a <strong>BUT</strong>.</p>
<p>These 2 solutions look the same, <strong>but</strong> act differently on receiving <strong>touch event</strong>.</p>
<ul>
<li>Solution #1: <code>alpha=0.f;</code>, according to Apple&#8217;s document:<br />
> To hide a view visually, you can either set its hidden property to YES or change its alpha property to 0.0. A hidden view does not receive touch events from the system. However, hidden views do participate in autoresizing and other layout operations associated with the view hierarchy. Thus, hiding a view is often a convenient alternative to removing views from your view hierarchy, especially if you plan to show the views again at some point soon.<br />
><br />
> See <a href="http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW47">Apple&#8217;s document</a></li>
<li>Solution #2: when background color is set to clear color, the alpha is still 1.0, so this view still can receive touch event.</li>
</ul>
<h2>Finally, we have the answer</h2>
<p>Before we get the correct answer, we need to use the correct terminologies to clarify the answer:</p>
<ul>
<li><strong>Hidden View</strong>: when <code>hidden=YES</code> or <code>alpha=0.f</code></li>
<li><strong>Transparent background View</strong>: when <code>backgroundColor</code> is set to clear color</li>
</ul>
<h3>The answer</h3>
<ul>
<li>a <strong>hidden view</strong> will not accept touch event, while a <strong>transparent background view</strong> will.</li>
<li>a <strong>hidden view</strong> may look like a <strong>transparent background view</strong> if add no subviews and draw nothing on the view.</li>
</ul>
<p>With this answer, I think we can use <strong>hidden view</strong> and <strong>transparent background view</strong> correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2012/01/22/transparent-view-vs-hidden-view-in-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to sync WordPress blog entries to Blogger.com and Tumblr and Posterous</title>
		<link>http://www.totodotnet.net/2012/01/13/how-to-sync-wordpress-blog-entries-to-blogger-com-and-tumblr-and-posterous/</link>
		<comments>http://www.totodotnet.net/2012/01/13/how-to-sync-wordpress-blog-entries-to-blogger-com-and-tumblr-and-posterous/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 08:20:17 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[Blog System]]></category>
		<category><![CDATA[My Blog]]></category>
		<category><![CDATA[Test Post]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/?p=830</guid>
		<description><![CDATA[Do you have multiple blog sites? If your answer is no, then, this blog entry is useless to you. Close this page please. If you DO have multiple blog sites, and you don&#8217;t care about synchronizing one blog site to others, then this blog entry is also useless to you. Close this page please. If &#8230; <a href="http://www.totodotnet.net/2012/01/13/how-to-sync-wordpress-blog-entries-to-blogger-com-and-tumblr-and-posterous/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Do you have multiple blog sites?</h2>
<p>If your answer is <strong>no</strong>, then, this blog entry is useless to you. Close this page please.</p>
<p>If you <strong>DO</strong> have multiple blog sites, and you don&#8217;t care about synchronizing one blog site to others, then this blog entry is also useless to you. Close this page please.</p>
<p>If you <strong>DO</strong> have multiple blog sites as me, and you <strong>DO</strong> want to synchronize your one blog site to others. You are viewing the right post.</p>
<h2>Why multiple blog site?</h2>
<p>It&#8217;s complicated. I&#8217;m owning my own domain <a href="http://www.totodotnet.net">totodotnet.net</a>, and is running WordPress on it. Then I also have an account in <a href="http://blog.totodotnet.net">Blogger.com</a>, it&#8217;s good, with elegant design and dashboard. I also happened to have an account in <a href="http://dev.totodotnet.net">Tumblr.com</a> all because it support markdown by default.</p>
<p>So, I like all of these 3 sites, and I don&#8217;t want to abandon any one of them. I decided to do a synchronization with all of these sites.</p>
<p>But, How?</p>
<h2>Have you ever heard about &#8220;<a href="http://ifttt.com">ifttt.com</a>&#8220;?</h2>
<p>This site is great! It saved me a lot of works. Synchronizing between each site is also done with <a href="http://ifttt.com">ifttt.com</a>&#8216;s help.</p>
<p>Here is how:</p>
<ol>
<li>
<p>You need to have a <strong>main site</strong>.<br />
This means, you need to post your <strong>original</strong> posts to this site. Since all blog systems provide RSS output, we will use RSS to synchronize entries to other sites.</p>
</li>
<li>
<p>Add a new rule in ifttt.com<br />
You usually, it can be read as &#8220;Sync any new items in RSS[<code>your main site's RSS</code>] to tumblr/posterous/Mail(etc.)&#8221;. It&#8217;s very straight forward, and easy to use. Just create a few such kind of rules to let it do the synchronizing works.</p>
</li>
<li>
<p>Blogger.com is not directly supported by ifttt.com</p>
</li>
</ol>
<p>My solution is enable the &#8220;Posting using email&#8221; option in blogger.com, then setup a rule to send an email to your posting email address on each new blog entry.</p>
<h2>Ifttt.com can do much more things</h2>
<p>[Ifttt.com] is such an awesome site, it integrated almost all the major web services in the world. You can send a tweet or a facebook post when your new blog entry is posted.</p>
<p>The concept can be separated as <strong>read in stream</strong> and <strong>output stream</strong>:</p>
<ul>
<li>
<p><strong>read in stream</strong>:<br />
<img src="http://www.totodotnet.net/wp-content/uploads/2012/01/Screen-shot-2012-01-13-at-17.02.50-807x880.png" alt="services available for read in stream" /></p>
</li>
<li>
<p><strong>output stream</strong>:<br />
<img src="http://www.totodotnet.net/wp-content/uploads/2012/01/Screen-shot-2012-01-13-at-17.08.14-880x816.png" alt="services available for output stream" /></p>
</li>
</ul>
<p><strong>Now, just enjoy the internet!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2012/01/13/how-to-sync-wordpress-blog-entries-to-blogger-com-and-tumblr-and-posterous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to set markdown as your default editor language for your WP based blog</title>
		<link>http://www.totodotnet.net/2012/01/08/how-to-set-markdown-as-your-default-editor-language-for-your-wp-based-blog/</link>
		<comments>http://www.totodotnet.net/2012/01/08/how-to-set-markdown-as-your-default-editor-language-for-your-wp-based-blog/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 15:33:02 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[Blog System]]></category>
		<category><![CDATA[My Blog]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/?p=814</guid>
		<description><![CDATA[Markdown is such a great Markup language Without saying any words, if you&#8217;re familiar with Markdown language, and when you get used to it, you will not be able to leave it. How to use markdown with WordPress I&#8217;m using a plugin called &#8220;Markdown on save&#8221; which was written by Mark Jaquith. The biggest right &#8230; <a href="http://www.totodotnet.net/2012/01/08/how-to-set-markdown-as-your-default-editor-language-for-your-wp-based-blog/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Markdown is such a great Markup language</h2>
<p>Without saying any words, if you&#8217;re familiar with Markdown language, and when you get used to it, you will not be able to leave it.</p>
<h2>How to use markdown with WordPress</h2>
<p>I&#8217;m using a plugin called &#8220;Markdown on save&#8221; which was written by <a href="http://coveredwebservices.com/">Mark Jaquith</a>. The biggest right thing this plugin had done is saving the raw markdown text in <code>post_content_formatted</code> column, and the converted HTML content will be stored in <code>post_content</code>. This idea brings 2 big advantages.</p>
<ol>
<li>No need to do the <code>Markdown -&gt; HTML</code> conversion on the fly.</li>
<li>Even the plugin is deactivated, you won&#8217;t loose your post, because the post will be rendered with <code>post_content</code>.</li>
</ol>
<h2>Simple and straightforward</h2>
<p>All you need to do, is</p>
<ol>
<li>search the plugin(markdown as save), and install it, activate it.</li>
<li>check the Markdown check on the up-right corner.</li>
<li>Write your post and preview it if it is necessary.</li>
<li>Post it</li>
</ol>
<p><strong>BOOM!</strong> You are done!</p>
<h2>Some simple test</h2>
<h1>H1 headline</h1>
<h2>H2 headline</h2>
<p>Following by a</p>
<h3>H3 headline</h3>
<p>without an empty line following an H4 headline</p>
<h4>H4 headline</h4>
<p>follow by an H5</p>
<h5>H5 headline</h5>
<p>follow by an H6</p>
<h6>H6 headline.</h6>
<p><strong>Bold</strong>, <em>italic</em>, <a href="http://www.google.com">link to google</a>,</p>
<blockquote>
<p>b-quote,</p>
<ul>
<li>quote with list1</li>
<li>quote with list2</li>
<li>quote with list3</li>
</ul>
<ol>
<li>quote with list</li>
<li>quote with list</li>
<li>quote with list</li>
</ol>
</blockquote>
<p><em>strike-out</em></p>
<p><img src="http://images01.olx.com.ph/ui/1/96/87/10048987_1.jpg" alt="image" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2012/01/08/how-to-set-markdown-as-your-default-editor-language-for-your-wp-based-blog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blogging from Flock</title>
		<link>http://www.totodotnet.net/2010/03/28/blogging-from-flock-2/</link>
		<comments>http://www.totodotnet.net/2010/03/28/blogging-from-flock-2/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 09:43:45 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[My Blog]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[writer]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/2010/03/28/blogging-from-flock-2/</guid>
		<description><![CDATA[How does this feel? -&#62; Not so bad. What if I need a picture? -&#62; It&#8217;s too weak! I need the basic picture manipulation functions. Like position and size. Category? -&#62; Damn it! Flock blogging does not support category! Unbelievable! -&#62; Oh, sorry, it does support category but not so obviously.]]></description>
			<content:encoded><![CDATA[<p>How does this feel?<br />
-&gt; Not so bad.</p>
<p>What if I need a picture?<br />
-&gt; It&#8217;s too weak! I need the basic picture manipulation functions. Like position and size.</p>
<p>Category?<br />
-&gt; Damn it! Flock blogging does not support category! Unbelievable!<br />
-&gt; Oh, sorry, it does support category but not so obviously.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2010/03/28/blogging-from-flock-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging from Flock</title>
		<link>http://www.totodotnet.net/2010/03/28/blogging-from-flock/</link>
		<comments>http://www.totodotnet.net/2010/03/28/blogging-from-flock/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 09:42:22 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[My Blog]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[writer]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/2010/03/28/blogging-from-flock/</guid>
		<description><![CDATA[How does this feel? -&#62; Not so bad. What if I need a picture? -&#62; It&#8217;s too weak! I need the basic picture manipulation functions. Like position and size. Category? -&#62; Damn it! Flock blogging does not support category! Unbelievable!]]></description>
			<content:encoded><![CDATA[<p>How does this feel?<br />
-&gt; Not so bad.</p>
<p>What if I need a picture?<br />
-&gt; It&#8217;s too weak! I need the basic picture manipulation functions. Like position and size.</p>
<p>Category?<br />
-&gt; Damn it! Flock blogging does not support category! Unbelievable!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2010/03/28/blogging-from-flock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 great videos you must see</title>
		<link>http://www.totodotnet.net/2010/03/02/3-great-videos-you-must-see/</link>
		<comments>http://www.totodotnet.net/2010/03/02/3-great-videos-you-must-see/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 13:38:44 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[My Blog]]></category>
		<category><![CDATA[Something really cool!]]></category>
		<category><![CDATA[cool!]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/2010/03/02/3-great-videos-you-must-see/</guid>
		<description><![CDATA[&#160; The Carbon Economy (View high quality video on YouTube) It’s time for real Hellmann’s &#8211; It’s Time for Real from CRUSH on Vimeo. The State of The Internet JESS3 / The State of The Internet from Jesse Thomas on Vimeo.]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h3>The Carbon Economy</h3>
<p>(View high quality video on <a href="http://www.youtube.com/watch?v=cju6Zi4OT54" target="_blank">YouTube</a>)</p>
<div style="padding-bottom: 0px; padding-left: 0px; width: 425px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:9e2290f4-f51e-41e8-86bf-3ea0ebb32817" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/cju6Zi4OT54&amp;hl=en"></param><embed src="http://www.youtube.com/v/cju6Zi4OT54&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
</div>
<h3>It’s time for real</h3>
<p> <object width="600" height="345"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5477517&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5477517&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="600" height="345"></embed></object>
<p><a href="http://vimeo.com/5477517">Hellmann’s &#8211; It’s Time for Real</a> from <a href="http://vimeo.com/user1879635">CRUSH</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</p>
<h3>The State of The Internet</h3>
<p> <object width="600" height="450"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9641036&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9641036&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="600" height="450"></embed></object>
<p><a href="http://vimeo.com/9641036">JESS3 / The State of The Internet</a> from <a href="http://vimeo.com/jessesaves">Jesse Thomas</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2010/03/02/3-great-videos-you-must-see/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gist</title>
		<link>http://www.totodotnet.net/2010/03/01/gist/</link>
		<comments>http://www.totodotnet.net/2010/03/01/gist/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 09:00:10 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[Something really cool!]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Share]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/2010/03/01/gist/</guid>
		<description><![CDATA[Higly recommend every developer to use Gist to share the snippets. It’s really great!]]></description>
			<content:encoded><![CDATA[<p>Higly recommend every developer to use <a href="http://gist.github.com/" target="_blank">Gist</a> to share the snippets.</p>
<p>It’s really great!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2010/03/01/gist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OK, Singleton in Java.</title>
		<link>http://www.totodotnet.net/2010/03/01/ok-singleton-in-java/</link>
		<comments>http://www.totodotnet.net/2010/03/01/ok-singleton-in-java/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 08:52:11 +0000</pubDate>
		<dc:creator>tonny.xu</dc:creator>
				<category><![CDATA[My Blog]]></category>
		<category><![CDATA[Something really cool!]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Singleton]]></category>

		<guid isPermaLink="false">http://www.totodotnet.net/2010/03/01/ok-singleton-in-java/</guid>
		<description><![CDATA[Fine, this topic has been talked many many times, and you can find a lot of great answers over the internet. Stackoverflow.com listed a lot of answers. And also, you can find great approach from Joshua Bloch’s Effective Java also pointed out 2 effective approaches. What’s more, Joshua Bloch also provided an enum approach(Page 31) &#8230; <a href="http://www.totodotnet.net/2010/03/01/ok-singleton-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Fine, this topic has been talked many many times, and you can find a lot of great answers over the internet. Stackoverflow.com listed <a href="http://stackoverflow.com/questions/70689/efficient-way-to-implement-singleton-pattern-in-java" target="_blank">a lot of answers</a>. And also, you can find great approach from <a href="http://en.wikipedia.org/wiki/Joshua_Bloch" target="_blank">Joshua Bloch</a>’s <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;ved=0CAYQFjAA&amp;url=http%3A%2F%2Fjava.sun.com%2Fdocs%2Fbooks%2Feffective%2F&amp;ei=JmqLS-bPG5eXkQWsqYQK&amp;usg=AFQjCNEq_ml9kE3mo3humdTXrkfuyjnYpg&amp;sig2=bzeg5kPQp9CkH8yUhWjtHg" target="_blank">Effective Java</a> also pointed out 2 effective approaches. What’s more, Joshua Bloch also <a href="http://developers.sun.com/learning/javaoneonline/2008/pdf/TS-6623.pdf" target="_blank">provided</a> an enum approach(Page 31) as the best practice for Serializable Singleton. If you like Wikipedia, you can also find a Java solution for <a href="http://en.wikipedia.org/wiki/Singleton_pattern#The_solution_of_Bill_Pugh" target="_blank">Singleton</a>, and for deep background knowledge behind this approach, please read “<a href="http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html" target="_blank">Double check locking</a>” and “<a href="http://www.cs.umd.edu/~pugh/java/memoryModel/" target="_blank">Java 5 memory management</a>” by <a href="http://www.cs.umd.edu/%7Epugh">Bill Pugh</a>.</p>
<p>If you are as lazy as me, just remember the following implementation, which is thread safe and can be used on all the java version. The key point in this implementation is using Java atomic class load mechanism to guarantee the thread safe and using static method to implement lazy initialization.</p>
<p> <script src="http://gist.github.com/318182.js"></script>
<p>If you also have some curious on the other implementations, please keep reading.</p>
<ol>
<li>The simplest implementation(Immutable class, thread safe, but no lazy initialization)      <br /><script src="http://gist.github.com/318153.js"></script></li>
<li>The double check locking implementation(Thread safe, lazy initialization, but requires Java 5+)      <br /><script src="http://gist.github.com/318209.js"></script></li>
<li>The enum implementation(Thread safe, Serializable, also requires Java 5+)      <br /><script src="http://gist.github.com/318214.js"></script></li>
</ol>
<p>After reading all of these, I don’t think you need any other implementations, but to understand why and how these implementations work, you need read something more[Typically those links I provided at the beginning]. There are things called Google and Bing on the earth, I guess you can find the answer very soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totodotnet.net/2010/03/01/ok-singleton-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

