<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hugo Heden&#039;s dump</title>
	<atom:link href="http://hugoheden.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hugoheden.wordpress.com</link>
	<description>Hardly thinking; hnnnggg -- plop</description>
	<lastBuildDate>Tue, 27 Dec 2011 18:44:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='hugoheden.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Hugo Heden&#039;s dump</title>
		<link>http://hugoheden.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hugoheden.wordpress.com/osd.xml" title="Hugo Heden&#039;s dump" />
	<atom:link rel='hub' href='http://hugoheden.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Opera Mobile: Problems with position of dialog box</title>
		<link>http://hugoheden.wordpress.com/2011/12/27/opera-mobile-problems-with-position-of-dialog-box/</link>
		<comments>http://hugoheden.wordpress.com/2011/12/27/opera-mobile-problems-with-position-of-dialog-box/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 18:44:51 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=208</guid>
		<description><![CDATA[For the benefits of the hoards of readers here, the flood of master pieces continues. I&#8217;m using Opera Mobile on Android. It works better than most other browsers in various ways. However, some sites have perhaps not tested with Opera Mobile? For instance, go to www.disqus.com and click the login link in the upper right [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=208&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For the benefits of the hoards of readers here, the flood of master pieces continues.</p>
<p>I&#8217;m using Opera Mobile on Android. It works better than most other browsers in various ways. However, some sites have perhaps not tested with Opera Mobile?</p>
<p>For instance, go to www.disqus.com and click the login link in the upper right corner. A little dialog box pops up. (It&#8217;s not a window, but an html-element). Unfortunately, in Opera Mobile the dialog box is positioned so that its edge ends up outside of the edge of the &#8220;main screen&#8221;. The result in this case is that the actual Login button is not visible.</p>
<p>In essence, it does not seem to be possible to login to disqus.com using Opera Mobile.</p>
<p>I&#8217;ve noticed a similar problem with erroneously positioned html-elements on lastpass.com .</p>
<p>Crappy work-around: Use a bookmarklet that removes all stylesheet (CSS) on the page where such a problem occurs. Paste the following one-liner javascript into a bookmark (it&#8217;s a javascript &#8220;link&#8221;):</p>
<pre>javascript:for(i=0;i&lt;document.styleSheets.length;i++)%7Bvoid(document.styleSheets.item(i).disabled=true);%7Del=document.getElementsByTagName('*');for(i=0;i&lt;el.length;i++)%7Bvoid(el%5Bi%5D.style.cssText='');%7D</pre>
<p>This is the bookmarklet named RemoveCSS from here: http://dorward.me.uk/software/disablecss/</p>
<p>By invoking/pressing the bookmarklet, the page will become ugly but functional &#8212; all elements will be visible on screen.</p>
<p>&#8220;Tjofjöjt i brallan&#8221;, as they say &#8212; it works!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=208&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2011/12/27/opera-mobile-problems-with-position-of-dialog-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>Bookmarklet to clean Sparknotes for printing</title>
		<link>http://hugoheden.wordpress.com/2011/03/13/bookmarklet-to-clean-sparknotes-for-printing/</link>
		<comments>http://hugoheden.wordpress.com/2011/03/13/bookmarklet-to-clean-sparknotes-for-printing/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 17:28:58 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=193</guid>
		<description><![CDATA[Apparently I can&#8217;t buy the pdf-versions of the stuff on www.sparknotes.com, because I don&#8217;t have an american home address? That makes me grumpy. I guess I can just print out the articles myself, though that&#8217;s not very convenient. But OK. To create a nice printable Sparknote page (without the mess, just the text), I use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=193&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Apparently I can&#8217;t buy the pdf-versions of the stuff on www.sparknotes.com, because I don&#8217;t have an american home address? That makes me grumpy. I guess I can just print out the articles myself, though that&#8217;s not very convenient.</p>
<p>But OK. To create a nice printable Sparknote page (without the mess, just the text), I use the following javascript code. It extracts the <strong>div</strong> element that has the className of <strong>studyGuideText</strong> and removes everything else (including all style sheets and an advert, <strong>floatingad</strong>).</p>
<pre style="color:#181615;background-color:#ffffff;"><span style="color:#0057ae;">javascript:</span> ( <strong>function</strong>() {

<strong>var</strong> body = <span style="color:#008000;">document</span>.<span style="color:#644a9b;">getElementsByTagName</span>(<span style="color:#ff80e0;">'body'</span>)[<span style="color:#b08000;">0</span>];
<strong>var</strong> divs = <span style="color:#008000;">body</span>.<span style="color:#644a9b;">getElementsByTagName</span>(<span style="color:#ff80e0;">'div'</span>);
<strong>var</strong> text = null;
<strong>for</strong>(<strong>var</strong> i=<span style="color:#b08000;">0</span>; i&lt;<span style="color:#008000;">divs</span>.<span style="color:#644a9b;">length</span>; i++){
	<strong>if</strong>(divs[i].<span style="color:#644a9b;">className</span>==<span style="color:#ff80e0;">'studyGuideText'</span>) {
		text = divs[i];
		<strong>break</strong>;
	}
}
<strong>if</strong> (text == null) {
	alert(<span style="color:#ff80e0;">'Did not find any text to extract (looking for divs of class studyGuideText)'</span>);
	<strong>return</strong>;
}
<strong>while</strong> (<span style="color:#008000;">body</span>.<span style="color:#644a9b;">hasChildNodes</span>()){
	<span style="color:#008000;">body</span>.<span style="color:#644a9b;">removeChild</span>(<span style="color:#008000;">body</span>.<span style="color:#644a9b;">firstChild</span>);
}

<span style="color:#008000;">body</span>.<span style="color:#644a9b;">appendChild</span>(text);

<strong>for</strong>(i=<span style="color:#b08000;">0</span>;i&lt;<span style="color:#008000;">document</span>.<span style="color:#644a9b;">styleSheets</span>.<span style="color:#644a9b;">length</span>;i++){
	<strong>void</strong>(<span style="color:#008000;">document</span>.<span style="color:#644a9b;">styleSheets</span>.<span style="color:#644a9b;">item</span>(i).<span style="color:#644a9b;">disabled</span>=<strong>true</strong>);
}
<strong>var</strong> els=<span style="color:#008000;">document</span>.<span style="color:#644a9b;">getElementsByTagName</span>(<span style="color:#ff80e0;">'*'</span>);
<strong>for</strong>(i=<span style="color:#b08000;">0</span>;i&lt;<span style="color:#008000;">els</span>.<span style="color:#644a9b;">length</span>;i++){
	<strong>void</strong>(els[i].<span style="color:#644a9b;">style</span>.<span style="color:#644a9b;">cssText</span>=<span style="color:#ff80e0;">''</span>);
	<strong>if</strong>(els[i].<span style="color:#644a9b;">className</span>==<span style="color:#ff80e0;">'floatingad'</span>){
		els[i].<span style="color:#644a9b;">parentNode</span>.<span style="color:#644a9b;">removeChild</span>(els[i]);
	}
}

})();</pre>
<p>The bookmarklet version &#8212; all in one line etc:</p>
<pre>javascript:(%20function()%20{%20var%20body%20=%20document.getElementsByTagName('body')[0];%20var%20divs%20=%20body.getElementsByTagName('div');%20var%20text%20=%20null;%20for(var%20i=0;%20i&lt;divs.length;%20i++){%20if(divs[i].className=='studyGuideText')%20{%20text%20=%20divs[i];%20break;%20}%20}%20if%20(text%20==%20null)%20{%20alert('Did%20not%20find%20any%20text%20to%20extract%20(looking%20for%20divs%20of%20class%20studyGuideText)');%20return;%20}%20while%20(body.hasChildNodes()){%20body.removeChild(body.firstChild);%20}%20body.appendChild(text);%20for(i=0;i&lt;document.styleSheets.length;i++){%20void(document.styleSheets.item(i).disabled=true);%20}%20var%20els=document.getElementsByTagName('*');%20for(i=0;i&lt;els.length;i++){%20void(els[i].style.cssText='');%20if(els[i].className=='floatingad'){%20els[i].parentNode.removeChild(els[i]);%20}%20}%20})();
</pre>
<p>Tested only with Firefox (Gecko) and Epiphany (Webkit). (I would have liked to just publish it as a link, but WordPress mangles it to something incomprehensible.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/193/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=193&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2011/03/13/bookmarklet-to-clean-sparknotes-for-printing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>Juholt och Röhm, lika som bär?</title>
		<link>http://hugoheden.wordpress.com/2011/03/12/juholt-och-rohm-lika-som-bar/</link>
		<comments>http://hugoheden.wordpress.com/2011/03/12/juholt-och-rohm-lika-som-bar/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 11:46:59 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=178</guid>
		<description><![CDATA[Ernst Röhm (nästan SS) och Håkan Juholt (f.d SSU, SS&#8217;s ungdomsförbund). (Nåja, likare bär har man ju sett, men ändå.)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=178&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[
<a href='http://hugoheden.wordpress.com/2011/03/12/juholt-och-rohm-lika-som-bar/juholt/' title='Juholt'><img data-attachment-id='180' data-orig-size='650,492' data-liked='0'width="150" height="113" src="http://hugoheden.files.wordpress.com/2011/03/juholt.jpg?w=150&#038;h=113" class="attachment-thumbnail" alt="Juholt" title="Juholt" /></a>
<a href='http://hugoheden.wordpress.com/2011/03/12/juholt-och-rohm-lika-som-bar/ernstrohm/' title='ErnstRöhm'><img data-attachment-id='179' data-orig-size='177,223' data-liked='0'width="119" height="150" src="http://hugoheden.files.wordpress.com/2011/03/ernstrc3b6hm.jpeg?w=119&#038;h=150" class="attachment-thumbnail" alt="ErnstRöhm" title="ErnstRöhm" /></a>

<p>Ernst Röhm (nästan SS) och Håkan Juholt (f.d SSU, SS&#8217;s ungdomsförbund). (Nåja, likare bär har man ju sett, men ändå.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/178/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=178&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2011/03/12/juholt-och-rohm-lika-som-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>

		<media:content url="http://hugoheden.files.wordpress.com/2011/03/juholt.jpg?w=150" medium="image">
			<media:title type="html">Juholt</media:title>
		</media:content>

		<media:content url="http://hugoheden.files.wordpress.com/2011/03/ernstrc3b6hm.jpeg?w=119" medium="image">
			<media:title type="html">ErnstRöhm</media:title>
		</media:content>
	</item>
		<item>
		<title>Order of mp3-tracks in Sansa Clip+</title>
		<link>http://hugoheden.wordpress.com/2011/03/12/order-of-mp3-tracks-in-sansa-clip/</link>
		<comments>http://hugoheden.wordpress.com/2011/03/12/order-of-mp3-tracks-in-sansa-clip/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 11:22:54 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=172</guid>
		<description><![CDATA[I use a Sansa Clip+ mp3-player for listening to audiobooks. It took me quite a while to understand how to get the player to play the tracks in the correct order, but I think the following should do it. One has to edit the mp3-tags (metadata embedded into the mp3-files). I use EasyTAG to do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=172&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I use a Sansa Clip+ mp3-player for listening to audiobooks. It took me quite a while to understand how to get the player to play the tracks in the correct order, but I think the following should do it.</p>
<p>One has to edit the mp3-tags (metadata embedded into the mp3-files). I use EasyTAG to do this (which is available for Ubuntu, and probably many other Linux distributions and operating systems.)</p>
<p>Sansa Clip+ derives the play-order by looking at the &#8220;NUMBER&#8221; tag. EasyTAG displays this as the &#8220;Track&#8221;.</p>
<p>The NUMBER tag for each track has to have the <strong>same number of digits</strong>, so it usually has to be padded with <strong>leading zeros</strong>.</p>
<p>That is, tracks numbered like this <strong>will not work:</strong> 1, 2, 3, &#8230; 8, 9, 10, 11&#8230; because the Sansa player will sort tracks 10 and 11 before track 2 (which obviously will screw up the literary experience considerably).</p>
<p>Padding with leading zeros <strong>will solve this</strong>: <strong>0</strong>1, <strong>0</strong>2, <strong>0</strong>3, &#8230; <strong>0</strong>8, <strong>0</strong>9, 10, 11&#8230;</p>
<p>In EasyTAG, this padding is not automatic, but has to be specified by the user under Settings -&gt; Preferences -&gt; Tag Settings -&gt; &#8220;Write the Track field with the following number of digits&#8221; (which I have set to 3, because I&#8217;ve never encountered an audiobook with more than 1000 files in it &#8211; <strong>00</strong>1, <strong>00</strong>2, <strong>00</strong>3, &#8230; <strong>00</strong>8, <strong>00</strong>9, <strong>0</strong>10, <strong>0</strong>11&#8230;).</p>
<p>Some more random tips from the Sansa forums (I haven&#8217;t verified that they are needed) is the following.</p>
<ul>
<li><strong>Do not</strong> specify the total number of tracks (like 01<strong>/87</strong>, 02<strong>/87</strong>, 03<strong>/87</strong>) because that may confuse the player. Just leave that field empty..?</li>
<li>Make sure that the GENRE tag is set to &#8220;Audiobook&#8221;&#8230;?</li>
</ul>
<p><em>End of post.</em></p>
<h2>(Appendix)</h2>
<p>The player will not handle the case with tracks in multiple subdirectories well. I think..? So one may as well move all files to one and the same directory, and then use EasyTAG to set the correct Track tag (NUMBER) on all of them. The following little script copies all mp3 files from within a directory tree to a directory named tmp. The file name of the new file while be $DIRNAME.x.$OLD_FILENAME (so that no filename information will get lost) rather than just $OLD_FILENAME.</p>
<pre>#!/bin/dash                                                                                                                                                             

mkdir tmp ;

find * -name *mp3 | while read FILE ; do
 NEWFILE=`echo "$FILE" | sed 's/\//.x./'` ;
 echo "Copying tmp/$NEWFILE" ;
 cp "$FILE" "tmp/$NEWFILE" ;
done</pre>
<p>It would be cool if one could just create the zero padded track numbers <em>command line</em> (i.e without needing to open EasyTAG), using something like this:</p>
<pre>NUMBER=0;
for FILE in tmp/* ; do
  NUMBER=$(($NUMBER+1));
  PADDEDNUMBER=`printf "%03d" "$NUMBER"`;
  echo "Tagging $FILE. Track number will be: $PADDEDNUMBER"
  # eyeD3 --track="$PADDEDNUMBER" "$FILE" | grep title
  # id3v2 --track "$PADDEDNUMBER" "$FILE"
done</pre>
<p>I&#8217;ve tried both eyeD3 and id3v2. Neither seems to create the necessary padding of leading zeros (at least not if there are more than 100 files). So &#8212; EasyTAG it is!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=172&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2011/03/12/order-of-mp3-tracks-in-sansa-clip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>StickyLookup for NetBeans</title>
		<link>http://hugoheden.wordpress.com/2010/12/23/stickylookup-for-netbeans/</link>
		<comments>http://hugoheden.wordpress.com/2010/12/23/stickylookup-for-netbeans/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 23:20:08 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=159</guid>
		<description><![CDATA[The following is a slightly more compact version of the elegant StickyLookup, first described by Ernest Lötter: http://netbeans.dzone.com/articles/sticky-lookup. Thanks, Ernest! public class StickyLookup extends ProxyLookup implements LookupListener { private final Lookup.Result result; private final InstanceContent ic; public StickyLookup(final Lookup lookup, final Class&#60;?&#62; clazz) { this(lookup, clazz, new InstanceContent()); } private StickyLookup(final Lookup lookup, final Class&#60;?&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=159&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following is a slightly more compact version of the elegant StickyLookup, first described by Ernest Lötter: <a title="Sticky Lookup | NetBeans Zone" href="http://netbeans.dzone.com/articles/sticky-lookup">http://netbeans.dzone.com/articles/sticky-lookup</a>. Thanks, Ernest!</p>
<pre><span style="color:#0000e6;">
public</span> <span style="color:#0000e6;">class</span> StickyLookup <span style="color:#0000e6;">extends</span> ProxyLookup <span style="color:#0000e6;">implements</span> LookupListener {
    <span style="color:#0000e6;">private</span> <span style="color:#0000e6;">final</span> Lookup.Result result;
    <span style="color:#0000e6;">private</span> <span style="color:#0000e6;">final</span> InstanceContent ic;

    <span style="color:#0000e6;">public</span> StickyLookup(<span style="color:#0000e6;">final</span> Lookup lookup, <span style="color:#0000e6;">fina</span><span style="color:#0000e6;">l</span> Class&lt;?&gt; clazz) {
        <span style="color:#0000e6;">this</span>(lookup, clazz, <span style="color:#0000e6;">new</span> InstanceContent());
    }

    <span style="color:#0000e6;">private</span> StickyLookup(<span style="color:#0000e6;">final</span> Lookup lookup, <span style="color:#0000e6;">final</span> Class&lt;?&gt; clazz, InstanceContent ic) {
        <span style="color:#0000e6;">super</span>(Lookups.exclude(lookup, clazz), <span style="color:#0000e6;">new</span> AbstractLookup(ic));
        <span style="color:#0000e6;">this</span>.ic = ic;

        <span style="color:#0000e6;">this</span>.result = lookup.lookupResult(clazz);
        <span style="color:#0000e6;">this</span>.ic.set(<span style="color:#0000e6;">this</span>.result.allInstances(), <span style="color:#0000e6;">null</span>);
        <span style="color:#0000e6;">this</span>.result.addLookupListener(<span style="color:#0000e6;">this</span>);
    }

    @Override
    <span style="color:#0000e6;">pub</span><span style="color:#0000e6;">lic</span> <span style="color:#0000e6;">void</span> resultChanged(LookupEvent ev) {
        <span style="color:#0000e6;">if</span> (<span style="color:#0000e6;">this</span>.result.allInstances().isEmpty()) {
            <span style="color:#969696;">// Wrapped lookup is empty. We pretend like nothing happened and</span><span style="color:#969696;"> keep </span>
            <span style="color:#969696;">// exposing the same instances as before.</span>
            <span style="color:#0000e6;">return</span>;
        } <span style="color:#0000e6;">else</span> {
            <span style="color:#969696;">// Just copy whatever the</span><span style="color:#969696;"> wrapped instance has</span>
            ic.set(result.allInstances(), <span style="color:#0000e6;">null</span>);
        }
    }
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=159&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2010/12/23/stickylookup-for-netbeans/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>Invoking emacs daemon and client easily</title>
		<link>http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/</link>
		<comments>http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 16:46:02 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=116</guid>
		<description><![CDATA[#!/bin/bash # http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/ # This script will invoke emacsclient. If there is no emacs daemon # running, then the daemon is automatically started. # If any of -nw, -t or -tty, or for that matter -c or --create-frame, # is specified on the command line, then the script will just pass on # all arguments [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=116&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-size:medium;">
<pre><span style="color:#888786;"><em>#!/bin/bash</em></span>

<span style="color:#888786;"><em># http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/
# This script will invoke emacsclient. If there is no emacs daemon</em></span>
<span style="color:#888786;"><em># running, then the daemon is automatically started.</em></span>

<span style="color:#888786;"><em># If any of -nw, -t or -tty, or for that matter -c or --create-frame,</em></span>
<span style="color:#888786;"><em># is specified on the command line, then the script will just pass on</em></span>
<span style="color:#888786;"><em># all arguments to emacsclient.</em></span>

<span style="color:#888786;"><em># But if none of that is specified, this script will assume that this</em></span>
<span style="color:#888786;"><em># is interactive usage. If $DISPLAY is set, the script assumes that</em></span>
<span style="color:#888786;"><em># the user would prefer to invoke the emacsclient with the --no-wait</em></span>
<span style="color:#888786;"><em># flag, opening the specified file (if any) in an existing frame (in</em></span>
<span style="color:#888786;"><em># the current $DISPLAY).  If there no frame currently open (in the</em></span>
<span style="color:#888786;"><em># current $DISPLAY) the script will add --create-frame as well.</em></span>

<span style="color:#888786;"><em># Because of --no-wait, it is not a good idea to let the EDITOR</em></span>
<span style="color:#888786;"><em># variable point to this script without command line flags. Suggested</em></span>
<span style="color:#888786;"><em># values for EDITOR would be "&lt;script&gt; --create-frame " or "&lt;script&gt;</em></span>
<span style="color:#888786;"><em># -nw"</em></span>

<span style="color:#888786;"><em># Tested with emacs 23.0.9 packaged for Ubuntu 8.10:</em></span>
<span style="color:#888786;"><em># $ emacs-snapshot --version</em></span>
<span style="color:#888786;"><em># GNU Emacs 23.0.90.1</em></span>
<span style="color:#888786;"><em># $ emacsclient.emacs-snapshot -V</em></span>
<span style="color:#888786;"><em># emacsclient 23.0.90</em></span>

<span style="color:#888786;"><em>##############</em></span>

<span style="color:#888786;"><em>#set -x # Print lots of debugging info</em></span>

<span style="color:#006e28;">this_script=</span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$0</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># Useful for prefixing printouts, and for self-invoking this script</em></span>

<span style="color:#141312;">  </span><span style="color:#888786;"><em># This script can invoke itself by giving the --alternate-editor</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># option to emacsclient. The MUST_START_EMACS_DAEMON environment</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># variable is used to keep track on that:</em></span>
<span style="color:#141312;"><strong>if</strong></span><span style="color:#880088;"><strong> [</strong></span><span style="color:#141312;"> </span><span style="color:#bf0303;">"x</span><span style="color:#006e28;">$MUST_START_EMACS_DAEMON</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#006e28;">!=</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"x"</span><span style="color:#880088;"><strong> ]</strong></span><span style="color:#141312;"> ; <strong>then</strong></span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>echo</strong></span><span style="color:#141312;"> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$this_script</span><span style="color:#bf0303;">: Starting emacs --daemon. Ignoring all arguments: </span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#223388;"><strong>&gt;&amp;2</strong></span>
<span style="color:#141312;">    emacs-snapshot --daemon</span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># No need to sleep or anything because the daemon will not fork</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># (return) until fully started.</em></span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>exit</strong></span><span style="color:#141312;"> 1</span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># We return an error code because starting the daemon implies a</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># previous failure to invoke the client. See usage below.</em></span>
<span style="color:#141312;"><strong>fi</strong></span>

<span style="color:#141312;">  </span><span style="color:#888786;"><em># Internal helper function that invokes the client, but if that</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># fails at least daemon is started before an error code is returned.</em></span>
<span style="color:#141312;"><strong>function</strong></span><span style="color:#644a9b;"> _invoke_client_orelse_start_daemon()</span><span style="color:#141312;"> <strong>{</strong></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># Note that stuff printed to stdout may/will be interpreted by</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># caller... So be careful with printouts -- use stderr:&gt;&amp;2</em></span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>local</strong></span><span style="color:#141312;"> </span><span style="color:#006e28;">MUST_START_EMACS_DAEMON=</span><span style="color:#141312;">1</span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>export</strong></span><span style="color:#141312;"> </span><span style="color:#006e28;">MUST_START_EMACS_DAEMON</span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># This script itself is specified as --alternate-editor, and it</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># will make sure to (try to) start the daemon at least. See</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em># above.</em></span>
<span style="color:#141312;">    emacsclient.emacs-snapshot </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> --alternate-editor </span><span style="color:#006e28;">$this_script</span>
<span style="color:#141312;">    </span><span style="color:#006e28;">retval=$?</span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>unset</strong></span><span style="color:#141312;"> </span><span style="color:#006e28;">MUST_START_EMACS_DAEMON</span>
<span style="color:#141312;">    </span><span style="color:#880088;"><strong>return</strong></span><span style="color:#141312;"> </span><span style="color:#006e28;">$retval</span>
<span style="color:#141312;"><strong>}</strong></span>

<span style="color:#141312;">  </span><span style="color:#888786;"><em># Invokes the client. Also starts the daemon if necessary.</em></span>
<span style="color:#141312;"><strong>function</strong></span><span style="color:#644a9b;"> _invoke_client()</span><span style="color:#141312;"><strong>{</strong></span>
<span style="color:#141312;">  _invoke_client_orelse_start_daemon </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> <strong>||</strong></span>
<span style="color:#141312;">  emacsclient.emacs-snapshot </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span>
<span style="color:#141312;"><strong>}</strong></span>

<span style="color:#006e28;">args=(</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#006e28;">)</span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># Need to be careful to treat args as an *array*, so that command</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># line arguments are preserved until we pass them on -- even though</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># they may be containing spaces.. See `man bash` for more about</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># using parantheses for arrays, and about stuff like "$@" and</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em># "${args[@]}"</em></span>

<span style="color:#141312;"><strong>if</strong></span><span style="color:#880088;"><strong> [</strong></span><span style="color:#141312;"> </span><span style="color:#bf0303;">"x</span><span style="color:#006e28;">$DISPLAY</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#006e28;">!=</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"x"</span><span style="color:#880088;"><strong> ]</strong></span><span style="color:#141312;"> ; <strong>then</strong></span>
<span style="color:#141312;">    </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">false;</span>
<span style="color:#141312;">    <strong>for</strong> opt <strong>in</strong> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$@</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> ; <strong>do</strong></span>
<span style="color:#141312;">	<strong>case</strong> </span><span style="color:#006e28;">$opt</span><span style="color:#141312;"><strong> in</strong> </span>
<span style="color:#141312;">	    -t<strong>)</strong>   </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">true; </span><span style="color:#880088;"><strong>break</strong></span><span style="color:#141312;"> <strong>;;</strong> </span><span style="color:#888786;"><em># breaks out of the loop</em></span>
<span style="color:#141312;">	    -tty<strong>)</strong> </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">true; </span><span style="color:#880088;"><strong>break</strong></span><span style="color:#141312;"> <strong>;;</strong></span>
<span style="color:#141312;">	    -nw<strong>)</strong>  </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">true; </span><span style="color:#880088;"><strong>break</strong></span><span style="color:#141312;"> <strong>;;</strong></span>
<span style="color:#141312;">	    -c<strong>)</strong>   </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">true; </span><span style="color:#880088;"><strong>break</strong></span><span style="color:#141312;"> <strong>;;</strong></span>
<span style="color:#141312;">	    --create-frame<strong>)</strong> </span><span style="color:#006e28;">user_has_specified_frame=</span><span style="color:#141312;">true; </span><span style="color:#880088;"><strong>break</strong></span><span style="color:#141312;"> <strong>;;</strong></span>
<span style="color:#141312;">	<strong>esac</strong></span>
<span style="color:#141312;">    <strong>done</strong></span>

<span style="color:#141312;">    <strong>if</strong></span><span style="color:#880088;"><strong> [</strong></span><span style="color:#141312;"> </span><span style="color:#006e28;">$user_has_specified_frame</span><span style="color:#141312;"> </span><span style="color:#006e28;">==</span><span style="color:#141312;"> false</span><span style="color:#880088;"><strong> ]</strong></span><span style="color:#141312;"> ; <strong>then</strong></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># Hmm, is this the only situation where we want to add</em></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># --no-wait?</em></span>
<span style="color:#141312;">        </span><span style="color:#006e28;">args=(</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"--no-wait"</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">${args[@]}</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#006e28;">)</span>

<span style="color:#141312;">	</span><span style="color:#006e28;">display=</span><span style="color:#bf0303;">"</span><span style="color:#0057ae;">\"</span><span style="color:#006e28;">$DISPLAY</span><span style="color:#0057ae;">\"</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># display will contain something like "", ":0.0" or</em></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># "localhost:10.0" (including the quotes)</em></span>
<span style="color:#141312;">	</span><span style="color:#006e28;">current_emacs_displays=</span><span style="color:#141312;"><strong>`</strong>_invoke_client_orelse_start_daemon --eval </span><span style="color:#bf0303;">"(x-display-list)"</span><span style="color:#141312;"><strong>`</strong> </span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># current_emacs_displays will contain something like (":0.0"</em></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># "localhost:10.0") current_emacs_displays may also be empty</em></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># if there was no daemon running, of if there is no frame</em></span>
<span style="color:#141312;">          </span><span style="color:#888786;"><em># open.</em></span>
<span style="color:#141312;">	<strong>if [[</strong> </span><span style="color:#006e28;">!</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$current_emacs_displays</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> =~ </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">$display</span><span style="color:#bf0303;">"</span><span style="color:#141312;"><strong> ]]</strong> ; <strong>then</strong></span>
<span style="color:#141312;">              </span><span style="color:#888786;"><em># If there is a match (display is included in</em></span>
<span style="color:#141312;">              </span><span style="color:#888786;"><em># current_emacs_displays), then there is already a frame</em></span>
<span style="color:#141312;">              </span><span style="color:#888786;"><em># open in this $DISPLAY. *Otherwise* we'll add the</em></span>
<span style="color:#141312;">              </span><span style="color:#888786;"><em># --create-frame option to the array:</em></span>
<span style="color:#141312;">            </span><span style="color:#006e28;">args=(</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"--create-frame"</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">${args[@]}</span><span style="color:#bf0303;">"</span><span style="color:#141312;"> </span><span style="color:#006e28;">)</span>
<span style="color:#141312;">	<strong>fi</strong></span>
<span style="color:#141312;">    <strong>fi</strong></span>

<span style="color:#141312;"><strong>fi</strong> </span><span style="color:#888786;"><em># if DISPLAY</em></span>

<span style="color:#141312;">_invoke_client </span><span style="color:#bf0303;">"</span><span style="color:#006e28;">${args[@]}</span><span style="color:#bf0303;">"</span>

<span style="color:#888786;"><em># </em></span><span style="color:#bf0303;"><strong>TODO</strong></span><span style="color:#888786;"><em>: the "emacsclient || (emacsdaemon &amp;&amp; emacsclient)" construct is</em></span>
<span style="color:#888786;"><em># ugly when the emacsclient call fails due to error in arguments --</em></span>
<span style="color:#888786;"><em># the daemon is invoked, but since it is already started a big error</em></span>
<span style="color:#888786;"><em># message is emitted -- FIXED -- now using the --alternate-editor</em></span>
<span style="color:#888786;"><em># mechanism, which works more gracefully.</em></span>

<span style="color:#888786;"><em># </em></span><span style="color:#bf0303;"><strong>TODO</strong></span><span style="color:#888786;"><em>: Check all if-statemenst for potentially empty values, for</em></span>
<span style="color:#888786;"><em># example "$current_emacs_displays" ..?</em></span></pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=116&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>dnsmasq</title>
		<link>http://hugoheden.wordpress.com/2009/03/08/dnsmasq/</link>
		<comments>http://hugoheden.wordpress.com/2009/03/08/dnsmasq/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 21:50:41 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=15</guid>
		<description><![CDATA[Abstract The host running dnsmasq: 1) Wherever  Static IP is configured the first &#8220;DNS Servers&#8221; entry  should specify 127.0.0.1 and the second should specify 192.168.0.254 (or whatever IP the nearest upstream DNS server has). 2) /etc/hosts.dnsmasq: foohost 192.168.1.100 3)  /etc/dnsmasq.conf domain-needed bogus-priv no-hosts addn-hosts=/etc/hosts.dnsmasq expand-hosts domain=foolan dhcp-range=192.168.1.50,192.168.1.100,12h dhcp-host=ahost,192.168.1.70,30m #dhcp-host=otherhost,192.168.1.71,12h #dhcp-host=yetanotherhost,192.168.1.72,30m dhcp-option=option:router,192.168.1.1 Intro I have a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=15&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Abstract</h3>
<p>The host running dnsmasq:</p>
<p>1) Wherever  Static IP is configured <span style="color:#ff0000;">the first &#8220;DNS Servers&#8221; entry  should specify <tt>127.0.0.1</tt> and the second should specify <tt>192.168.0.254</tt> (or whatever IP the nearest upstream DNS server has).</span></p>
<p>2) <span style="color:#ff0000;"><strong>/etc/hosts.dnsmasq:</strong></span></p>
<blockquote><p><span style="color:#ff0000;"><tt>foohost 192.168.1.100</tt></span></p></blockquote>
<p>3)  <strong><span style="color:#ff0000;">/etc/dnsmasq.conf</span></strong></p>
<blockquote><p><span style="color:#ff0000;"><tt>domain-needed<br />
bogus-priv<br />
no-hosts<br />
addn-hosts=/etc/hosts.dnsmasq<br />
expand-hosts<br />
domain=foolan<br />
dhcp-range=192.168.1.50,192.168.1.100,12h<br />
dhcp-host=ahost,192.168.1.70,30m<br />
#dhcp-host=otherhost,192.168.1.71,12h<br />
#dhcp-host=yetanotherhost,192.168.1.72,30m<br />
dhcp-option=option:router,192.168.1.1</tt></span></p></blockquote>
<h3>Intro</h3>
<p>I have a few computers at home (all running Ubuntu Linux 8.10, Intrepid Ibex) forming a small home network. I use <strong><a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a></strong> to achieve the following:</p>
<ul>
<li>Any host can be plugged in &#8220;without configuration&#8221;, i.e the dhcp-server functionality within dnsmasq is used.</li>
<li>After having been plugged in, hosts are able to ping or connect to each other by host name (thus not only by ip numbers), still without configuration, i.e that dhcp-server will be used together with the DNS functionality that dnsmasq provides.</li>
<li>Some of the hosts need a &#8220;constant&#8221; IP within the LAN (or &#8220;static&#8221; if you will, though using dhcp). This is needed for port forwarding to these hosts (so that they can be used for bittorrent and as various types of servers). We achieve this by letting dnsmasq manage a list of hostnames and their respective &#8220;constant&#8221; IP addresses within the LAN. So there is only <em>one</em> place within the whole LAN where that information is maintained, see below. The hosts themselves are still using zero configuration dhcp.</li>
<li>dnsmasq also works as a local dns cache for the LAN, which <a href="http://ubuntu.wordpress.com/2006/08/02/local-dns-cache-for-faster-browsing/">speeds up web browsing</a>.</li>
<li>All this is very easy to set up</li>
</ul>
<p>I tried for a while to set up a WINS server (using samba), but I could never really make that working..</p>
<p>A limitation is that the host running dnsmasq needs to be up pretty all the time (or at least whenever a host on the network needs web access). I have a desktop computer constantly turned on anyway (hosting a few server processes) that dnsmasq can run on.</p>
<p>Another option would be to install it dnsmasq on a router. This would be your only option if there is only Windows computers on your network, because dnsmasq does not run on Windows. I have no experience with this, but see for example <a href="http://www.polarcloud.com/tomato">Tomato Firmware</a>.</p>
<h3>So, how do we set up all this?</h3>
<p>The <span style="color:#ff0000;">host running dnsmasq has a static ip within the LAN</span>. We want other applications <em>on that same host</em> to use dnsmasq for DNS services, and not some other DNS server on some other host. So, within Network Manager (or wherever that Static IP was configured) <span style="color:#ff0000;">the first &#8220;DNS Servers&#8221; entry  should specify <tt>127.0.0.1</tt></span>. When the connection is enabled, NetworkManager will generate a <strong>/etc/resolv.conf</strong> containing something like the following:</p>
<blockquote><p><tt># Generated by NetworkManager<br />
nameserver 127.0.0.1</tt></p></blockquote>
<p>By default, dnsmasq will read <strong>/etc/resolv.conf</strong> and use the hosts specified there (the lines starting with &#8220;nameserver&#8221;) as &#8220;upstream nameservers&#8221; to forward non-local DNS-requests to. In this case that file will point back to localhost (127.0.0.1), see above. But that&#8217;s ok, dnsmasq will understand to ignore <tt>127.0.0.1</tt> and look at the other lines in <strong>/etc/resolv.conf</strong>. In my case I will need to add the ip address that my adsl-modem has on the LAN, because the modem in turn is auto-configured by the ISP (dhcp) to know what dns servers to contact further upstream. So, within Network Manager (or wherever that Static IP was configured) <span style="color:#ff0000;">the second &#8220;DNS Servers&#8221; entry  should specify <tt>192.168.0.254</tt></span>. When the connection is enabled, <span style="color:#ff0000;">NetworkManager will then generate a<strong> /etc/resolv.conf</strong> containing something like the following:</span></p>
<blockquote><p><span style="color:#ff0000;"><tt># Generated by NetworkManager<br />
nameserver 127.0.0.1<br />
nameserver 192.168.0.254</tt></span></p></blockquote>
<p>Further, dnsmasq is configured to ignore the usual <strong>/etc/hosts</strong> and use a <a href="http://hugoheden.wordpress.com/2009/02/24/dnsmasq-and-etchosts/">custom hosts-file instead</a>, <span style="color:#ff0000;"><strong>/etc/hosts.dnsmasq</strong></span>,  containing something like the following (&#8220;foohost&#8221; is the name of the host running dnsmasq)</p>
<blockquote><p><span style="color:#ff0000;"><tt>foohost 192.168.1.100</tt></span></p></blockquote>
<p><strong>/etc/dnsmasq.conf</strong> would then need the entry <strong><tt>no-hosts</tt></strong> to tell dnsmasq to ignore the usual hosts-file, and the entry <strong><tt>addn-hosts=/etc/hosts.dnsmasq</tt></strong> which specifies what file to use instead.</p>
<h3>Wrap-up</h3>
<p>A suitable <strong>/etc/dnsmasq.conf</strong> is shown above. (As always, do a backup of the original before experimenting.) Most of the options are well documented elsewhere (for example in the example configuration file and the man-page). Note the <span style="color:#ff0000;"><tt>dhcp-option=option:router,192.168.1.1</tt></span> line which tells dnsmasq to tell any dhcp-clients what the <span style="color:#ff0000;">gateway</span> of the network is. In my case I&#8217;ve specified the address to my router.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=15&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2009/03/08/dnsmasq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy/paste with emacs in terminal</title>
		<link>http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/</link>
		<comments>http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 18:57:58 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=77</guid>
		<description><![CDATA[I often run emacs in a terminal window. The following is a way to get copy-paste &#8220;working&#8221; to and from other applications. Note that it requires xsel, &#8220;a command-line program for getting and setting the contents of the X selection&#8221;. See also http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/ ;; http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/ ;; I prefer using the "clipboard" selection (the one the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=77&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I often run emacs in a terminal window. The following is a way to get copy-paste &#8220;working&#8221; to and from other applications. Note that it requires <a href="http://www.vergenet.net/~conrad/software/xsel/">xsel</a>, &#8220;a command-line program for getting and setting the contents of the X selection&#8221;. See also <a href="http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/">http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/</a></p>
<div style="font-size:medium;">
<pre><span style="color:#888786;"><em>;; http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/</em></span>
<span style="color:#888786;"><em>;; I prefer using the "clipboard" selection (the one the</em></span>
<span style="color:#888786;"><em>;; typically is used by c-c/c-v) before the primary selection</em></span>
<span style="color:#888786;"><em>;; (that uses mouse-select/middle-button-click)</em></span>
<span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>setq</strong> x-select-enable-clipboard <strong>t</strong></span><span style="color:#0000ff;"><strong>)</strong></span>

<span style="color:#888786;"><em>;; If emacs is run in a terminal, the clipboard- functions have no</em></span>
<span style="color:#888786;"><em>;; effect. Instead, we use of xsel, see</em></span>
<span style="color:#888786;"><em>;; http://www.vergenet.net/~conrad/software/xsel/ -- "a command-line</em></span>
<span style="color:#888786;"><em>;; program for getting and setting the contents of the X selection"</em></span>
<span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>unless</strong> window-system</span><span style="color:#009900;">
</span> <span style="color:#009900;">(when (getenv "DISPLAY")</span>
<span style="color:#008000;">  </span><span style="color:#888786;"><em>;; Callback for when user cuts</em></span>
<span style="color:#141312;">  </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#d22811;"><strong>defun</strong></span><span style="color:#644a9b;"> xsel-cut-function </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">text &amp;optional <strong>push</strong></span><span style="color:#0000ff;"><strong>)</strong></span>
<span style="color:#141312;">    </span><span style="color:#888786;"><em>;; Insert text to temp-buffer, and "send" content to xsel stdin</em></span>
<span style="color:#141312;">    </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">with-temp-buffer</span>
<span style="color:#141312;">      </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">insert text</span><span style="color:#0000ff;"><strong>)</strong></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em>;; I prefer using the "clipboard" selection (the one the</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em>;; typically is used by c-c/c-v) before the primary selection</em></span>
<span style="color:#141312;">      </span><span style="color:#888786;"><em>;; (that uses mouse-select/middle-button-click)</em></span>
<span style="color:#141312;">      </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">call-process-region </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">point-min</span><span style="color:#0000ff;"><strong>)</strong></span><span style="color:#141312;"> </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">point-max</span><span style="color:#0000ff;"><strong>)</strong></span><span style="color:#141312;"> </span><span style="color:#bf0303;">"xsel"</span><span style="color:#141312;"> <strong>nil</strong> </span><span style="color:#b08000;">0</span><span style="color:#141312;"> <strong>nil</strong> </span><span style="color:#bf0303;">"--clipboard"</span><span style="color:#141312;"> </span><span style="color:#bf0303;">"--input"</span><span style="color:#0000ff;"><strong>)))</strong></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em>;; Call back for when user pastes</em></span>
<span style="color:#141312;">  </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#d22811;"><strong>defun</strong></span><span style="color:#644a9b;"> xsel-paste-function</span><span style="color:#0000ff;"><strong>()</strong></span>
<span style="color:#141312;">    </span><span style="color:#888786;"><em>;; Find out what is current selection by xsel. If it is different</em></span>
<span style="color:#141312;">    </span><span style="color:#888786;"><em>;; from the top of the kill-ring (car kill-ring), then return</em></span>
<span style="color:#141312;">    </span><span style="color:#888786;"><em>;; it. Else, nil is returned, so whatever is in the top of the</em></span>
<span style="color:#141312;">    </span><span style="color:#888786;"><em>;; kill-ring will be used.</em></span>
<span style="color:#141312;">    </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>let</strong> </span><span style="color:#0000ff;"><strong>((</strong></span><span style="color:#141312;">xsel-output </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;">shell-command-to-string </span><span style="color:#bf0303;">"xsel --clipboard --output"</span><span style="color:#0000ff;"><strong>)))</strong></span>
<span style="color:#141312;">      </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>unless</strong> </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>string=</strong> </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>car</strong> kill-ring</span><span style="color:#0000ff;"><strong>)</strong></span><span style="color:#141312;"> xsel-output</span><span style="color:#0000ff;"><strong>)</strong></span>
<span style="color:#141312;">	xsel-output </span><span style="color:#0000ff;"><strong>)))</strong></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em>;; Attach callbacks to hooks</em></span>
<span style="color:#141312;">  </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>setq</strong> interprogram-cut-function 'xsel-cut-function</span><span style="color:#0000ff;"><strong>)</strong></span>
<span style="color:#141312;">  </span><span style="color:#0000ff;"><strong>(</strong></span><span style="color:#141312;"><strong>setq</strong> interprogram-paste-function 'xsel-paste-function</span><span style="color:#0000ff;"><strong>)</strong></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em>;; Idea from</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em>;; http://shreevatsa.wordpress.com/2006/10/22/emacs-copypaste-and-x/</em></span>
<span style="color:#141312;">  </span><span style="color:#888786;"><em>;; http://www.mail-archive.com/help-gnu-emacs@gnu.org/msg03577.html</em></span>
<span style="color:#141312;"> </span><strong><span style="color:#009900;">)</span><span style="color:#0000ff;">)
</span></strong></pre>
</div>
<p>Thanks to Nikolaj Schumacher and Miles Bader on the <a href="http://lists.gnu.org/archive/html/help-gnu-emacs/2009-03/msg00181.html">help-gnu-emacs mailing list</a> for helping out.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=77&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>dnsmasq and /etc/hosts</title>
		<link>http://hugoheden.wordpress.com/2009/02/24/dnsmasq-and-etchosts/</link>
		<comments>http://hugoheden.wordpress.com/2009/02/24/dnsmasq-and-etchosts/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 19:26:31 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hugoheden.wordpress.com/?p=39</guid>
		<description><![CDATA[Abstract /etc/hosts.dnsmasq: 192.168.1.100 foohost (/etc/hosts is left alone) /etc/dnsmasq.conf: &#8230; no-hosts addn-hosts=/etc/hosts.dnsmasq &#8230; Intro dnsmasq will, by default, read the contents of /etc/hosts and use the information there for looking up those hosts that are configured to have a static IP on the LAN. (Hosts using dnsmasq as a dhcp-server are not specified there). Problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=39&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Abstract</h3>
<blockquote>
<div style="color:#ff0000;"><strong>/etc/hosts.dnsmasq:</strong><br />
192.168.1.100 foohost<br />
(<strong>/etc/hosts </strong>is left alone)</div>
</blockquote>
<blockquote>
<div style="color:#ff0000;"><strong>/etc/dnsmasq.conf:</strong><br />
&#8230;<br />
no-hosts<br />
addn-hosts=/etc/hosts.dnsmasq<br />
&#8230;</div>
</blockquote>
<h3>Intro</h3>
<p><strong><a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a></strong> will, by default, read the contents of <strong>/etc/hosts</strong> and use the information there for looking up those hosts that are configured to have a static IP on the LAN. (Hosts using dnsmasq as a dhcp-server are not specified there).</p>
<h3>Problem</h3>
<p>However, in Debian, Ubuntu  and others, <strong>/etc/hosts</strong> seems to contain lines that break this &#8212; something like the following (the host name is <strong>foohost</strong> in this example):</p>
<blockquote><p>127.0.0.1 foohost    localhost.localdomain   localhost<br />
127.0.1.1 foohost<br />
&#8230;</p></blockquote>
<p>A consequence is that if <em>another</em> host on the network for example tries to <strong>ping foohost</strong>, the DNS lookup performed by dnsmasq on foohost will return 127.0.0.1 or 127.0.1.1, which will not be the address that was intended&#8212;the <em>other</em> host will end up pinging <em>itself</em>.</p>
<h3>Solution</h3>
<p>Now, apparently the above /etc/hosts is broken &#8212; for Debian and derivatives it should be rewritten as</p>
<blockquote><p>127.0.0.1   localhost<br />
127.0.1.1 foohost<br />
&#8230;</p></blockquote>
<p>&#8211; see  [1], [2] and Google.</p>
<p>Further,  if the host has a permanent IP then that IP should be specified instead of 127.0.1.1. And the host running dnsmasq will need to have a <strong>static IP, so problem solved:</strong></p>
<blockquote><p># Fixed /etc/hosts:<br />
127.0.0.1   localhost<br />
192.168.1.100 foohost<br />
&#8230;</p></blockquote>
<h3>Other solution</h3>
<p><span style="color:#ff0000;">I think I prefer to leave /etc/hosts alone though</span>. I suspect various network configuration tools  will edit that file, and may unfix it.  dnsmasq can instead be configured to use <em>another</em> host-file (as suggested by <a href="https://lists.ubuntu.com/archives/ubuntu-users/2008-December/168833.html">Nils Kassube on ubuntu-users</a>). So, I have added a file <span style="color:#ff0000;"><strong>/etc/hosts.dnsmasq</strong></span>, specifying the static ip of the host running dnsmasq:</p>
<blockquote><p><span style="color:#ff0000;">192.168.1.100 foohost</span></p></blockquote>
<p><span style="color:#ff0000;"><strong>/etc/dnsmasq.conf</strong></span> would then need the entry <span style="color:#ff0000;"><strong>no-hosts</strong></span> to tell dnsmasq to ignore the usual hosts-file, and the entry <span style="color:#ff0000;"><strong>addn-hosts=/etc/hosts.dnsmasq</strong></span> which specifies what file to use instead.</p>
<p>(The above mentioned file, <strong>/etc/hosts.dnsmasq</strong>, could also contain other typical <strong>/etc/hosts</strong> entries for other hosts on the LAN using static ip, as described in the very nice <a href="http://www.enterprisenetworkingplanet.com/netos/article.php/10951_3377351_2">article on  enterprisenetworkingplanet</a> &#8230; but why would we do that when all hosts can use configuration-less dhcp instead?)</p>
<p>[1] <a href="http://www.debian.org/doc/manuals/reference/ch-gateway.en.html#s-net-dns">http://www.debian.org/doc/manuals/reference/ch-gateway.en.html#s-net-dns</a></p>
<p>[2] <a href="https://bugs.launchpad.net/ubuntu/+source/netcfg/+bug/19775/comments/23">https://bugs.launchpad.net/ubuntu/+source/netcfg/+bug/19775/comments/23</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=39&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2009/02/24/dnsmasq-and-etchosts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
		<item>
		<title>Port forwarding through modem and router</title>
		<link>http://hugoheden.wordpress.com/2009/02/10/port-forwarding-through-modem-and-router/</link>
		<comments>http://hugoheden.wordpress.com/2009/02/10/port-forwarding-through-modem-and-router/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 10:06:31 +0000</pubDate>
		<dc:creator>Hugo Heden</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I have a SpeedTouch 510 ADSL modem at home (firmware 4.2.7.16.0), and behind that there is a Linksys WRT54G wireless router. Being total rookie I had big trouble setting up port forwarding for this system, so I decided to document this. There are probably a zillion different ways to do this, and I tried many combinations of settings. The following was the only variant I managed to get working: <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=1&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a SpeedTouch 510 ADSL modem at home (firmware 4.2.7.16.0), and behind that there is a Linksys WRT54G wireless router. Being a total rookie I had big trouble setting up port forwarding for this system, so I decided to document this.</p>
<p>There are probably a zillion different ways to do this, and I tried many combinations of settings. The following was the only variant I managed to get working:</p>
<p><strong>-A-</strong></p>
<p><em>The modem</em> will be configured to be completely &#8220;open&#8221; i.e forward all incoming connections to the router, by specifying the <em>router IP address</em> as the &#8220;NAPT &#8211; Default Server&#8221; within the modem web-UI. (<em>NAPT</em> stands for Network Address and Port Translation.)</p>
<p><strong>-B-</strong></p>
<p><em>The router</em> will act as a firewall (except for the port forwarding that will be configured below). The <em>router IP address</em> will need to be <em>static</em>. Had it had a dynamic IP (using for example the modems built-in dhcp-server), that &#8220;NAPT &#8211; Default Server&#8221; setting within the modem web-UI would have needed to be manually updated whenever the router IP changed. Obviously very inconvenient.</p>
<blockquote><p><strong>Pitfall: </strong>I wanted to just quickly test port forwarding without fiddling with setting the router IP address to static. But no, that just did not seem to work. The modem seemed to refuse to forward any connections if &#8220;NAPT &#8211; Default Server&#8221; was set to &#8230; to a dynamic IP address handed out by the modem..? Or something. So, my tip would be to <em>start</em> with setting the router to have a static IP. That worked a lot better.</p>
<p>So, <em>start</em> with setting the router to have a static IP, say 192.168.0.1, instead of a dynamic one. On the Linksys this is done in the web-UI under &#8220;Setup =&gt; Basic Setup&#8221;. When choosing Static IP in the drop-down, the UI seemed to intelligently fill in some of the needed values.</p>
<ul>
<li>Internet IP Address: 192.168.0.1 &lt;is typical&gt;</li>
<li>Subnet Mask: 255.255.255.0       &lt;is typical&gt;</li>
<li>Gateway: &lt;The LAN IP address that the modem has, 192.168.0.254 maybe&gt;</li>
<li>Static DNS 1: &lt;The LAN IP address that the modem has, same as Gateway&gt;</li>
</ul>
<p>Fiddle with this until there is a reliable internet connection again.. Use Google.. Perhaps the modem and/or the router need to be restarted?</p></blockquote>
<p><strong>-C-</strong></p>
<p>The router in turn will act as a firewall, but <em>some</em> incoming connections (coming from the Internet via the modem) will be forwarded &#8212; as specified in the router web-UI under &#8220;Application &amp; Gaming&#8221; =&gt; &#8220;Port Range Forward&#8221;. Here we specify port(range)s that we want forwarded, and to what IP address within the LAN each port(range) will be forwarded:</p>
<ul>
<li>Application (not sure what this is for)</li>
<li>Start (of port range)</li>
<li>End (of port range)</li>
<li>Protocol (tcp, udp or both)</li>
<li>IP-Address (LAN address to forward to, for example 192.168.1.100)</li>
</ul>
<p><strong>Step by step</strong></p>
<p>After having configured the router to have a static IP (see -B- above), the following steps outline what needs to be performed.</p>
<p><strong>-1-</strong></p>
<p>We need a working Internet connection so that we can test that we don&#8217;t break stuff. Visit a site that will assist in testing our port-forwarding. A good candidate seems to be:</p>
<blockquote><p>http://www.yougetsignal.com/tools/open-ports/</p></blockquote>
<p><strong>-2-</strong></p>
<p>For testing purposes, temporarily open some port on the local desktop, say port 55555, by opening a program that listens for incoming connections, for example sshd:</p>
<blockquote><p>$ sudo /usr/sbin/sshd -D -p 55555</p></blockquote>
<p>Verify on yougetsignal.com that the port is not (yet) open on the modem when connected to from the Internet.</p>
<p><strong>-3-</strong></p>
<p>In the modem web-UI, under &#8220;Advanced =&gt; NAPT =&gt; Default Server&#8221;, enter the static IP that the router now has (see -B- above, 192.168.0.1 in that example).</p>
<p><strong>-4-</strong></p>
<p>As described in -C- above, configure the router to forward ports&#8230; Verify on yougetsignal.com that the port is now open on the modem when connected to from the Internet.</p>
<p><strong>-5-</strong></p>
<p>Shut down whatever program was opened in step -2- above.</p>
<p><strong>-DONE-</strong></p>
<p>&#8212;</p>
<p><strong>QUESTION:</strong> Should the modem firewall be turned off now that we forward everything to the router anyway? I guess so.</p>
<p>&#8212;</p>
<p><strong>PS: </strong>See also these sites that does things in a way I could not really understand or get to work:</p>
<p>http://portforward.com/</p>
<p>http://www.xs4all.nl/~eeuwen/speedtouch_510.htm</p>
<p>&#8212;</p>
<p><strong>PS: </strong>I am not able go get UPnP (Universal Plug and Play) in the linksys router working (using the Administration=&gt;Management=&gt;UPnP area in the web-UI) even if I disable the firewall within the modem and enable UPnP within the modem. Perhaps UPnP does not work in &#8220;two layers&#8221; (router *and* modem).. or what is the problem? I am using the Transmission Bittorrent client which supports UPnP. Might as well turn off UPnP then, both in the router and in the modem (Advanced=&gt;NAPT=&gt;UPnP), as it may pose a security risk..?</p>
<p>&#8212;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hugoheden.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hugoheden.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hugoheden.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hugoheden.wordpress.com&amp;blog=6526606&amp;post=1&amp;subd=hugoheden&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hugoheden.wordpress.com/2009/02/10/port-forwarding-through-modem-and-router/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/777d0139fee600842b41d0d783d72e87?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hugoheden</media:title>
		</media:content>
	</item>
	</channel>
</rss>
