<?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>blog « yichuan shen</title>
	<atom:link href="http://yichuanshen.de/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://yichuanshen.de/blog</link>
	<description>Developer blog</description>
	<lastBuildDate>Fri, 04 May 2012 16:45:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>A matches game puzzle</title>
		<link>http://yichuanshen.de/blog/2012/05/04/a-matches-game-puzzle/</link>
		<comments>http://yichuanshen.de/blog/2012/05/04/a-matches-game-puzzle/#comments</comments>
		<pubDate>Fri, 04 May 2012 16:42:03 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[puzzle]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=108</guid>
		<description><![CDATA[Photo: aftermat(c)h by ankaatje &#8211; CC This nifty little puzzle comes from an excercise sheet of our algorithms and data structures course at the university. Our task was to find a winning formula for a game and prove it. Imagine 100 matches laying on the table. Alice and Bob take at most 10 matches from [...]]]></description>
			<content:encoded><![CDATA[<div class="right">

<p><img src="http://ryanblack.lima-city.de/yaiu/p/223665693-1181457897.jpg" alt="Matches everywhere" /></p>

<p>Photo: <a href="http://www.flickr.com/photos/32212805@N00/251383627/">aftermat(c)h</a> by <a href="http://www.flickr.com/photos/32212805@N00/">ankaatje</a> &#8211; <a href="http://creativecommons.org/licenses/by-nc/2.0/" title="Licensed under a Creative Commons license">CC</a></p>

</div>

<p>This nifty little puzzle comes from an excercise sheet of our algorithms and data structures course at the university. Our task was to find a winning formula for a game and prove it.</p>

<p>Imagine 100 matches laying on the table. Alice and Bob take at most 10 matches from the table in turn. They can choose how many matches they want to take, but they have to take <em>at least</em> one match. Whoever gets the last match, wins the game. Suppose Alice starts, how should she play to win the game every time?</p>

<p>You should really try to solve this puzzle on your own before reading my explanation after the jump.</p>

<p><span id="more-108"></span></p>

<h2>The explanation</h2>

<p>Instead of reasoning from the very beginning, you should rather ask yourself how Alice can win in the end. Suppose there&#8217;s only one match left from the game and it&#8217;s Bob&#8217;s turn. He can snatch the last match and therefore wins the game, which is not what we want. The same is also true if there&#8217;s two to ten matches left.</p>

<p>The interesting part comes when there&#8217;s 11 matches left for Bob. Bob can&#8217;t snatch up the last match, because he can only remove ten matches at most. Then Alice can take all of the remaining matches, including the last one, which makes her the winner, because Bob has to remove at least one match, leaving at most ten matches behind.</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/821868266-1567709606.png" alt="Eleven matches left" /></p>

<p>If Alice can leave 11 matches to Bob, she&#8217;ll win. Now we can reduce the problem to the following: How can she ensure that Bob gets the last 11 matches?</p>

<h2>Inception</h2>

<div class="left">

<p><img src="http://ryanblack.lima-city.de/yaiu/p/384938061-571655712.jpg" alt="Spinning top" /></p>

<p>Photo: <a href="http://www.flickr.com/photos/schjelderup/6141436742/">Inception</a> by <a href="http://www.flickr.com/photos/schjelderup/">Schjelderup</a> &#8211; <a href="http://creativecommons.org/licenses/by/2.0/" title="Licensed under a Creative Commons license">CC</a></p>

</div>

<p>Now, mathematicians are lazy people. Really! If they&#8217;ve already proven something, they would want to reduce other more complex problems to the already proven ones. Believe it or not, we&#8217;ve already shown the core of this puzzle.</p>

<p>Now back to our problem at hand. How does Alice ensure that Bob gets the last 11 matches? It&#8217;s very simple: She has to take the 12th match from last. How is that simple? Because we&#8217;ve already solved that problem.</p>

<p>Let&#8217;s imagine our 100 matches laying on our table. If we put 11 matches aside<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, we get 89 matches. How to get the last one of those 89 matches? Well, that&#8217;s solved: Alice has to leave 11 matches (of those 89) for Bob behind. If we put the 11 matches back on the table, we can see that Alice can snatch up the 12th match from last (and therefore win), if she can leave 22 matches for Bob.</p>

<p>This implies that she has to take the 23rd match from last. She does that by leaving 33 matches for Bob, etc&#8230;</p>

<p>If we do that over and over again, this becomes: Alice can win, if she can leave <img src="http://www.numberempire.com/equation.render?11k,\%20k\in\mathbb{N}" alt="11k (where k is a natural number)" /> matches for Bob behind at the beginning. Since Alice starts the game, she just have to take one match, leaving <img src="http://www.numberempire.com/equation.render?100-1=99=11\cdot%209" alt="100 - 1 = 99 = 11*9" /> for Bob behind. And if she plays according to our strategy, she can also win.</p>

<h2>More excercises</h2>

<ol>
<li>Suppose there are <img src="http://www.numberempire.com/equation.render?n\in\mathbb{N}" alt="n (a natural number)" /> matches on the table at the beginning and the players can remove at most <img src="http://www.numberempire.com/equation.render?m\in\mathbb{N}" alt="m (a natural number)" /> matches. Can Alice still win?</li>
<li>Consider the &#8220;inverted&#8221; game: Whoever gets the last match, loses. How can Alice win?</li>
</ol>

<p>Just remember to reduce the problems to the ones we&#8217;ve already solved&#8230; Happy thinking!</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>We don&#8217;t actually put 11 matches aside. We do that in our <em>minds</em>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2012/05/04/a-matches-game-puzzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Google weather API</title>
		<link>http://yichuanshen.de/blog/2012/02/09/the-google-weather-api/</link>
		<comments>http://yichuanshen.de/blog/2012/02/09/the-google-weather-api/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 09:06:37 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[secret]]></category>
		<category><![CDATA[weather]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=105</guid>
		<description><![CDATA[If you happen to want a quick way for looking up the weather in your own applications, you can use the hidden Google weather API. To access it, just fetch the response for http://www.google.com/ig/api?weather=[your city]. You can replace [your city] with anything you want&#8230; a ZIP code or the name of the city you want [...]]]></description>
			<content:encoded><![CDATA[<p>If you happen to want a quick way for looking up the weather in your own applications, you can use the hidden Google weather API. To access it, just fetch the response for <code>http://www.google.com/ig/api?weather=[your city]</code>. You can replace <code>[your city]</code> with anything you want&#8230; a ZIP code or the name of the city you want to look up. This API provides the current weather and a three-day forecast in a handy XML format.</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/534974918-1451413789.png" alt="" /></p>

<p>The usage is quite straight forward&#8230; just try it out. Originally it&#8217;s apparently used for iGoogle&#8217;s weather widget, so it&#8217;s not very detailed. However it&#8217;s still very handy for a quick look at the weather.</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2012/02/09/the-google-weather-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monte Carlo Pi</title>
		<link>http://yichuanshen.de/blog/2012/01/06/monte-carlo-pi/</link>
		<comments>http://yichuanshen.de/blog/2012/01/06/monte-carlo-pi/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 14:12:01 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[calculate]]></category>
		<category><![CDATA[gcd]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[monte carlo]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[pi]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[theory]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=104</guid>
		<description><![CDATA[Today we&#8217;re gonna calculate pi. You might say, it doesn&#8217;t seem too interesting; it&#8217;s an old hat. You may be true, but we&#8217;re going to calculate pi using a method, other than approximating a circle with a polygon. So here&#8217;s what we do: We draw the unit circle on our cartesian coordinate system. We randomly [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ryanblack.lima-city.de/yaiu/p/696405501-1285938886.gif" alt="Unit circle" class="right"></p>

<p>Today we&#8217;re gonna calculate pi. You might say, it doesn&#8217;t seem too interesting; it&#8217;s an old hat. You may be true, but we&#8217;re going to calculate pi using a method, other than approximating a circle with a polygon. So here&#8217;s what we do:</p>

<ol>
<li>We draw the unit circle on our cartesian coordinate system.</li>
<li>We randomly drop points on the square, which contains our unit circle.</li>
<li>The probability of the point dropping on the <em>circle</em> is <img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=\frac{\pi}{4}" alt="Pi/4" /></li>
</ol>

<p><span id="more-104"></span></p>

<h2>Explanation</h2>

<p>Why? The explanation is easy. The area of the unit circle is <img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=\pi" alt="pi" /> and the area of the square is <img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=2^2" alt="2^2" />. As the points are randomly chosen, the probability of a point dropping on the circle is</p>

<p><img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=p=\frac{\text{area+of+the+circle}}{\text{area+of+the+square}}=\frac{\pi}{4}" alt="p = area of the circle/area of the square = pi/4" /></p>

<p>This gives us an interesting computational method for &#8220;calculating&#8221; pi using random numbers&#8230; Such algorithms are called <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo methods</a>, by the way. A highly inefficient way perhaps, but nevertheless interesting. I don&#8217;t want to implement this example, in fact I wanted to blog about another Monte Carlo method for calculating pi originally, which is easy on the outside, but more difficult to grasp in its entirety.</p>

<h2>Another Monte Carlo</h2>

<ol>
<li>Randomly pick two positive natural numbers.</li>
<li><p>The probability of these two numbers being coprime is</p>

<p><img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=p=\frac{6}{\pi^2}\approx+60.79%" alt="p = 6/pi^2 = 60.79%" /></p></li>
</ol>

<p>This gives us a formula for pi:</p>

<p><img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=\pi=\sqrt{\frac{6}{p}}" alt="pi = sqrt(6/p)" /></p>

<p>Wait, you don&#8217;t believe me? With a quick demonstration, you could easily verify it&#8217;s true. Here&#8217;s a quick implementation in C#:</p>

<pre><code>static Random r = new Random();

static int getGcd(int a, int b) {
    // Euclid's algorithm
    return b == 0 ? a : getGcd(b, a % b);
}

static bool doExperiment() {
    // Pick two random numbers
    int a = r.Next();
    int b = r.Next();

    // Calculate greatest common divisor
    int gcd = getGcd(a, b);

    // two numbers are coprime iff their greatest common divisor is 1
    return gcd == 1;
}

static void Main(string[] args) {
    while (true) {
        Console.Write("Count: ");

        int count = int.Parse(Console.ReadLine());
        int successes = 0;

        if (count == 0) break; // End application

        for (int i = 0; i &lt; count; i++) {
            if (doExperiment()) successes++;
        }

        // Calculate probability
        double p = (double)successes / count;

        // Calculate pi
        Console.WriteLine("Probability: {0}%", p * 100);
        Console.WriteLine("Calculated pi: {0}", Math.Sqrt(6 / p));
        Console.WriteLine();
    }
}
</code></pre>

<p>You can also <a href="http://dl.dropbox.com/u/138451/Downloads/Blog/MonteCarloPi.cs?dl=1">download the source code</a>.</p>

<h2>Test run</h2>

<pre><code>Count: 100
Probability: 59%
Calculated pi: 3.1889640207164

Count: 1000
Probability: 59.8%
Calculated pi: 3.16756133579975

Count: 10000
Probability: 60.91%
Calculated pi: 3.1385664314759

Count: 100000
Probability: 60.819%
Calculated pi: 3.14091358277565

Count: 1000000
Probability: 60.8672%
Calculated pi: 3.13966971072351

Count: 10000000
Probability: 60.78924%
Calculated pi: 3.14168232203594

Count: 100000000
Probability: 60.796216%
Calculated pi: 3.14150207229303

Count: 1000000000
Probability: 60.7912067%
Calculated pi: 3.14163150221403
</code></pre>

<p>As you can see, the approximation of pi is very bad and highly inefficient. The last iteration took me more than a minute to calculate, but it shows an interesting result.</p>

<p>Also the probability is not an approximation of <img src="http://chart.apis.google.com/chart?cht=tx&amp;chl={6}/{\pi^2}" alt="6/pi^2" />, it is indeed <em>exactly</em> <img src="http://chart.apis.google.com/chart?cht=tx&amp;chl={6}/{\pi^2}" alt="6/pi^2" />. Is that logical? Yes, it&#8217;s been proven<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>. Is that intuitive? Hell fucking no!</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>For the mathematically challenged: Here&#8217;s a <a href="http://en.wikipedia.org/wiki/Coprime#Probabilities">proof sketch on Wikipedia</a>, but beware! Infinite products and the Riemann zeta function awaits you.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2012/01/06/monte-carlo-pi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Happy new year!</title>
		<link>http://yichuanshen.de/blog/2012/01/02/happy-new-year/</link>
		<comments>http://yichuanshen.de/blog/2012/01/02/happy-new-year/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 16:41:33 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=102</guid>
		<description><![CDATA[So, I&#8217;ve been quite lazy again&#8230; My bad, but I&#8217;ve also been really busy with my studies at the university. I&#8217;ll put &#8220;write more blog posts&#8221; in my new year resolutions&#8230; You know what? To make it up to you, I&#8217;ll write two interesting math-related blog articles in the next two weeks, so look forward [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve been quite lazy <em>again</em>&#8230; My bad, but I&#8217;ve also been really busy with my studies at the university. I&#8217;ll put &#8220;write more blog posts&#8221; in my new year resolutions&#8230; You know what? To make it up to you, I&#8217;ll write two interesting math-related blog articles in the next two weeks, so look forward to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2012/01/02/happy-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Homework 3 gets colored</title>
		<link>http://yichuanshen.de/blog/2011/09/18/homework-3-gets-colored/</link>
		<comments>http://yichuanshen.de/blog/2011/09/18/homework-3-gets-colored/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 11:18:12 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Homework]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[gtd]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[metro]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[task]]></category>
		<category><![CDATA[todo]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=98</guid>
		<description><![CDATA[Hi there, how&#8217;s it going? It has been a while&#8230; again&#8230; I know. Even though it was summer vacation, I&#8217;ve been very busy. Applying for universities, searching for a place to live, get used to new cities&#8230; with success. I&#8217;ll be a mathematics student of Heidelberg University starting this semester. Remember Homework 3? Yeah, I [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ryanblack.lima-city.de/yaiu/p/769849105-1316251519.png" alt="Homework 3 color coding" class="left" /></p>

<p>Hi there, how&#8217;s it going? It has been a while&#8230; again&#8230; I know. Even though it was summer vacation, I&#8217;ve been very busy. Applying for universities, searching for a place to live, get used to new cities&#8230; with success. I&#8217;ll be a mathematics student of <a href="http://uni-heidelberg.de/">Heidelberg University</a> starting this semester.</p>

<p>Remember Homework 3? Yeah, I know some of you believed this project was dead&#8230; (The <a href="http://yichuanshen.de/blog/2010/12/06/animating-in-c-sharp-without-wpf/">last blog post update</a> was ages ago.) However, I&#8217;m happy to inform you that it is not.</p>

<p>I&#8217;ve added a major feature and made some minor changes to the settings panel and the edit panel.</p>

<p>See for yourself&#8230; <span id="more-98"></span></p>

<h2>Colored, more joyful &amp; productivity</h2>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/84e64f2b-6c3c-40f6-9844-6ea43fdab3c4.png" alt="Homework 3: Tasks" />
<em>Yeah, my clarinet playing skills has to be improved&#8230;</em></p>

<p>First of all, I thought about adding colors to tasks&#8230; For compensating the lack of categories. Color is a nice way to group tasks together. It gives us visual representation of what belongs together and is absolutely beautiful to look at. The color has to be shown unobtrusively and the assignment should be quick and easy.</p>

<p>There are nine colors in total&#8230; one for each digit on the keyboard. Select a task and press <code>Ctrl</code>+<code>[digit]</code> to assign the corresponding color to the task. Naturally, you can change the color in the edit task panel as shown below.</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/6bc72462-97da-45a6-9b1f-f7d409239117.png" alt="Homework 3: Edit task" /></p>

<p>I&#8217;ve also added the ability to change the names of colors in the settings panel. For example, I&#8217;ve changed &#8220;Purple&#8221; (<code>Ctrl</code>+<code>2</code>) into &#8220;Blog&#8221;, so that all tasks with purple color represent tasks I need to do for my blog.</p>

<p>All colors are official Windows Phone 7 accent colors, with the lack of red, which still denotes an &#8220;important&#8221; task and shown on the right of a task.</p>

<h2>Metro, modern &amp; clean</h2>

<p>As you can see (or not) I&#8217;ve redesigned the edit task and settings panel. Now simpler and more elegant. With the recent release of Windows 8 Developer Preview, I was able to experience the official Metro myself.</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/9d13bb48-733e-42a8-90a9-558d4c81a447.png" alt="Homework 3: Settings panel" /></p>

<h2>Release?</h2>

<p>I&#8217;m still not sure when to release Homework 3 to the public. I wanted to complete this piece of software before this semester started, so that everyone can plan their homework efficiently in this year, but I fear it&#8217;s not possible now.</p>

<p>I&#8217;m determined to complete the synchronization feature first. And maybe develop a Windows Phone 7.5 App&#8230; But that&#8217;s just speculation. I&#8217;m not sure how to make the synchronization work yet, but I&#8217;ll sure find a way.</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2011/09/18/homework-3-gets-colored/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing FTPUploader</title>
		<link>http://yichuanshen.de/blog/2011/06/25/introducing-ftpuploader/</link>
		<comments>http://yichuanshen.de/blog/2011/06/25/introducing-ftpuploader/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 16:26:15 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Other Apps]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=95</guid>
		<description><![CDATA[Hello everybody&#8230; I know it&#8217;s been a long, long time. But, look at the bright side: exams are finally over, I can write more again, I got my Abitur&#8230; and a lot of free time. So I went through old projects to see if I can find anything interesting. And I found something very interesting [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ryanblack.lima-city.de/yaiu/p/34bb009e-0e3d-4174-8fe0-8b737ae8fc60.png" alt="FTPUploader tray icon" /></p>

<p>Hello everybody&#8230; I know it&#8217;s been a long, long time. But, look at the bright side: exams are finally over, I can write more again, I got my Abitur&#8230; and a lot of free time. So I went through old projects to see if I can find anything interesting. And I found something very interesting indeed and thought of sharing it with you guys.</p>

<p><span id="more-95"></span></p>

<h2>Hello FTPUploader</h2>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/1292652794-1589004575.png" alt="FTPUploader" /></p>

<p>So let me explain why <a href="/apps/ftpuploader">this little app</a> is genius. As you can see, you can specify a local directory and a remote directory lying on a FTP server. Once you&#8217;re done, click on &#8220;Save settings&#8221;. Your infos will be stored in a specific <code>.xml</code> file on your computer, so you don&#8217;t need to retype it again next time.</p>

<p><a href="/apps/ftpuploader">FTPUploader</a> creates a <code>FileSystemWatcher</code> to <em>monitor</em> your local directory and applies all local change to the FTP server with a click on the tray icon. If you change a file, it just uploads the new file to the FTP server. If you remove a file, it removes the corresponding file on the server. If you rename a file, it removes the old file on the server and uploads the renamed file.</p>

<p>Great for someone who doesn&#8217;t use an IDE or an editor with an integrated FTP client to code his web projects. Someone like me.</p>

<p>This app is still experimental, so please don&#8217;t blame me if something goes wrong&#8230; (not that something <em>will</em> go wrong, of course.) Only works with .NET Framework 4.0.</p>

<p><a href="http://dl.dropbox.com/u/138451/Downloads/Apps/ftpuploader_v0-1beta.zip">Download FTPUploader v0.1&beta;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2011/06/25/introducing-ftpuploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy Valentine&#8217;s Day</title>
		<link>http://yichuanshen.de/blog/2011/02/14/happy-valentines-day/</link>
		<comments>http://yichuanshen.de/blog/2011/02/14/happy-valentines-day/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 15:47:57 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=94</guid>
		<description><![CDATA[Just being my geeky self, I guess&#8230; Sorry for the lack of posts lately, but I have lots of work to do, as exams are drawing nearer and nearer! I&#8217;ll post more articles after my written Abitur exams, I promise.]]></description>
			<content:encoded><![CDATA[<p>Just being my geeky self, I guess&#8230;</p>

<p><img src="http://latex.codecogs.com/png.latex?x^2+(y-\sqrt[3]{x^2})^2%20=%201" alt="x^2+(y-\sqrt[3]{x^2})^2 = 1" /></p>

<p>Sorry for the lack of posts lately, but I have lots of work to do, as exams are drawing nearer and nearer! I&#8217;ll post more articles after my written Abitur exams, I promise.</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2011/02/14/happy-valentines-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On CSS pseudo elements</title>
		<link>http://yichuanshen.de/blog/2011/01/22/on-css-pseudo-elements/</link>
		<comments>http://yichuanshen.de/blog/2011/01/22/on-css-pseudo-elements/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 08:49:25 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[elements]]></category>
		<category><![CDATA[pseudo]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=93</guid>
		<description><![CDATA[With the end of Internet Explorer 6 drawing near and a new era of CSS3 coming, knowing how the so-called CSS pseudo elements work is crucial for creating modern, beautiful and semantic code. The concept of pseudo elements already existed in the CSS1 specification with the two pseudo elements :first-letter and :first-line. However, I want [...]]]></description>
			<content:encoded><![CDATA[<p>With the end of Internet Explorer 6 drawing near and a new era of CSS3 coming, knowing how the so-called CSS <em>pseudo elements</em> work is crucial for creating modern, beautiful and semantic code. The concept of pseudo elements already existed in the CSS1 specification with the two pseudo elements <code>:first-letter</code> and <code>:first-line</code>.</p>

<p>However, I want to concentrate on the other two pseudo elements which were introduced in CSS2. They were quite underused, mainly because Internet Explorer 6 just refused to understand them. With the upcoming death of IE6, they have regained popularity among web designers. I&#8217;m talking about <code>:before</code> and <code>:after</code>.</p>

<p><span id="more-93"></span></p>

<h2>Get started</h2>

<p>With <code>:before</code> and <code>:after</code> you can literally insert content before or after an element. Example: You want to insert text before an <code>a</code> element.</p>

<pre><code>&lt;!-- HTML code --&gt;
&lt;a href="#" class="mark"&gt;I'm a link&lt;/a&gt;
</code></pre>

<pre><code>/* CSS code */
.mark:before {
    content: "This is a link: ";
}
</code></pre>

<p>We might think that a browser is going to interpret the code like this:</p>

<pre><code>&lt;span class="before"&gt;This is a link: &lt;/span&gt;&lt;a href="#"&gt;I'm a link&lt;/a&gt;
</code></pre>

<p>We might think that the text is literally inserted <em>before</em> the element. But it&#8217;s not. The browser will rather create a code like this:</p>

<pre><code>&lt;a href="#" class="mark"&gt;&lt;span class="before"&gt;This is a link: &lt;/span&gt; I'm a link&lt;/a&gt;
</code></pre>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/ca45d630-8346-4577-b60f-7254bac2174a.png" alt="Link with :before pseudo element" /></p>

<p>It creates an element with the text &#8220;This is a link: &#8221; <em>within</em> the <code>a</code> element and applies the <code>.mark:before</code> rules on it. You can specify any rules you want; there are no restrictions. The browser applies the rules on an imagined element which isn&#8217;t really there, thus a <em>pseudo</em> element.</p>

<p>There&#8217;s a reason why I chose the <code>&lt;span&gt;</code> element for these pseudo elements. It&#8217;s because the pseudo elements are <em>inline</em> elements from begin with. Of course you can change their <code>display</code> property, but more on that topic later.</p>

<p>Now that we know a browser would insert the pseudo element within the given element, a question arises: What about pseudo elements on elements which has <em>no</em> content? For example the <code>&lt;img /&gt;</code> element or the separator <code>&lt;hr /&gt;</code>? Several experiments with <code>:before</code> and <code>:after</code> have shown that these pseudo elements does <em>not</em> work on non-content elements (which is a shame btw).</p>

<p>It&#8217;s also possible to insert images with the <code>content</code> property:</p>

<pre><code>/* CSS code */
.mark:before {
    content: url('linkmark.png');
}
</code></pre>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/c316c4d4-7fd5-450d-b453-433086c6b455.png" alt="Link with :before content image" /></p>

<p>Again the interpreted code:</p>

<pre><code>&lt;a href="#" class="mark"&gt;&lt;span class="before"&gt;&lt;img src="linkmark.png" /&gt;&lt;/span&gt;I'm a link&lt;/a&gt;
</code></pre>

<p>Combining both text and images is no problem, either. It&#8217;s done by separating the arguments with a space:</p>

<pre><code>/* CSS code */
.mark:before {
    content: url('linkmark.png') " This is a link: ";
}
</code></pre>

<h2>Get creative</h2>

<p>Now think outside the box. Think of all the possibilities with pseudo elements! You can create extra elements without polluting your HTML markup. You can use these elements as decoration. Or overlays. Or simple graphical objects. Nicolas Gallagher has some nice <a href="http://nicolasgallagher.com/tag/pseudo-elements/">pseudo element experiments</a> on <a href="http://nicolasgallagher.com/">his blog</a> including pure CSS folded corner effects, pure CSS speech bubbles and pure CSS icons. Yeah, icons. Check it out, it&#8217;s very intriguing!</p>

<p>Most of these techniques require you to change the pseudo element property <code>display</code> to <code>block</code>, so you can make use of the full potential of CSS3. But if you do, you have to remember to set the <code>content</code> property, otherwise the element won&#8217;t show. If you don&#8217;t want any content inside your pseudo element (because you&#8217;ve set a background image or something) you can set <code>content</code> to an empty string as shown in the code snippet below.</p>

<pre><code>/* CSS code */
.mark:before {
    background-image: url('linkmark.png');
    content: " ";
    display: block;
    float: left;
    height: 16px;
    width: 16px;
}
</code></pre>

<p>I hope you&#8217;ve gained more insight of the inner workings of pseudo elements. Or as a wise man would say: &#8220;Understanding is the first step to change&#8221;. Or something similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2011/01/22/on-css-pseudo-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflecting text with pure CSS3</title>
		<link>http://yichuanshen.de/blog/2011/01/08/reflecting-text-with-pure-css3/</link>
		<comments>http://yichuanshen.de/blog/2011/01/08/reflecting-text-with-pure-css3/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 17:46:22 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[flip]]></category>
		<category><![CDATA[gradient]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=92</guid>
		<description><![CDATA[While designing some new site, I&#8217;ve decided to use some text reflections on the header in my designs… I&#8217;ve already created the header using @font-face and I didn&#8217;t want to create an header image, so I thought… hey, just try to imitate the reflection with CSS only. Demo page &#187; The HTML code is very [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ryanblack.lima-city.de/yaiu/p/1978708880-785442352.png" alt="" class="left" /></p>

<p>While designing some new site, I&#8217;ve decided to use some text reflections on the header in my designs… I&#8217;ve already created the header using <code>@font-face</code> and I didn&#8217;t want to create an header image, so I thought… hey, just try to imitate the reflection with CSS only.</p>

<ul>
<li><a href="/demos/reflectedtext">Demo page &raquo;</a></li>
</ul>

<p>The HTML code is very straight forward and semantic:</p>

<pre><code>&lt;!-- HTML code --&gt;
&lt;h1 class="reflected"&gt;Reflected Text!&lt;/h1&gt;
</code></pre>

<p><span id="more-92"></span></p>

<hr />

<h2>Flipping the text vertically</h2>

<p>I used the <code>:after</code> and <code>:before</code> pseudo-elements to insert the reflection. The tricky part is where you have to flip the reflection-text vertically. This can be done with a CSS 2D transformation. One could write a transformation matrix which does the flipping. However this requires knowledge of Linear Algebra and too difficult for us to handle. The trick is simply using a negative value for <code>scaleY</code>.</p>

<p>For the mathematically challenged who are reading my blog: Here&#8217;s an excellent article <a href="http://www.useragentman.com/blog/2011/01/07/css3-matrix-transform-for-the-mathematically-challenged/">how those transformation matrices work &rarr;</a> and how to create them.</p>

<pre><code>/* CSS code */

.reflected {
    position: relative;
}
.reflected:after {
    content: 'Reflected Text!';
    display: block;
    position: absolute;
    bottom: -.55em; /* You should change this value to fit your font */
    left: 0;
    right: 0;
    opacity: .5;

    /* This is how the text is flipped vertically */
    -webkit-transform: scaleY(-1);
    -moz-transform: scaleY(-1);
    -o-transform: scaleY(-1);
}
</code></pre>

<h2>Fading reflection…</h2>

<p>Now we have to fade the reflection out. One could use a fade-out <code>png</code> image with alpha transparency, but what&#8217;s the fun in that? I researched on cross-browser CSS gradients and found an interesting article at <a href="http://www.webdesignerwall.com/tutorials/cross-browser-css-gradient/">WebDesignerWall &rarr;</a>.</p>

<pre><code>/* CSS code */

.reflected:after {
    /* Fading using CSS gradient */
    /* Don't forget to change the colors to your background color */
    background: -webkit-gradient(linear, left top, left center, from(rgba(255,255,255,0)), to(rgb(255,255,255)));
    background: -moz-linear-gradient(top, rgba(255,255,255,0), rgb(255,255,255));
    /* I left out the `filter` property,
       because IE doesn't know `:before` and `:after` pseudo-elements anyway */

    content: ' ';
    display: block;
    height: 1em;
    position: absolute;
    bottom: -.8em;
    left: 0;
    right: 0;
}
</code></pre>

<p>And finally you can simplify the whole CSS by grouping common properties together:</p>

<pre><code>/* CSS code */

.reflected {
    position: relative;
}
.reflected:before, .reflected:after {
    display: block;
    position: absolute;
    bottom: -.8em; /* You should change this value to fit your font */
    left: 0;
    right: 0;
}
.reflected:before {
    content: 'Reflected Text!';
    opacity: .3;
    /* This is how the text is flipped vertically */
    -webkit-transform: scaleY(-1);
    -moz-transform: scaleY(-1);
    -o-transform: scaleY(-1);
}
.reflected:after {
    /* Fading using CSS gradient */
    /* Don't forget to change the colors to your background color */
    background: -webkit-gradient(linear, left top, left center, from(rgba(255,255,255,0)), to(rgb(255,255,255)));
    background: -moz-linear-gradient(top, rgba(255,255,255,0), rgb(255,255,255));
    /* I left out the `filter` property,
       because IE doesn't know `:before` and `:after` pseudo-elements anyway */
    content: ' ';
    height: 1em;
}
</code></pre>

<h2>Some inconveniences</h2>

<p>As you can see, one <em>can</em> actually make a text reflection with CSS3 only. It just comes with some inflexibleness.</p>

<ul>
<li>It only works on a non-changing plain-color background.</li>
<li>The reflection text is generated using CSS. Which means you have to change the CSS file if you change the corresponding text in the HTML file.</li>
<li>It doesn&#8217;t work on all browsers (e.g. Opera)</li>
<li>It looks differently on different browsers (see figure below)</li>
</ul>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/2073409647-197976709.png" alt="Pure CSS text reflection in Safari, Firefox and Opera" /></p>

<h2>Try it out</h2>

<ul>
<li><a href="/demos/reflectedtext">Demo page &raquo;</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2011/01/08/reflecting-text-with-pure-css3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Smoothing text on Windows</title>
		<link>http://yichuanshen.de/blog/2010/12/30/smoothing-text-on-windows/</link>
		<comments>http://yichuanshen.de/blog/2010/12/30/smoothing-text-on-windows/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 18:20:23 +0000</pubDate>
		<dc:creator>Yichuan Shen</dc:creator>
				<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[blur]]></category>
		<category><![CDATA[cleartype]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[rendering]]></category>
		<category><![CDATA[smooth]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[text-shadow]]></category>
		<category><![CDATA[webdesign]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://yichuanshen.de/blog/?p=90</guid>
		<description><![CDATA[Font rendering on Windows is (still) really hideous and the way fonts gets rendered just can&#8217;t get out of one&#8217;s head, because it&#8217;s too awful and it haunts you in your nightmares. Especially big sans-serif fonts look unbearable. It really sucks and you can&#8217;t really do anything about it at all. One can use Safari [...]]]></description>
			<content:encoded><![CDATA[<p>Font rendering on Windows is (still) really hideous and the way fonts gets rendered just can&#8217;t get out of one&#8217;s head, because it&#8217;s too awful and it haunts you in your nightmares. Especially big sans-serif fonts look unbearable. It really sucks and you can&#8217;t really do anything about it at all. One can use Safari on Windows with Apple&#8217;s font rendering engine&#8230; but I, myself, can&#8217;t survive with my favorite browser of choice: Firefox.</p>

<p>Last week, when I took a peek at some examples of <a href="http://code.google.com/apis/webfonts/">Google&#8217;s Font API</a> on Windows, I got goose bumps. The font rendering was too bad. Typefaces aren&#8217;t smooth at all. It looks like crap. You can&#8217;t make the web beautiful like that.</p>

<p>To smooth the text I have come up with a fairly simple solution. I&#8217;ll just use <code>text-shadow</code>, apply some blur on it and the text will be as smooth as butter. Well at least in theory.</p>

<p><span id="more-90"></span></p>

<p>Firstly, here&#8217;s what I&#8217;m talking about:</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/1556970137-455300799.png" alt="Windows font rendering (Crap) vs Mac font rendering" /></p>

<h2>The solution</h2>

<p>For those, who are not familiar with the syntax of <code>text-shadow</code>; this is how you use it:</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/1034022659-2018735799.png" alt="Syntax: text-shadow: {offset-x} {offset-y} {blur-radius} {color};" /></p>

<p>We&#8217;re just going to blur the text, so we leave the offset to <code>0 0</code>.</p>

<pre><code>/* CSS code */
text-shadow: 0 0 1px black;
</code></pre>

<p>The difference is clear:</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/250086993-1620192515.png" alt="Text with text-shadow: 0 0 1px black;" /></p>

<p>We have achieved our desired effect, but it is a bit of an overkill. The blur is too strong, making it look bolder than it actually is. We can&#8217;t make the blur radius any smaller as <code>1px</code> is the smallest value it can get. To make the blur less strong, we can play around with the color opacity.</p>

<pre><code>/* CSS code */
text-shadow: 0 0 1px rgba(0, 0, 0, .5); /* 50% opacity black */
</code></pre>

<p>Overview of all versions:</p>

<p><img src="http://ryanblack.lima-city.de/yaiu/p/1544994667-536655216.png" alt="Text with text-shadow: 0 0 1px rgba(0, 0, 0, .5);" /></p>

<p>This already looks really usable, although still nothing compared to Mac&#8217;s font rendering. You can play around with the opacity value of the color to see what value fits best.</p>

<p>So next time you design a website you can use this little trick to smoothen your logo and headers on Windows to make it look at least bearable.</p>

<p>Keep in mind that this technique will <em>not</em> work on Mac. Why would you, anyway? Also don&#8217;t apply blur on small text. It&#8217;ll render your text unreadable and that&#8217;s equally bad and annoying.</p>

<p>Remember that the &#8216;text shadow&#8217; should be in the same color as the text. Otherwise, there will be no smoothing effect and the blur shadow will appear as a glow.</p>
]]></content:encoded>
			<wfw:commentRss>http://yichuanshen.de/blog/2010/12/30/smoothing-text-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

