<?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>Mixu&#039;s tech blog</title>
	<atom:link href="http://blog.mixu.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mixu.net</link>
	<description>When I read what I write I learn what I think</description>
	<lastBuildDate>Thu, 10 May 2012 21:26:57 +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>Git tips and tricks</title>
		<link>http://blog.mixu.net/2012/04/06/git-tips-and-tricks/</link>
		<comments>http://blog.mixu.net/2012/04/06/git-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 23:35:02 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=2259</guid>
		<description><![CDATA[Zsh/bash aliases alias ga=&#8217;git add&#8217; alias gp=&#8217;git push&#8217; alias gl=&#8217;git log&#8217; alias gs=&#8217;git status&#8217; alias gd=&#8217;git diff&#8217; alias gdc=&#8217;git diff &#8211;cached&#8217; alias g=&#8217;git&#8217; git config &#8211;global alias.lg &#8220;log &#8211;graph &#8211;pretty=format:&#8217;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&#60;%an&#62;%Creset&#8217; &#8211;abbrev-commit &#8211;date=relative&#8221; Add all changes or all changes to existing files $ git add -A Adds all files and file [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Zsh/bash aliases</strong></p>
<p>alias ga=&#8217;git add&#8217;<br />
alias gp=&#8217;git push&#8217;<br />
alias gl=&#8217;git log&#8217;<br />
alias gs=&#8217;git status&#8217;<br />
alias gd=&#8217;git diff&#8217;<br />
alias gdc=&#8217;git diff &#8211;cached&#8217;<br />
alias g=&#8217;git&#8217;</p>
<p>git config &#8211;global alias.lg &#8220;log &#8211;graph &#8211;pretty=format:&#8217;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&#8217; &#8211;abbrev-commit &#8211;date=relative&#8221;</p>
<p><strong>Add all changes or all changes to existing files</strong></p>
<p>$ git add -A</p>
<p>Adds all files and file deletes, so you don&#8217;t need to enter them manually.</p>
<p>$ git add -u</p>
<p>Same, but doesn&#8217;t add files that didn&#8217;t exist before.</p>
<p><strong>Differences between the staged files and the last commit</strong></p>
<p>$ git diff &#8211;cached</p>
<p>.. is something I use a lot just before committing the changes to check what my commit changed.</p>
<p><strong>Log-fu</strong></p>
<p>$ git log -p</p>
<p>Show the patches alongside the log</p>
<p>$ git log &#8211;stat</p>
<p>Show the changed files only.</p>
<p>$ git log &#8211;author=foo</p>
<p>Only commits by author foo.</p>
<p>$ git log &#8211;stat subdirectory</p>
<p>Show the commits affecting only &#8220;./subdirectory&#8221;, with a summary of the files (&#8211;stat).</p>
<p><strong>Diff-fu</strong></p>
<p>$ git diff my_branch master</p>
<p>What&#8217;s different between my branch and some other branch, e.g. master.</p>
<p>$ git diff HEAD^3</p>
<p>What changed in the last three commits.</p>
<p>Remember, git diff outputs an applicable patch:</p>
<p>$ git diff &gt; my.patch</p>
<p>$ git apply &lt; my.patch</p>
<p><strong>Creating a feature branch and merging it back</strong></p>
<p>Checkout the branch you want to base your work on:</p>
<p>$ git checkout master</p>
<p>Then create a branch and check it out:</p>
<p>$ git checkout -b local_name</p>
<p>Later on, merge it:</p>
<p>$ git checkout master</p>
<p>$ git merge local_name</p>
<p><strong>Stashing changes</strong></p>
<p>$ git stash</p>
<p>$ git stash list</p>
<p>$ git stash apply</p>
<p><strong>Blaming</strong></p>
<p>$ git blame path/to/file</p>
<p>See who changed what.</p>
<p>$ git blame abce1234^ path/to/file</p>
<p>See the blame, starting one commit before abce1234. E.g. when you need to trace back a particular line of code in history.</p>
<p><strong>Keeping the number of merges lower on small commits</strong></p>
<p>For small commits made on top of a frequently changing branch like master, you might want to rebase your local changes on top of the current remote before you merge a feature branch (<a href="http://gitready.com/advanced/2009/02/11/pull-with-rebase.html">more in depth</a>):</p>
<p>$ git pull &#8211;rebase</p>
<p>$ git push</p>
<p><strong>Resetting the current branch</strong></p>
<p>When you want to reset to the current HEAD.</p>
<p>$ git reset &#8211;hard HEAD</p>
<p>When a branch tracking a remote has become outdated (e.g. you are on staging now but your commits have diverged):</p>
<p>$ git reset &#8211;hard origin/staging</p>
<p><strong>Cherry-picking a commit</strong></p>
<p>$ git cherry-pick sha1_of_commit</p>
<p><strong>Total number of remote branches</strong></p>
<p>First, remove local branches that do not exist on origin (&#8211;dry-run if you want to preview):</p>
<p>$ git remote prune origin</p>
<p>$ git branch -r | wc -l<br />
123</p>
<p><strong>Get the latest commit of all remote branches</strong></p>
<div id="gist-2313880" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c">#/bin/bash</span></div><div class='line' id='LC2'>git branch -r | <span class="k">while </span><span class="nb">read </span>line ;</div><div class='line' id='LC3'><span class="k">do</span></div><div class='line' id='LC4'><span class="k">  </span><span class="nb">echo </span></div><div class='line' id='LC5'><span class="nb">  echo</span> <span class="s2">&quot;************&quot;</span> <span class="k">${</span><span class="nv">line</span><span class="p">#origin/</span><span class="k">}</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nb">echo</span></div><div class='line' id='LC7'><span class="nb">  </span>git log -1 <span class="nv">$line</span></div><div class='line' id='LC8'><span class="k">done</span></div><div class='line' id='LC9'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/2313880/e448fc0623e0992b73f5c34879aa18bc2596ed85/gistfile1.sh" style="float:right;">view raw</a>
            <a href="https://gist.github.com/2313880#file_gistfile1.sh" style="float:right;margin-right:10px;color:#666">gistfile1.sh</a>
            <a href="https://gist.github.com/2313880">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p><strong>Get the latest commit of all remote branches, and summary, ordered by age</strong></p>
<p>Use this Node script:</p>
<p><a href="https://gist.github.com/91ba46dee32b221b3a84">https://gist.github.com/91ba46dee32b221b3a84</a></p>
<div><strong>Delete a local or remote branch</strong></div>
<p># delete a local branch<br />
git branch -d some_branch_name</p>
<p># really delete a local branch even if git complains about it in the previous command<br />
git branch -D some_branch_name</p>
<p># delete a remote branch<br />
git push origin :some_branch_name</p>
<p>The reason for that syntax is that you can do `git push origin local_branch_name:remote_branch_name` so what that line above is doing is essentially pushing NULL to the remote branch, thereby killing it off.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2012/04/06/git-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mechanical keyboards rock!</title>
		<link>http://blog.mixu.net/2012/02/17/mechanical-keyboards-rock/</link>
		<comments>http://blog.mixu.net/2012/02/17/mechanical-keyboards-rock/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 18:00:21 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=2230</guid>
		<description><![CDATA[I&#8217;m a big believer in having the best tools possible for the job. I&#8217;ve gone through at least 3 Microsoft Ergonomic Keyboard 4000&#8242;s, and used to think those were the best keyboards ever (as did Jeff Atwood). Well, there is whole world of keyboards that are even better, namely: buckling spring keyboards (e.g. the IBM [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big believer in having the best tools possible for the job. I&#8217;ve gone through at least 3 <a href="http://programmers.stackexchange.com/questions/2254/what-are-good-keyboards-for-programming">Microsoft Ergonomic Keyboard 4000&#8242;s</a>, and used to think those were the best keyboards ever (as did <a href="http://www.codinghorror.com/blog/2010/10/the-keyboard-cult.html">Jeff Atwood</a>).</p>
<p>Well, there is <a href="http://www.overclock.net/t/491752/mechanical-keyboard-guide">whole world of keyboards that are even better</a>, namely: buckling spring keyboards (e.g. the IBM Model M), Cherry MX switch keyboards and Topre switch keyboards.</p>
<p>I got this one for my place &#8211; Cherry MX brown switches, which are less noisy (though definitely they could be even more silent):</p>
<p><a href="http://blog.mixu.net/files/2012/02/IMG_20120217_001846.jpg"><img title="IMG_20120217_001846" src="http://blog.mixu.net/files/2012/02/IMG_20120217_001846.jpg" alt="" width="512" height="384" /></a></p>
<p>The major difference between a mechanical keyboard and a regular one is in the feel of the keys. Mechanical keyboards have metallic springs, while cheaper keyboards just have some flexible plastic.  After a short while typing on the MS Ergonomic keyboard started feeling like typing on a mushy piece of plastic compared to the mechanical keyboard. I do kind of miss the more ergonomic split layout, but typing is just a lot nicer overall on a mechanical keyboard.</p>
<p>I ended up buying two keyboards, both with Cherry MX switches (~110 USD from <a href="http://elitekeyboards.com/">here</a>). I didn&#8217;t get a buckling spring keyboard, because they are more noisy and there aren&#8217;t any space-saving tenkeyless models available. The third alternative &#8211; keyboards with Topre switches &#8211; are more expensive (~300+ USD) and have been described as less tactile. I&#8217;ll probably get a Topre keyboard eventually anyway, just so I can try it out.</p>
<p>Here is the new keyboard I use at work, which has Cherry MX blue switches (a bit more noisy than my other keyboard, but definitely one I prefer):</p>
<p><a href="http://blog.mixu.net/files/2012/02/IMG_20120216_183611.jpg"><img title="IMG_20120216_183611" src="http://blog.mixu.net/files/2012/02/IMG_20120216_183611.jpg" alt="" width="512" height="384" /></a></p>
<p>Best purchase in a long time!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2012/02/17/mechanical-keyboards-rock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: thinkpad_acpi and fan control on Arch</title>
		<link>http://blog.mixu.net/2012/01/19/how-to-thinkpad_acpi-and-fan-control-on-arch/</link>
		<comments>http://blog.mixu.net/2012/01/19/how-to-thinkpad_acpi-and-fan-control-on-arch/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 08:04:45 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=2201</guid>
		<description><![CDATA[From the &#8220;this might help some random person&#8221; department &#8211; setting up manual Thinkpad fan control in Arch Linux. 1. Edit /etc/rc.conf. Add thinkpad_acpi to MODULES=() in the hardware section. 2. Create a new file enabling fan control as /etc/modprobe.d/thinkfan.conf: options thinkpad_acpi fan_control=1 3. Reload the thinkpad_acpi module: sudo modprobe -r thinkpad_acpi &#38;&#38; sudo modprobe [...]]]></description>
			<content:encoded><![CDATA[<p>From the &#8220;this might help some random person&#8221; department &#8211; setting up manual Thinkpad fan control in Arch Linux.</p>
<p>1. Edit /etc/rc.conf. Add thinkpad_acpi to MODULES=() in the hardware section.</p>
<p>2. Create a new file enabling fan control as /etc/modprobe.d/thinkfan.conf:</p>
<pre>options thinkpad_acpi fan_control=1</pre>
<p>3. Reload the thinkpad_acpi module:</p>
<pre>sudo modprobe -r thinkpad_acpi &amp;&amp; sudo modprobe thinkpad_acpi</pre>
<p>To view the current fan speed:</p>
<pre>[~]$ cat /proc/acpi/ibm/fan
status: enabled
speed: 2887
level: 4
commands: level ( is 0-7, auto, disengaged, full-speed)
commands: enable, disable
commands: watchdog ( is 0 (off), 1-120 (seconds))</pre>
<p>To control fan speed:</p>
<pre># echo level 0 | sudo tee /proc/acpi/ibm/fan (fan off)
# echo level 2 | sudo tee /proc/acpi/ibm/fan (low speed)
# echo level 4 | sudo tee /proc/acpi/ibm/fan (medium speed)
# echo level 7 | sudo tee /proc/acpi/ibm/fan (maximum speed)
# echo level auto | sudo tee /proc/acpi/ibm/fan (automatic - default)</pre>
<p>For easy control from the command line:</p>
<pre>function fan() {
  sensors
  echo level $@ | sudo tee /proc/acpi/ibm/fan
}</pre>
<p>Now you can run <code>fan 2</code> to set the fan level to 2 and so on.</p>
<p>To view fan speed, install lm_sensors <a href="https://wiki.archlinux.org/index.php/Lm_sensors">following the instructions on the Arch wiki</a>. Example output:</p>
<pre>[~]$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +37.0°C  (crit = +99.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1:        2904 RPM

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +39.0°C  (high = +86.0°C, crit = +100.0°C)
Core 0:         +37.0°C  (high = +86.0°C, crit = +100.0°C)
Core 1:         +37.0°C  (high = +86.0°C, crit = +100.0°C)
Core 2:         +35.0°C  (high = +86.0°C, crit = +100.0°C)
Core 3:         +39.0°C  (high = +86.0°C, crit = +100.0°C)</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2012/01/19/how-to-thinkpad_acpi-and-fan-control-on-arch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance benchmarking Socket.io 0.8.7, 0.7.11 and 0.6.17 and Node&#8217;s native TCP</title>
		<link>http://blog.mixu.net/2011/11/22/performance-benchmarking-socket-io-0-8-7-0-7-11-and-0-6-17-and-nodes-native-tcp/</link>
		<comments>http://blog.mixu.net/2011/11/22/performance-benchmarking-socket-io-0-8-7-0-7-11-and-0-6-17-and-nodes-native-tcp/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 23:07:37 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=2088</guid>
		<description><![CDATA[I&#8217;ve been working with Socket.io quite a bit recently. It&#8217;s a great library. However, after upgrading to 0.8.x, I ran into problems with increased CPU usage. Since performance is very important for high traffic pubsub implementations, I decided to investigate this further &#8211; and try to quantify the performance impact of upgrading to a newer [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with Socket.io quite a bit recently. It&#8217;s a great library. However, after upgrading to 0.8.x, I ran into problems with increased CPU usage. Since performance is very important for high traffic pubsub implementations, I decided to investigate this further &#8211; and try to quantify the performance impact of upgrading to a newer version of Socket.io.</p>
<p>I wrote a benchmarking suite (<a href="https://github.com/mixu/siobench">siobench</a>). The benchmark is rather simple. Clients connect one at a time, and a new client is only allowed to connect when the previous one is connected. When the server has used up 5000 milliseconds of CPU time, the benchmark is stopped. Every second, every connected client sends a single message which is echoed back by the server (<a href="https://github.com/mixu/siobench">more details</a>).</p>
<p>This workload is geared towards a situation where Socket.io is used to notify people of things as part of a larger application: e.g. most of the load is assumed to be idling connections rather than real-time messaging like in, say, a multiplayer game.</p>
<p>The &#8220;end of test&#8221; condition is 5000 ms of CPU time, because this seemed to be a easy way to give all implementations the same amount of time. CPU usage % is not accurate, since it is dependent on how much CPU time the process gets over a particular amount of wallclock time. In the graphs the CPU usage % calculated over a 100ms interval, while usertime and systime are the actual numbers reported at that particular time.</p>
<h2>Summary</h2>
<table>
<tbody>
<tr>
<td>Node (0.4.12) using tcp</td>
<td>~ 8000 connections on a single core</td>
</tr>
<tr>
<td>socket.io 0.6.17 using websockets</td>
<td>~ 2300 connections on a single core</td>
</tr>
<tr>
<td>socket.io 0.7.11 using websockets</td>
<td>~ 1800 connections on a single core</td>
</tr>
<tr>
<td>socket.io 0.8.6 using websockets</td>
<td>~ 1900 connections on a single core</td>
</tr>
</tbody>
</table>
<p>Remember, this is just one server on one core, with 5000 ms of CPU time on that core. The rest of the cores are used to generate sufficient load. The full graphs are at the end of the post.</p>
<p>Note that the absolute numbers are mostly unimportant &#8211; I ran this on the following 15&#8243; Macbook Pro running Arch with the 3.1.04 Linux kernel in Virtualbox with 4096 Mb of RAM, a SSD and four cores (Intel(R) Core(TM) i7-2635QM CPU @ 2.00GHz GenuineIntel GNU/Linux). You can get numbers that are more representative of your system <a href="https://github.com/mixu/siobench">by getting siobench</a> and running it:</p>
<pre>Usage: node siobench.js [env]
A tool for benchmarking your Socket.io server.

Available environments:
	0.6.17
	0.6.17_poll
	0.7.11
	0.8.7
	0.8.7_poll
	tcp</pre>
<div>
<p>You can also write your own benchmarks under ./bench, by writing a new server.js (<a href="https://github.com/mixu/siobench/blob/master/bench/tcp/server_tcp.js">example #1</a>, <a href="https://github.com/mixu/siobench/blob/master/bench/sio087/server.js">#2</a>) and a new client.js (<a href="https://github.com/mixu/siobench/blob/master/bench/tcp/client_tcp.js">example #1</a>, <a href="https://github.com/mixu/siobench/blob/master/bench/sio087/client.js">#2</a>). Each benchmark has it&#8217;s own set of npm dependencies installed, so that one can run benchmarks against many versions of socket.io.</p>
<p><strong>Some notes on performance</strong></p>
<p>The relative performance is more interesting.</p>
<p>First, the node TCP speed represents the highest achievable performance on this benchmark, since it only uses the built-in TCP implementation. Compared to this, Socket.io is has about 1/3 of the performance (~ 2300 vs ~8000 connections) when using WebSockets.</p>
<p>Second, it appears that 0.8.7 is about 20% slower than 0.6.17 on this benchmark. If I remember correctly, Socket.io 0.7 switched to a new protocol, and there are clearly some performance improvements over 0.7.11 in 0.8.7 (+100 connections in this bench); it&#8217;s just that the overall performance is still worse in this benchmark than in the old 0.6.17 branch.</p>
<div>
<p><strong>Working towards higher-performance</strong></p>
</div>
<p>As this is just a simple benchmark, I don&#8217;t really have solutions &#8211; only some suggestions.</p>
<p><strong>1) A CI build that includes benchmarks and community contributed test cases</strong></p>
<p>First, I&#8217;d love to see a CI build for Socket.io that would include performance benchmarks and community contributed test cases.</p>
<p>However, currently setting up a CI build for Socket.io is difficult because <a href="https://github.com/LearnBoost/socket.io/issues/519">the bundled test suite only works on OSX</a>. It would be a lot easier to contribute if the tests worked on other platforms.</p>
<p>I am hoping that as <a href="https://github.com/LearnBoost/engine.io">Engine.io gets going</a>, the test suite will be fixed so that it can be run on other platforms. Otherwise, contributing improvements will be tricky/impossible since there is no way to tell whether the code works.</p>
<p><strong>2) More realistic performance test scenarios</strong></p>
<p>The current test scenario is rather limited in that it mostly tests performance in terms of establishing connections (without terminating them). I&#8217;d love to hear more realistic scenario suggestions, particularly from people who have run into memory usage issues.</p>
<p><a href="https://github.com/mixu/siobench">siobench</a> is only a starting point: it&#8217;s way better than just looking at htop and wondering whether performance was better in the last version or not. There are still specific questions that should be formulated as replicable tests.</p>
<p><strong>3) A polling transport that works on Node.js</strong></p>
<p>I did write tests for the xhr-polling transport for Socket.io as well. These showed much worse performance, around:</p>
<ul>
<li>~ 550 connections on Socket.io 0.6.17 (vs ~2300 using WS)</li>
<li>~ 450 connections on Socket.io 0.8.7 (vs ~ 1900 using WS)</li>
</ul>
<p>However, the xhr-polling is severely broken in that it stops connecting after 4-5 connections on Node v0.4.12. So I had to force each load generating client to only make four connections and then spawn a new load generating process to work around the problem. I wouldn&#8217;t vouch for the accuracy of the test with xhr-polling until the xhr-polling transport is fixed on Node when using socket.io-client (it&#8217;s been broken for the last three releases, though).</p>
<p><strong>4) Comparative benchmarks</strong></p>
<p>Hopefully, this will help with performance testing new releases of Socket.io and other Comet libraries. Since the plan is that Engine.io will allow people to work with a lower level than Socket.io, there might be new performance oriented versions, and it would be useful to see benchmarks for those. Re: the other Node.js pubsub frameworks: I can&#8217;t benchmark Faye, because it does not provide the right API out of the box, and Juggernaut uses Socket.io internally.</p>
<p>I&#8217;m going to use siobench it for internal testing to ensure that the pubsub implementation I am working on (built over Socket.io) will not have performance regressions.</p>
<p>The full graphs are below. Please leave comments and suggestions for improvements &#8211; I am hoping that the developer community around Socket.io can help in improving the performance going forward, kind of like what Mozilla did with &#8220;<a href="http://arewefastyet.com/">arewefastyet.com</a>&#8220;.</p>
</div>
<p><strong>Socket.io 0.6.17 &#8211; Websockets &#8211; CPU usage and time</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/sio_617_cpu.png"><img class="alignnone size-full wp-image-2115" title="sio_617_cpu" src="http://blog.mixu.net/files/2011/11/sio_617_cpu.png" alt="" width="384" height="288" /></a> <a href="http://blog.mixu.net/files/2011/11/sio_617_cputime.png"><img class="alignnone size-full wp-image-2116" title="sio_617_cputime" src="http://blog.mixu.net/files/2011/11/sio_617_cputime.png" alt="" width="384" height="288" /></a></p>
<p><strong>Socket.io 0.6.17 &#8211; Websockets &#8211; resident set size</strong></p>
<div><strong><a href="http://blog.mixu.net/files/2011/11/sio_617_mem.png"><img title="sio_617_mem" src="http://blog.mixu.net/files/2011/11/sio_617_mem.png" alt="" width="384" height="288" /></a><br />
</strong></div>
<p>&nbsp;</p>
<p><strong>Socket.io 0.7.11 &#8211; Websockets &#8211; CPU usage and time</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/sio_711_cpu.png"><img class="alignnone size-full wp-image-2119" title="sio_711_cpu" src="http://blog.mixu.net/files/2011/11/sio_711_cpu.png" alt="" width="384" height="288" /></a><a href="http://blog.mixu.net/files/2011/11/sio_711_cputime.png"><img class="alignnone size-full wp-image-2120" title="sio_711_cputime" src="http://blog.mixu.net/files/2011/11/sio_711_cputime.png" alt="" width="384" height="288" /></a></p>
<p><strong>Socket.io 0.7.11 &#8211; Websockets &#8211; resident set size</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/sio_711_mem.png"><img class="alignnone size-full wp-image-2120" title="sio_711_cputime" src="http://blog.mixu.net/files/2011/11/sio_711_mem.png" alt="" width="384" height="288" /></a></p>
<p><strong>Socket.io 0.8.7 &#8211; Websockets &#8211; CPU usage and time</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/sio_87_cpu.png"><img class="alignnone size-full wp-image-2120" title="sio_87_cpu" src="http://blog.mixu.net/files/2011/11/sio_87_cpu.png" alt="" width="384" height="288" /></a><a href="http://blog.mixu.net/files/2011/11/sio_87_cputime.png"><img class="alignnone size-full wp-image-2120" title="sio_87_cputime" src="http://blog.mixu.net/files/2011/11/sio_87_cputime.png" alt="" width="384" height="288" /></a></p>
<p><strong>Socket.io 0.8.7 &#8211; Websockets &#8211; resident set size</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/sio_87_mem.png"><img class="alignnone size-full wp-image-2120" title="sio_87_mem" src="http://blog.mixu.net/files/2011/11/sio_87_mem.png" alt="" width="384" height="288" /></a></p>
<p><strong>Node 0.4.12 &#8211; TCP &#8211; CPU usage and time</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/tcp_cpu.png"><img class="alignnone size-full wp-image-2120" title="tcp_cpu" src="http://blog.mixu.net/files/2011/11/tcp_cpu.png" alt="" width="384" height="288" /></a><a href="http://blog.mixu.net/files/2011/11/tcp_cputime.png"><img class="alignnone size-full wp-image-2120" title="tcp_cputime" src="http://blog.mixu.net/files/2011/11/tcp_cputime.png" alt="" width="384" height="288" /></a></p>
<p><strong>Node 0.4.12 &#8211; TCP &#8211; resident set size</strong></p>
<p><a href="http://blog.mixu.net/files/2011/11/tcp_mem.png"><img class="alignnone size-full wp-image-2120" title="tcp_mem" src="http://blog.mixu.net/files/2011/11/tcp_mem.png" alt="" width="384" height="288" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/11/22/performance-benchmarking-socket-io-0-8-7-0-7-11-and-0-6-17-and-nodes-native-tcp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>My Arch Linux setup</title>
		<link>http://blog.mixu.net/2011/11/10/my-arch-linux-setup/</link>
		<comments>http://blog.mixu.net/2011/11/10/my-arch-linux-setup/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 04:22:41 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=2033</guid>
		<description><![CDATA[This is mostly just a reminder for myself &#8211; but I always learn new things when I read how other people set up their system. Leave a comment if you have a tip &#8211; that&#8217;s how I learned about wicd-gtk . Oh, and install my window manager (tiling, written in C++ and node.js, configurable using Javascript). [...]]]></description>
			<content:encoded><![CDATA[<p>This is mostly just a reminder for myself &#8211; but I always learn new things when I read how other people set up their system. Leave a comment if you have a tip &#8211; that&#8217;s how I learned about wicd-gtk <img src='http://blog.mixu.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Oh, and install <a href="https://github.com/mixu/nwm">my window manager</a> (tiling, written in C++ and node.js, configurable using Javascript).</p>
<p><strong>First steps</strong></p>
<ul>
<li>do the basic arch setup first (or <a href="https://wiki.archlinux.org/index.php/Installing_Arch_Linux_in_VMware">VMware</a>, or Virtualbox)</li>
</ul>
<p><strong>Update the system (and install/setup sudo)</strong></p>
<pre>dhcpcd eth0 #if you did not add "interface=eth0" in rc.conf during setup
pacman -Syu</pre>
<p>Fixes:</p>
<p><a href="http://www.archlinux.org/news/initscripts-update-manual-intervention-required/">http://www.archlinux.org/news/initscripts-update-manual-intervention-required/</a></p>
<pre>rm /etc/profile.d/locale.sh</pre>
<p><a href="http://www.archlinux.org/news/filesystem-upgrade-manual-intervention-required/">http://www.archlinux.org/news/filesystem-upgrade-manual-intervention-required/</a></p>
<pre>pacman -S filesystem --force</pre>
<pre>pacman -S sudo
vim /etc/sudoers # add yourself to sudoers
sudo vim /etc/pacman.conf # set SigLevel = Never TrustAll
sudo shutdown-r now</pre>
<p>Install X11:</p>
<pre>pacman -S xorg-server xorg-xinit xorg-utils xorg-server-utils xterm</pre>
<p>If virtualized in VirtualBox, make copy-paste work first:</p>
<pre>pacman -S virtualbox-archlinux-additions</pre>
<p><a href="https://wiki.archlinux.org/index.php/Arch_Linux_VirtualBox_Guest#Arch_Linux_guests">Details</a></p>
<p><strong> Create a new user</strong></p>
<pre>pacman -S zsh
useradd -m -g users -G audio,lp,optical,storage,video,games,power,scanner -s /bin/zsh USERNAME
su USERNAME
passwd</pre>
<p><strong>Add x11</strong></p>
<pre>pacman -S xorg-server xorg-xinit xorg-utils xorg-server-utils</pre>
<p><strong>Copy ssh keys over from old machine</strong><br />
<strong>Useful packages</strong></p>
<pre>pacman -S base-devel sudo python2 git libev mlocate mercurial nitrogen \
sakura wicd-gtk pcmanfm gnome-icon-theme htop unzip \
openssl chromium flashplugin bash-completion xterm \
epdfview mysql ruby tilda tmux wget redis xcursor-vanilla-dmz \
xarchiver gzip bzip2 zip unzip unrar p7zip \
meld ttf-ubuntu-font-family mpg123 alsa-utils redis mysql ruby libxslt</pre>
<ul>
<li>base-devel and python2 for compiling node</li>
<li>libev for nwm</li>
<li>mlocate for locate command</li>
<li>nitrogen is better than feh for multiple screens</li>
<li>sakura is a nice terminal</li>
<li>wicd-gtk is a simple wifi network gui</li>
<li>pcmanfm gnome-icon-theme are for pcmanfm, a Nautilus alternative</li>
</ul>
<p>Remember to visudo and remove the password requirement from wheel. And add dbus and wicd to /etc/rc.conf just like pacman tells you to.<br />
<strong>Configuring X11</strong></p>
<p>Add ~/.Xresources:</p>
<pre>Xcursor.theme: vanilla-dmz
Xcursor.size:  16       !  32, 48 or 64 may also be good values</pre>
<p><strong>Configuring git</strong></p>
<pre>git config --global color.ui true</pre>
<p><strong>Configuring sakura</strong></p>
<p>I want to use ctrl + Page_Up / Page_Down to switch tabs, so edit ~/.config/sakura/sakura.conf:</p>
<pre>switch_tab_accelerator=4 # since <a>GDK_CONTROL_MASK</a> is 1 &lt;&lt; 2, e.g. 4.
prev_tab_key=Page_Down
next_tab_key=Page_Up</pre>
<p><strong>Some basic niceties: whatprovides, service and chkconfig</strong></p>
<pre>pacman -S pkgtools</pre>
<ul>
<li>pkgtools provides the pkgfile tool. It works like yum whatprovides (e.g. allows you to search for a particular command or dependency in all the pacman packages)</li>
<li>&#8220;sudo pkgfile -u&#8221; to update the db</li>
<li>&#8220;pgkfile zipinfo&#8221; to search for zipinfo</li>
</ul>
<p>Arch don&#8217;t have a service and chkconfig, but we can make the new things curve a bit less steep by adding some functions to .bashrc:</p>
<pre>function service() {
  sudo /etc/rc.d/$1 $2
}

alias chkconfig='cat /etc/rc.conf | grep DAEMONS &amp;&amp; echo "cat + grep /etc/rc.conf"'</pre>
<p>This makes service an alias for /etc/rc.d/ and prints out the enabled services from /etc/rc.conf. While we&#8217;re editing .bashrc, might as well add:</p>
<pre>PS1="[\W]\$ " # my preferred bash prompt (e.g. only the current dirname).
ulimit -s 16400 # higher stack limit
# ssh-agent
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
     echo "Initialising new SSH agent..."
     /usr/bin/ssh-agent | sed 's/^echo/#echo/' &gt; "${SSH_ENV}"
     echo succeeded
     chmod 600 "${SSH_ENV}"
     . "${SSH_ENV}" &gt; /dev/null
     /usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" &gt; /dev/null
     #ps ${SSH_AGENT_PID} doesn't work under cywgin
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ &gt; /dev/null || {
         start_agent;
     }
else
     start_agent;
fi</pre>
<p><strong>Installing Node and NPM</strong></p>
<p>You can just do:</p>
<pre>pacman -S nodejs</pre>
<p>If you&#8217;re OK with that version, which seems to track the Node releases pretty well.</p>
<p>Arch uses python3 as python. You need to change python to python2 (thanks <a href="http://www.robsearles.com/2011/02/11/nodejs-v0-4-0-on-arch-linux/">Rob Searles</a>!)</p>
<pre># node.js fix for arch (use python2) 
mkdir /tmp/bin
ln -s /usr/bin/python2 /tmp/bin/python
export PATH=/tmp/bin:$PATH</pre>
<p>You can then do a regular node install:</p>
<p>git clone git://github.com/joyent/node.git</p>
<p>git checkout v0.4.12</p>
<p>./configure</p>
<p>make</p>
<p>sudo make install</p>
<p>Remember to install npm as well:</p>
<pre>curl http://npmjs.org/install.sh | sudo sh</pre>
<p><strong>Installing my window manager and personal config</strong></p>
<pre>git clone git://github.com/mixu/nwm.git
cd nwm
node-waf clean || true &amp;&amp; node-waf configure build
sudo npm link # add a global npm symlink to this repository - so nwm-user can find it (man npm link)
cd ..
git clone git://github.com/mixu/nwm-user.git
cd nwm-user
npm link nwm # now make a symlink to the nwm installation</pre>
<p>Add it to ~/.xinitrc (change paths!!):</p>
<pre>exec /usr/local/bin/node ~/mnt/nwm-user/nwm-user.js 2&gt;~/nwm.err.log 1&gt;~/nwm.log</pre>
<p>And while we&#8217;re at it, lets add some other stuff:</p>
<pre>VBoxClient-all &amp;
export PATH=/tmp/bin:$PATH # for node-waf, too lazy to work on a better solution
xset +fp /usr/share/fonts/local
xset fp rehash</pre>
<p>Run &#8220;startx&#8221; to start X11 with nwm.</p>
<p><strong>Installing my mp3 player</strong></p>
<p>First, we need to configure alsa (included by default):</p>
<pre>pacman -S mpg123 alsa-utils</pre>
<p>Run:</p>
<pre>alsamixer</pre>
<p>and turn on Master and PCM channels (by pressing m) as they are muted by default.</p>
<pre>sudo alsactl store</pre>
<p>Then continue:</p>
<pre>git clone git://github.com/mixu/nplay.git</pre>
<p>Run nplay with</p>
<pre>node nplay.js</pre>
<p>TODO: fix directory in source code and change backend from mpg321 to mpg123.</p>
<p><strong>Switching the keyboard language in X11</strong></p>
<p>I sometimes need to write emails in Finnish, so here is how to switch the layout:</p>
<pre><code>setxkbmap -layout fi # revert back </code><span class="Apple-style-span" style="font-family: monospace;">setxkbmap -layout us</span><span class="Apple-style-span" style="font-family: monospace;"> </span></pre>
<p>Install yaourt</p>
<p>Install dependencies</p>
<p>yaourt libpng12 gtk2-theme-dust</p>
<p>&nbsp;</p>
<p><strong>Install Sublime Text 2</strong></p>
<p>Sublime Text needs libpng12, which you have to install from AUR:</p>
<pre>wget http://aur.archlinux.org/packages/li/libpng12/libpng12.tar.gz
tar -xzvf libpng12.tar.gz
cd libpng12
makepkg
pacman -U ./libpng12-1.2.46-2-x86_64.pkg.tar.xz</pre>
<p>Then download and run Sublime Text 2.</p>
<p>Also, you might want to ger http://aur.archlinux.org/packages/gt/gtk2-theme-dust/gtk2-theme-dust.tar.gz.</p>
<p><strong>Configuring Sublime Text 2</strong></p>
<pre>locate Packages # returns ~/.config/sublime-text-2/Packages
cd ~/.config/sublime-text-2/Packages
git clone https://github.com/buymeasoda/soda-theme/ "Theme - Soda"
cd User
wget http://blog.mixu.net/files/2010/05/my_themes.zip # Install my themes
unzip my_themes
rm my_themes.zip</pre>
<p><strong>Base File settings</strong></p>
<pre>{
  // FONTS and COLORS
  "color_scheme": "Packages/User/Mixu Espresso.tmTheme",
  "font_size": 11,
  "tab_size": 2,
  // WHITESPACE
    // Set to true to insert spaces when tab is pressed
    "translate_tabs_to_spaces": true,
    "trim_automatic_white_space": true,
    "trim_trailing_white_space_on_save": true,
    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": false,
  "shift_tab_unindent": true,
  // Set to false to disable highlighting any line with a caret
  "highlight_line": true,
  // Set to "none" to turn off drawing white space, "selection" to draw only the
  // white space within the selection, and "all" to draw all white space
  "draw_white_space": "selection",
  // Set to true to ensure the last line of the file ends in a newline
  // character when saving
  "ensure_newline_at_eof_on_save": true,
  "fold_buttons": false
}</pre>
<p><strong>Global Settings</strong></p>
<pre>{
  "theme": "Soda Light.sublime-theme"
}</pre>
<p><strong>Other tweaks</strong></p>
<p>I put these in my usual &#8220;startup&#8221; command, nwm-setup.sh and run it manually:</p>
<pre>xrandr --output VBOX0 --auto --left-of VBOX1 # Virtualbox displays
chromium &amp; # start chromium
export PS1="[\W]\$ "
xsetroot -cursor_name left_ptr # Set pointer
nitrogen --restore &amp; # Restore desktop background using nitrogen</pre>
<p><strong>Other dependencies</strong></p>
<pre>pacman -S redis mysql ruby libxslt</pre>
<p>Setting up ree:</p>
<pre>cd
bash &lt; &lt;(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] &amp;&amp; . "$HOME/.rvm/scripts/rvm" # Load RVM function' &gt;&gt; ~/.bashrc
source .bashrc
rvm install ree-1.8.7-2011.03</pre>
<p>Installing REE will fail. <a href=" http://stackoverflow.com/questions/6134456/error-while-installing-ruby-1-8-7-on-fedora-15">You need to</a>run the installer from /home/m/.rvm/src/ree-1.8.7-2011.03/installer manually:</p>
<pre>./installer -no-tcmalloc</pre>
<p>Then continue on:</p>
<pre>rvm ree-1.8.7-2011.03 --default</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/11/10/my-arch-linux-setup/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Nginx, Websockets, SSL and Socket.IO deployment</title>
		<link>http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/</link>
		<comments>http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/#comments</comments>
		<pubDate>Sat, 13 Aug 2011 01:54:42 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=1955</guid>
		<description><![CDATA[I&#8217;ve spent some time recently figuring out the options for deploying Websockets with SSL and load balancing &#8211; and more specifically, Socket.IO &#8211; while allowing for dual stacks (e.g. Node.js and another dev platform). Since there seems to be very little concrete guidance on this topic, here are my notes &#8211; I&#8217;d love to hear [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some time recently figuring out the options for deploying Websockets with SSL and load balancing &#8211; and more specifically, Socket.IO &#8211; while allowing for dual stacks (e.g. Node.js and another dev platform). Since there seems to be very little concrete guidance on this topic, here are my notes &#8211; I&#8217;d love to hear from you on your implementation  (leave a comment or write about and link back)&#8230;</p>
<p><strong>The goal here is to:</strong></p>
<ol>
<li>Expose Socket.io and your main application from a single port &#8212; avoiding cross-domain communication</li>
<li>Support HTTPS for both connections &#8212; enabling secure messaging</li>
<li>Support the Websockets and Flashsockets transports from Socket.io &#8212; for performance</li>
<li>Perform load balancing for both the backends somewhere &#8212; for performance</li>
</ol>
<p><span style="font-size: 20px; font-weight: bold;">Socket.io&#8217;s various transports</span></p>
<p>Socket.io supports multiple different transports:</p>
<div>
<ul>
<li>WebSockets &#8212; which are essentially long lived HTTP 1.1 requests, which after a handshake upgrade to the Websockets protocol</li>
<li>Flash sockets &#8212; which are plain TCP sockets with optional SSL support (but Flash seems to use some older SSL encryption method)</li>
<li>various kinds of polling &#8212; which work over long lived HTTP 1.0 requests</li>
</ul>
</div>
<h2>Starting point: Nginx and Websockets</h2>
<p>Nginx is generally the first recommendation for Node.js deployments. It&#8217;s a high-performance server and even includes support for proxying requests via the <a href="http://wiki.nginx.org/NginxHttpProxyModule">HttpProxyModule</a>.</p>
<p>However, &#8212; and this should be made much obvious to people starting with Socket.io &#8212; the problem is that while Nginx can talk HTTP/1.1 to the client (browser), it talks HTTP/1.0 to the server. Nginx&#8217;s default HttpProxyModule does not support HTTP/1.1, which is needed for Websockets.</p>
<p>Websockets 76 requires support for HTTP/1.1 as the handshake mechanism is not compatible with HTTP/1.0. What this means is that if Nginx is used to reverse proxy a Websockets server (like Socket.io), then the WS connections will fail. So no Websockets for you if you&#8217;re behind Nginx.</p>
<p>There is a workaround, but I don&#8217;t see the benefit: use a TCP proxy (there is a <a href="https://github.com/yaoweibin/nginx_tcp_proxy_module">custom module for this by Weibin Yao</a>, <a href="http://www.letseehere.com/reverse-proxy-web-sockets">see here </a>). However, you cannot run another service on the same port (e.g. your main app and Socket.io on port 80) as the TCP proxy does not support routing based on the URL (e.g. /socket.io/ to Socket.io and the rest to the main app), only simple load balancing.</p>
<p>So the benefit gained from doing this is quite marginal: sure, you can use Nginx for load balancing, but you will still be working with alternative ports for your main app and Socket.io.</p>
<h2>Alternatives to Nginx</h2>
<p>Since you can&#8217;t use Nginx and support Websockets,  you&#8217;ll need to deal with two separate problems:</p>
<ol>
<li>How to terminate SSL connections and</li>
<li>How to route HTTP traffic to the right backend based on the URL / load balance</li>
</ol>
<p>If you want to run two services on the same port, then you will have to terminate SSL connections before doing anything else. There are several alternatives for SSL termination:</p>
<ul>
<li><a href="http://www.stunnel.org/">Stunnel</a>. Supports multiple SSL certificates per process, does simple SSL termination to another port.</li>
<li><a href="https://github.com/bumptech/stud">Stud</a>. Only supports one SSL certificate per invocation, does simple SSL termination to another port.</li>
<li><a href="http://www.apsis.ch/pound/">Pound</a>. An SSL-termination-capable reverse proxy and load balancer.</li>
<li>Node&#8217;s https. Can be made to do anything, but you&#8217;ll have to write it yourself.</li>
</ul>
<p>If you choose Stunnel or Stud, then you need a load balancer as well if you plan on having more than one Node instance in the backend.</p>
<p>HAProxy is not <em>generally compatible</em> with Websockets, but Socket.IO <span style="text-decoration: underline;">contains code which works around this issue</span> and allows you to use HAProxy. This means that the alternatives are:</p>
<ul>
<li>Stunnel for SSL termination + HAProxy for routing/load balancing</li>
<li>Stud for SSL termination + HAProxy for routing/load balancing</li>
<li>Pound (SSL and routing/load balancing)</li>
</ul>
<p>I haven&#8217;t looked into Pound more &#8211; mainly as I could not find info on it&#8217;s TCP reverse proxying capabilities (see the section on Flash sockets below), but <a href="http://the-rig.refinery29.com/post/7263057532/pound-and-varnish">it seems to work for these guys</a>.</p>
<h2>Setting up Stunnel</h2>
<p>The Stunnel part is quite simple:</p>
<pre>cert = /path/to/certfile.pem
; Service-level configuration
[https]
accept  = 443
connect = 8443</pre>
<p>If you only have one Node instance, you can skip setting up HAProxy, since you don&#8217;t need load balancing.</p>
<h2><strong>Setting up HAProxy</strong></h2>
<p><strong>Would you like Flash Sockets with that?</strong></p>
<p>Note that we need TCP mode in order to support Flash sockets, which do not speak HTTP.</p>
<p>Flash sockets are just plain and simple TCP sockets, which will start by sending the following payload: &#8216;&lt;policy-file-request/&gt;\0&#8242;. They expect to receive a Flash cross domain policy as a response.</p>
<p>Since Flash sockets don&#8217;t use HTTP, we need a load balancer which is capable of detecting the protocol of the request, and of forwarding non-HTTP requests to Socket.io.</p>
<p>HAProxy can do that, as it has two different modes of operation:</p>
<ul>
<li>HTTP mode &#8211; which allows you to specify the backend based on the URI</li>
<li>TCP mode &#8211; which can be used to load balance non-HTTP transports.</li>
</ul>
<p><strong>Main frontend</strong></p>
<p>We accept connections on two ports: 80 (HTTP) and 8443 (Stunnel-terminated HTTPS connections).</p>
<p>By default, everything goes to the backend app at port 3000. Some HTTP paths are selectively routed to socket.io</p>
<p>TCP mode is needed so that Flash socket connections can be passed through, and all non HTTP connections are sent to the TCP mode socket.io backend.<br />
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Main frontend</span><br />
frontend app<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">bind</span> 0.0.0.0:80<br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">bind</span> 0.0.0.0:<span style="color: #000000;">8443</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># Mode is TCP</span><br />
&nbsp; mode tcp<br />
&nbsp; <span style="color: #666666; font-style: italic;"># allow for many connections, with long timeout</span><br />
&nbsp; maxconn <span style="color: #000000;">200000</span><br />
&nbsp; timeout client <span style="color: #000000;">86400000</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;"># default to webapp backend</span><br />
&nbsp; default_backend webapp<br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;"># two URLs need to go to the node pubsub backend</span><br />
&nbsp; acl is_socket_io path_beg <span style="color: #000000; font-weight: bold;">/</span>node<br />
&nbsp; acl is_socket_io path_beg <span style="color: #000000; font-weight: bold;">/</span>socket.io<br />
&nbsp; &nbsp; &nbsp;use_backend socket_io <span style="color: #000000; font-weight: bold;">if</span> is_socket_io<br />
<br />
&nbsp; &nbsp;tcp-request inspect-delay 500ms<br />
&nbsp; &nbsp;tcp-request content accept <span style="color: #000000; font-weight: bold;">if</span> HTTP<br />
&nbsp; &nbsp;use_backend sio_tcp <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span>HTTP</div></div></div></p>
<p><strong>Port 843: Flash policy</strong></p>
<p>Flash policy should be made available on 843.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Flash policy frontend</span><br />
frontend flashpolicy 0.0.0.0:<span style="color: #000000;">843</span><br />
&nbsp; &nbsp;mode tcp<br />
&nbsp; &nbsp;default_backend sio_tcp</div></div></div>
<p><strong>Default backend</strong></p>
<p>This is just for your main application.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;">backend webapp<br />
&nbsp; &nbsp;mode http<br />
&nbsp; &nbsp;option httplog<br />
&nbsp; &nbsp;option httpclose<br />
&nbsp; &nbsp;server nginx1s localhost:<span style="color: #000000;">3000</span> check</div></div></div>
<p><strong>Socket.io backend</strong></p>
<p>Here, we have a bunch of settings in order to allow Websockets connections through HAProxy.</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;">backend socket_io<br />
&nbsp; mode http<br />
&nbsp; option &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;httplog<br />
&nbsp; <span style="color: #666666; font-style: italic;"># long timeout</span><br />
&nbsp; timeout server <span style="color: #000000;">86400000</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># check frequently to allow restarting</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># the node backend</span><br />
&nbsp; timeout check 1s<br />
&nbsp; <span style="color: #666666; font-style: italic;"># add X-Forwarded-For</span><br />
  &nbsp;option forwardfor<br />
&nbsp; <span style="color: #666666; font-style: italic;"># Do not use httpclose (= client and server</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># connections get closed), since it will close</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># Websockets connections</span><br />
&nbsp; no &nbsp; option httpclose<br />
&nbsp; <span style="color: #666666; font-style: italic;"># Use &quot;option http-server-close&quot; to preserve</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># client persistent connections while handling</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># every incoming request individually, dispatching</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># them one after another to servers, in HTTP close mode</span><br />
&nbsp; option http-server-close<br />
&nbsp; option forceclose<br />
&nbsp; <span style="color: #666666; font-style: italic;"># just one node server at :8000</span><br />
&nbsp; server node1 localhost:<span style="color: #000000;">8000</span> maxconn <span style="color: #000000;">2000</span> check</div></div></div>
<p><strong>Socket.io backend in TCP mode</strong></p>
<p>This is the same server as above, but accessed in TCP mode.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;">backend sio_tcp<br />
&nbsp; mode tcp<br />
&nbsp; server node2 localhost:<span style="color: #000000;">8000</span> maxconn <span style="color: #000000;">2000</span> check</div></div></div>
<h2>Conclusion</h2>
<p>The configs above allow you to serve Websockets, Flash and polling from a single port.</p>
<p>However, I am dissatisfied by the complexity of this configuration. In particular, Flash sockets&#8217; TCP requirements are rather painful since they require protocol detection in order to work from a single port.</p>
<p>The alternative is of course to run Socket.io on a different port than your main app. This would mean that you configure HAProxy to just do TCP mode load balancing at that port, with SSL termination in front of HAProxy.</p>
<p>If you do that, you might want to configure a fallback from Nginx at port 80 to Socket.io for those clients who are behind draconian corporate firewalls which disallow ports other than 80 and 443. The fallback will only support long polling and I don&#8217;t think Socket.io itself supports automatically switching ports during transport negotiation, but you can detect a failure in Socket.io and re-initialize manually with a different port and polling-only transport.</p>
<p>Do you have a better way? How do you deploy Socket.io? Let me know in the comments below.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Collaborative git reference</title>
		<link>http://blog.mixu.net/2011/08/06/collaborative-git-reference/</link>
		<comments>http://blog.mixu.net/2011/08/06/collaborative-git-reference/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 03:11:02 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=1977</guid>
		<description><![CDATA[Here is a basic reference for collaborative git commands: Checkout a remote branch # list branches first git branch -a # * master # remotes/origin/branch_name git checkout -b local_name remotes/origin/branch_name Merging # switch to master git checkout master # merge with experimental branch git merge experimental Create a tag # list tags git tag # [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a basic reference for collaborative git commands:</p>
<h2>Checkout a remote branch</h2>
<pre># list branches first
git branch -a
# * master
# remotes/origin/branch_name
git checkout -b local_name remotes/origin/branch_name</pre>
<h2>Merging</h2>
<pre># switch to master
git checkout master
# merge with experimental branch
git merge experimental</pre>
<h2>Create a tag</h2>
<pre># list tags
git tag
# add a tag
git tag tagname
# push to remote
git push origin master --tags</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/08/06/collaborative-git-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dwm tips on Fedora</title>
		<link>http://blog.mixu.net/2011/06/11/dwm-tips-on-fedora/</link>
		<comments>http://blog.mixu.net/2011/06/11/dwm-tips-on-fedora/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 20:49:24 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=1885</guid>
		<description><![CDATA[I&#8217;ve been testing out Fedora 15&#8242;s Gnome 3 and Ubuntu&#8217;s Unity, and didn&#8217;t like either of them. They both take up too much precious screen space just to show a fancy UI, and requiring hardware acceleration is a pain for low end netbooks and virtual machines. So I decided to move to an alternative window [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been testing out Fedora 15&#8242;s Gnome 3 and Ubuntu&#8217;s Unity, and didn&#8217;t like either of them. They both take up too much precious screen space just to show a fancy UI, and requiring hardware acceleration is a pain for low end netbooks and virtual machines.</p>
<p>So I decided to move to an alternative window manager. DWM (dynamic window manager, <a href="http://dwm.suckless.org/">http://dwm.suckless.org/</a>) is an extremely lightweight tiling window manager written in C which saves screen space and works pretty well as long as you don&#8217;t need to connect to wireless networks.</p>
<p>I&#8217;ve been pretty happy with it. The main drawback is that connecting to wireless networks is a pain in the ass as there are no proper GUI tools to do this. Check out these tips to get started with dwm</p>
<h2>0. Installing dwm on Fedora, keyboard shortcuts</h2>
<p>To install DWM, run yum install dwm. You can then choose to use dwm or Gnome or Kde in the login screen.</p>
<p>The default keyboard shortcuts are listed at man dwm or at <a href="http://man.suckless.org/dwm/1/dwm">http://man.suckless.org/dwm/1/dwm</a>.</p>
<h2>1. Customizing dwm</h2>
<p>Customizing dwm can be done by making changes to config.h and recompiling the window manager.</p>
<p>Fedora has a really nice package called dwm-user, which automates this process! Here is the package description:</p>
<p><em>dwm-start is a helper script for running and reconfiguring dwm if neccessarry. It&#8217;s the preferred way of starting dwm in Fedora.</em><br />
<em>Running  dwm-start starts Fedora build by default. If you wish to customize your configuration, put the dwm config header file to $HOME/.dwm/config.h and adjust it according to your needs. Every time the user configuration file has changed, dwm-start will rebuild the user dwm binary prior to its execution.</em></p>
<p>All you need to do is:</p>
<pre>sudo yum install dwm-user</pre>
<pre>mkdir ~/.dwm</pre>
<pre>cp /usr/src/dwm-user-5.8.2-6.fc14/config.def.h ~/.dwm/config.h</pre>
<p>E.g. install via yum, then make a ~/.dwm folder, then copy the config.h file and edit it. When you restart, you can choose dwm-user as your window manager which uses you custom version of dwm. For example, I remapped Meta (Cmd/Windows key) + h and meta + l to meta + pg up / pg down and meta + shift + q to meta + shift + end since I&#8217;m currently running Fedora on an OSX host.</p>
<p>You will probably make changes to the keyboard shortcuts. To find the keymap:</p>
<pre>sudo updatedb</pre>
<pre>locate keysymdef.h</pre>
<p>Keysymdef.h lists the names of the keys in X11.</p>
<h2>2. Tip: Guake is just as awesome on dwm</h2>
<p>By default, dwm launches xterm. I prefer to use guake, since that allows me to get the tabbed terminal window on any workspace when I need them. Just launch guake&amp; to run it in the background.</p>
<p><strong>UPDATE</strong>: I moved to F15 (deciding simply to ignore Gnome 3) and noticed that guake has problems starting. To fix those:</p>
<pre>sudo yum install xfce4-notifyd</pre>
<p>Basically you need a notify daemon to allow Guake to print that pretty message &#8220;Guake is running&#8221;, and xfce4-notifyd provides an alternative notifications daemon.</p>
<h2>3. Launch netbeans and other Java programs with font smoothing and GTK look and feel</h2>
<p>You need to specify a couple of extra switches to get the GTK look and feel in Java programs, for example:</p>
<p>/home/username/netbeans-7.0/bin/netbeans -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=on &#8211;laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel</p>
<h2>4. Launch nautilus without the desktop</h2>
<pre>nautilus --no-desktop</pre>
<h2>5. Use dwm with a dual screen setup</h2>
<p>If dwm starts with mirroring output to your secondary screen, then you need to run xrandr to get the names your screens. E.g. VBOX0 and VBOX1.</p>
<p>Then configure the screen layout:</p>
<pre>xrandr --output VBOX1 --auto --right-of VBOX0</pre>
<p>dwm will now let you have your own workspaces for each screen.</p>
<h2>6. Change your desktop background</h2>
<p>Use feh to change your desktop background:</p>
<pre>feh --bg-tile /path/to/background/image</pre>
<h2>7. xterm config</h2>
<p>For a usable xterm, create the following ~/.Xresources and run</p>
<div>
<pre><code>xrdb -merge .Xresources</code></pre>
</div>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.mixu.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><div class="bash" style="font-family:monospace;">xterm<span style="color: #000000; font-weight: bold;">*</span>faceName: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; monospace:<span style="color: #007800;">pixelsize</span>=14<br />
xterm<span style="color: #000000; font-weight: bold;">*</span>saveLines: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9999<br />
xterm<span style="color: #000000; font-weight: bold;">*</span>scrollBar: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">false</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>background: &nbsp;<span style="color: #666666; font-style: italic;">#000000</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>foreground: &nbsp;<span style="color: #666666; font-style: italic;">#dfdfdf</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color0: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#000000</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color1: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#9e1828</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color2: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#aece92</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color3: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#968a38</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color4: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#414171</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color5: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#963c59</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color6: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#418179</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color7: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#bebebe</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color8: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#666666</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color9: &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">#cf6171</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color10: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#c5f779</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color11: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#fff796</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color12: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#4186be</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color13: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#cf9ebe</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color14: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#71bebe</span><br />
xterm<span style="color: #000000; font-weight: bold;">*</span>color15: &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#ffffff</span></div></div></div>
<h2>8. Add a clock using xsetroot</h2>
<p>You can do something like this in a bash script to show the time in dwm on the top right corner.</p>
<div>
<div>
<pre>
<pre>while true; do
   xsetroot -name "$( date +"%F %R" )"
   sleep 1m    # Update time every minute
done</pre>
</pre>
<h2>9. Connect to wifi</h2>
<p>This is rather painful. The instructions here were collected from the mailing list, and I did get them to work, but I&#8217;m too lazy to write a full tutorial on this right now.</p>
<p>Basically, you need to scan, then do different things depending on whether the wifi uses WEP or WPA for authentication.</p>
<p>Start by running:</p>
</div>
</div>
<pre>iwlist scan</pre>
<h2>9.1 WEP wifi</h2>
<pre>&gt; &gt; #wep connect to a wep wifi
&gt; &gt; #! /bin/sh
&gt; &gt;
&gt; &gt; key="`grep $1 /home/pmarin/wep | cut -d' ' -f2`"
&gt; &gt; sudo ifconfig wlan0 up
&gt; &gt; sudo iwconfig wlan0 essid $1
&gt; &gt; sudo iwconfig wlan0 key s:$key
&gt; &gt; sudo dhclient wlan0
&gt; &gt; #end</pre>
<pre>&gt; &gt; The wep is a plain file with to columms
&gt; &gt;
&gt; &gt; essid  key</pre>
<h2>9.2 WPA wifi</h2>
<pre>&gt; &gt;
&gt; &gt; #wpa connect to a wpa wifi
&gt; &gt; #! /bin/sh
&gt; &gt;
&gt; &gt; sudo ifconfig wlan0 up
&gt; &gt; sudo iwconfig wlan0 essid $1
&gt; &gt; sudo wpa_supplicant -iwlan0 -c/home/pmarin/wpa -B
&gt; &gt; sudo dhclient wlan0
&gt; &gt; #end
&gt; &gt;
&gt; &gt; the wpa file is similar than /etc/wpa_supplicant.conf</pre>
<p>To create the wpa file:</p>
<div>
<pre dir="ltr">wpa_passphrase your_ssid_of_network your_network_password</pre>
<pre dir="ltr">Create the file:</pre>
<pre dir="ltr">
<div>
<pre dir="ltr">ctrl_interface=/var/run/wpa_supplicant
#ap_scan=2

network={
       ssid="your_ssid"
       scan_ssid=1
       proto=WPA RSN
       key_mgmt=WPA-PSK
       pairwise=CCMP TKIP
       group=CCMP TKIP
       psk=your_psk_from_wpa_passphrase
}</pre>
</div>
<div>
<pre dir="ltr">sudo wpa_supplicant -Bw -Dwext -i eth0 -c/etc/wpa_supplicant.conf</pre>
</div>
</pre>
</div>
<h2>9.3 Wifi troubleshooting:</h2>
<p>1) CHECK THAT YOU DON&#8217;T have the NetworkManager service or wpa_supplicant running already!!!</p>
<p>You can run wpa_supplicant with -dd flag for a detailed debug output.1) If you don&#8217;t manage to connect to the AccessPoint, try to uncomment line 2 in /etc/wpa_supplicant.conf.</p>
<p>2) If that doesn&#8217;t help, try change its value to 0 or 1.</p>
<p>3) If you get troubles while authenticating, try removing &#8220;RSN&#8221; and/or&#8221;CCMP&#8221; strings from /etc/wpa_supplicant.conf.</p>
<p>Sources for Wifi stuff:</p>
<p><a href="http://ubuntuforums.org/showthread.php?t=263136">http://ubuntuforums.org/showthread.php?t=263136</a></p>
<p><a href="http://www.mail-archive.com/dwm@suckless.org/msg06800.html">http://www.mail-archive.com/dwm@suckless.org/msg06800.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/06/11/dwm-tips-on-fedora/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hello San Francisco!</title>
		<link>http://blog.mixu.net/2011/06/06/hello-san-francisco/</link>
		<comments>http://blog.mixu.net/2011/06/06/hello-san-francisco/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 04:32:16 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=1870</guid>
		<description><![CDATA[If you&#8217;ve been wondering why I haven&#8217;t been writing much on the blog recently, here is why: I just got my visa to the US and moved to San Francisco for an internship! I&#8217;ll be here for the next 12 months on that visa. That process + wrapping up my life in Finland took a [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been wondering why I haven&#8217;t been writing much on the blog recently, here is why: I just got my visa to the US and moved to San Francisco for an internship! I&#8217;ll be here for the next 12 months on that visa. That process + wrapping up my life in Finland took a lot of my free time, the rest went to reviewing a coming-soon Kohana 3 book from Apress for which I&#8217;m a technical reviewer, and my writing project related to Node.js which I am hoping to move forward soon. I also gave a talk at <a href="http://frontend.fi/">Frontend.fi</a> on Node (my first tech talk), and released a small library (node-winamp) to control Winamp over LAN from the console using Node.</p>
<p>My new years resolution was to ship more, but I never expected to ship my own ass over to San Francisco! It&#8217;ll be awesome.</p>
<p>I flew in on June 3rd, and have been here for two days. So far, everything has been pretty awesome, though I still need to find an apartment rental and get the final paperwork done on this side!</p>
<p>Since I&#8217;ll be able to concentrate more on code instead of living the triple life of a doctoral student, individual entrepreneur and open source programmer, I hope to start building a solid streak of open source/fun coding while I&#8217;m here. I read something on HN recently which I think will be good to keep in mind:</p>
<p><em>&#8220;I have a rule: I refuse to go to sleep if I haven’t read and written some code on a given day (this doesn’t include the code I write for work, of course). So far, this rule has had a positive impact on my ability to code.&#8221;</em></p>
<p>I&#8217;ll try to apply that rule, perhaps using <a href="http://42goals.com/demo/">42goals.com</a> or the <a href="http://calendaraboutnothing.com/">Calendar About Nothing</a>&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/06/06/hello-san-francisco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick tip: Fix Flash audio stutter on Fedora 14 (64bit)</title>
		<link>http://blog.mixu.net/2011/02/24/quick-tip-fix-flash-audio-stutter-on-fedora-14-64bit/</link>
		<comments>http://blog.mixu.net/2011/02/24/quick-tip-fix-flash-audio-stutter-on-fedora-14-64bit/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 15:16:37 +0000</pubDate>
		<dc:creator>Mikito Takada</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.mixu.net/?p=1817</guid>
		<description><![CDATA[On my FC14 machine, I had a problem with Flash (64bit) audio playback: the sound on sites other than Youtube would stutter terribly. It appears that this a systematic problem; but luckily there is a fix! Check out Ahmed Abdo&#8217;s post on Flash audio stutter for the details. Works perfectly for me! Details: https://bugzilla.redhat.com/show_bug.cgi?id=638477 The bug [...]]]></description>
			<content:encoded><![CDATA[<p>On my FC14 machine, I had a problem with Flash (64bit) audio playback: the sound on sites other than Youtube would stutter terribly. It appears that this a systematic problem; but luckily there is a fix!</p>
<p>Check out <a href="http://ahabdo.wordpress.com/2011/01/03/flash-64-bit-crappy-sound-fix-for-fedora-14/">Ahmed Abdo&#8217;s post on Flash audio stutter for the details</a>. Works perfectly for me!</p>
<p>Details: <a href="https://bugzilla.redhat.com/show_bug.cgi?id=638477">https://bugzilla.redhat.com/show_bug.cgi?id=638477</a> </p>
<p>The bug is triggered by a change in glibc. Who proposed the fix? <strong>Linus Torvalds</strong>. So I guess the following isn&#8217;t quite true?</p>
<p><img class="alignnone" title="xkcd" src="http://imgs.xkcd.com/comics/supported_features.png" alt="" width="324" height="326" /></p>
<p>I love the pragmatism from his part:</p>
<blockquote><p>
<em>So in the kernel we have a pretty strict &#8220;no regressions&#8221; rule, and that if people depend on interfaces we exported having side effects that weren&#8217;t intentional, we try to fix things so that they still work unless there is a major reason not to.</p>
<p>So I&#8217;m disappointed glibc just closes this as NOTABUG. There&#8217;s no real reason to do the copy backwards that I can see, so doing it that way is just stupid. </p>
<p>But whatever. You can do a LD_PRELOAD trick to get a sane memcpy(), and it does indeed fix the sound for me.<br />
[...]<br />
The fact that the glibc people don&#8217;t do that, and that this hasn&#8217;t been elevated despite clearly being a big usability problem (normal users SHOULD NOT HAVE TO google bugzillas and play with LD_PRELOAD to have a working system), is just sad.</em>
</p></blockquote>
<p>Although overall, as an end user it the conversation around this bug and its persistence makes me sad. I know it&#8217;s selfish not to care about the technical superiority of a solution or about who is to blame here &#8211; but I&#8217;d just like to have my smooth Flash playback&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mixu.net/2011/02/24/quick-tip-fix-flash-audio-stutter-on-fedora-14-64bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

