<?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>lxg</title>
	<atom:link href="http://www.lxg.de/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lxg.de</link>
	<description>personal website of alex günsche</description>
	<lastBuildDate>Tue, 01 May 2012 21:57:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>A script&#8217;s own directory in bash</title>
		<link>http://www.lxg.de/code/a-scripts-own-directory-in-bash</link>
		<comments>http://www.lxg.de/code/a-scripts-own-directory-in-bash#comments</comments>
		<pubDate>Tue, 01 May 2012 21:55:50 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=329</guid>
		<description><![CDATA[If you want to find out a shell script&#8217;s own path, you might be tempted to use $(pwd). But this will not work when you call the script from a different directory than the one where the script resides. This is due to the fact that commands like pwd refer to the environment of the [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to find out a shell script&#8217;s own path, you might be tempted to use <code>$(pwd)</code>. But this will not work when you call the script from a different directory than the one where the script resides. This is due to the fact that commands like <code>pwd</code> refer to the environment of the calling shell, not the script.</p>
<p>A better approach is to use the bash variable <code>$0</code>. If the script is in a different location, <code>$0</code> will contain the relative path from the shell to the script. Combined with <code>dirname</code> and <code>realpath</code>, you get a waterproof solution for the path problem:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="re2">MYDIR</span>=<span class="st0">&quot;<span class="es4">$(realpath $(dirname $0)</span>)&quot;</span></pre></div></div></div></div></div></div></div>


<p><code>$MYDIR</code> will then hold the absolute path to the script, no matter from where it was called.</p>
<p>There is, however, one pitfall: <code>realpath</code> is not a bash builtin, but it must be installed via the package manager on most distributions. Therefore, this is not an ultimatively portable solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/a-scripts-own-directory-in-bash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Helper for multi-select fields</title>
		<link>http://www.lxg.de/code/helper-for-multi-select-fields</link>
		<comments>http://www.lxg.de/code/helper-for-multi-select-fields#comments</comments>
		<pubDate>Mon, 13 Feb 2012 12:51:38 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=321</guid>
		<description><![CDATA[Multi-select fields are still a big problem for users. For one, it is almost impossible to unselect all items. And users often don&#8217;t understand that they may select more than one item, or how they could accomplish this. Therefore I&#8217;ve written a little helper which is automatically appended to multi-select fields. It allows to select/unselect [...]]]></description>
			<content:encoded><![CDATA[<p>Multi-select fields are <a href="/?p=17">still</a> a big problem for users. For one, it is almost impossible to unselect all items. And users often don&#8217;t understand that they may select more than one item, or how they could accomplish this.</p>
<p>Therefore I&#8217;ve written a little helper which is automatically appended to multi-select fields. It allows to select/unselect all items, and it offers a little help icon that explains how to use the multi-select fields. I&#8217;m doing this with jQuery, but this can be done with any other framework or plain JavaScript.</p>
<p>Check out the <strong><a href="/pages/demo.multiselecthelper.html">demo</a></strong> and its source code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/helper-for-multi-select-fields/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating arbitrary elements in OpenLayers at SelectFeature position</title>
		<link>http://www.lxg.de/code/creating-arbitrary-elements-in-openlayers-at-selectfeature-position</link>
		<comments>http://www.lxg.de/code/creating-arbitrary-elements-in-openlayers-at-selectfeature-position#comments</comments>
		<pubDate>Sun, 12 Feb 2012 13:55:58 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[OpenLayers]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=319</guid>
		<description><![CDATA[OpenLayers is able to creates SVG elements (vectors) on a map and listen for “select” events on them – usually a mouseover or click. Unfortunately, it is not easy to find out the screen position of the event. This is strange, because it works well for other event types (like drag). There are some “hidden” [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://openlayers.org/">OpenLayers</a> is able to creates SVG elements (vectors) on a map and listen for “select” events on them  – usually a mouseover or click. Unfortunately, it is not easy to find out the screen position of the event. This is strange, because it works well for other event types (like drag). There are some “hidden” methods like <code>….object.events.getMousePosition()</code>, but they don&#8217;t seem to work as intended, at least for me.</p>
<p>However, the element passed to the event callback contains a <code>geometry</code> property, a reference to the Geometry object of the vector, which provides the <code>getBounds()</code>, which again can be used with <code>getCenterLonLat()</code>. Now we do at least know the longitude/latitude position of the center of the selected element.</p>
<p>To determine the actual position on the screen, we use a bit of jQuery magic in this example, but this will work with other frameworks or plain JavaScript, too.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="javascript"><pre class="de1">jQuery<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>jQ<span class="br0">&#41;</span><span class="br0">&#123;</span>
&nbsp;
<span class="co1">// put your other OpenLayers code here (omitted for simplicity)</span>
<span class="co1">// create a map, add a base layer, set center, etc.</span>
&nbsp;
&nbsp;
    <span class="kw2">var</span>
        vectorsLayer <span class="sy0">=</span> <span class="kw2">new</span> OpenLayers.<span class="me1">Layer</span>.<span class="me1">Vector</span><span class="br0">&#40;</span><span class="st0">&quot;Vectors Layer&quot;</span><span class="sy0">,</span> <span class="br0">&#123;</span>
            styleMap<span class="sy0">:</span> <span class="kw2">new</span> OpenLayers.<span class="me1">StyleMap</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
                fillColor<span class="sy0">:</span> <span class="st0">'#D6A000'</span><span class="sy0">,</span>
                fillOpacity<span class="sy0">:</span> <span class="nu0">0.8</span><span class="sy0">,</span>
                strokeWidth<span class="sy0">:</span> <span class="nu0">3</span><span class="sy0">,</span>
                strokeColor<span class="sy0">:</span> <span class="st0">'#665932'</span><span class="sy0">,</span>
                pointRadius<span class="sy0">:</span> <span class="nu0">4</span>
            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">,</span>
            rendererOptions<span class="sy0">:</span> <span class="br0">&#123;</span>yOrdering<span class="sy0">:</span> <span class="kw2">true</span><span class="br0">&#125;</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">,</span>
        pointsRaw <span class="sy0">=</span> <span class="br0">&#91;</span>
            <span class="br0">&#91;</span><span class="nu0">51.33453</span><span class="sy0">,</span><span class="nu0">7.32293</span><span class="br0">&#93;</span><span class="sy0">,</span>
            <span class="br0">&#91;</span><span class="nu0">51.1071</span><span class="sy0">,</span><span class="nu0">7.1422</span><span class="br0">&#93;</span><span class="sy0">,</span>
            <span class="br0">&#91;</span><span class="nu0">50.88998</span><span class="sy0">,</span><span class="nu0">6.67058</span><span class="br0">&#93;</span><span class="sy0">,</span>
            <span class="br0">&#91;</span><span class="nu0">50.73246</span><span class="sy0">,</span><span class="nu0">6.11502</span><span class="br0">&#93;</span>
        <span class="br0">&#93;</span><span class="sy0">,</span>
        point<span class="sy0">,</span>
        points <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span>
&nbsp;
    map.<span class="me1">addLayer</span><span class="br0">&#40;</span>vectorsLayer<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>pointsRaw.<span class="me1">length</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        point <span class="sy0">=</span> <span class="kw2">new</span> OpenLayers.<span class="me1">Geometry</span>.<span class="me1">Point</span><span class="br0">&#40;</span>pointsRaw<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">,</span> pointsRaw<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        point.<span class="me1">transform</span><span class="br0">&#40;</span>
            <span class="kw2">new</span> OpenLayers.<span class="me1">Projection</span><span class="br0">&#40;</span><span class="st0">&quot;EPSG:4326&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>
            map.<span class="me1">getProjectionObject</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
        <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        points.<span class="me1">push</span><span class="br0">&#40;</span><span class="kw2">new</span> OpenLayers.<span class="me1">Feature</span>.<span class="me1">Vector</span><span class="br0">&#40;</span>point<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        vectorsLayer.<span class="me1">addFeatures</span><span class="br0">&#40;</span>points<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw2">var</span> onSelectCallback <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span>vector<span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw2">var</span>
            lonlat <span class="sy0">=</span> vector.<span class="me1">geometry</span>.<span class="me1">getBounds</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getCenterLonLat</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
            xy <span class="sy0">=</span> map.<span class="me1">getViewPortPxFromLonLat</span><span class="br0">&#40;</span>lonlat<span class="br0">&#41;</span><span class="sy0">,</span>
            mapOffset <span class="sy0">=</span> jQ<span class="br0">&#40;</span><span class="st0">'#map'</span><span class="br0">&#41;</span>.<span class="me1">offset</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        jQ<span class="br0">&#40;</span><span class="st0">'&lt;div&gt;foobar&lt;/div&gt;'</span><span class="br0">&#41;</span>.<span class="me1">css</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
            position<span class="sy0">:</span> <span class="st0">'absolute'</span><span class="sy0">,</span>
            top<span class="sy0">:</span> <span class="br0">&#40;</span>xy.<span class="me1">y</span> <span class="sy0">+</span> mapOffset.<span class="me1">top</span><span class="br0">&#41;</span><span class="sy0">+</span><span class="st0">'px'</span><span class="sy0">,</span>
            left<span class="sy0">:</span> <span class="br0">&#40;</span>xy.<span class="me1">x</span> <span class="sy0">+</span> mapOffset.<span class="me1">left</span><span class="br0">&#41;</span><span class="sy0">+</span><span class="st0">'px'</span><span class="sy0">,</span>
            backgroundColor <span class="sy0">:</span> <span class="st0">'#ffffff'</span><span class="sy0">,</span>
            border <span class="sy0">:</span> <span class="st0">'1px solid #ccc'</span><span class="sy0">,</span>
            zIndex <span class="sy0">:</span> <span class="nu0">2000</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">appendTo</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw2">var</span> selectControl <span class="sy0">=</span>  <span class="kw2">new</span> OpenLayers.<span class="me1">Control</span>.<span class="me1">SelectFeature</span><span class="br0">&#40;</span>vectorsLayer<span class="sy0">,</span> <span class="br0">&#123;</span>
        clickout<span class="sy0">:</span> <span class="kw2">true</span><span class="sy0">,</span>
        toggle<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span>
        multiple<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span>
        hover<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span>
        onSelect <span class="sy0">:</span> onSelectCallback
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    map.<span class="me1">addControl</span><span class="br0">&#40;</span>selectControl<span class="br0">&#41;</span><span class="sy0">;</span>
    selectControl.<span class="me1">activate</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>Why would we need the position? For example, to create custom popup-like elements on the map. Yes, OL provides its own popups, but they are … not so beautiful, and its not easy to style them properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/creating-arbitrary-elements-in-openlayers-at-selectfeature-position/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Globalize</title>
		<link>http://www.lxg.de/code/jquery-globalize</link>
		<comments>http://www.lxg.de/code/jquery-globalize#comments</comments>
		<pubDate>Tue, 07 Feb 2012 13:16:25 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=317</guid>
		<description><![CDATA[If you have developed a larger web application with support for multiple languages, you will certainly have a number of functions that help with language-specific formatting of numbers, dates, currency expressions. For those of you using jQuery, check out Globalize, an add-on library for jQuery that supports lots of formatting structures in a whole lot [...]]]></description>
			<content:encoded><![CDATA[<p>If you have developed a larger web application with support for multiple languages, you will certainly have a number of functions that help with language-specific formatting of numbers, dates, currency expressions.</p>
<p>For those of you using jQuery, check out <a href="https://github.com/jquery/globalize">Globalize</a>, an add-on library for jQuery that supports lots of formatting structures in a whole lot of languages (or, “cultures” in Globalize&#8217;s terms).</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="javascript"><pre class="de1">jQuery<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="co1">// make sure to have jQuery, the Globalize library and the respective culture file loaded</span>
&nbsp;
    Globalize.<span class="me1">cultureSelector</span> <span class="sy0">=</span> <span class="st0">'de'</span><span class="sy0">;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span> Globalize.<span class="me1">format</span><span class="br0">&#40;</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span>timestamp<span class="sy0">*</span><span class="nu0">1000</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st0">'D'</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span> Globalize.<span class="me1">format</span><span class="br0">&#40;</span><span class="nu0">12345.67</span><span class="sy0">,</span> <span class="st0">&quot;n2&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    Globalize.<span class="me1">cultureSelector</span> <span class="sy0">=</span> <span class="st0">'en'</span><span class="sy0">;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span> Globalize.<span class="me1">format</span><span class="br0">&#40;</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span>timestamp<span class="sy0">*</span><span class="nu0">1000</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="st0">'D'</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">alert</span><span class="br0">&#40;</span> Globalize.<span class="me1">format</span><span class="br0">&#40;</span><span class="nu0">12345.67</span><span class="sy0">,</span> <span class="st0">&quot;n2&quot;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>However, the Globalize library along with its culture files is pretty heavy-weight. You should only consider using them if you plan support for lots of languages and have various data types to format.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/jquery-globalize/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GUI prototyping with Pencil</title>
		<link>http://www.lxg.de/technology/gui-prototyping-with-pencil</link>
		<comments>http://www.lxg.de/technology/gui-prototyping-with-pencil#comments</comments>
		<pubDate>Wed, 30 Nov 2011 15:12:27 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[rapid prototyping]]></category>
		<category><![CDATA[wireframes]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=303</guid>
		<description><![CDATA[I recently discovered a very nice tool for GUI prototyping, called Pencil. It can be installed as a Firefox AddOn or as a standalone software. The Firefox XPI is unfortunately not in the Mozilla repositories which means you have to install it from their site, which also means no package verification and no automated upgrades. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered a very nice tool for GUI prototyping, called <a href="http://pencil.evolus.vn/en-US/Home.aspx" target="_blank">Pencil</a>. It can be installed as a Firefox AddOn or as a standalone software. The Firefox XPI is unfortunately not in the Mozilla repositories which means you have to install it from their site, which also means no package verification and no automated upgrades.</p>
<p>Apart from that, Pencil is a very nice tool. It&#8217;s a very easy to use it allows to create interface prototyping in no time. Of course, you should know what <a href="http://en.wikipedia.org/wiki/Website_wireframe" target="_blank">wireframes</a> are and what they are used for.</p>
<p>To demonstrate how quick you can create drafts for a website layout, let&#8217;s assume we are creating a booking site for events and we want to create a first draft of the home page. Here&#8217;s what you could get after 15 minutes sketching with Pencil. (Yes, that is Comic Sans MS. <img src='http://www.lxg.de/wp-includes/images/smilies/icon_eek.gif' alt='8O' class='wp-smiley' /> As awkward as it sounds: this font is actually suitable for this sort of work.)</p>
<p><a href="http://www.lxg.de/wp-content/uploads/2011/11/pencil.jpg"><img src="http://www.lxg.de/wp-content/uploads/2011/11/pencil-740x446.jpg" alt="" title="pencil" width="740" height="446" class="alignnone size-medium wp-image-304" /></a></p>
<p>Of course, Pencil doesn&#8217;t offer the fancy features of elaborate drawing software like, for example, <a href="http://inkscape.org/" target="_blank">Inkscape</a>. In fact, it doesn&#8217;t offer much more than a collection of common web UI elements which can be easily placed, resized, aligned and colored. The great thing about this is that you don&#8217;t need a tutorial or FAQ to get started – Pencil is completely self-explanatory.</p>
<p>It has multi-sheet documents, and you can copy/paste elements from one sheet to another one, which allows to quickly create variations of one screen. A variety of exporters (ODF, PDF, HTML) will help you to discuss your ideas with co-workers or customers.</p>
<p>Although Pencil still misses a number of essential features like guides, more shortcuts or better configurability, it is an ideal tool to put your ideas to paper.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/technology/gui-prototyping-with-pencil/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gentoo tip: Clean your world file</title>
		<link>http://www.lxg.de/code/gentoo-tip-clean-your-world-file</link>
		<comments>http://www.lxg.de/code/gentoo-tip-clean-your-world-file#comments</comments>
		<pubDate>Tue, 08 Nov 2011 11:30:09 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Gentoo]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=299</guid>
		<description><![CDATA[As a Gentoo user, you sometimes emerge packages which you don&#8217;t want to be in the world set, you just emerged them because you needed to fix or test something. (Of course, there&#8217;s the -1 flag, but you don&#8217;t always remember to use it.) With time, these packages become unneccessary, pull in useless dependencies and [...]]]></description>
			<content:encoded><![CDATA[<p>As a Gentoo user, you sometimes emerge packages which you don&#8217;t want to be in the world set, you just emerged them because you needed to fix or test something. (Of course, there&#8217;s the <code>-1</code> flag, but you don&#8217;t always remember to use it.) With time, these packages become unneccessary, pull in useless dependencies and cause stupid conflicts. Therefore you should remove them from the <code>@world</code> set.</p>
<p>The <code>@world</code> set is stored in a plain text file located at <code>/var/lib/portage/world</code>. You should be aware that manipulating it may cause problems, therefore you&#8217;re advised to make a backup before editing. Also, you should do a full update of your system with <code>emerge -uND world</code>. Now you can open the world file in an editor of your choice, as root.</p>
<p>You may delete entries for packages you don&#8217;t need anymore, line by line. In order to actually remove those packages and their dependencies from your system, you must run depclean and revdep-rebuild:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">emerge <span class="re5">-a</span> <span class="re5">--depclean</span>
revdep-rebuild <span class="re5">--</span> <span class="re5">-q</span> <span class="re5">--keep-going</span></pre></div></div></div></div></div></div></div>


<p>After this, you will have a much leaner system.</p>
<p>Bonus hint: Also check your <code>/etc/make.conf</code> as well as your <code>/etc/portage/package.use</code> for no longer needed USE flags. These also tend to cause conflicts and stuff your system with needless dependencies. (Remember to run <code>emerge -auND world; emerge -a --depclean; revdep-rebuild -- -q --keep-going</code> afterwards.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/gentoo-tip-clean-your-world-file/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Search doesn&#8217;t support the + operator anymore</title>
		<link>http://www.lxg.de/technology/google-search-doesnt-support-the-plus-operator-anymore</link>
		<comments>http://www.lxg.de/technology/google-search-doesnt-support-the-plus-operator-anymore#comments</comments>
		<pubDate>Tue, 01 Nov 2011 10:56:01 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Search Engine]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=291</guid>
		<description><![CDATA[Google&#8217;s + operator is appearently no longer supported. For those who didn&#8217;t know, Google used to have a + operator which you could place directly in front of a word and which had two features: it would make sure that the word was included in every result, and it would make sure that only results [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lxg.de/technology/google-search-doesnt-support-the-plus-operator-anymore/attachment/google_plus_operator" rel="attachment wp-att-296"><img src="http://www.lxg.de/wp-content/uploads/2011/11/google_plus_operator-740x309.jpg" alt="" title="google_plus_operator" class="alignnone size-medium wp-image-296" /></a><br />
Google&#8217;s + operator is appearently no longer supported.</p>
<p>For those who didn&#8217;t know, Google used to have a + operator which you could place directly in front of a word and which had two features: it would make sure that the word was included in every result, and it would make sure that only results with the exact spelling of that word would be returned. This feature is not the same as using the quote operator, because that one only enforces the exact spelling – but it does not make sure the word is included in each result.</p>
<p>Of course, not always both features were desired at the same time – for example, you may have wanted to make sure the word was included in the results, but you would have accepted alternative spellings. But even then, the + operator was be a nice addition for a search strategy.</p>
<p>I like search engines who provide advanced tools for fine-tuning searches. And this move of Google is one in a direction I don&#8217;t like.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/technology/google-search-doesnt-support-the-plus-operator-anymore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Very lightweight redirect service for self-hosting</title>
		<link>http://www.lxg.de/code/very-lightweight-redirect-service-for-self-hosting</link>
		<comments>http://www.lxg.de/code/very-lightweight-redirect-service-for-self-hosting#comments</comments>
		<pubDate>Mon, 31 Oct 2011 12:44:21 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=282</guid>
		<description><![CDATA[There are lots of URL redirecting services – all of them do the job. But if you still want to do redirects yourself from your own domain (especially if you have a short domain name ), you may want to have your own little service for that. And, it just feels nice to have the [...]]]></description>
			<content:encoded><![CDATA[<p>There are lots of URL redirecting services – all of them do the job. But if you still want to do redirects yourself from your own domain (especially if you have a short domain name <img src='http://www.lxg.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ), you may want to have your own little service for that. And, it just feels nice to have the power over redirects in your own hands.</p>
<p>I have created such a service for this website, so have a try right away: <a href="http://lxg.de/r/eff" target="_blank">lxg.de/r/eff</a>.</p>
<p>The URL should be as short as possible. Also, you don&#8217;t want the URL shortener to conflict with your other web stuff. Therefore, you should create a subdirectory <code>r/</code> in your document root and put a <code>.htaccess</code> file with the following content there.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="txt"><pre class="de1">&lt;IfModule mod_rewrite.c&gt;
	RewriteEngine On
	RewriteBase /r/
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /r/index.php [L]
&lt;/IfModule&gt;</pre></div></div></div></div></div></div></div>


<p>Now create the file <code>index.php</code> with the following content:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="re0">$req</span>     <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st_h">'|[^a-z0-9\-\_\.]|i'</span><span class="sy0">,</span> <span class="st_h">''</span><span class="sy0">,</span> <span class="kw3">strrchr</span><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st_h">'REQUEST_URI'</span><span class="br0">&#93;</span><span class="sy0">,</span> <span class="st_h">'/'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$list</span>    <span class="sy0">=</span> <span class="kw3">file</span><span class="br0">&#40;</span>__DIR__<span class="sy0">.</span><span class="st_h">'/list.php'</span><span class="sy0">,</span> FILE_IGNORE_NEW_LINES <span class="sy0">&amp;</span> FILE_SKIP_EMPTY_LINES<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$url</span>     <span class="sy0">=</span> <span class="st_h">''</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#41;</span><span class="re0">$list</span> <span class="kw1">as</span> <span class="re0">$line</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re0">$line</span><span class="sy0">,</span> <span class="st0">&quot;<span class="es4">$req</span><span class="es1">\t</span>&quot;</span><span class="br0">&#41;</span> <span class="sy0">!==</span> <span class="nu0">0</span><span class="br0">&#41;</span>
		<span class="kw1">continue</span><span class="sy0">;</span>
&nbsp;
	<span class="re0">$url</span> <span class="sy0">=</span> <span class="kw3">trim</span><span class="br0">&#40;</span><span class="kw3">strrchr</span><span class="br0">&#40;</span><span class="re0">$line</span><span class="sy0">,</span> <span class="st0">&quot;<span class="es1">\t</span>&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">break</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw3">header</span><span class="br0">&#40;</span><span class="st0">&quot;Location: <span class="es4">$url</span>&quot;</span><span class="sy0">,</span> <span class="kw4">true</span><span class="sy0">,</span> <span class="nu0">302</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw3">printf</span><span class="br0">&#40;</span><span class="st_h">'If your browser doesn\'t redirect you, click here: &lt;a href=&quot;%1$s&quot;&gt;%1$s&lt;/a&gt;.'</span><span class="sy0">,</span> <span class="re0">$url</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">else</span>
<span class="br0">&#123;</span>
	<span class="kw1">echo</span> <span class="st_h">'Sorry, no redirect found. Please check the spelling of the URL.'</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw3">exit</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre></div></div></div></div></div></div></div>


<p>The actual mapping of redirection identifiers to target URLs is in the file <code>list.php</code>:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="kw2">&lt;?php</span> <span class="kw3">die</span><span class="br0">&#40;</span><span class="st_h">'Error'</span><span class="br0">&#41;</span> <span class="sy1">?&gt;</span>
&nbsp;
eff		http://www.eff.org/
aclu		http://www.aclu.org/</pre></div></div></div></div></div></div></div>


<p>The first line of this file is important to make sure that nobody can simply download the list (this is also why we use a PHP file and no plain TXT). The other lines consist of arbitrary identifiers and the target URLs, separated by one or more tab characters. The identifiers may contain latin letters, numbers, and the dot, minus and underscore characters. It may be advisable to make them human readable, but you may also optimize them for length.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/very-lightweight-redirect-service-for-self-hosting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>eBay spam</title>
		<link>http://www.lxg.de/business/ebay-spam</link>
		<comments>http://www.lxg.de/business/ebay-spam#comments</comments>
		<pubDate>Wed, 07 Sep 2011 18:51:18 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[eBay]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=278</guid>
		<description><![CDATA[Who else with a developer account from eBay has gotten more than five dedicated e-mails from eBay about their freakin&#8217; confercence within the last days? Everybody? I thought so. Ok, eBay: so you&#8217;re holding a conference on X.com, the new blabla of eCommerce, whatever. Send me one e-mail, ok. Send me two e-mails, well. But [...]]]></description>
			<content:encoded><![CDATA[<p>Who else with a developer account from eBay has gotten more than five dedicated e-mails from eBay about their freakin&#8217; confercence within the last days? Everybody? I thought so.</p>
<p>Ok, eBay: so you&#8217;re holding a conference on X.com, the new blabla of eCommerce, whatever. Send me one e-mail, ok. Send me two e-mails, well. But is your crappy conference selling so badly that you need to constantly spam everybody about it? – Yes? I thought so.</p>
<p>Goodbye, eBay. Hope you&#8217;re announcing that you&#8217;re going the way of all dinosaurs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/business/ebay-spam/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First or last element of an array in PHP</title>
		<link>http://www.lxg.de/code/first-or-last-element-of-an-array-in-php</link>
		<comments>http://www.lxg.de/code/first-or-last-element-of-an-array-in-php#comments</comments>
		<pubDate>Mon, 29 Aug 2011 20:57:04 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.lxg.de/?p=272</guid>
		<description><![CDATA[I&#8217;ve seen horrible things today. Somebody (the file didn&#8217;t carry an author … good for him or her) tried to get the first element of a PHP array – using array_shift. Of course, array_shift modifies the source array, so he worked on a copy of his original array, as (of course) he didn&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen horrible things today. Somebody (the file didn&#8217;t carry an author … good for him or her) tried to get the first element of a PHP array – using <code>array_shift</code>. Of course, <code>array_shift</code> modifies the source array, so he worked on a copy of his original array, as (of course) he didn&#8217;t want to alter the array itself. Looked something like this:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$copyOfArray</span> <span class="sy0">=</span> <span class="re0">$array</span><span class="sy0">;</span>
<span class="re0">$firstElementOfArray</span> <span class="sy0">=</span> <span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re0">$copyOfArray</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>That is obviously a waste of memory and CPU cycles. Usually not noticable, of course. But with large arrays or when frequently executed, it will add stress to the system.</p>
<p>There&#8217;s a very “cheap” way to get the first value of any given array. The <code>reset</code> function does just that. (<code>end</code> returns the last element.)</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><pre class="de1"><span class="re0">$firstElementOfArray</span> <span class="sy0">=</span> <span class="kw3">reset</span><span class="br0">&#40;</span><span class="re0">$array</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>


<p>Now, <code>reset</code> will set the internal <em>array pointer</em> to the first value. However, unless your doing crazy things or writing sloppy code, you shouldn&#8217;t care about that anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lxg.de/code/first-or-last-element-of-an-array-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

