<?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>Oli&#039;s 2 cents</title>
	<atom:link href="http://www.oelerich.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oelerich.org</link>
	<description>webdevelopment, physics &#039;n&#039; stuff</description>
	<lastBuildDate>Tue, 10 Apr 2012 14:03:21 +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>How to set the urgency hint for new mail in Thunderbird</title>
		<link>http://www.oelerich.org/how-to-set-the-urgency-hint-for-new-mail-in-thunderbird/</link>
		<comments>http://www.oelerich.org/how-to-set-the-urgency-hint-for-new-mail-in-thunderbird/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 14:03:10 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[i3wm]]></category>
		<category><![CDATA[thunderbird]]></category>
		<category><![CDATA[urgency hint]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=446</guid>
		<description><![CDATA[Some window managers, including i3wm, the one I use at the moment, highlight windows and desktop tabs when the window or one of it&#8217;s children sets the X urgency hint. irssi, for example, supports that, allowing for nice and silent notifications when somebody querys or mentions you. However, even after hours of googeling, I couldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Some window managers, including <a href="http://www.i3wm.org" title="i3 WM" target="_blank">i3wm</a>, the one I use at the moment, highlight windows and desktop tabs when the window or one of it&#8217;s children sets the <strong>X urgency hint</strong>. <a href="http://irssi.org/" title="irssi" target="_blank">irssi</a>, for example, supports that, allowing for nice and silent notifications when somebody querys or mentions you. However, even after hours of googeling, I couldn&#8217;t find any way to make <a href="http://www.mozilla.org/thunderbird/" title="Thunderbird" target="_blank">Thunderbird</a> set this flag when new mail arrives. This is why I came up with my own solution. I wrote a python script that finds the Thunderbird window and set&#8217;s the urgency hint using the <a href="http://python-xlib.sourceforge.net/" title="Python Xlib" target="_blank">python-xlib</a> (which you would have to install yourself!) bindings. I then installed the Thunderbird extension <a href="http://tjeb.nl/Projects/Mailbox_Alert/" title="Mailbox Alert" target="_blank">Mailbox Alert</a>, that allows you to specify scripts to be executed when new mail arrives &#8211; even on a per-folder basis. (The extension is pretty awesome, you should definitely check it out!) With that, everything works perfectly now.</p>
<p>The script setting the urgency hint is pretty basic. Here it is:</p>
<div class="codecolorer-container python railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/python2</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">from</span> Xlib <span style="color: #ff7700;font-weight:bold;">import</span> X<span style="color: #66cc66;">,</span> display<span style="color: #66cc66;">,</span> Xutil<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> find_window<span style="color: black;">&#40;</span>name<span style="color: #66cc66;">,</span> w<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> win <span style="color: #ff7700;font-weight:bold;">in</span> w.<span style="color: black;">query_tree</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">children</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> win.<span style="color: black;">get_wm_class</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> win.<span style="color: black;">get_wm_class</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">==</span> name:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> win<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>win.<span style="color: black;">query_tree</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">children</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a <span style="color: #66cc66;">=</span> find_window<span style="color: black;">&#40;</span>name<span style="color: #66cc66;">,</span> win<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> a:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> a<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span>disp<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; win <span style="color: #66cc66;">=</span> find_window<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Thunderbird&quot;</span><span style="color: #66cc66;">,</span> disp.<span style="color: black;">screen</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">root</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; hints <span style="color: #66cc66;">=</span> win.<span style="color: black;">get_wm_hints</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'flags'</span>: <span style="color: #ff4500;">0</span> <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; hints<span style="color: black;">&#91;</span><span style="color: #483d8b;">'flags'</span><span style="color: black;">&#93;</span> |<span style="color: #66cc66;">=</span> Xutil.<span style="color: black;">UrgencyHint</span><br />
<br />
&nbsp; &nbsp; win.<span style="color: black;">set_wm_hints</span><span style="color: black;">&#40;</span>hints<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; disp.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'__main__'</span>:<br />
&nbsp; &nbsp; main<span style="color: black;">&#40;</span>display.<span style="color: black;">Display</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/how-to-set-the-urgency-hint-for-new-mail-in-thunderbird/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to host your own dyndns clone</title>
		<link>http://www.oelerich.org/how-to-host-your-own-dyndns-clone/</link>
		<comments>http://www.oelerich.org/how-to-host-your-own-dyndns-clone/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 09:01:07 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[dyndns]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=437</guid>
		<description><![CDATA[One of the things I use my vServer for is some sort of dyndns service. I need my home computer to be accessible from the outside without knowing it&#8217;s dynamic IP address. In this article, I will describe briefly how you can reach that. You will need some sort of own webserver with at least [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I use my vServer for is some sort of dyndns service. I need my home computer to be accessible from the outside without knowing it&#8217;s dynamic IP address. In this article, I will describe briefly how you can reach that. You will need some sort of own webserver with at least a static IP address and you need to be able to edit the zone file of one of your domains. Also, you should know what a zone file is or dig into it, before you start.<br />
<span id="more-437"></span><br />
What I basically did is the following: I installed a DNS server on my vServer and set the subdomains <code class="codecolorer text default"><span class="text">*.SUB.DOMAIN.TLD</span></code> to be redirected to my server. When the main DNS server encounters a request to one of those sub-sub-domains, it will redirect it to my server and thus allow me to answer dynamically with my home computer&#8217;s IP address. Throughout the article I will use the above scheme for the domains, that you will want to edit to fit your purposes: <code class="codecolorer text default"><span class="text">PC.SUB.DOMAIN.TLD</span></code>, where <code class="codecolorer text default"><span class="text">DOMAIN.TLD</span></code> is some domain you own and are able to edit the zone file for, <code class="codecolorer text default"><span class="text">SUB</span></code> is some subdomain to chose for your DNS namespace and <code class="codecolorer text default"><span class="text">PC</span></code> would be the identifier of your computer at home. (You can choose this arbitrarily).</p>
<h3>Set up a DNS server</h3>
<p>I must say, that I don&#8217;t know exactly anymore, what I did. I believe after installing the named daemon, <code class="codecolorer text default"><span class="text">bind9</span></code>, I only edited <code class="codecolorer text default"><span class="text">/etc/bind/named.conf.local</span></code> and added the following:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">zone <span style="color: #ff0000;">&quot;SUB.DOMAIN.TLD&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">type</span> master;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #ff0000;">&quot;/etc/bind/zones/db.SUB.YOURDOMAIN.org&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow-update <span style="color: #7a0874; font-weight: bold;">&#123;</span> key <span style="color: #ff0000;">&quot;rndc-key&quot;</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; notify <span style="color: #c20cb9; font-weight: bold;">yes</span>;<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span>;</div></div>
<p>Then, create <code class="codecolorer text default"><span class="text">/etc/bind/zones/db.SUB.DOMAIN.TLD</span></code> and insert your desired zone file code, for example:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ORIGIN .<br />
$TTL 86400 &nbsp; &nbsp; &nbsp;; 1 day<br />
SUB.DOMAIN.TLD &nbsp; &nbsp; &nbsp; &nbsp; IN SOA &nbsp;SUB.DOMAIN.TLD. EMAIL.DOMAIN.TLD. (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2001072085 ; serial<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10800 &nbsp; &nbsp; &nbsp;; refresh (3 hours)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3600 &nbsp; &nbsp; &nbsp; ; retry (1 hour)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1814400 &nbsp; &nbsp;; expire (3 weeks)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 86400 &nbsp; &nbsp; &nbsp;; minimum (1 day)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NS &nbsp; &nbsp; &nbsp;SUB.DOMAIN.TLD.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; YOUR.SERVER.IP.ADDRESS<br />
$ORIGIN SUB.DOMAIN.TLD.<br />
PC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A &nbsp; &nbsp; &nbsp; YOUR.HOME.IP.ADDRESS</div></div>
<p>Replace <code class="codecolorer text default"><span class="text">PC</span></code>, <code class="codecolorer text default"><span class="text">SUB.DOMAIN.TLD</span></code>, <code class="codecolorer text default"><span class="text">EMAIL.DOMAIN.TLD</span></code>, <code class="codecolorer text default"><span class="text">YOUR.SERVER.IP.ADDRESS</span></code> and <code class="codecolorer text default"><span class="text">YOUR.HOME.IP.ADDRESS</span></code> with the appropriate values. (The last one is the line we will constantly be updating) As described above, your home computer will then be reachable with <code class="codecolorer text default"><span class="text">PC.SUB.DOMAIN.TLD</span></code>. </p>
<h3>Redirect SUB.DOMAIN.TLD to your server</h3>
<p>As I said, you need access to the zone file of <code class="codecolorer text default"><span class="text">DOMAIN.TLD</span></code>. If you have, just insert this line:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SUB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IN NS &nbsp; &nbsp; &nbsp;YOUR.SERVER.IP.ADDRESS</div></div>
<p>replacing <code class="codecolorer text default"><span class="text">SUB</span></code> with what you want to use as a subdomain and <code class="codecolorer text default"><span class="text">YOUR.SERVER.IP.ADDRESS</span></code> with the IP address of your server.<br />
It will take a while for the DNS servers to update the zone. </p>
<h3>Create the update scripts</h3>
<p>To make your server aware of a change of your IP address, you have to tell it whenever you reconnect to the internet and are assigned a new IP address. We thus create two scripts in <code class="codecolorer text default"><span class="text">/etc/bind/zones/</span></code>:</p>
<ul>
<li> updatescript
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #666666; font-style: italic;"># usage: &nbsp;do-nsupdate [text-file-containing-nsupdate-instructions]</span><br />
nsupdate <span style="color: #660033;">-y</span> <span style="color: #ff0000;">&quot;rndc-key:YOUR_RNDC_KEY&quot;</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">$1</span></div></div>
</li>
<li> updatefile
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">server SUB.DOMAIN.TLD<br />
zone SUB.DOMAIN.TLD<br />
update delete PC.SUB.DOMAIN.TLD A<br />
update add PC.SUB.DOMAIN.TLD 86400 A 0.0.0.0<br />
show<br />
send</div></div>
</li>
</ul>
<p>Replace <code class="codecolorer text default"><span class="text">YOUR_RNDC_KEY</span></code> with the secret value in <code class="codecolorer text default"><span class="text">/etc/bind/rndc.key</span></code> and edit the updatefile according to your data.</p>
<h3>Replace the IP address and run the updatescript</h3>
<p>You will now need the following, and I will leave it up to you how you do this. (I would be glad about nice solutions in the comments!) Whenever you reconnect to the internet (there are hooks for <strong>WICD</strong>, <strong>NetworkManager</strong> etc. that you can use), update the <code class="codecolorer text default"><span class="text">0.0.0.0</span></code> in <code class="codecolorer text default"><span class="text">/etc/bind/zones/updatefile</span></code> with your home computer&#8217;s new IP address and run <code class="codecolorer text default"><span class="text">/etc/bind/zones/updatescript /etc/bind/zones/updatefile</span></code> and your zone file will be updated. </p>
<p>I myself solved this with a small PHP script, reading out the requester&#8217;s IP address and then updating and running the DNS update:</p>
<div class="codecolorer-container php railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">...</span><br />
<span style="color: #000088;">$upd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sed -i 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/g' /etc/bind/zones/updatefile&quot;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/system"><span style="color: #990000;">system</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$upd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.php.net/system"><span style="color: #990000;">system</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/etc/bind/zones/updatescript /etc/bind/zones/updatefile&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">...</span></div></div>
<p>However, there certainly are nicer solutions involving just one request. One can, for example, read out the IP address when using an SSH request and then just execute the above commands over SSH. This would be more elegant than my solution. </p>
<p>The hook for WICD would be placed on your home computer in <code class="codecolorer text default"><span class="text">/etc/wicd/scripts/postconnect/hook.sh</span></code> and will be executed after successfull connection to the internet. NetworkManager stores it&#8217;s hooks in <code class="codecolorer text default"><span class="text">/etc/NetworkManager/dispatcher.d</span></code>. You have to google to find the appropriate way to use these hooks.</p>
<h3>Soooooooo&#8230;</h3>
<p>I hope I could be a bit helpful, and at least make clear how you can use your own server to act as some Dyndns-like service. If you succeed in setting the service up following my guidelines and/or if there is something missing here, I would be glad about a comment. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/how-to-host-your-own-dyndns-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a virtual machine as local development webserver</title>
		<link>http://www.oelerich.org/using-a-virtual-machine-as-local-development-webserver/</link>
		<comments>http://www.oelerich.org/using-a-virtual-machine-as-local-development-webserver/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 21:33:44 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[virtualbox]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=426</guid>
		<description><![CDATA[I like my linux to be as clean as possible and therefore hate packages with gazillions of dependencies, that I may only need once.  I tend to forget about these packages and they are then sitting there, eating precious SSD space (where my root system is located). Especially when it comes to webdevelopment, webservers etc. [...]]]></description>
			<content:encoded><![CDATA[<p>I like my linux to be as clean as possible and therefore hate packages with gazillions of dependencies, that I may only need once.  I tend to forget about these packages and they are then sitting there, eating precious SSD space (where my root system is located). Especially when it comes to webdevelopment, webservers etc. this bugs me a lot, since a working LAMP server together with Python and all the extensions I need takes up a lot of space, config files in <code class="codecolorer text default"><span class="text">/etc</span></code> and consists of many packages. This is why I recently switched to a virtual machine as development server. The advantages are the following:</p>
<ul>
<li>I can separate all the webserver and scripting language stuff from my root filesystem</li>
<li>It is portable</li>
<li>I can use a distribution similar to the one running on my (real) webserver, which makes deployment easier.</li>
<li>It works (nearly) exactly as if I used the main filesystem, since today&#8217;s computers are powerful and memory big enough.</li>
</ul>
<p>I will outline briefly what I did:<br />
<span id="more-426"></span></p>
<ol>
<li>Install Debian in a VirtualBox VM without graphical interface (that option is displayed during the Debian installation)</li>
<li> Start the VM once with VirtualBox and configure SSH access.</li>
<li>Configure Port forwarding for ports <code class="codecolorer text default"><span class="text">80</span></code> and <code class="codecolorer text default"><span class="text">22</span></code> (HTTP and SSH) in VirtualBox: Go to the &#8220;Network&#8221; Settings of the VM, expand the &#8220;Advanced Settings&#8221; of &#8220;Adapter 1&#8243; (should be attached to NAT) and click on &#8220;Port Forwarding&#8221;. Now map the host ports <code class="codecolorer text default"><span class="text">8080</span></code> and <code class="codecolorer text default"><span class="text">2222</span></code> to <code class="codecolorer text default"><span class="text">80</span></code> and <code class="codecolorer text default"><span class="text">22</span></code> respectively. (You can of course feel free to use the ports you like)</li>
<li>When SSH access (<code class="codecolorer text default"><span class="text">localhost:2222</span></code>) works, shut down the VM. You will now always use the VBoxHeadless tool to start it, which starts the VM in the background. (Attention: Don&#8217;t forget it after you are done working. It eats up a lot of memory!)</li>
</ol>
<p>To control the VM and ease access to it, you can create an init script or a systemd service. Here is the latter one I use:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Unit<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #007800;">Description</span>=Webserver<br />
<br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Service<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #007800;">Type</span>=simple<br />
<span style="color: #007800;">ExecStart</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>vboxheadless <span style="color: #660033;">--startvm</span> <span style="color: #ff0000;">&quot;NAME_OF_WEBSERVER_VM&quot;</span> <span style="color: #660033;">--vrde</span> off<br />
<span style="color: #007800;">ExecStop</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>VBoxManage controlvm <span style="color: #ff0000;">&quot;NAME_OF_WEBSERVER_VM&quot;</span> savestate<br />
<span style="color: #007800;">Restart</span>=always<br />
<span style="color: #007800;">User</span>=YOUR_USERNAME</div></div>
<p>Also, you should configure your SSH to have an easy shortcut to access the server:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Host SHORTCUT<br />
&nbsp; Hostname localhost<br />
&nbsp; Port <span style="color: #000000;">2222</span><br />
&nbsp; User SHORTCUT</div></div>
<p>There are two options to work on the files.</p>
<ol>
<li>Use sshfs: <code class="codecolorer text default"><span class="text">sshfs SHORTCUT webserver/</span></code> and then work within this directory. (It mounts the webserver using SSH) This is my preferred way, since the files are then stored on the VM.</li>
<li>Use Virtualbox&#8217;s shared folder feature.</li>
</ol>
<p>All urls defined in <code class="codecolorer text default"><span class="text">/etc/hosts</span></code> on the host machine should be redirected on the vm if you append <code class="codecolorer text default"><span class="text">:8080</span></code> to the address.</p>
<p>I hope, some of you find the idea useful. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/using-a-virtual-machine-as-local-development-webserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I love free software!</title>
		<link>http://www.oelerich.org/i-love-free-software/</link>
		<comments>http://www.oelerich.org/i-love-free-software/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 08:48:06 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=422</guid>
		<description><![CDATA[And today is the &#8220;I love free software day&#8221; where everybody is encouraged to express his love for free software. I am doing it with this post. Have a nice valentines and free software day!]]></description>
			<content:encoded><![CDATA[<p>And today is the &#8220;I love free software day&#8221; where everybody is encouraged to express his love for free software. I am doing it with this post.</p>
<p><a href="http://fsfe.org/campaigns/ilovefs/2012/ilovefs-2012.html"><img class="aligncenter" style="border: 0 !important;" src="http://fsfe.org/campaigns/valentine/vd-i-love-fs-trans-150x90.png" alt="I love Free Software!" /></a></p>
<p>Have a nice valentines and free software day!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/i-love-free-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Openbox pipemenu to control virtual machines of VirtualBox</title>
		<link>http://www.oelerich.org/openbox-pipemenu-to-control-virtual-machines-of-virtualbox/</link>
		<comments>http://www.oelerich.org/openbox-pipemenu-to-control-virtual-machines-of-virtualbox/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 16:05:21 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[openbox]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=411</guid>
		<description><![CDATA[Openbox, Virtualbox&#8230; Coincidence? I don&#8217;t know. Anyway, I am a huge fan of VirtualBox, for the virtual machines are extremely fast, stable and nice to control. With the command line tool VBoxManage comes a nice tool for all those CLI-lovers out there. You can literally do anything with it, what the GUI can do. (at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://openbox.org/">Openbox</a>, <a href="https://www.virtualbox.org/">Virtualbox</a>&#8230; Coincidence? I don&#8217;t know. Anyway, I am a huge fan of VirtualBox, for the virtual machines are extremely fast, stable and nice to control. With the command line tool <code class="codecolorer text default"><span class="text">VBoxManage</span></code> comes a nice tool for all those CLI-lovers out there. You can literally do anything with it, what the GUI can do. (at least it looks like that) </p>
<p>Now, starting the GUI to start a VM is a bit slow, so <code class="codecolorer text default"><span class="text">VBoxManage startvm &quot;vm&quot;</span></code> is a huge time- and memorysaver.<br />
Since I work with Openbox, the natural thing for me was to google for a suitable <strong>pipemenu</strong>. Unfortunately, I couldn&#8217;t find one. Long story short: Here is my self-written Openbox pipemenu to control VirtualBox&#8217;s VMs. (It can start and stop them, at least.)<br />
<span id="more-411"></span><br />
Put it somewhere, make it executable and set it as a pipemenu in your menu.xml file.</p>
<div class="codecolorer-container python railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span><span style="color: #66cc66;">,</span><span style="color: #dc143c;">re</span><br />
<br />
<span style="color: #808080; font-style: italic;"># kill action: 0 -&gt; power off, 1 -&gt; save state</span><br />
killAction <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Only change anything below this comment if you know, what you're doing!!</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;?xml version=<span style="color: #000099; font-weight: bold;">\&quot;</span>1.0<span style="color: #000099; font-weight: bold;">\&quot;</span> encoding=<span style="color: #000099; font-weight: bold;">\&quot;</span>UTF-8<span style="color: #000099; font-weight: bold;">\&quot;</span>?&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;openbox_pipe_menu&gt;&quot;</span><span style="color: black;">&#41;</span><br />
<br />
killActions &nbsp; <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">'poweroff'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'savestate'</span><span style="color: black;">&#93;</span><br />
notRunningVms <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
runningVms &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
vmNamePattern <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;(.+)&quot; .*'</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> vm <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">check_output</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'VBoxManage'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'list'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'vms'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf-8&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; match <span style="color: #66cc66;">=</span> vmNamePattern.<span style="color: black;">match</span><span style="color: black;">&#40;</span>vm<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> match:<br />
&nbsp; &nbsp; &nbsp; &nbsp; notRunningVms.<span style="color: black;">append</span><span style="color: black;">&#40;</span>match.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> vm <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">check_output</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'VBoxManage'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'list'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'runningvms'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf-8&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; match <span style="color: #66cc66;">=</span> vmNamePattern.<span style="color: black;">match</span><span style="color: black;">&#40;</span>vm<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> match:<br />
&nbsp; &nbsp; &nbsp; &nbsp; runningVms.<span style="color: black;">append</span><span style="color: black;">&#40;</span>match.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; notRunningVms.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>match.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>notRunningVms<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;separator label=<span style="color: #000099; font-weight: bold;">\&quot;</span>Start VM<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> vm <span style="color: #ff7700;font-weight:bold;">in</span> notRunningVms:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;item label=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + vm + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;action name=<span style="color: #000099; font-weight: bold;">\&quot;</span>Execute<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;execute&gt;VBoxManage startvm <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + vm + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;/execute&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/action&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/item&gt;&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>runningVms<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;separator label=<span style="color: #000099; font-weight: bold;">\&quot;</span>Stop VM<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> vm <span style="color: #ff7700;font-weight:bold;">in</span> runningVms:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;item label=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + vm + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;action name=<span style="color: #000099; font-weight: bold;">\&quot;</span>Execute<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;execute&gt;VBoxManage controlvm <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + vm + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> + killActions<span style="color: black;">&#91;</span>killAction<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;&lt;/execute&gt;&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/action&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/item&gt;&quot;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/openbox_pipe_menu&gt;&quot;</span><span style="color: black;">&#41;</span></div></div>
<p>To set whether VMs should be powered off or if their state should be saved, edit the value of <code class="codecolorer text default"><span class="text">killAction</span></code> in the script. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/openbox-pipemenu-to-control-virtual-machines-of-virtualbox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My new emacs setup (no .emacs here, don&#8217;t worry)</title>
		<link>http://www.oelerich.org/my-new-emacs-setup/</link>
		<comments>http://www.oelerich.org/my-new-emacs-setup/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 19:10:29 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=345</guid>
		<description><![CDATA[After having used emacs for a couple of months now, I discovered the emacs --daemon option today and was astonished. Having quite a big emacs config, it takes ages for emacs to start preventing me from using it as the standard editor for config files etc. The --daemon mode starts emacs in the background acting [...]]]></description>
			<content:encoded><![CDATA[<p>After having used emacs for a couple of months now, I discovered the <code class="codecolorer text default"><span class="text">emacs --daemon</span></code> option today and was astonished. Having quite a big emacs config, it takes ages for emacs to start preventing me from using it as the standard editor for config files etc. The <code class="codecolorer text default"><span class="text">--daemon</span></code> mode starts emacs in the background acting as a server and allows one to create emacs frames using the <code class="codecolorer text default"><span class="text">emacsclient</span></code> in various ways. EMacs shows up lightning-fast then and becomes an option for the always-to-use text editor.</p>
<p><a href="http://www.oelerich.org/wp-content/uploads/2011/10/10848648.jpg"><img src="http://www.oelerich.org/wp-content/uploads/2011/10/10848648.jpg" alt="" title="10848648" width="400" height="300" class="aligncenter size-full wp-image-349" /></a><br />
<span id="more-345"></span><br />
Here is my setup on how to work with emacs and use it as an editor for quickly editing files on the command line.</p>
<h3>Starting the daemon using systemd</h3>
<p>I switched from sysVinit to systemd some time ago, so the most convenient thing to do is to start the emacs daemon using a custom systemd service file. Put the following code into the file  <code class="codecolorer text default"><span class="text">/etc/systemd/system/multi-user.target.wants/emacs.service</span></code>:</p>
<div class="codecolorer-container ini railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>Unit<span style="">&#93;</span></span><br />
<span style="color: #000099;">Description</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">Emacs: the extensible, self-documenting text editor</span><br />
<br />
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>Service<span style="">&#93;</span></span><br />
<span style="color: #000099;">Type</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">forking</span><br />
<span style="color: #000099;">ExecStart</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/usr/bin/emacs --daemon</span><br />
<span style="color: #000099;">ExecStop</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/usr/bin/emacsclient --eval </span><span style="color: #933;">&quot;(progn (setq kill-emacs-hook 'nil) (kill-emacs))&quot;</span><br />
<span style="color: #000099;">Restart</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">always</span><br />
<span style="color: #000099;">User</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">YOUR_USERNAME</span></div></div>
<p>Make sure you insert your username in the bottom line. Now, enable the service executing <code class="codecolorer text default"><span class="text">systemctl enable emacs.service</span></code> and after the next boot the daemon is started automatically.</p>
<h3>Shell aliases and sudo-ing</h3>
<p>One thing you will quickly notice is that <code class="codecolorer text default"><span class="text">sudo emacsclient ...</span></code> doesn&#8217;t work since the daemon runs under your username. To be able to edit files as root, we need to load the tramp plugin of emacs. Put the following line somewhere in your <code class="codecolorer text default"><span class="text">.emacs</span></code> or <code class="codecolorer text default"><span class="text">.emacs.d/init.el</span></code>:</p>
<div class="codecolorer-container lisp railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>require 'tramp<span style="color: #66cc66;">&#41;</span></div></div>
<p>Now, you would use <code class="codecolorer text default"><span class="text">emacsclient -c /sudo::/etc/somefile</span></code> which is still a bit too long for quick file editing. (As well as the emacsclient command itself). This is why we create shell aliases. I am using zsh which is why I will use its syntax here.</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EDITOR</span>=<span style="color: #ff0000;">&quot;emacsclient -t -n -a nano&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ec</span>=<span style="color: #ff0000;">'emacsclient -c -n -a nano'</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">et</span>=<span style="color: #ff0000;">'emacsclient -t -a nano'</span><br />
ecs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> emacsclient <span style="color: #660033;">-c</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-a</span> emacs <span style="color: #ff0000;">&quot;/sudo::$*&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
ets<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> emacsclient <span style="color: #660033;">-t</span> <span style="color: #660033;">-a</span> emacs <span style="color: #ff0000;">&quot;/sudo::$*&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
<p>It sets emacs as the default editor and defines the commands <code class="codecolorer text default"><span class="text">ec</span></code> (emacs in a separate window) and <code class="codecolorer text default"><span class="text">et</span></code> (emacs in the terminal) as well as its sudo friends for write-protected files, <code class="codecolorer text default"><span class="text">ecs</span></code> and <code class="codecolorer text default"><span class="text">ets</span></code>. Simply put the code in your .zshrc or .bashrc (after editing it to fit bash&#8217;s syntax) and restart the terminal. Then you can use <code class="codecolorer text default"><span class="text">ec/et/ecs/ets /some/directory/some/file</span></code> to edit the file. <del datetime="2011-11-20T18:53:37+00:00">I think tramp uses ssh to connect to your pc as root, so you might need to install ssh to use it.</del></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/my-new-emacs-setup/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to make ReMoot work with mpd</title>
		<link>http://www.oelerich.org/how-to-make-remoot-work-with-mpd/</link>
		<comments>http://www.oelerich.org/how-to-make-remoot-work-with-mpd/#comments</comments>
		<pubDate>Tue, 31 May 2011 16:22:30 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[remoot]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=329</guid>
		<description><![CDATA[Heya, I was struggling with ReMoot commands not having effect on the MPD (music player daemon), which is a nifty tool I discovered yesterday. Anyway, even though ReMoot lists this software as supported on it&#8217;s website, nothing happened when I executed &#8220;remoot playpause&#8221; or something like that. The reason is that ReMoot only looks for [...]]]></description>
			<content:encoded><![CDATA[<p>Heya, I was struggling with <a href="http://www.remoot.org/">ReMoot</a> commands not having effect on the <a href="https://wiki.archlinux.org/index.php/Mpd">MPD</a> (music player daemon), which is a nifty tool I discovered yesterday. Anyway, even though ReMoot lists this software as supported on it&#8217;s website, nothing happened when I executed &#8220;remoot playpause&#8221; or something like that.</p>
<p>The reason is that ReMoot only looks for programs that belong to the current user, while the mpd most of the times has it&#8217;s own user. (At least that is what&#8217;s proposed for example here)</p>
<p>To get ReMoot running with mpd you have to do the following two things:</p>
<ul>
<li>ReMoot uses mpc to interface with mpd, so make sure it is installed!</li>
<li>edit <em>/usr/bin/daemoot</em> (or whereever it may be) and change line 470 (version 0.9 of ReMoot) to <em>my @apps = `ps -L -u $ENV{USER},<strong>mpd</strong> -o comm,lwp`;</em> where, of course, mpd has to be the user the mpd runs under.</li>
</ul>
<p>That should be it. Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/how-to-make-remoot-work-with-mpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hide the ugly status bar in Pidgin</title>
		<link>http://www.oelerich.org/hide-the-ugly-status-bar-in-pidgin/</link>
		<comments>http://www.oelerich.org/hide-the-ugly-status-bar-in-pidgin/#comments</comments>
		<pubDate>Wed, 25 May 2011 20:47:33 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hide statusbar]]></category>
		<category><![CDATA[pidgin]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=325</guid>
		<description><![CDATA[Hello together, a short summary what happened since the last blog entry and led me to the creation of a small Pidgin plugin. I switched to linux I decided to use Pidgin instant messanger I hated the big, fat, ugly status bar in pidgin I wasn&#8217;t able to find a plugin that hides it (and [...]]]></description>
			<content:encoded><![CDATA[<p>Hello together, a short summary what happened since the last blog entry and led me to the creation of a small Pidgin plugin.</p>
<ul>
<li>I switched to linux</li>
<li>I decided to use Pidgin instant messanger</li>
<li>I hated the big, fat, ugly status bar in pidgin</li>
<li>I wasn&#8217;t able to find a plugin that hides it (and does nothing more)</li>
<li>So I wrote my own</li>
</ul>
<p>It is just for Unix (I guess..) and you have to build it yourself. A small README is included in the tarball. </p>
<p><a href='http://www.oelerich.org/wp-content/uploads/2011/05/hidestatusbar.tar.gz'>Sourcecode hidestatusbar.tar</a></p>
<p>I hope it helps anybody.</p>
<p>All the best, Oli</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/hide-the-ugly-status-bar-in-pidgin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrate Doctrine 2.0.1 with Zend Framework 1.11.3</title>
		<link>http://www.oelerich.org/integrate-doctrine-2-with-zend-framework-1-11-3/</link>
		<comments>http://www.oelerich.org/integrate-doctrine-2-with-zend-framework-1-11-3/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 16:56:28 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[doctrine 2]]></category>
		<category><![CDATA[integration]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=315</guid>
		<description><![CDATA[Hello readers! The most frequently visited and linked article on my blog is by far the tutorial, how to integrate Doctrine 2 with Zend Framework 1.09. However &#8211; it is written in german and since I published it, a couple of new versions of both libraries were released. So I decided to rewrite it in [...]]]></description>
			<content:encoded><![CDATA[<p>Hello readers! The most frequently visited and linked article on my blog is by far the tutorial, how to <a href="http://www.oelerich.org/?p=193">integrate Doctrine 2 with Zend Framework 1.09</a>. However &#8211; it is written in german and since I published it, a couple of new versions of both libraries were released. So I decided to rewrite it in english and adjust it so that it fits the most up-to-date versions of both <a href="http://www.doctrine-project.org">Doctrine</a> and the <a href="http://framework.zend.com/">Zend Framework</a>.</p>
<p>I will presume you know more or less exactly what these software packages do, and how to use them. Also, I assume that you are able to set up a virtual host by yourself. You should be familiar with how to use a command line, too!<br />
<span id="more-315"></span></p>
<h3>Step 1 &#8211; Download libraries and set up the project</h3>
<p>First of all, we need to download the libraries and set up our project.<br />
Start with the Zend Framework. Go to it&#8217;s <a href="http://framework.zend.com/download/latest">download page</a> and download (at least) the minimal version. Right now, it is ZF <em>1.11.3</em>. Unpack the download, go to a command line (whichever your system provides), change to the <em>bin/</em> folder of the package and type the following lines:</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">chmod +x zf.sh<br />
./zf.sh create project /path/to/App</div></div>
<p>This is what you do on a Unix shell. It is slightly different on Windows machines, there you would have to use the <em>zf.bat</em> file. However, you will have to figure out how to do that on your own, since I don&#8217;t work on Windows and am too lazy to google it right now.</p>
<p>Your project should be created now, meaning that the folder <em>/path/to/App</em> should contain several subfolder such as <em>application/</em>, <em>library/</em> and so on. We create a subfolder with the name <em>bin/</em> in this folder. </p>
<p>What has to be done next is to move all the libraries into our project. First of all, in the downloaded package of the Zend Framework, there should be a <em>libraries/</em> folder containing another folder named <em>Zend/</em>. We move that <em>Zend/</em> folder into the <em>library/</em> folder of our project. </p>
<p>We then go on by downloading the Doctrine packages. I say packages, because we need the Doctrine ORM as well as the DBAL and the Doctrine Commons project. Luckily, all of them are included in one package, which can be downloaded on the <a href="http://www.doctrine-project.org/projects/orm/download">Doctrine ORM&#8217;s download page</a>. It is the latest Doctrine package. (As of now, it is version <em>2.0.1</em>) Unpack it and simply copy the <em>Doctrine/</em> folder into our project&#8217;s <em>library/</em> folder. </p>
<p>The last step in setting up the project is to move or copy the contents of the <em>bin/</em> folders of both downloaded packages into the <em>bin/</em> folder that we just created in our project.</p>
<h3>Step 2 &#8211; The configuration file</h3>
<p>In this tutorial, I will show how to integrate Doctrine using MySQL as database engine. The config settings might be different for other engines or when you use different database interfaces. However, we open the <em>application/configs/application.ini</em> of our project and insert the following lines into the <em>[production]</em> block of the ini file.</p>
<div class="codecolorer-container ini railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">doctrine.conn.host <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> '127.0.0.1'</span><br />
doctrine.conn.user <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 'root'</span><br />
doctrine.conn.pass <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ''</span><br />
doctrine.conn.driv <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 'pdo_mysql'</span><br />
doctrine.conn.dbname <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 'app'</span><br />
doctrine.path.models <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/models&quot;</span></div></div>
<p>At this point, you have to fill in your personal database connection settings. These might be completely different from the ones shown here. You should also adjust the database driver now, when you don&#8217;t want to use MySQL. </p>
<h3>Step 3 &#8211; Bootstrapping</h3>
<p>Now comes the fun part. We have to load all the Doctrine libraries and set them up correctly. To do that, we open the <em>application/Bootstrap.php</em> file of our project and fill it with the required functions. I will first post the whole file here and explain it below.</p>
<div class="codecolorer-container php railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">class</span> Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Bootstrap_Bootstrap<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* generate registry<br />
&nbsp; &nbsp; &nbsp;* @return Zend_Registry<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initRegistry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Register namespace Default_<br />
&nbsp; &nbsp; &nbsp;* @return Zend_Application_Module_Autoloader<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Default_'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'basePath'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* Initialize Doctrine<br />
&nbsp; &nbsp; &nbsp;* @return Doctrine_Manager<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _initDoctrine<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// include and register Doctrine's class loader</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Doctrine/Common/ClassLoader.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'Doctrine'</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library/'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// create the Doctrine configuration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\ORM\Configuration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// setting the cache ( to ArrayCache. Take a look at</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// the Doctrine manual for different options ! )</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\Cache\ArrayCache<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetadataCacheImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setQueryCacheImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// choosing the driver for our database schema</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// we'll use annotations</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$driver</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newDefaultAnnotationDriver</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/models'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMetadataDriverImpl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$driver</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// set the proxy dir and set some options</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProxyDir</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/models/Proxies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAutoGenerateProxyClasses</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProxyNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'App\Proxies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// now create the entity manager and use the connection</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings we defined in our application.ini</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$connectionSettings</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'driver'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$connectionSettings</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conn'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'driv'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'user'</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$connectionSettings</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conn'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'password'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$connectionSettings</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conn'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'dbname'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$connectionSettings</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conn'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dbname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'host'</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$connectionSettings</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'conn'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$entityManager</span> <span style="color: #339933;">=</span> \Doctrine\ORM\EntityManager<span style="color: #339933;">::</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// push the entity manager into our registry for later use</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$entityManager</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$entityManager</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>The first two methods don&#8217;t have anything to to with Doctrine. We just want to use a registry in our project (later, our <em>EntityManager</em> instance will be stored here!) and we want to register a namespace <em>Default_</em> for use in our project. These methods are pure Zend Framework-ish, so I assume you know what they do. If not, consult the <a href="http://framework.zend.com/docs/overview">ZF manual</a>. </p>
<p>Now for the <em>_initDoctrine()</em> method. The first thing we do in line <strong>33</strong> is to include the class loader of Doctrine. Unfortunately, Doctrine already uses the new namespacing of PHP 5 (or 6?). The Zend Framework doesn&#8217;t. So we need another class loader with the correct namespacing scheme. We set it up in the following five lines <strong>34-38</strong>, telling it that we need the namespace <em>Doctrine</em> and where the include path of the library is. </p>
<p>We then create a Doctrine Configuration instance and configure Doctrine (lines <strong>41-59</strong>). Depending on how you want to control the database scheme and stuff like that, you might want to adjust some of the settings here. The <em>ArrayCache</em> can be changed and set to something more performant and if you don&#8217;t want to use annotations in the Entities to define the database scheme, you should use a different <em>MetadataDriver</em>. In this tutorial, we use both the <em>ArrayCache</em> and the <em>DefaultAnnotationDriver</em>. When we instantiate the last one, we have to tell it where our classes with the annotations (I will talk about these more, later) are. </p>
<p>I never _really_ understood what the <em>Proxy</em> classes are. They are created at runtime by Doctrine and my guess is, they are to speed up the database interaction by sort of caching joined requests. Anyways, we need to define where these classes should be saved and what namespace that is. This is done in lines <strong>57-59</strong>. </p>
<p>After that, we get our connection settings from the <em>application.ini</em> file and can finally create the <em>EntityManager</em> instance by telling it all our configurations and connection information. This<em> EntityManager</em> can be understood as the interface between the Database and our models (called Entities). We are saving it&#8217;s instance in the Zend Registry we created earlier. </p>
<p>And that&#8217;s it. We can now start creating Entities (models) and trying to do some database interaction!</p>
<h3>Step 4 &#8211; The Entity</h3>
<p>To test everything, we create a small dummy Entity. I will not go into detail on how to create Entites and define the database scheme of their tables. As we defined in the Doctrine config earlier, we want to use annotations (in the Docblock of our Entity) to define the database scheme. We create a file <em>application/models/Test.php</em> and fill it with the following code:</p>
<div class="codecolorer-container php railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* @Entity<br />
&nbsp;* @Table(name=&quot;test123&quot;)<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">class</span> Default_Model_Test<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* @Id @Column(type=&quot;integer&quot;)<br />
&nbsp; &nbsp; &nbsp;* @GeneratedValue(strategy=&quot;AUTO&quot;)<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/** @Column(type=&quot;string&quot;) */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>As you see, we want a models with the fields <em>id</em> and <em>name</em>, <em>id</em> being an integer and auto_incremented and <em>name</em> being a string. The table name is set to <strong>test123</strong>. As you can see, an Entity is nothing more than a PHP class with some members and methods. Only the definitions for how Doctrine should build the table have to be given in the annotations. You could as well use YAML or XML files to define these. </p>
<p>The next step is to adjust the command line tool of Doctrine to fit into our project.</p>
<h3>Step 5 &#8211; the command line tool</h3>
<p>Simply copy the following code into <em>bin/doctrine.php</em> replacing all of the code already in the file.</p>
<div class="codecolorer-container php railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'development'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
<a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/realpath"><span style="color: #990000;">realpath</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../application'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/set_include_path"><span style="color: #990000;">set_include_path</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span>PATH_SEPARATOR<span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/realpath"><span style="color: #990000;">realpath</span></a><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/get_include_path"><span style="color: #990000;">get_include_path</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Doctrine and Symfony Classes</span><br />
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Doctrine/Common/ClassLoader.php'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Doctrine'</span><span style="color: #339933;">,</span> APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Symfony'</span><span style="color: #339933;">,</span> APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library/Doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\Common\ClassLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Entities'</span><span style="color: #339933;">,</span> APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/models'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNamespaceSeparator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Zend Components</span><br />
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Application.php'</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;">// Create application</span><br />
<span style="color: #000088;">$application</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; APPLICATION_ENV<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/configs/application.ini'</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// bootstrap doctrine</span><br />
<span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// generate the Doctrine HelperSet</span><br />
<span style="color: #000088;">$helperSet</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> \Symfony\Component\Console\Helper\HelperSet<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'db'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$em</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'em'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper<span style="color: #009900;">&#40;</span><span style="color: #000088;">$em</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
\Doctrine\ORM\Tools\Console\ConsoleRunner<span style="color: #339933;">::</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$helperSet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>We do some bootstrapping of our project here to obtain the <em>EntityManager</em> instance. We then create a <em>HelperSet</em> with the EntityManager and run the cli tool. </p>
<p>To create our database table based on the Entity we created earlier, we open a command line, change into the <em>bin/</em> folder of our project and run</p>
<div class="codecolorer-container text railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">chmod +x ./doctrine<br />
./doctrine orm:schema-tool:create</div></div>
<p>Again, this is for the Unix shell and is different on Windows machines!<br />
Fire up your favourite database administration tool and have a look! The table <em>test123</em> should have been created properly.</p>
<h3>Step 6 &#8211; Using the database</h3>
<p>I will just post a small example of how to use everything. Replace the content of your <em>application/controllers/IndexController.php</em> with the following:</p>
<div class="codecolorer-container php railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp;<br />
<span style="color: #000000; font-weight: bold;">class</span> IndexController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_em <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$testEntity</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_Test<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$testEntity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zaphod Beeblebrox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_em<span style="color: #339933;">-&gt;</span><span style="color: #004000;">persist</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$testEntity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_em<span style="color: #339933;">-&gt;</span><a href="http://www.php.net/flush"><span style="color: #990000;">flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This is just some quick and dirty dummy code to check if everything works. We get our <em>EntityManager</em> out of the registry and save it as a member of the <em>Controller.</em> We then create a new model (Entity), set the name and by using the <em>EntityManager</em>&#8216;s persist method, we save it. <em>EntityManager->flush()</em> actually invokes the database action and the row should occur in our table.</p>
<p>Test this by simply browse to your project in your favourite webbrowser. If everything worked fine, the table should now have one entry with the name <em>Zaphod Beeblebrox</em>.</p>
<p>If anything did not work, feel free to ask in the comments here! I will be glad to answer any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/integrate-doctrine-2-with-zend-framework-1-11-3/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
		<item>
		<title>On the accelerometer of the HTC Desire</title>
		<link>http://www.oelerich.org/on-the-accelerometer-of-the-htc-desire/</link>
		<comments>http://www.oelerich.org/on-the-accelerometer-of-the-htc-desire/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 21:06:19 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[gingerbread]]></category>
		<category><![CDATA[sensor]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=309</guid>
		<description><![CDATA[It has been a looong time since I wrote my last blog entry, please excuse me. I haven&#8217;t been busy or anything, it was just lazyness. Since I recently got one _real_ comment among all the spam saying, it would be nice if I wrote in english, I will do that from now on. So [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a looong time since I wrote my last blog entry, please excuse me. I haven&#8217;t been busy or anything, it was just lazyness. Since I recently got one _real_ comment among all the spam saying, it would be nice if I wrote in english, I will do that from now on.</p>
<p>So I started diving into Android development last autumn and today, just for fun, I tried to use some sensors included in my phone. (HTC Desire running Android 2.3.1)</p>
<p>My idea was to <strong>use the accelerometer along with the orientation measurement to measure both the distance the phone was moved and also it&#8217;s trajectory</strong>. Both values, of course, relative to the starting point of the motion.<br />
<span id="more-309"></span><br />
So the first difficulty was to transform the measures of acceleration into the coordinate system of the lab (room&#8230;). Luckily, Android provides methods that need the acceleration and the magnetic field as input and return the transformation matrix for vectors. (Have a look at <strong>SensorManager.getRotationMatrix()</strong>). </p>
<p>The next thing I had to take care of was the earth acceleration. Trying to just remove a constant offset from the z-component of my acceleration vector wasn&#8217;t really accurate. (Somehow my phone measured the gravity to somewhat around 10.5 m/s^2&#8230;) So I just moved to the SDK version 9, which is Android 2.3, and used the sensor type <strong>Sensor.TYPE_LINEAR_ACCELERATION</strong>. This is the measured acceleration where the gravity was already taken care of. </p>
<p>Now, I took care of everything: I measured the acceleration and transformed it into the room&#8217;s coordinate system (before each measurement step, so that I could rotate the phone however I like and it wouldn&#8217;t change the measured values). After integrating everything my app was perfect and ready for a tryout.</p>
<p>Walking through my room and trying to measure the distances from wall to wall didn&#8217;t work at all. Moving the phone in a circle resulted in a measured distance of about 20+ m, which had to be wrong, too. </p>
<p>I don&#8217;t know yet what went wrong or whether it&#8217;s just the unprecision of the sensors. However, I will attach the source code of my activity and the layout file. Keep in mind that you need a phone running Android 2.3 to try it. The emulator can&#8217;t be moved, so It would be useless to emulate the app.) Please excuse the bad coding style, it was just meant to be an experiment.</p>
<div class="codecolorer-container java railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.janoliver.andmote</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.DecimalFormat</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.Sensor</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEvent</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEventListener</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.LayoutInflater</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View.OnClickListener</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AndMote <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #000000; font-weight: bold;">implements</span> SensorEventListener <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SensorManager mSensorManager<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Sensor mAccelerometer<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Sensor mLinearAccelerometer<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Sensor mMagneto<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> TextView one,two,three<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> matrix_size <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> inR <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span>matrix_size<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> I <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span>matrix_size<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> accels <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> laccels <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> mags <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> loc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> veloc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> distance <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> time <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> startTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> measure <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> correction<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onResume<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onResume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mSensorManager.<span style="color: #006633;">registerListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, mAccelerometer, SensorManager.<span style="color: #006633;">SENSOR_DELAY_NORMAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mSensorManager.<span style="color: #006633;">registerListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, mMagneto, SensorManager.<span style="color: #006633;">SENSOR_DELAY_NORMAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mSensorManager.<span style="color: #006633;">registerListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, mLinearAccelerometer, SensorManager.<span style="color: #006633;">SENSOR_DELAY_NORMAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onPause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mSensorManager.<span style="color: #006633;">unregisterListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSensorChanged<span style="color: #009900;">&#40;</span>SensorEvent event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">accuracy</span> <span style="color: #339933;">==</span> SensorManager.<span style="color: #006633;">SENSOR_STATUS_UNRELIABLE</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">sensor</span>.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> Sensor.<span style="color: #006633;">TYPE_MAGNETIC_FIELD</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mags <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span>.<span style="color: #006633;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> Sensor.<span style="color: #006633;">TYPE_LINEAR_ACCELERATION</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; laccels <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span>.<span style="color: #006633;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> Sensor.<span style="color: #006633;">TYPE_ACCELEROMETER</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accels <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span>.<span style="color: #006633;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mags <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> accels <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> laccels <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> measure<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adecimalformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">DecimalFormat</span></a> formatter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adecimalformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">DecimalFormat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#,###.##&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SensorManager.<span style="color: #006633;">getRotationMatrix</span><span style="color: #009900;">&#40;</span>inR, I, accels, mags<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values <span style="color: #339933;">=</span> convertVector<span style="color: #009900;">&#40;</span>laccels, inR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> now <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> dt <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>now<span style="color: #339933;">-</span>time<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">1000.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> dx <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0.5</span><span style="color: #339933;">*</span>values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">*</span>dt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> dy <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0.5</span><span style="color: #339933;">*</span>values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">*</span>dt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> dz <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0.5</span><span style="color: #339933;">*</span>values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">*</span>dt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> dx<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> dy<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> dz<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; veloc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> values<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>dt<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance <span style="color: #339933;">+=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #006633;">sqrt</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span>dx, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span>dy, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Math</span></a>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span>dz, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time <span style="color: #339933;">=</span> now<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter<span style="color: #339933;">++;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; one.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Distance: &quot;</span><span style="color: #339933;">+</span>formatter.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>distance<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; two.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location (x;y;z): (&quot;</span><span style="color: #339933;">+</span>formatter.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">+</span>formatter.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">+</span>formatter.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>loc<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;) m&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; three.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Elapsed time: &quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>time<span style="color: #339933;">-</span>startTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">1000.0</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> convertVector<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> vec, <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> matrix<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span>matrix<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>vec<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> startMeasure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; time <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; startTime <span style="color: #339933;">=</span> time <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; veloc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; distance <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; measure <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> stopMeasure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; measure <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; mSensorManager <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SensorManager<span style="color: #009900;">&#41;</span>getSystemService<span style="color: #009900;">&#40;</span>SENSOR_SERVICE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mLinearAccelerometer <span style="color: #339933;">=</span> mSensorManager.<span style="color: #006633;">getDefaultSensor</span><span style="color: #009900;">&#40;</span>Sensor.<span style="color: #006633;">TYPE_LINEAR_ACCELERATION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mAccelerometer <span style="color: #339933;">=</span> mSensorManager.<span style="color: #006633;">getDefaultSensor</span><span style="color: #009900;">&#40;</span>Sensor.<span style="color: #006633;">TYPE_ACCELEROMETER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mMagneto <span style="color: #339933;">=</span> mSensorManager.<span style="color: #006633;">getDefaultSensor</span><span style="color: #009900;">&#40;</span>Sensor.<span style="color: #006633;">TYPE_MAGNETIC_FIELD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; LayoutInflater inflater <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getLayoutInflater</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aview+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">View</span></a> row <span style="color: #339933;">=</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; one <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> row.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">eins</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; two <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> row.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">zwei</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; three <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> row.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">drei</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; setContentView<span style="color: #009900;">&#40;</span>row<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> button <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aview+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">View</span></a> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startMeasure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> button2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">stop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; button2.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aview+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">View</span></a> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopMeasure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccuracyChanged<span style="color: #009900;">&#40;</span>Sensor sensor, <span style="color: #000066; font-weight: bold;">int</span> accuracy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
<span style="color: #009900;">&#125;</span></div></div>
<div class="codecolorer-container xml railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> &nbsp;</span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Blablub&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/eins&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> &nbsp;</span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Blablub&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/zwei&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> &nbsp;</span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Blablub&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/drei&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Start&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/start&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Stop&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/stop&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> </span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/on-the-accelerometer-of-the-htc-desire/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

