<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Twigleaf's Crossed Wires</title>
	<atom:link href="http://twigleaf.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://twigleaf.wordpress.com</link>
	<description>technology programming</description>
	<lastBuildDate>Wed, 21 Sep 2011 12:58:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='twigleaf.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Twigleaf's Crossed Wires</title>
		<link>http://twigleaf.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://twigleaf.wordpress.com/osd.xml" title="Twigleaf&#039;s Crossed Wires" />
	<atom:link rel='hub' href='http://twigleaf.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Unposted drafts &#8211; Algorithm optimization: indexation</title>
		<link>http://twigleaf.wordpress.com/2011/09/21/unposted-drafts-algorithm-optimization-indexation/</link>
		<comments>http://twigleaf.wordpress.com/2011/09/21/unposted-drafts-algorithm-optimization-indexation/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 12:58:42 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=206</guid>
		<description><![CDATA[Many a times in programming you&#8217;ll use the magic words For or While, or your language equivalents, but sometimes a little too much. Any loop you&#8217;ll use will slow down your algorithm by n times t. The moment you add a millisecond of computing to 1 iteration, you&#8217;ll automatically end up with n times that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=206&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Many a times in programming you&#8217;ll use the magic words For or While, or your language equivalents, but sometimes a little too much. Any loop you&#8217;ll use will slow down your algorithm by n times t. The moment you add a millisecond of computing to 1 iteration, you&#8217;ll automatically end up with n times that millisecond as extra time spent.</p>
<p>In the area of looking up or finding an element in an array of n elements, a lot of times we won&#8217;t bother to optimize or perhaps we can&#8217;t imagine an optimization to a simple variable comparison. Sure we can cheat our way out with a break or exit from the loop when we found our needle, but that&#8217;s as far as it goes.</p>
<p>The moment where we again put our find method inside another loop, the time spent with our lookup is going to matter if we value our users time.</p>
<p>Indexation is a common concept of lookup optimization, but why, and how do we do it?</p>
<p>The basic idea of indexation, in programming that is, is that given a space of addressable memory, and a lot of possible objects to find, we can find out if that object exists &#8211; by already knowing where it&#8217;s <strong><em>supposed</em></strong> to be.</p>
<p>It seems like the world upside down; instead of trying find the object we&#8217;re looking for, we&#8217;re supposed to know already know, and perhaps find out if we&#8217;re right.</p>
<p>We can&#8217;t of course stick our hand in the mud randomly and hope for the best. We need to find a way first to make the objects we&#8217;re going to look up later, are either where their supposed to be, or nowhere.</p>
<p>If we look at our indexation masterminds: databases, we can find a complicated amount of indexation techniques that work pretty well. Our fancy scripting languages may have a little bit of that in their non-default datastructures and functions. But I want to focus on the simplest form of indexation, well, second simplest.</p>
<h2>About arrays</h2>
<p>In the world of programming, the standard array is going to be your template for your algorithm. The array works in a way that you arrange memory at the position of variable x, starting from index 0, counting to n, and you assign or requests values in that array by supplying p as in x[p]. Internally this works as a function resulting in another address, f(x,p) = x + p * c. In this formula, c is the size of your datatype; if your type is a byte then c = 1, if your type is a 32bit integer it&#8217;s 4, etc.</p>
<p>There&#8217;s no magic lookup in regular arrays, its just calculating the start of the requested fragment in a larger fragment of memory, and this works pretty fast.</p>
<p>Simplification to its core when going back to the indexation aspect; e.g. given the array x = {0,1,2,3,4,5}, we&#8217;ll know that the number 4 will reside in x[4]. But of course, why look up something you already know.</p>
<h2><strong>Textbook example: IntToHex</strong></h2>
<p>Integers to hexadecimal text is a textbook example of indexation (<em>unless the writer is a complete nitwit</em>). Given your base &#8216;hex&#8217;, 16 possible values, represented by the array x={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}. We can &#8220;find&#8221; our character by fetching the n-th value in array x, where n is the number we want to translate.</p>
<p>Since in reality there&#8217;s a slim chance we only want to translate numbers under 16, we&#8217;ll have to find out a way to deduce our translation to 1 or more simple array indexations.</p>
<p>With the hexadecimal system being close friends to the binary system, we know we can physically divide our byte into 2 x 4bit codes, and 4 bits can form 16 combinations.</p>
<p>Easy enough we can thus make a 2 character string of our given bytevalue p in 1 long line;</p>
<p>str = hex[(p &amp; 0xf0) &gt;&gt; 4] + hex[(p &amp; 0x0f)];</p>
<h2><strong>Magic</strong></h2>
<p>Real life applications might not be so simple or magical as hexing, but the principle is the same:</p>
<ul>
<li>determine a way to calculate a predetermined and (unique if non-tree) index</li>
<li>put the items in the array with your calculated indices on startup and on modifications</li>
<li>locate your item by calculating the possible position and see if it&#8217;s there</li>
</ul>
<p>&nbsp;</p>
<p><em>Unposted drafts feature; here I stopped writing for some reason, and I&#8217;m not going to finish it&#8230;</em></p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=206&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2011/09/21/unposted-drafts-algorithm-optimization-indexation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>color profile madness</title>
		<link>http://twigleaf.wordpress.com/2010/02/08/color-profile-madness/</link>
		<comments>http://twigleaf.wordpress.com/2010/02/08/color-profile-madness/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 01:50:36 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=200</guid>
		<description><![CDATA[I have a Cintiq 21ux since forever it seems now, and I always had issues with the colours being &#8220;off&#8221; on the normal iMac screen. Obviously the reason lies in the ICC profiles&#8230; I thought. They were set the right way however, and embedding the right profile in the picture didn&#8217;t help either. After a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=200&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a Cintiq 21ux since forever it seems now, and I always had issues with the colours being &#8220;off&#8221; on the normal iMac screen. Obviously the reason lies in the ICC profiles&#8230; I thought. They were set the right way however, and embedding the right profile in the picture didn&#8217;t help either.</p>
<p>After a lot of fondling around with the profiles on both screens, I decided to do a restore factory settings on the Cintiq. Yet the problem remained. Until I found out that the Default color setting was wrong.</p>
<p>The temperature of the colours was at 6500k, but naturally that doesn&#8217;t match the ICC profile at all. The setting &#8220;Direct&#8221; however did the trick. I have to fix all the colouring now in my pictures, but at least I know they&#8217;re going to be the same almost everywhere.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=200&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2010/02/08/color-profile-madness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>OSPatch Part 2</title>
		<link>http://twigleaf.wordpress.com/2009/12/07/ospatch-part-2/</link>
		<comments>http://twigleaf.wordpress.com/2009/12/07/ospatch-part-2/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 00:29:16 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=197</guid>
		<description><![CDATA[I know I&#8217;ve kept a bit silent and sketchy about it all, I haven&#8217;t had much inspiration and been busy with things and whatnot. But I finally sat down tonight and tried to just sketch whatever came to mind, erase, sketch again, etc. And after a few tries I came up with [this]. It&#8217;s not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=197&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I know I&#8217;ve kept a bit silent and sketchy about it all, I haven&#8217;t had much inspiration and been busy with things and whatnot.</p>
<p>But I finally sat down tonight and tried to just sketch whatever came to mind, erase, sketch again, etc. And after a few tries I came up with <a href="http://picasaweb.google.com/lh/photo/mn5VqmKTCHWr-UEOOZ6oxQ?feat=directlink" target="_blank"><strong>[this]</strong></a>. It&#8217;s not your typical website, it&#8217;s a little risky and new I guess. But it has I think some nice quirky things in it that makes it fun while being a bit minimalistic (<em>I wanted to get rid of sidebars so patches and other texts have free reign over the rest of the page</em>)</p>
<p>And actually, the reason why I did the main menu like this, is because I couldn&#8217;t get buttons or or gradients and what not to work in my limited knowledge of Pixelmator. It&#8217;s not as fancy as photoshop, which I cannot afford. I&#8217;ve already drawn the close/logout button, and it&#8217;s rather fun, metallic and weird. Ofcourse it has nothing to do with sourcecode, but that&#8217;s where the actual functionality of the website is going to be.</p>
<p>I also thought it to be nice to have a little sliding thing coming out of windows, because Mac OS X has those things about and it looks rather fun. Am hoping no patent is on that *cross fingers*, though there might be.</p>
<p>The actual &#8220;patch&#8221; is a bit of a joke, the site is about patches, but that patch represent patching the webpage with other content. It&#8217;s ridiculous when you think about it ofcourse, different patches to apply to your website sourcecode to create another page?</p>
<p>Anyway, I&#8217;m going to draw this up, and since I&#8217;m hopeless at it, I&#8217;m actually going to draw it by hand brushstroke by brushstroke. It&#8217;s going to take ages, but ah well&#8230;</p>
<p>Before I got the sketching phase I did some coding around the website and plugged in an OpenID login (<em>which wasn&#8217;t easy, Google OpenID was being annoying, but I got it in the end</em>). I&#8217;m all done with having to remember another set of credentials and filling in the same forms, and I don&#8217;t really need all kinds of information. Just the email and a name would suffice, which I can store and link various website related information to it.</p>
<p>Feel free to say the design sucks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=197&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/12/07/ospatch-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>Open Source Project</title>
		<link>http://twigleaf.wordpress.com/2009/11/12/open-source-project/</link>
		<comments>http://twigleaf.wordpress.com/2009/11/12/open-source-project/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 14:49:15 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=194</guid>
		<description><![CDATA[So the project itself is a rather simple little thing. It&#8217;s a framework for making websites with complete separation of view and data, which I&#8217;m already using for e.g. http://saikosoft.inaspro.nl/ (not that you can notice anything) Since I figured it might be of value to someone else, I wanted to make it Open Source and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=194&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So the project itself is a rather simple little thing. It&#8217;s a framework for making websites with complete separation of view and data, which I&#8217;m already using for e.g. <a href="http://saikosoft.inaspro.nl/" target="_blank">http://saikosoft.inaspro.nl/</a> (not that you can notice anything)</p>
<p>Since I figured it might be of value to someone else, I wanted to make it Open Source and let it grow over time into something better, perhaps with help of others.</p>
<p>There is however a slight hitch in my plan, for I dislike the concept of Mailinglists that has been generally accepted to be a Open Source Thing. To me it seems a cumbersome thing that takes up way too much time to go through and pick up the patches, but I don&#8217;t want to just give anyone commit access to the repository.</p>
<p>So I had this image in my head where there was a website where people could just upload their patches, put a few comments under it explaining what it does and why, and other people can comment on the same thing, perhaps attach a revision of the patch, and give the thumbs up for specific patches. Once enough thumbs up have been given, the committers can check the list of patches and commit those that have been generally accepted as a good patch (<em>given the committer likes it too of course</em>). (<em>which might be another open source project I might send out if this works</em>)</p>
<p>But images in your head never translate to actual computer graphics in the real world when I&#8217;m trying to do the website. Sure I can handle code, but design?</p>
<p>Perhaps more updates and links over here soon&#8230;</p>
<p>ASCII Preview: <a href="http://www.ospatch.com/" target="_blank">http://www.ospatch.com/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/194/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/194/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/194/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=194&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/11/12/open-source-project/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>IP Lookup tool</title>
		<link>http://twigleaf.wordpress.com/2009/09/13/ip-lookup-tool/</link>
		<comments>http://twigleaf.wordpress.com/2009/09/13/ip-lookup-tool/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 20:00:11 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=188</guid>
		<description><![CDATA[This tool is to retreive ip addresses for a given hostname. This isn&#8217;t very new, but I noticed that if you need to refresh ip without wanting or able to call ipconfig /flushdns, you can still refresh the ip&#8217;s for the given hostname. It also has an option to return the ip address that is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=188&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This tool is to retreive ip addresses for a given hostname. This isn&#8217;t very new, but I noticed that if you need to refresh ip without wanting or able to call ipconfig /flushdns, you can still refresh the ip&#8217;s for the given hostname.</p>
<p>It also has an option to return the ip address that is used to indicate a hostname is either invalid or could not be found.</p>
<p><a href="http://www.inaspro.nl/chalkncode_attachments/getip/getip.exe" target="_blank">getip.exe</a></p>
<p><em>(free, freeware, no spyware, use for whatever you want, unlicensed, win32 console exe optimized for i586)</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=188&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/09/13/ip-lookup-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>hobby multi-isp serving routing scheme revisited</title>
		<link>http://twigleaf.wordpress.com/2009/09/08/hobby-multi-isp-serving-routing-scheme-revisited/</link>
		<comments>http://twigleaf.wordpress.com/2009/09/08/hobby-multi-isp-serving-routing-scheme-revisited/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 21:45:50 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[cisco]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=180</guid>
		<description><![CDATA[After my last two posts about multi-isp serving over 2 routers, some time has went by and one of my isp&#8217;s dsl-modem slash router changed and went ballistic with fixed settings. They decided that nobody ever wants a different subnet from 192.168.2.0/24, and therefor dump everything else to the outside interface. This didn&#8217;t only make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=180&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After my last two posts about multi-isp serving over 2 routers, some time has went by and one of my isp&#8217;s dsl-modem slash router changed and went ballistic with fixed settings. They decided that nobody ever wants a different subnet from 192.168.2.0/24, and therefor dump everything else to the outside interface. This didn&#8217;t only make a router inbetween very much needed (since I didn&#8217;t want to change my local network besides a /16 mask), it also made my network a lot more complicated.</p>
<p>Since the router would ditch everything going to 192.168.0.0, I decided to connect the secondary network interfaces (that happened to be configured to 192.168.2.0 as well) to the network as the serving interface. However, as usual this doesn&#8217;t matter when it comes to outgoing traffic. Anything it considers outside its network is send to the default interface instead, eventhough the incoming packets came from the other interface.</p>
<p>At some moment of clarity, I found that I could split up 192.168.2.0 into 2 networks as well, namely in this case (since the isp&#8217;s dsl-router has its local ip set fixed to 192.168.2.254) into networks 192.168.2.128/25 and 192.168.2.0/25. This allowed everything beneath 192.168.2.128 to be sent to the internal network, and everything above, including the dsl-router, to belong to the other side.</p>
<p>Basically like this:</p>
<p><img class="alignnone size-medium wp-image-182" title="multiisproutes" src="http://twigleaf.files.wordpress.com/2009/09/multiisproutes.png?w=300&#038;h=207" alt="multiisproutes" width="300" height="207" /></p>
<p><strong>The trivial stuff</strong></p>
<pre>interface FastEthernet0/0
 ip address 192.168.2.130 255.255.255.128
 ip access-group defaultallin in
 ip mask-reply
 ip nat inside
 ip route-cache flow
 duplex auto
 speed auto
 no cdp enable
!
interface FastEthernet0/1
 ip address 192.168.2.101 255.255.255.128
 ip access-group defaultallout out
 ip mask-reply
 no ip redirects
 ip nat outside
 ip route-cache flow
 duplex auto
 speed auto
!
ip classless
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0 192.168.2.254
ip route 192.168.0.0 255.255.255.0 FastEthernet0/1
ip route 192.168.2.0 255.255.255.128 FastEthernet0/1
!
ip access-list extended defaultallin
 permit ip any any
ip access-list extended defaultallout
 permit ip any any</pre>
<p><em>Note: default interface setting &#8220;no ip proxy-arp&#8221; is negated and thus on.</em></p>
<p><strong>The headache stuff, yet in the end not that hard</strong></p>
<p>The normal way of NAT is to e.g. &#8220;ip nat inside source list 1 interface FastEthernet0/0 overload&#8221;, to replace the <strong>source </strong>ip, with the ip of <strong>interface fa0/0</strong>, if the packet is permitted by <strong>list 1</strong>.<br />
Where list 1 is often casually defined as &#8220;access-list 1 permit any&#8221;, allowing everything to be translated.</p>
<p>A line like &#8220;ip nat inside source static tcp 192.168.0.10 80 interface FastEthernet0/0 80&#8243; is often used to change the <strong>destination </strong>ip/port to 192.168.0.10 if a packet arrives at the external interface fa0/0 on port 80.</p>
<p>In this particular case, we still want a &#8220;normal&#8221; NAT source ip translation from the inside to the outside (because we need to force our server to not send traffic to the default gateway), but not All traffic, since we still want to use the other ISP for regular Internet traffic when we fancy such a thing. Unfortunately a standard access-list doesn&#8217;t allow us to be very specific unless we want to define the source. Since the source ip could be anything (because the traffic is coming from the Internet), we can&#8217;t use a standard ACL.</p>
<p>We can however use a Extended ACL, which allows to be specific about the Destination IP and portnumber, which goes as followed:</p>
<pre>ip nat inside source list ourspecialnat interface FastEthernet0/0 overload
!
ip access-list extended ourspecialnat
 permit tcp any host 192.168.2.2 eq www</pre>
<p>And there you have it. A specific permission for destination 192.168.2.2 port=80, to be translated. Now all we need to do is to set a portforward from our ISP&#8217;s dsl-router from port 80 to 192.168.2.2. It routes traffic inside because the ip matches its 192.168.2.0/24 network, and our special nat router makes sure the packets are sent and received via  the same route due to obscuring the source ip.</p>
<p>PS. Perhaps it should be noted that this is just a funny exploit in search of better solutions. Most of the time you will want to know the actual IP address a visitor of your website is using, and not get a local IP instead. Chances are however that setting up either your server or your network to remember which route they should be going (with an IPv4 NAT-ted network) is considerably more difficult. When no traffic is translated in the first place (like for example when you have a large number of IPv4 addresses or a couple of IPv6 addresses), there wouldn&#8217;t be an issue of rejecting source/destination mismatches, because they would always be the same.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=180&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/09/08/hobby-multi-isp-serving-routing-scheme-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>

		<media:content url="http://twigleaf.files.wordpress.com/2009/09/multiisproutes.png?w=300" medium="image">
			<media:title type="html">multiisproutes</media:title>
		</media:content>
	</item>
		<item>
		<title>db component chain</title>
		<link>http://twigleaf.wordpress.com/2009/07/19/d20072009-dbx-component-chain/</link>
		<comments>http://twigleaf.wordpress.com/2009/07/19/d20072009-dbx-component-chain/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 16:25:13 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=171</guid>
		<description><![CDATA[If you want to connect visual components like grids or editboxes to a dataset, you&#8217;d expect things to be a bit straightforward, like for example: DBGrid -&#62; DataSource -&#62; SQLQuery -&#62; DBConnection Unfortunately, when it comes to db components, this chain will result in a &#8220;Operation not allowed on a unidirectional dataset&#8221; error. Which would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=171&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you want to connect visual components like grids or editboxes to a dataset, you&#8217;d expect things to be a bit straightforward, like for example:</p>
<p>DBGrid -&gt; DataSource -&gt; SQLQuery -&gt; DBConnection</p>
<p>Unfortunately, when it comes to db components, this chain will result in a &#8220;Operation not allowed on a unidirectional dataset&#8221; error. Which would make a tiny bit of sense if you want to make the Grid editable, but even when you switch off every possible property off to edit the grid, the error will still come up.</p>
<p>If you&#8217;re like me, you&#8217;d probably just put a StringGrid on your form and loop over the SQLQuery to show all the data. That does however take a lot more writing code for something that <em>should</em> be quite easy to do.</p>
<p>Aparantly, this is the way to do chain the components to be able to link your things together:</p>
<p><img class="alignnone size-full wp-image-172" title="dbX component chain" src="http://twigleaf.files.wordpress.com/2009/07/datasets_d2009.png?w=455&#038;h=79" alt="dbX component chain" width="455" height="79" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=171&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/07/19/d20072009-dbx-component-chain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>

		<media:content url="http://twigleaf.files.wordpress.com/2009/07/datasets_d2009.png" medium="image">
			<media:title type="html">dbX component chain</media:title>
		</media:content>
	</item>
		<item>
		<title>Short: Happy undocumented quirks</title>
		<link>http://twigleaf.wordpress.com/2009/07/05/short-happy-undocumented-quirks/</link>
		<comments>http://twigleaf.wordpress.com/2009/07/05/short-happy-undocumented-quirks/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 12:31:09 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=167</guid>
		<description><![CDATA[Description of AdjustWindowRectEx() on MSDN: The AdjustWindowRect function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size. Description of GetWindowRect() on MSDN: The GetClientRect function retrieves the coordinates of a window&#8217;s client [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=167&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Description of <a href="http://msdn.microsoft.com/en-us/library/ms632665(VS.85).aspx" target="_blank">AdjustWindowRectEx()</a> on MSDN:</p>
<blockquote><p>The <strong>AdjustWindowRect</strong> function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the <a id="ctl00_MTContentSelector1_mainContentContainer_ctl01" style="text-decoration:none;color:#800080;" href="http://msdn.microsoft.com/en-us/library/ms632679(VS.85).aspx">CreateWindow</a> function to create a window whose client area is the desired size.</p></blockquote>
<p>Description of <a href="http://msdn.microsoft.com/en-us/library/ms633503(VS.85).aspx" target="_blank">GetWindowRect()</a> on MSDN:</p>
<blockquote><p>The <strong>GetClientRect</strong> function retrieves the coordinates of a window&#8217;s client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window&#8217;s client area, the coordinates of the upper-left corner are (0,0).</p></blockquote>
<p>You would think that these functions are eachothers counterpart, you give a clientrectangle to AdjustWindowRectEx(), say (200&#215;200) and you&#8217;ll get something like 214&#215;234 if you have the Vista look active on your window. When you set your window to those dimensions with for example <a href="http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx" target="_blank">SetWindowPos()</a>, and afterwards you check the size with GetClientRect(), you&#8217;ll get 212&#215;232. This works the same with other themes, and if you copy-paste a screenshot into MS Paint, you&#8217;ll be able to measure the same 212&#215;232 while the outside of the window is the exact given 214&#215;234 &#8211; properly set by SetWindowPos().</p>
<p>The dirty ugly solution of course is to add 2 pixels to whatever you get back from AdjustWindowRectEx() &#8211; but surely someone at Microsoft is supposed to Test these functions?</p>
<p><code> </code></p>
<p><code> </code></p>
<p><code></p>
<pre>RECT size;
size.left	= myWindowObj-&gt;x;
size.top	= myWindowObj-&gt;y;
size.right	= size.left + myWindowObj-&gt;w;
size.bottom	= size.top + myWindowObj-&gt;h;

AdjustWindowRectEx( &amp;size, GetWindowLong(hWND, GWL_STYLE), FALSE, GetWindowLong(hWND, GWL_EXSTYLE) );
SetWindowPos( hWND, NULL, myWindowObj-&gt;x, myWindowObj-&gt;y, size.right - size.left + 2, size.bottom - size.top + 2, SWP_NOZORDER | SWP_NOACTIVATE );</pre>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=167&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/07/05/short-happy-undocumented-quirks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>Probability</title>
		<link>http://twigleaf.wordpress.com/2009/05/26/probability/</link>
		<comments>http://twigleaf.wordpress.com/2009/05/26/probability/#comments</comments>
		<pubDate>Tue, 26 May 2009 00:07:31 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=159</guid>
		<description><![CDATA[*** I&#8217;m not a mathematician, the explanation here is probably crap, so have a look on the internet on factorials and sets. A friend of mine asked me today if I had a script lying around to produce anagrams. After saying no and secretly checking what the heck an anagram was again, I started thinking about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=159&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>*** I&#8217;m not a mathematician, the explanation here is probably crap, so have a look on the internet on </em><a href="http://en.wikipedia.org/wiki/Factorial" target="_blank"><em>factorials</em></a><em> and </em><a href="http://en.wikipedia.org/wiki/Set_(mathematics)" target="_blank"><em>sets</em></a><em>.</em></p>
<p>A friend of mine asked me today if I had a script lying around to produce anagrams. After saying no and secretly checking what the heck an anagram was again, I started thinking about what it reminded me of.</p>
<p>My thoughts diverged on the symbol &#8220;!&#8221;, which is used in probability to calculate what your chance might be when you eliminate your previous results from the equation. So for example if you have a set of [1,2,3,4,5,6] &#8211; after rolling 3 with a dice, the set will become [1,2,4,5,6] so you can&#8217;t roll 3 again.</p>
<p>Anagrams are a combination of a set of predefined characters, and then mixed around. And while you might think you&#8217;ll have 6^6 possibilities, you actually have less, because you can&#8217;t use more of the same characters that are available.</p>
<p>Say for example you have a word of &#8220;abc&#8221;, you can make &#8220;acb&#8221;, but you can&#8217;t make &#8220;aab&#8221;, because you only have 1 &#8220;a&#8221;. Thus in the example of [1,2,3,4,5,6] you actually have 6! possibilities. We can write 6! as 6*5*4*3*2*1 = 720 possibilities.</p>
<p>And the rewrite of 6! is exactly what made me think of this simple algorithm:</p>
<pre><code>procedure factorWord( const sBeginning: string; const sWord: string; const lstPermutations: TStrings );
var
  i, c: integer;
begin
  c := Length( sWord );

  if c = 0 then
  begin
    lstPermutations.Add( sBeginning );
  end;

  for i := 1 to c do
  begin
    factorWord( sBeginning + sWord[i], Copy( sWord, 1, i - 1 ) + Copy( sWord, i + 1 ), lstPermutations );
  end;
end;</code></pre>
<p> </p>
<p>You&#8217;ll initially call it for example with <em>factorWord( &#8221;, Edit1.Text, Memo1.Lines );</em> and you&#8217;ll end up with all the possible anagrams. The function works recursively on 2 sets, one that defines the entire set (Edit1.Text), and one thats starts out empty. With every recursion the possibilities of new characters to add gets smaller, while the anagram is filled with the same amount of characters in a different order, and is added to the stringlist when the recursionpath ends up with 0 remaining characters.</p>
<p>The biggest problem however of making anagrams is that there are simply too much possibilities when you go over about 6 characters. The worst of it, and this is after some code rewrites to append the words to a file occasionally to avoid an out-of-memory error, is that a word with 14 characters will make your textfile about the size of 2.4GB until a file streaming error occurs&#8230;</p>
<p>14! = 87178291200 lines, multiplied by &#8220;14 byte anagrams plus 2 bytes for the crlf&#8221;, you&#8217;ll end up with 1394852659200 bytes which amounts to 1299GB of data.</p>
<p>Have fun storing that on your desktop pc&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=159&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/05/26/probability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
		<item>
		<title>Search cmp to 0</title>
		<link>http://twigleaf.wordpress.com/2009/05/07/search-cmp-to-0/</link>
		<comments>http://twigleaf.wordpress.com/2009/05/07/search-cmp-to-0/#comments</comments>
		<pubDate>Thu, 07 May 2009 09:40:19 +0000</pubDate>
		<dc:creator>twigleaf</dc:creator>
				<category><![CDATA[/roll]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://twigleaf.wordpress.com/?p=155</guid>
		<description><![CDATA[Search: optimization &#8220;cmp eax,0&#8243; You don&#8217;t have to compare EAX to 0 to know it&#8217;s 0, just make sure the item in EAX is edited last, with any opcode that you see in your cpu manual with the appendage that it modifies the ZF. That&#8217;s a fancy flag that says a value you just put [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=155&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Search: optimization &#8220;cmp eax,0&#8243;</p>
<p>You don&#8217;t have to compare EAX to 0 to know it&#8217;s 0, just make sure the item in EAX is edited last, with any opcode that you see in your cpu manual with the appendage that it modifies the ZF. That&#8217;s a fancy flag that says a value you just put in a register is zero.</p>
<p>Any mathematical, bitwise or just plain MOV into a register, modifies the Zero flag. Skip the CMP and just use either JZ (jump if zero) or JNZ (jump if not zero) to see if the zero flag is set and jump somewhere accordingly.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/twigleaf.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/twigleaf.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/twigleaf.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=twigleaf.wordpress.com&amp;blog=3120608&amp;post=155&amp;subd=twigleaf&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://twigleaf.wordpress.com/2009/05/07/search-cmp-to-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d04a5483c87df7c84084cc153d7f251?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">twigleaf</media:title>
		</media:content>
	</item>
	</channel>
</rss>
