<?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>Benny's Blog</title>
	<atom:link href="http://blog.projectnibble.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.projectnibble.org</link>
	<description>House Of Code</description>
	<lastBuildDate>Fri, 13 Aug 2010 15:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>What is the currently active workspace in Eclipse?</title>
		<link>http://blog.projectnibble.org/2010/08/13/what-is-the-currently-active-workspace-in-eclipse/</link>
		<comments>http://blog.projectnibble.org/2010/08/13/what-is-the-currently-active-workspace-in-eclipse/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 07:21:36 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[workspace]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=591</guid>
		<description><![CDATA[Imagine you are dealing with multiple workspaces, which for example can be expected if you split up a code base in several Eclipse projects and you are working on several releases at once. Now wouldn&#8217;t it be handy if Eclipse would tell you which workspace is active? There are two ways. 1. Increase workspace history [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you are dealing with multiple workspaces, which for example can be expected if you split up a code base in several Eclipse projects and you are working on several releases at once. Now wouldn&#8217;t it be handy if Eclipse would tell you which workspace is active?</p>
<p><strong>There are two ways.</strong></p>
<p><span id="more-591"></span></p>
<h2>1. Increase workspace history and derive from this list</h2>
<p>You can derive from the workspace history list which workspace isn&#8217;t in there: that one will be the one currently active. This is the list you see when you got to <i>File -> Switch Workspace</i>.</p>
<p>Depending on how many workspaces you need, you might want to increase the size of the workspace history. You can configure this setting at:</p>
<p><i>Window -> Preferences -> General -> Startup and Shutdown -> Workspaces -> &#8216;Number of workspaces to remember&#8217;</i>.</p>
<h2>2. Show the current workspace in the titlebar</h2>
<p>This one is obviously better as it requires no action on your part. Here’s a clear and simple post I found to solve this the right way.</p>
<p><a href="http://www.rekk.de/bloggy/2007/eclipse-show-workspace-location-in-title-bar/">Eclipse – Show Workspace Location in Title Bar</a></p>
<blockquote><p>eclipse -showlocation -vmargs -Xmx700M</p></blockquote>
<p>(those vmargs are optional and have nothing to do with showing the workspace.)</p>
<p>Thanks uhm&#8230; admin guy!</p>
<p><a href="http://blog.projectnibble.org/2010/08/13/what-is-the-currently-active-workspace-in-eclipse/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/08/13/what-is-the-currently-active-workspace-in-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Ubuntu’s broken bluetooth support came to be</title>
		<link>http://blog.projectnibble.org/2010/08/08/how-ubuntus-broken-bluetooth-support-came-to-be/</link>
		<comments>http://blog.projectnibble.org/2010/08/08/how-ubuntus-broken-bluetooth-support-came-to-be/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 17:56:09 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[bluez]]></category>
		<category><![CDATA[jaunty]]></category>
		<category><![CDATA[karmic]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lynx]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=560</guid>
		<description><![CDATA[A couple of years ago it happened, Linux land was getting a Bluetooth upgrade. However, everything was not well afterwards. CLI Bluetooth suicide by bluez: Bluetooth is dead! Long live Bluetooth!]]></description>
			<content:encoded><![CDATA[<p><img src="http://projectnibble.org/dump/blog/ubuntu/bluetoothquestion.jpg" alt="Bluetooth supported?" style="float:left;width:150px;height: 150px" /> Pairing up your Bluetooth device was relatively well documented, by the community anyway. It was mostly done using the bluez package from <a href="http://www.bluez.org/">bluez.com</a>. Ubuntu town and in fact all of Linux land was generally at peace and the trendy folk at the BlueTooth Bar were being all trendy-like.</p>
<p>Then it happened. Ubuntu went up one release: <strong>Jaunty came to be and subsequently Bluetooth support died</strong>. Even now the Internet is teeming with Bluetooth bug reports, problems and forums are filled with questions such as &#8216;my keyboard is not being paired&#8217;. In fact, Debian seemed to be hit as well as some other distributions that leveled up.</p>
<p><strong>What had happened?</strong></p>
<p><span id="more-560"></span></p>
<h2>Bluez changed is what happened</h2>
<p>The developers of bluez, once the nice Bluetooth package everyone could live with, decided <a href="http://www.bluez.org/bluez-40/">it was time for a major overhaul</a>: they merged the packages <em>bluez-libs</em> and <em>bluez-utils</em> and then some. And with &#8216;and then some&#8217; meaning completely changing the way Bluetooth devices are configured and thereby breaking backwards compatibility.</p>
<p>All of this shouldn&#8217;t really matter, except for one little detail: <strong>The Ubuntu dev team thought it was a good idea to drop the old Bluetooth support and go for the new version</strong>. They included bluez 4.0 and everybody broke in tears. That&#8217;s all there is to this little story, Bluetooth has been neglected since 2008 when Jaunty came about and <strong>things have not improved</strong>.</p>
<p><strong>Why is that?</strong></p>
<h2>Bluez is a bunch of cowboy coders is why</h2>
<p>Actually, I know nothing of the team except that <a href="http://git.kernel.org/?s=bluetooth">it seemingly has about one active developer</a>. Bluez arguably is an awesome team: they have these coders, stomping away on probably wireless keyboards to create utterly thorough Bluetooth support for Linux. They&#8217;re awesome right? Perhaps not.</p>
<p><strong>Bluez doesn&#8217;t document anything</strong>. At all. It&#8217;s a <a href="http://forums.gentoo.org/viewtopic-t-833038-highlight-.html">widely acknowledged fact</a> (Gentoo too?) they didn&#8217;t document the legacy Bluetooth support and they didn&#8217;t document the new support. If you read the <a href="http://www.bluez.org/bluez-40/">bluez 4.0 release notes</a> you still don&#8217;t know anything and you won&#8217;t either. Nobody will, because there is no documentation! Oh, they&#8217;ll completely overhaul Bluetooth support but they&#8217;ll never tell how it works now. That&#8217;s for you to find out. I&#8217;ve even glanced over the source code only to find out that they don&#8217;t like to comment their code either.</p>
<p style="background-color: rgb(225,225,225);padding: 5px;text-align: center;">
<a href="http://c2.com/cgi/wiki?CowboyCoder">Definition of a Cowboy Coder</a><br />
Although normally I couldn&#8217;t care less about some random piece of software, but if you include a significant framework in your operating system, there have got to be <i>some</i> kind of set of standards that includes documentation, right?
</p>
<p>That&#8217;s why everyone is still dealing with the same problems it did in 2008: <strong>the old <a href="https://help.ubuntu.com/community/BluetoothSetup">community documentation</a> is still there, but it isn&#8217;t getting updated</strong>. That page is just one of hundreds ofcourse. Here&#8217;s the <a href="http://forums.overclockers.com.au/showthread.php?t=875957">typical research process</a> one goes through figuring out how to get Bluetooth working (notice how he&#8217;s constantly confronted with conflicting guides and ultimately didn&#8217;t find a solution). The problem again is that nobody <i>can</i> update those pages. If you are feeling particularly masochistic, try reading <a href="http://www.linuxquestions.org/questions/debian-26/bluetooth-problems-715839/#post3512495">this thread</a> (especially the last post where it says &#8216;SOLVED&#8217;).</p>
<p>Let&#8217;s discuss what must be one of the most encountered problem: &#8216;hcid.conf is missing!&#8217;. <a href="http://ubuntuforums.org/showthread.php?t=594624">Old documentation</a> will tell you how to configure your Bluetooth device in Ubuntu so that it connects when your pc boots. That is to say, how you need to edit a <em>/etc/bluetooth/hcid.conf</em> configuration file. Well, that file was removed by the bluez team in bluez 4.0. Reread the <a href="http://www.bluez.org/bluez-40/">bluez 4.0 release notes</a>:</p>
<blockquote><p>With this new major version a lot of things have been changed:<br />
   &#8211; The main daemon is now called bluetoothd (instead of hcid)<br />
   &#8211; The main configuration file is /etc/bluetooth/main.conf and follows INI-style syntax</p></blockquote>
<p>And indeed, scanning the source files reveal that the hcid.conf is no longer used, but other configuration files instead. It appears to me that hcid.conf has become main.conf, except that scanning the code doesn&#8217;t confirm this. Instead, main.conf and input.conf are only used to read the options already provided. Changing the names of configuration files ofcourse isn&#8217;t the only thing that changed, since just using main.conf or whatever doesn&#8217;t seem to magically do the trick. I still can&#8217;t figure out how to enumerate devices in the new configuration files, it&#8217;s not like you can&#8217;t just say, <i>&#8216;Well, instead of hcid.conf just use blah.conf&#8217;</i>. I did get a long way <a href="http://hoyhabloyo.wordpress.com/2009/10/04/howto-using-your-mobile-phone-as-a-bluetooth-modem/">configuring my keyboard in rfcomm.conf</a>, but since my keyboard doesn&#8217;t seem to support SMP (Session Multiplex Protocol, I got errors reporting this to me), I assume it is used mainly for pairing phones.</p>
<p>Even now, everyone still uses the deprecated but still supported <a href="http://manpages.ubuntu.com/manpages/lucid/en/man1/hidd.1.html">hidd</a>, primitive but effective bluetooth adapter tool. You can install it using the command <i>sudo apt-get install bluez-compat</i> and then use it they way I used it to <a href="http://blog.projectnibble.org/2010/01/28/how-to-connect-a-bluetooth-keyboard-in-ubuntu-9-04-jaunty-and-9-10-karmic-workaround/">connect my keyboard</a>. You just can&#8217;t use it to reconnect devices with from reboot, wake up, or the device coming out of suspension. The hcid.conf was used for this, but now it is dead.</p>
<h2>About hidd being deprecated anyway</h2>
<p>If hidd has become deprecated, I wonder what replaced it. Searching the internet revealed <em>nothing</em>. Until I found this <a href="http://groups.google.com/group/linux.debian.bugs.dist/browse_thread/thread/2f27aa10c60ef1c4?pli=1">deeply hidden gem</a>. In this Debian bug report, this guy &#8216;Phil&#8217; mentions how a guy on the bluez mailing list mentioned that a wiki mentioned something about hidd being replaced with a more generic so called &#8216;&#8221;input service&#8221; over <a href="http://www.freedesktop.org/wiki/Software/dbus">dbus</a>&#8216; approach? Woh, have I just found a vague piece of information about how things changed? Let&#8217;s see this Wiki! Oh wait! IT DOESN&#8217;T EXIST! Sigh.</p>
<blockquote><p>I had set up my bluetooth keyboard based on the instructions in /usr/share/doc/bluez-utils/README.Debian, i.e. starting hidd &#8211;server by enabling it in /etc/default/bluetooth, running hcitool scan, and then hidd &#8211;conect <addr>.  This method is now deprecated; instead we should use something called the &#8220;input service&#8221; over dbus.  See the following page, which contains examples of dbus-send commands to do this: http://wiki.bluez.org/wiki/HOWTO/InputDevices</p></blockquote>
<p>Ofcourse I just *had* to know what was on that Wiki, so I turned to the ever so awesome Wayback Machine. <a href="http://web.archive.org/web/20080420100303/http://wiki.bluez.org/wiki/HOWTO/InputDevices">Here&#8217;s what I found</a>. Read it yourself. Hint: you won&#8217;t get anywhere, but here&#8217;s what I get from it. It seems the new approach is a more generic ultra obfuscated command that accepts an instruction class or identifier such as &#8216;org.bluez.input.Manager.RemoveDevice&#8217;. No manual and certainly nothing about configuring your connections for auto-connect during boot.</p>
<p>I don&#8217;t know why they took down the wiki, but from the looks of it, most of it was about the API anyway, useful for developers, not end-users using the command-line.</p>
<p>Also, there&#8217;s an <a href="https://bbs.archlinux.org/viewtopic.php?pid=563760">interesting discussion on bluez 4.0 in Arch Linux</a> I found, the first one I&#8217;ve encountered where the participants actually try to get the new &#8216;dbus&#8217; way working. Nothing we can use in Ubuntu though. I&#8217;ve tried to get bluez talking to me using dbus, but I couldn&#8217;t get it to do anything but spout a range of errors.</p>
<p>Finally, a guide I found on <a href="http://wiki.openmoko.org/wiki/Manually_using_Bluetooth">using Bluetooth with bluez 3 and 4</a> not related to a particular Linux distribution. Unfortunately, the dbus keeps barfing up on everything I throw at it, so no dice for Ubuntu I guess.</p>
<h2>Current state of Ubuntu&#8217;s Bluetooth support</h2>
<p>Technically the title of this blog post is wrong: <strong>Ubuntu&#8217;s Bluetooth support is probably better now than it ever was, it&#8217;s just that nobody knows how to use it</strong>. To be fair, it&#8217;s not an entirely lost cause; people still get their devices to work properly after many people have tried to fix some variation of a given problem and people figured out how to connect a mouse or a phone using the new Bluetooth support for example, often with obscure workarounds. But a lot of people, including me, <a href="http://blog.projectnibble.org/2010/01/28/how-to-connect-a-bluetooth-keyboard-in-ubuntu-9-04-jaunty-and-9-10-karmic-workaround/">still can&#8217;t get a Bluetooth keyboard to connect and pair during boot</a>.</p>
<p>Also there is a solution if you happen to use some desktop, using the <a href="http://library.gnome.org/users/gnome-bluetooth/stable/gnome-bluetooth-applet.html.en">Bluetooth Applet</a>. It handles everything for you and reportedly it generally works. It&#8217;s no use to me however as I&#8217;m only running a server, but I might check out the applet&#8217;s source code to see how it works, hopefully using bluez&#8217; command line API.</p>
<p>As of yet, there has been no answer from the dev team on the number one <a href="http://www.google.com/search?hl=en&#038;q=hcid.conf+missing+OR+gone">search result for &#8216;missing hcid.conf&#8217;</a> bug report: <a href="https://bugs.launchpad.net/ubuntu/+source/bluez-utils/+bug/365779">Bug 365779</a>. Technically it&#8217;s not a bug, but the fact that it hasn&#8217;t been closed, deferred to another bug or had a dev on it since May 2009 indicates it either has no priority or nobody had the balls to fix it. Notice though there are literally hundreds of bluez related bug reports for numrous distro&#8217;s.</p>
<p>Also a search on the original writers of the <a href="http://manpages.ubuntu.com/manpages/hardy/en/man5/hcid.conf.5.html">last hcid.conf man page</a> didn&#8217;t reveal a comment on how things changed and how things now work.</p>
<p>So what needs to be done to get some clarity on the matter? If you know, please shout out, because yes, I&#8217;m currently still looking to fix my keyboard under Ubuntu 10.04. </p>
<p>Meanwhile, try <strong><a href="http://vikashazrati.wordpress.com/2008/06/11/bluetooth-problems-ubuntu-804/">downgrading the bluez package to its previous version</a></strong> (note: I couldn&#8217;t get the bluetooth package to work with the older bluez packages in Ubuntu 10.04, good luck and have fun).</p>
<p><a href="http://blog.projectnibble.org/2010/08/08/how-ubuntus-broken-bluetooth-support-came-to-be/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/08/08/how-ubuntus-broken-bluetooth-support-came-to-be/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[solved] Ubuntu’s partman hangs on ‘scanning disks’</title>
		<link>http://blog.projectnibble.org/2010/08/03/solved-ubuntu-partman-hangs-on-scanning-disks/</link>
		<comments>http://blog.projectnibble.org/2010/08/03/solved-ubuntu-partman-hangs-on-scanning-disks/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 18:51:46 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[jaunty]]></category>
		<category><![CDATA[karmic]]></category>
		<category><![CDATA[lynx]]></category>
		<category><![CDATA[partman]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=544</guid>
		<description><![CDATA[Here&#8217;s another gem from the Ubuntu malaise: partitioning a disk hangs when booting from an Ubuntu Live USB stick. Depending on a couple of factors partman, Ubuntu&#8217;s installer partion manager, will hang on &#8216;scanning disks&#8217;, from around 43% to 47%. Following are two possible reasons and solutions. Partman barfs up on your USB stick Apparently, [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another gem from the Ubuntu malaise: partitioning a disk hangs when booting from an Ubuntu Live USB stick.</p>
<p>Depending on a couple of factors <a href="https://help.ubuntu.com/6.10/ubuntu/installation-guide/ia64/partition-programs.html">partman</a>, Ubuntu&#8217;s installer partion manager, will hang on &#8216;scanning disks&#8217;, from around 43% to 47%. Following are two possible reasons and solutions.</p>
<p><span id="more-544"></span></p>
<h2>Partman barfs up on your USB stick</h2>
<p>Apparently, <a href="http://blog.stochasticbytes.com/2010/05/installing-ubuntu-1004-server-on-usb.html">partman doesn&#8217;t tolerate USB sticks with logical sector size of anything but 512 bytes</a>. Seriously, the damn thing boots fine and runs an installation fine, but when running partman the whole things grinds to a halt.</p>
<p><strong>Solution</strong>: pull out your USB stick about the moment the installation starts running partman. It works like a charm: the installation keeps running and when it&#8217;s done you can even put it back in. I don&#8217;t know if you have to, but I did and it didn&#8217;t barf up in my face.</p>
<h2>Partman barfs up on existing partions</h2>
<p>Apparently, partman is a bit sensitive because <a href="http://ubuntuforums.org/showthread.php?p=9674428#post9650968">partman also doesn&#8217;t tolerate certain partitioning schemes</a>.</p>
<p><strong>Solution</strong>: <a href="http://www.linuxquestions.org/questions/linux-newbie-8/using-dd-to-zero-the-mbr-query-606489/">wipe out the partition table using the DD command</a> to zero out those sectors and abort the formatting stage. Once gone, partman won&#8217;t have a problem accessing the partitions&#8230; which you had to remove like you remove grass with a bulldozer.</p>
<p><a href="http://blog.projectnibble.org/2010/08/03/solved-ubuntu-partman-hangs-on-scanning-disks/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/08/03/solved-ubuntu-partman-hangs-on-scanning-disks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Bezier curves and for loops</title>
		<link>http://blog.projectnibble.org/2010/07/08/fun-with-bezier-curves-and-for-loops/</link>
		<comments>http://blog.projectnibble.org/2010/07/08/fun-with-bezier-curves-and-for-loops/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 13:47:24 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Bezier]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=461</guid>
		<description><![CDATA[[REPOST] &#8211; this is a repost of an old but still relevant forum post of mine (Fun with Bezier curves), which I&#8217;m moving to my blog on my own server. Bezier curves are cool. They are curves calculated through a formula with control points. These control points are crucial, as these determine how long, big [...]]]></description>
			<content:encoded><![CDATA[<div style="color:#999999; font-size: 8pt">
<p>[REPOST] &#8211; this is a repost of an old but still relevant forum post of mine (<a href="http://www.ultrashock.com/forums/sources-and-experiments/fun-with-bezier-curves-72789.html">Fun with Bezier curves</a>), which I&#8217;m moving to my blog on my own server.</p>
</div>
<p>
Bezier curves are cool. They are curves calculated through a formula with control points. These control points are crucial, as these determine how long, big and curved the Bezier curves are. There are optimized formulas for three, four and five control points, but in this post we&#8217;ll deal with an arbitrary number of control points and interactively drawing the curves.
</p>
<div style="text-align:center;">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="350" height="350" id="example2_bezierlookup" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#dddddd" /><embed src="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.swf" quality="high" bgcolor="#cccccc" width="350" height="350" name="example2_bezierlookup" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
</object><br />
<span style="color:999999">(<a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.fla">download source</a>)</span>
</div>
<p><span id="more-461"></span></p>
<p style="background-color: #C3FDB8; padding: 5px">
To get some background information on Bezier curves, quadratic and cubic curves, visit <a href="http://www.webreference.com/dlab/9902/bezier.html">Bezier</a>, <a href="http://www.timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm">cubic Bezier curves in flash</a> and <a href="http://www.macromedia.com/devnet/flash/articles/precision_drawing.html">flash drawing methods</a>. Also check out <a href="http://www.ultrashock.com/forums/showthread.php?threadid=11651">Ultrashock&#8217;s thread on Bezier curves by robert Penner</a>.
</p>
<p style="border-top: 1px dotted black; border-bottom: 1px dotted black; padding: 1em 0em 1em 0em;">
I was doing some personal research in Bezier curves and was interested in finding way to draw Bezier curves through a dynamic number of control points. The problem was, everywhere I looked for information it was always about Bezier curves up to 5 control points, which were calculated with an optimized formula for exactly that amount of control points (a simplified version of the general formula for n+1 control points). So I wrote my own take on it; one that can handle an unlimited amount of control points added dynamically and lets you control how smooth the curves are.
</p>
<h2>Bezier curves &#8211; from math to code</h2>
<p><a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/emptysetup.html">empty setup preview</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/emptysetup.fla">source</a>)</p>
<p>Here we go. Take a look at this fla. The only code in it is to create the draggable control points and the empty <i>drawBezierCurves</i> function that is being called when a controlpoint has changed (because you dragged it, or added new ones). The buttons at the bottom reset the movie with a number of control points, and the buttons below that change how smooth the line should be. The textfield in the upper right corner indicates how fast the Bezier curve was drawn. We&#8217;ll add more to this movie as we go along.</p>
<p>Now take a look at this Bezier formula.<br />
<img src="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/bezierfomula.png"/></p>
<p>Converted into Actionscript, this is:</p>
<pre  name="code" class="javascript">
(factorial(N) / (factorial(k) * factorial(N - k))) * Math.pow(u, k) * Math.pow(1 - u, N - k);

// where factorial '!' is our custom recursive function

function factorial(x:Number):Number {
	return (x <= 1) ? 1 : x * factorial(x - 1);
}
</pre>
<p>To actually calculate x and y, consider the following example, where we have 5 control points, and thus N is 4 (the formula says N+1 control points). The control points are the movieclips that you can drag.</p>
<pre  name="code" class="javascript">
var stepsize:Number = 1/30;
var N:Number = 4;
for (var u = 0; u <= 1; u += stepsize) {
		x = y = 0;
		for (var k = 0; k <= N; k++) {
			var blend:Number = (factorial(N) / (factorial(k) * factorial(N - k))) *
Math.pow(u, k) * Math.pow(1 -  u, N - k);
			x += this["controlPoint" + k]._x * blend;
			y += this["controlPoint" + k]._y * blend;
		}
		this.lineTo(x, y);
	}
</pre>
<p>First of, <i>u</i> is the 'lifetime' variable of the Bezier curve. For example u = 1 is all the way to the end of the curve on the last control point, u = 0 is at the beginning at the first control point, and u = 0.5 is exactly in the middle of the line. The smaller the steps you take, the smoother the line is going to be, because you use smaller intervals. Also, the stepSize has to be at least as big as the number of control points. Otherwise, the line won't even reach the control points on the end.</p>
<p>This is what the movie does with this code: <a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example1.html">example1</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example1.fla">source</a>)</p>
<p>Cool huh, this works for every N. Try it at 15 control points in overkill mode; it now is doing (15 control points * 6 smoothmodifier) steps * 15 = 1350 cycles of Bezier calculations on *each* update. See the speed at around 30ms in standalone player? As you can imagine, this is rather heavy duty for the cpu, as it has to do three factorials, two powers and some multiplications for every x,y point we calculate each cycle. In older players this used to be 220ms so things have been improving, but this is why most examples you find don't use this method and instead use a formula that is optimized for (and limited to) up to 5 control points. For example this <a href="http://web.archive.org/web/20060912063411/local.wasp.uwa.edu.au/~pbourke/curves/bezier/">Bezier summary by Paul Bourke</a> shows special cases for exactly 2 and 3 control points. This greatly increases speed, but you are limited to 2 and 3 controlpoints.</p>
<p>There is another way however to speed things up: Lookup tables. First, we'll create a lookup table for the factorial calculations.</p>
<pre  name="code" class="javascript">
var factorialTable:Array = new Array();

for (var k = 0; k <= N; k++) {
	factorialTable[k] = factorial(k);
}
</pre>
<p>You see, we only calculate the values that we'll need for the Bezier curves. No more, no less. However, this means we have to update the lookup table every time we add or remove a control point.</p>
<p>Now the lookup table for power.</p>
<pre  name="code" class="javascript">
var powerTable:Array = new Array();

for (var u = 0; u <= 1; u += stepsize) {
	if (powerTable[u] == undefined) {
		powerTable[u] = new Array();
	}
	if (powerTable[1 - u] == undefined) {
		powerTable[1 - u] = new Array();
	}
	for (var k = 0; k <= N; k++) {
		powerTable[u][k] = Math.pow(u, k);
		powerTable[1 - u][k] = Math.pow(1 - u, k);
	}
}
</pre>
<p>Now, our method to calculate the Bezier curves looks like this:</p>
<pre  name="code" class="javascript">
var stepsize:Number = 1 / 30;
var N:Number = 4;

for (var u = 0; u <= 1; u += stepsize) {
	x = y = 0;
	for (var k = 0; k <= N; k++) {
		var blend:Number = (factorialTable[N] / (factorialTable[k] *
factorialTable[N - k])) * powerTable[u][k] *  powerTable[1 - u][N - k];
		x += this["controlPoint" + k]._x * blend;
		y += this["controlPoint" + k]._y * blend;
	}
	this.lineTo(x, y);
}
</pre>
<p>I also made a version with a lookup table for the Bezier blend values instead of power and factorial values. Here are the results.</p>
<ul>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_powerlookup.fla">power &#038; factorial lookup table source</a></li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.fla">Bezier blend value lookup table source</a></li>
</ul>
<div style="text-align:center;">
<div style="border: 1px dotted grey; padding: 5px; width: 600px; height: 300px; margin-left: auto; margin-right: auto;">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="600" height="300" id="JelloWave" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.projectnibble.org/dump/ultrashock/bezier/Jello/JelloWave.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="http://www.projectnibble.org/dump/ultrashock/bezier/Jello/JelloWave.swf" quality="high" bgcolor="#ffffff" width="600" height="300" name="JelloWave" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
</object>
</div>
<p><span style="color:999999">(<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Jello/JelloWave.fla">download source</a>)</span>
</div>
<ul><strong>Here are some more experimental Bezier examples:</strong></p>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.html">Bezier controlpoint demonstration</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier/example2_bezierlookup.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/Jello/JelloWave.html">JelloWave.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Jello/JelloWave.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_a.html">Globb_a.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_a.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_b.html">Globb_b.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_b.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_c.html">donut</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_c.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_d.html">Globbor</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/Globb/Globb_d.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/trailer/trailer.html">trailer.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/trailer/trailer.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/wheeler/wheeler.html">wheeler.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/wheeler/wheeler.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/sketcher/sketcher.html">sketcher.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/sketcher/sketcher.fla">source</a>)</li>
<li><a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier3d/Bezier3D.html">Bezier3D.html</a> (<a href="http://www.projectnibble.org/dump/ultrashock/bezier/bezier3d/bezier3D.zip">source</a>)</li>
</ul>
<p><a href="http://blog.projectnibble.org/2010/07/08/fun-with-bezier-curves-and-for-loops/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/07/08/fun-with-bezier-curves-and-for-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Papervision3D star (sun) tutorial and source</title>
		<link>http://blog.projectnibble.org/2010/02/11/papervision3d-star-sun-tutorial-and-source/</link>
		<comments>http://blog.projectnibble.org/2010/02/11/papervision3d-star-sun-tutorial-and-source/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 22:33:04 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[star]]></category>
		<category><![CDATA[sun]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=423</guid>
		<description><![CDATA[Read how by combing Perlin noise and a trick using two planes, you can make a real-time animated glaring sun corona in Papervision3D.]]></description>
			<content:encoded><![CDATA[<p>If you are looking for a cool sun effect (no pun intended) with flaring corona, you&#8217;re in the right place. This post isn&#8217;t about some practical sun in some shooter though: it would require some tweaking to make it useful in such context, as the animation is rather cpu heavy due to its massive corona noise textures.</p>
<p>No, this post is about combining cool PV3D features in order to achieve a nice looking animated sun. I’ve used the trunk of the papervision code repository, revision 851 (it works up to r910, after that <a href="http://code.google.com/p/papervision3d/issues/detail?id=250">a bug was introduced</a>). Note that I&#8217;m no PV3D guru; I&#8217;m just sharing what I&#8217;ve learned so far.</p>
<div style="text-align:center">
<ul>
<li><a href="http://projectnibble.org/dump/blog/papervision3d_sun/suntutorial.rar">download sun source</a></li>
</ul>
<p>
<object width="400" height="400">
<param name="movie" value="http://projectnibble.org/dump/blog/papervision3d_sun/Suntutorial.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#000000"></param>
<embed type="application/x-shockwave-flash" width="400" height="400" src="http://projectnibble.org/dump/blog/papervision3d_sun/Suntutorial.swf" quality="high" bgcolor="#000000" wmode="window" menu="false" ></embed>
</object>
<br />
<span style="color:999999">(note: this sun uses the skybox from the <a href="http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/">skybox tutorial</a>)</span>
</div>
<p>Closely watch that corona for a while!</p>
<p><span id="more-423"></span></p>
<h2>How it works</h2>
<ul>In short: the sun exist entirely of planes, controlled by alpha ratios and always facing the camera:</p>
<li>one plane with a gradient texture white to red with glow</li>
<li>two planes with a perlin texture, that resize and tag eachother as to provide a continuous outwards motion</li>
<li>one plane that acts as a mask for the other planes to provide a perfect circle giving the illusion of a round star</li>
</ul>
<h3>The star&#8217;s gradient</h3>
<p>Actually, it took quite some tweaking to get a nice gradient of white in the middle and yellow to red on the edge. It&#8217;s a basic <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html#beginGradientFill()">Sprite gradient fill</a>, using three colors, alpha layering and a specific color ratio array to get the last two colors (yellow and red) on the edge. Then I&#8217;m applying this gradient <em>twice</em> on the same canvas to get the result I want when the flaring corona&#8217;s are added. I couldn&#8217;t get it the way I wanted with the alpha array alone (let me know if you got a better way), but this worked and the gradients are only calculated and drawn once.</p>
<p>Drawing it twice means less transparency and that means more dense flares as we&#8217;ll see later on when we&#8217;re combining the star glow layer and corona layer using <a href="http://www.bukisa.com/articles/38637_papervision-3d-programming-tutorial-blend-modes">BlendMode.ADD</a> (which is also the reason why we need MovieMaterial here: otherwise they won&#8217;t interact on layer-level).</p>
<div style="text-align:center">
<img src="http://projectnibble.org/dump/blog/papervision3d_sun/sunglow.png" alt="sunglow" />
</div>
<pre  name="code" class="java">
// pseudo code
var sunColors:Array = [0xfefefe, 0xFAEB61, 0xff0000]; // white, orange/yellow, red
var sunAlphas:Array = [1, .8, 0]; // white part opaque, 20% from the edge out fading out
var sunRatios:Array = [0x85, 0xAA, 0xDD]; // all white except for the edges

var size:Number = 1000;
var sunglowMaterial:MovieMaterial = createSunglowMaterial(size, sunColors, sunAlphas, sunRatios);
var sun:Plane = new Plane(sunglowMaterial, size, size, null, null);

/**
 * Creates a disc texture using radial alpha. Draw twice for extra intensity of the colors.
 */
private function createSunglowMaterial(size:Number, colors:Array, alphas:Array, ratios:Array):MovieMaterial {
	var mat:Matrix = new Matrix();
	mat.createGradientBox(size, size);
	var sunTexture:Sprite = new Sprite();
	for (var i:Number = 0; i < 2; i++) {
		sunTexture.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, mat);
		sunTexture.graphics.drawRect(0, 0, size, size);
		sunTexture.graphics.endFill();
	}
	return new MovieMaterial(sunTexture, true);
}
</pre>
<h3>The star's flaring corona</h3>
<p>The corona was tricky. I needed to find some way to create a seamless and continuous outward motion of a Perlin noise map that would function as a flare animation. In the end I settled for a two plane solution where one slowly grows and finally fades out at which point the second fades in, rotated randomly and grows until it fades out again. Rinse and repeat. When calibrated carefully, the resizing, rotating and fading is imperceptible to the eye, due to the naturally distributed Perlin noise:</p>
<div style="text-align:center">

<object width="300" height="300">
<param name="movie" value="http://projectnibble.org/dump/blog/papervision3d_sun/imperceptible%20corona.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#000000"></param>
<embed type="application/x-shockwave-flash" width="300" height="300" src="http://projectnibble.org/dump/blog/papervision3d_sun/imperceptible%20corona.swf" quality="high" bgcolor="#000000" wmode="window" menu="false" ></embed>
</object>
<br />
<span style="color:999999">(imperceptible version)</span><br />
<br />

<object width="300" height="300">
<param name="movie" value="http://projectnibble.org/dump/blog/papervision3d_sun/perceptible%20corona.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#000000"></param>
<embed type="application/x-shockwave-flash" width="300" height="300" src="http://projectnibble.org/dump/blog/papervision3d_sun/perceptible%20corona.swf" quality="high" bgcolor="#000000" wmode="window" menu="false" ></embed>
</object>
<br />
<span style="color:999999">(perceptible version)</span><br />
<br />

<object width="200" height="200">
<param name="movie" value="http://projectnibble.org/dump/blog/papervision3d_sun/sun%20final%20corner.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#000000"></param>
<embed type="application/x-shockwave-flash" width="200" height="200" src="http://projectnibble.org/dump/blog/papervision3d_sun/sun%20final%20corner.swf" quality="high" bgcolor="#000000" wmode="window" menu="false" ></embed>
</object>
<br />
<span style="color:999999">(result)</span>
</div>
<p>The Perlin noise is added with a simple Perlin noise command as follows:</p>
<pre  name="code" class="java">
var coronaMaterial1:BitmapMaterial = createCoronaMaterial(size / 1.25, size / 100, SEGMENTS);
var coronaMaterial2:BitmapMaterial = createCoronaMaterial(size / 1.25, size / 100, SEGMENTS);
var corona1:Plane = new Plane(coronaMaterial1);
var corona2:Plane = new Plane(coronaMaterial2);

/**
 * Creates a perlin noise texture to simulate the flaring flames on the sun's outer glow.
 */
private function createCoronaMaterial(textureSize:Number, noiseSize:Number, segments:Number):BitmapMaterial {
	var coronaBitmap:BitmapData = new BitmapData(textureSize, textureSize);
	coronaBitmap.perlinNoise(noiseSize, noiseSize, 4, 61, true, true, 1, false);
	return new BitmapMaterial(coronaBitmap, true);
}
</pre>
<p>The algorithm to animate the two planes is included in the attached sources.</p>
<h3>The corona and star glow combined and masked by a perfect circle</h3>
<p>The planes are all on the same depth and level. This works because we're using alpha ratios to determine where one plane's visibility starts and the other disappears. The star glow textures stands on its own, it is inherently radial and as such doesn't need a circle mask. This leaves the Perlin noise textures which need masking. To do this, I've put them in separate layers, which are then both masked by a third layer.</p>
<pre  name="code" class="java">
/*
 * use root corona layer so we can perform an alpha mask to both child layers at once
 *     - contains child corona layers so we can control individual alpha properties
 *         - contains child corona planes so we can apply a perlin noise texture to it for 'flaring' effect
 */
var coronaLayer:ViewportLayer = new ViewportLayer(viewport, null);
coronaChildLayer1 = new ViewportLayer(viewport, null);
coronaChildLayer2 = new ViewportLayer(viewport, null);
coronaLayer.addLayer(coronaChildLayer1);
coronaLayer.addLayer(coronaChildLayer2);
coronaChildLayer1.addDisplayObject3D(corona1);
coronaChildLayer2.addDisplayObject3D(corona2);
viewport.containerSprite.addLayer(coronaLayer);
// give the corona of the sun a 'flaring' effect
coronaLayer.blendMode = BlendMode.ADD;

// only show the corona part of the flaring perlin noise planes
var coronaMaskLayer:ViewportLayer = viewport.getChildLayer(coronaMask);
coronaLayer.cacheAsBitmap = true;
coronaMaskLayer.cacheAsBitmap = true;
coronaLayer.mask = coronaMaskLayer;
</pre>
<p>On a final note, I'm using the skybox from the <a href="http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/">skybox tutorial</a> and also the <a href="http://blog.projectnibble.org/2009/06/15/papervision3d-displayobject3d-helper-baseclass-for-realtime-updates/">RealtimeDisplayObject3D helper baseclass</a> for the sun's scene updates (which is why the coronas keep animating smoothly even at low FPS).</p>
<p><a href="http://blog.projectnibble.org/2010/02/01/papervision3d-star-sun-tutorial-and-source/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/02/11/papervision3d-star-sun-tutorial-and-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Want to play Mass Effect 2, but lost your Mass Effect 1 save games?</title>
		<link>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/</link>
		<comments>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:21:40 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mass Effect]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=413</guid>
		<description><![CDATA[Want to play Mass Effect 2, but lost your Mass Effect 1 save games? Get new save games at masseffectsaves.com!]]></description>
			<content:encoded><![CDATA[<p>Yes, I play video games too. I won&#8217;t miss out on <a href="http://masseffect.bioware.com/">Mass Effect</a>, which I think portraits a world almost as intricate as any good sci-fi novel (oh yeah I read those too, you should try <a href="http://www.amazon.com/Fire-Upon-Deep-Zones-Thought/dp/0812515285/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1264888373&#038;sr=1-1">A Fire Upon the Deep</a>, by Vernor Vinge). </p>
<p>Since Mass Effect is going to be a trilogy (<a href="http://www.shacknews.com/onearticle.x/62032">and more</a> apparently), Bioware included a system that will use old save games as input for continuity in upcoming games, including ME2. Note that you&#8217;ll still be able to pick a different face and class.</p>
<h2>Get your Mass Effect 1 save games at masseffectsaves.com</h2>
<p>I didn&#8217;t know there would be an option to use ME1 save games as input until recently and I&#8217;ve deleted my save games a long time ago. No undelete program would find them. <a href="http://www.annakie.com/">Annakie</a> recognized this would be a problem and started a <a href="http://www.masseffectsaves.com/">small site</a> that offers various save games each with a different set of key choices made over time in ME1.</p>
<p>How awesome is that!</p>
<p>Take your pick as the list is growing fast and the website is becoming a popular hub for Shepards.</p>
<p><a href="http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/trackback/">trackback</a></p>
<p><img src="http://projectnibble.org/dump/blog/images/tali.jpg" alt="Mass Effect 2" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/01/30/want-to-play-mass-effect-2-but-lost-your-mass-effect-1-save-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to connect a bluetooth keyboard in Ubuntu 9.04 Jaunty and 9.10 Karmic (workaround)</title>
		<link>http://blog.projectnibble.org/2010/01/28/how-to-connect-a-bluetooth-keyboard-in-ubuntu-9-04-jaunty-and-9-10-karmic-workaround/</link>
		<comments>http://blog.projectnibble.org/2010/01/28/how-to-connect-a-bluetooth-keyboard-in-ubuntu-9-04-jaunty-and-9-10-karmic-workaround/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 21:54:57 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[jaunty]]></category>
		<category><![CDATA[karmic]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=374</guid>
		<description><![CDATA[Here&#8217;s a quick workaround for connecting and reconnecting a bluetooth keyboard (or any bluetooth device for that matter) in Ubuntu Jaunty and Karmic, even after rebooting. In short it&#8217;s a shell script that keeps connecting to your device in the background on a regular interval. Dirty? Absolutely. Does it work? Absolutely, no bluetooth configuration required [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick workaround for connecting and reconnecting a bluetooth keyboard (or any bluetooth device for that matter) in Ubuntu Jaunty and Karmic, even after rebooting. In short it&#8217;s a shell script that keeps connecting to your device in the background on a regular interval. Dirty? Absolutely. Does it work? Absolutely, no bluetooth configuration required at all.</p>
<p><span id="more-374"></span></p>
<p>Originally, this whole workaround came from a <a href="http://ubuntuforums.org/showthread.php?p=8739447#post8174091">post on ubuntuforums.org</a> by Unkie, which I modified only slightly (I&#8217;m plantface there). This workaround revolves around <a href="http://linuxcommand.org/man_pages/hidd1.html">hidd</a>, which was removed in Ubuntu 9.04 which you can get back as follows:</p>
<pre  name="code">sudo apt-get install bluez-compat</pre>
<p>Hidd is a tool that works like a charm for scanning and connecting to bluetooth devices. It&#8217;s still used these days because  the Ubuntu dev team somehow manages to kill bluetooth support  every new version. There are so many tutorials and flavors floating around to get a bluetooth device working and apparently with so little success that hidd remains popular. With 9.04 they gave bluetooth an <a href="http://ubuntuforums.org/showthread.php?t=952168">overhaul</a> and deprecated hidd.</p>
<p>Anyway, here&#8217;s the shell script that keeps connecting your keyboard. There&#8217;s one catch though: I haven&#8217;t figured out how to let the keyboard sleep, awake and reconnect itself, so you&#8217;ll need to hit the reset button on the keyboard to reveal itself to the bluetooth adapter looking for it. Reconnecting this way requires thus one extra manual action before it reconnects (same thing goes for when you rebooted). But it reconnects when you want it to, which is what I&#8217;m content with for the moment, considering the alternative.</p>
<ol>
<li>
First create a new file for the script:</p>
<pre  name="code">sudo nano /etc/keyboard.sh</pre>
<p>Add the following script:</p>
<pre  name="code">
while (sleep 10)
do
sudo hidd --connect AA:BB:CC:DD:EE:FF > /dev/null 2>&#038;1
done
</pre>
<p>Close and save. </p>
<p style="font-size: 4pt; background-color: rgb(225,225,225);"><strong>Note</strong>: that AA:BB address should be the MAC address of your keyboard. You can find it using the new bluetooth tool <i>hcitool scan</i> (make sure your keyboard is findable by hitting its reset switch) or with <i>hidd &#8211;search</i>, which coincidently will automatically attempt to connect your device while scanning it.</p>
<p style="font-size: 4pt; background-color: rgb(225,150,150);"><strong>EDIT: August 8th, 2010</strong><br />
I updated the above script to react much more quickly and avoid unnecessary connect attempts:</p>
<pre  name="code">

#! /bin/bash

address="AA:BB:CC:DD:EE:FF"

while (sleep 1)
do
 connected=`sudo hidd --show` > /dev/null
 if [[ ! $connected =~ .*${address}.* ]] ; then
  sudo hidd --connect ${address} > /dev/null 2>&#038;1
 fi
done
</pre>
</li>
<li>
Next we&#8217;ll make sure it&#8217;ll run in the background when booted. Create a new boot entry:</p>
<pre  name="code">sudo nano /etc/init.d/keyboard</pre>
<p>Add the following script:</p>
<pre  name="code">
#!/bin/sh

/etc/keyboard.sh &#038;

exit 0
</pre>
<p>Close and save.
</li>
<li>
Give both files execution rights with <i>chmod +x {filename}</i>
</li>
<li>
Now run the following command to get the script executing during boot:</p>
<pre  name="code">sudo update-rc.d keyboard defaults</pre>
</li>
</ol>
<p>Reboot and check if it works. Remember to hit your keyboard&#8217;s reset switch when you want Ubuntu to connect your keyboard.</p>
<p><a href="http://blog.projectnibble.org/2010/01/28/how-to-connect-bluetooth-keyboard-in-ubuntu-9-04-jaunty-workaround/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2010/01/28/how-to-connect-a-bluetooth-keyboard-in-ubuntu-9-04-jaunty-and-9-10-karmic-workaround/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Excluding resources and test classes from war/ear in Eclipse</title>
		<link>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/</link>
		<comments>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 15:15:24 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=358</guid>
		<description><![CDATA[Today I was trying to figure out how to exclude certain resources/classes from the war that was being deployed to my embedded server in Eclipse. I couldn&#8217;t find out how to do this in the Eclipse settings file. Apparently, it has nothing to do with the source folder you see in the Project Explorer view, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to figure out how to exclude certain resources/classes from the war that was being deployed to my embedded server in Eclipse. I couldn&#8217;t find out how to do this in the Eclipse settings file. </p>
<p>Apparently, it has nothing to do with the source folder you see in the Project Explorer view, or the export settings in the Buildpath dialogs: instead you need to edit the Eclipse settings file “project-war\.settings\org.eclipse.wst.common.component” (viewable in the Navigator view) and modify the deployed source folders in there. Changes there do *not* reflect in the Project explorer (at least not with my version of Eclipse, Galileo). I’ve removed the test sourcefolder from there and everything was honky dory.</p>
<pre  name="code" class="xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project-modules id=&quot;moduleCoreId&quot; project-version=&quot;1.5.0&quot;&gt;
  &lt;wb-module deploy-name=&quot;foo-war&quot;&gt;
    &lt;wb-resource deploy-path=&quot;/&quot; source-path=&quot;/src/main/webapp&quot;/&gt;
    &lt;wb-resource deploy-path=&quot;/WEB-INF/classes&quot; source-path=&quot;/src/main/java&quot;/&gt;
    &lt;wb-resource deploy-path=&quot;/WEB-INF/classes&quot; source-path=&quot;/src/main/resources&quot;/&gt;
    &lt;property name=&quot;context-root&quot; value=&quot;foo&quot;/&gt;
    &lt;property name=&quot;java-output-path&quot;/&gt;
  &lt;/wb-module&gt;
&lt;/project-modules&gt;
</pre>
<p><a href="http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/08/24/excluding-test-classes-from-war-ear/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repost: Make Eclipse ignore .svn directories</title>
		<link>http://blog.projectnibble.org/2009/08/11/repost-make-eclipse-ignore-svn-directories/</link>
		<comments>http://blog.projectnibble.org/2009/08/11/repost-make-eclipse-ignore-svn-directories/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 11:37:28 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=353</guid>
		<description><![CDATA[Eclipse has the annoying little problem where Eclipse will copy .svn folders to the target/classes output folder and then complain about duplicate resources. After wading through some vague solutions, here&#8217;s a clear and simple post I found to solve this annoyance. Make Eclipse ignore .svn directories Window -> Preferences…, Java -> Compiler -> Building. Under [...]]]></description>
			<content:encoded><![CDATA[<p>Eclipse has the annoying little problem where Eclipse will copy .svn folders to the target/classes output folder and then complain about duplicate resources. After wading through some vague solutions, here&#8217;s a clear and simple post I found to solve this annoyance.</p>
<p><a href="http://radfordbw.squidpower.com/2007/04/12/make-eclipse-ignore-svn-directories/">Make Eclipse ignore .svn directories</a></p>
<blockquote><p>Window -> Preferences…, Java -> Compiler -> Building. Under “Output folder” add “, .svn/” to “Filtered Resources” (so that you get “*.launch, .svn/”).</p></blockquote>
<p>It still works like a charm. Thanks Brian.</p>
<p><a href="http://blog.projectnibble.org/2009/08/11/repost-make-eclipse-ignore-svn-directories/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/08/11/repost-make-eclipse-ignore-svn-directories/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Java generic paged lazy List with JSF/JPA example implementation</title>
		<link>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/</link>
		<comments>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 12:58:53 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[JSF/Facelets]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=310</guid>
		<description><![CDATA[Here&#8217;s a list implementation I came up with to enable true paged data fetching completely transparent to any user. It works independent of persistence layers, such as JPA implementations etc. download PagedList Lazy loading with the PagedList Originally I made the PagedList because I needed paged data fetching using JMS queues for a JSF Rich [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a list implementation I came up with to enable true paged data fetching completely transparent to any user. It works independent of persistence layers, such as JPA implementations etc.</p>
<ul>
<li><a href="http://projectnibble.org/dump/blog/pagedlist/PagedList.rar">download PagedList</a></li>
</ul>
<p><span id="more-310"></span></p>
<h3>Lazy loading with the PagedList</h3>
<p>Originally I made the PagedList because I needed paged data fetching using JMS queues for a JSF Rich datatable and datascroller; a common problem in JSF but less commonly solved, even less documented and less still solved in an elegant way. Most people are able to solve this problem by using an <a href="https://www.hibernate.org/43.html">OpenSessionInView</a> antipattern (keeping Hibernate-oid session open until the view requests the lazy loaded data) but since I&#8217;m using JMS queue, this was not an option. I decided to circumvent the entire JSF to JMS queue integration by providing my data in a paging lazy list. It works beautifully.</p>
<pre  name="code" class="java">
public class PagedList&lt;Dto, QueryParameters&gt; extends AbstractList&lt;Dto&gt; {

    private final QueryParameters queryParameters;

    private final PagedDataProvider&lt;Dto, QueryParameters&gt; pagedDataProvider;

    private final Map&lt;Integer, List&lt;Dto&gt;&gt; fetchedPages;

    private final int dataSize;

    private final int pageSize;

    public PagedList(PagedDataProvider&lt;Dto, QueryParameters&gt; pagedDataProvider, QueryParameters queryParameters) {
        this.pagedDataProvider = pagedDataProvider;
        this.queryParameters = queryParameters;
        fetchedPages = new HashMap&lt;Integer, List&lt;Dto&gt;&gt;();
        dataSize = pagedDataProvider.getDataSize();
        pageSize = pagedDataProvider.getPageSize();
    }

    public Dto get(int index) {
        int pageNr = (int) Math.floor(index / pageSize);
        if (fetchedPages.get(pageNr) == null) {
            fetchedPages.put(pageNr, pagedDataProvider.provide(pageNr, queryParameters));
        }
        return fetchedPages.get(pageNr).get(index % pageSize);
    }

    public int size() {
        return dataSize;
    }
}
</pre>
<p>It is different from <a href="http://commons.apache.org/collections/apidocs/org/apache/commons/collections/list/LazyList.html">Apache&#8217;s LazyList</a> (and many other implementations) in that it relies on an external dataprovider to provide the dataset&#8217;s total size, pagesize and data provision itself. For example, using my lazy list version the <i>size()</i> method actually returns the total size of data potentially available, not just physically available in the list at the present. This way the list works completely transparent to its users. Also, there is no simple factory being passed in that creates dummy objects or something: actual remote data is being fecthed in pages by a data provider. Pages being fetched are independent of each other; when requesting page 5, page 1 through 4 are not need or fetched.</p>
<p>The PagedList works in combo with a <em>PagedDataProvider</em> interface that external dataproviders (some dao for example) could implement. So it has no dependencies whatsoever on some specific implementation. The paged data provider provides the total size of the dataset, the page size and pages of the dataset itself when needed.</p>
<h3>Example implementation for JSF and JPA dao</h3>
<p>Here&#8217;s an example implementation which ties a JSF Richfaces datatable to a JPA dao using a PagedList. I cut out the service layer, view handlers/controllers and whatnot for sake of simplicity.</p>
<pre  name="code" class="xhtml">
&lt;rich:dataTable id="searchResults" value="#{appleService.apples}" var="apple"&gt;
...
&lt;/rich:dataTable&gt;
</pre>
<pre  name="code" class="java">
/**
 * JPA dao which acts as paged data provider for the paged list.
 *
 * Relies on two JPA named queries specified on the Entity being fetched.
 *
 * @author Benny Bottema
 * @see PagedDataProvider
 */
public class AppleJPADao implements AppleDao, PagedDataProvider&lt;AppleDto, AppleQueryParameters&gt; {

    // entitymanager stuff omitted for example (real world: injected by Spring)

    private static final int PAGESIZE = 50;

    /**
     * @see AppleDao#getAllApples(String, String)
     */
    public List&lt;AppleDto&gt; getAllApples(String type, String quality) {
        // optional query parameters: can be null
        AppleQueryParameters params = new AppleQueryParameters();
        params.setAppleType(type);
        params.setAppleQuality(quality);
        return new PagedList&lt;AppleDto, AppleQueryParameters&gt;(this, params);
    }

    /**
     * @see PagedDataProvider#provide(int, Object)
     */
    public List&lt;AppleDto&gt; provide(int page, AppleQueryParameters queryCriteria) {
        Query query = entityManager.createNamedQuery("Apple.findAll");
        query.setParameter("appleType", queryCriteria.getAppleType());
        query.setParameter("appleQuality", queryCriteria.getAppleQuality());
        // JPA's paging mechanism
        query.setFirstResult(PAGESIZE * page);
        query.setMaxResults(PAGESIZE);
        return (List&lt;AppleDto>) query.getResultList();
    }

    /**
     * @see PagedDataProvider#getDataSize()
     */
    public int getDataSize() {
        Query countQuery = entityManager.createNamedQuery("Apple.count");
        return ((Long) countQuery.getSingleResult()).intValue();
    }

    /**
     * @see PagedDataProvider#provide()
     */
    public int getPageSize() {
        return PAGESIZE;
    }
}
</pre>
<h3>Known issues</h3>
<p>So far there is only one known issue, which is more of a problem with lazy loading in general: synchronizing the lazy loading list with the remote dataset to avoid becoming stale when changes happen to the dataset. Example: when the dataset changes, the size of the list is not being updated and the <i>get()</i> method may try to fetch wrong or even unavailable data throwing an exception. Since I&#8217;m using the paged list in a limited way, I&#8217;ve not yet encountered this problem. </p>
<p>One way would be to solve this problem for the Rich datable and datascroller specifically is to have a a4j poll component that listens for dataset changes on the server and refreshes the entire datatable as necessary. Just thinking out loud here&#8230;</p>
<p><a href="http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/07/22/java-generic-paged-lazy-list-with-jsfjpa-example-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
