<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">

	<title>ElasticDog.com</title>
	
	<link href="http://elasticdog.com/" />
	<updated>2012-02-06T15:23:03-08:00</updated>
	<id>http://elasticdog.com/</id>
	<author>
		<name>Aaron Bull Schaefer</name>
		<email>aaron@elasticdog.com</email>
	</author>

	
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/elasticdog" /><feedburner:info uri="elasticdog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
		<title>Use sshuttle to Keep Safe on Insecure Wi-Fi</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/oeyJK6tsjeA/use-sshuttle-to-keep-safe-on-insecure-wi-fi" />
		<updated>2011-12-31T10:56:00-08:00</updated>
		<id>http://elasticdog.com/2011/12/use-sshuttle-to-keep-safe-on-insecure-wi-fi</id>
		<content type="html">&lt;p&gt;If you&amp;#8217;ve ever used an insecure Wi-Fi connection in a public place (think coffee shop, airport, etc.), your personal information could be at risk. Anyone on the local network could potentially be monitoring your traffic and they could even &lt;a href="http://codebutler.github.com/firesheep/"&gt;hijack your sessions&lt;/a&gt; to control accounts that you&amp;#8217;ve logged into.&lt;/p&gt;
&lt;p&gt;Every week I &lt;a href="http://hackerbreakfast.com/"&gt;meet up with some friends&lt;/a&gt; to work on personal projects, and the venue only offers an open wireless connection with no encryption. To mitigate the risk of leaking personal information, I&amp;#8217;ve tried a handful of strategies and eventually settled on using &lt;a href="https://github.com/apenwarr/sshuttle"&gt;sshuttle&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="sshuttle"&gt;What is sshuttle?&lt;/h2&gt;
&lt;p&gt;The sshuttle utility is part transparent proxy, part Virtual Private Network (&lt;span class="caps"&gt;VPN&lt;/span&gt;), and part &lt;acronym title="Secure Shell"&gt;&lt;span class="caps"&gt;SSH&lt;/span&gt;&lt;/acronym&gt;. It solves a lot of common problems with encrypting your traffic, and it does so in a very efficient way.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s no need for a complicated pre-existing infrastructure. All you need is Python 2.x, and a remote machine you can &lt;span class="caps"&gt;SSH&lt;/span&gt; to that also has Python installed. You don&amp;#8217;t even have to be an administrator on the remote machine. The project&amp;#8217;s &lt;a href="https://github.com/apenwarr/sshuttle/blob/master/README.md"&gt;&lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt; has a lot more information on its theory, design, and alternate uses.&lt;/p&gt;
&lt;h3 id="previous"&gt;Previous Method&lt;/h3&gt;
&lt;p&gt;As an aside, I had previously relied on creating a &lt;span class="caps"&gt;SOCKS&lt;/span&gt; proxy with &lt;span class="caps"&gt;SSH&lt;/span&gt;, and then tunnelling my web traffic through it&amp;#8230;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh -fqND 1080 example.com
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But, you have to adjust your machine&amp;#8217;s proxy configuration settings each time you set up the tunnel, and then tear it all down when you&amp;#8217;re done. This method &lt;strong&gt;will not&lt;/strong&gt; force absolutely all traffic over the tunnel, as things like &lt;acronym title="Domain Name System"&gt;&lt;span class="caps"&gt;DNS&lt;/span&gt;&lt;/acronym&gt; lookups and a lot of command-line tools will just ignore the proxy. You&amp;#8217;re also encapsulating &lt;acronym title="Transmission Control Protocol"&gt;&lt;span class="caps"&gt;TCP&lt;/span&gt;&lt;/acronym&gt;-over-&lt;span class="caps"&gt;TCP&lt;/span&gt;, which can cause performance problems.&lt;/p&gt;
&lt;p&gt;I briefly messed with the &lt;a href="http://chetansurpur.com/projects/sidestep/"&gt;Sidestep project&lt;/a&gt; to automate these setup/teardown steps on OS X, but ran across repeated authentication issues and wasn&amp;#8217;t overly impressed with its developer. Overall, I needed a more elegant solution.&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;p&gt;I wanted to use sshuttle on OS X Lion, and even though it&amp;#8217;s primarily a command-line utility, it also comes with a graphical user interface wrapper that will sit in the menu bar. If you just want the command-line script and already use &lt;a href="http://mxcl.github.com/homebrew/"&gt;Homebrew&lt;/a&gt;, &lt;code&gt;brew install sshuttle&lt;/code&gt; is the way to go. If you don&amp;#8217;t use Homebrew and/or want the &lt;span class="caps"&gt;GUI&lt;/span&gt;, I&amp;#8217;ve got your back&amp;#8230;&lt;/p&gt;
&lt;h3 id="building"&gt;Building sshuttle from Source&lt;/h3&gt;
&lt;p&gt;Unfortunately, pre-compiled binaries are not made available for every release, and documentation for building sshuttle is non-existent. The project uses a &lt;a href="https://github.com/apenwarr/redo"&gt;build system called &amp;#8216;redo&amp;#8217;&lt;/a&gt; instead of the more-customary &amp;#8216;make&amp;#8217;, so the process is a bit different than what most people are used to.&lt;/p&gt;
&lt;p&gt;Luckily, the sshuttle repository includes a shell script named &amp;#8216;do&amp;#8217;, which is a simplified version of redo, so you &lt;em&gt;won&amp;#8217;t need to&lt;/em&gt; install any additional build software. The only real dependencies are &lt;a href="http://python.org/"&gt;Python&lt;/a&gt; and two Python modules to generate the man page (feel free to use &lt;code&gt;pip install&lt;/code&gt; instead of &lt;code&gt;easy_install&lt;/code&gt;, if you prefer):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;easy_install markdown BeautifulSoup
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once you&amp;#8217;ve installed those two modules, you&amp;#8217;re all set to build&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;NOTE: You may have to adjust paths or permissions slightly depending on your machine&amp;#8217;s setup.&lt;/i&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;mkdir -p /usr/local/libexec
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone git://github.com/apenwarr/sshuttle.git /usr/local/libexec/sshuttle
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /usr/local/libexec/sshuttle/
&lt;span class="nv"&gt;$ &lt;/span&gt;./do all
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once sshuttle is built, we just make symlinks so the binary and man page are in the proper places:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ln -s /usr/local/libexec/sshuttle/sshuttle /usr/local/bin
&lt;span class="nv"&gt;$ &lt;/span&gt;mkdir -p /usr/local/share/man/man8
&lt;span class="nv"&gt;$ &lt;/span&gt;ln -s /usr/local/libexec/sshuttle/Documentation/sshuttle.8 /usr/local/share/man/man8
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For the &lt;span class="caps"&gt;GUI&lt;/span&gt; app, we need to create an &lt;em&gt;alias&lt;/em&gt; instead a symlink, because &lt;a href="http://en.wikipedia.org/wiki/Spotlight_(software)"&gt;Spotlight&lt;/a&gt; will not index symlinks. Yes, you could just copy &lt;i&gt;Sshuttle VPN.app&lt;/i&gt; directly into &lt;i&gt;/Applications&lt;/i&gt;, but then you&amp;#8217;d have to remember to copy it every time you update/rebuild sshuttle.&lt;/p&gt;
&lt;p&gt;Without getting too technical, aliases are a lot like symlinks but they use extra metadata called &amp;#8220;resource forks&amp;#8221; to follow a file (even when it&amp;#8217;s moved) rather then blindly pointing to a path. More importantly, Spotlight &lt;strong&gt;will&lt;/strong&gt; index them. There&amp;#8217;s no way to create an alias from the command line, so you have to use Finder:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Open Finder and press &lt;strong&gt;Command-Shift-G&lt;/strong&gt; to open the &amp;#8220;Go to the folder:&amp;#8221; dialog box.&lt;/li&gt;
	&lt;li&gt;Type &lt;code&gt;/usr/local/libexec/sshuttle/ui-macos&lt;/code&gt; in the box and click the &lt;strong&gt;Go&lt;/strong&gt; button.&lt;br /&gt;
&lt;img src="http://elasticdog.com/images/2011/12/go-to-the-folder.png" alt="Go to the folder: Dialog Box" width="868" height="536" /&gt;&lt;/li&gt;
	&lt;li&gt;Click and hold &lt;i&gt;Sshuttle VPN.app&lt;/i&gt;, then while holding down both the &lt;strong&gt;Command&lt;/strong&gt; and &lt;strong&gt;Option&lt;/strong&gt; keys, drag the app over to &lt;em&gt;Applications&lt;/em&gt; on the left and release the mouse button.&lt;br /&gt;
&lt;img src="http://elasticdog.com/images/2011/12/sshuttle-alias.png" alt="Create the sshuttle Alias" width="868" height="536" /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="configuration"&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Due to some sysctl changes in OS X Lion, you will have to reboot your machine after you run sshuttle for the first time. An adjustment to the &lt;code&gt;net.inet.ip.scopedroute&lt;/code&gt; kernel flag needs to be made, and it can no longer be done during runtime. This is required so forwarding rules will be honored by the firewall.&lt;/p&gt;
&lt;p&gt;Everything should be handled automatically by sshuttle, but if your curious to see the change, you can display the boot kernel flags and current settings with the following commands:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;defaults &lt;span class="nb"&gt;read&lt;/span&gt; /Library/Preferences/SystemConfiguration/com.apple.Boot
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;Kernel Flags&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;sysctl -a | grep scopedroute
net.inet.ip.scopedroute: 1
net.inet6.ip6.scopedroute: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;After you run sshuttle for the first time and then reboot the machine, you can confirm the updated status:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;defaults &lt;span class="nb"&gt;read&lt;/span&gt; /Library/Preferences/SystemConfiguration/com.apple.Boot
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;Kernel Flags&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;net.inet.ip.scopedroute=0&amp;quot;&lt;/span&gt;;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;sysctl -a | grep scopedroute
kern.bootargs: net.inet.ip.scopedroute&lt;span class="o"&gt;=&lt;/span&gt;0
net.inet.ip.scopedroute: 0
net.inet6.ip6.scopedroute: 1
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id="usage"&gt;Usage&lt;/h2&gt;
&lt;p&gt;Finally we can get down to actually using sshuttle! It&amp;#8217;s flexible enough to do fancier things, but for our particular use case, we just need to forward all traffic over the tunnel.&lt;/p&gt;
&lt;p&gt;The basic command to achieve our goal looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;sshuttle --dns -r example.com 0/0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;i&gt;NOTE: Sshuttle will honor your &lt;code&gt;~/.ssh/config&lt;/code&gt; connection settings, but you can also manually specify a different username/port, if necessary:&lt;/i&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;sshuttle --dns -r username@example.com:2222 0/0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Run that, and all of your traffic (&lt;em&gt;including&lt;/em&gt; &lt;span class="caps"&gt;DNS&lt;/span&gt; requests) will be transparently proxied through an &lt;span class="caps"&gt;SSH&lt;/span&gt; connection to &lt;em&gt;example.com&lt;/em&gt;. You can verify this by browsing to &lt;a href="http://ifconfig.me"&gt;http://ifconfig.me&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To stop forwarding traffic, just press &lt;code&gt;Ctrl-c&lt;/code&gt; back in the terminal. We can do a bit better though by forking the process into the background so we don&amp;#8217;t tie up our terminal session. These are the aliases I use to make setting up and tearing down the tunnel easier:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;tunnel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;sshuttle --dns --daemon --pidfile=/tmp/sshuttle.pid --remote=example.com 0/0&amp;#39;&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;tunnelx&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;[[ -f /tmp/sshuttle.pid ]] &amp;amp;&amp;amp; kill $(cat /tmp/sshuttle.pid) &amp;amp;&amp;amp; echo &amp;quot;Disconnected.&amp;quot;&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;i&gt;Sshuttle VPN.app&lt;/i&gt; &lt;span class="caps"&gt;GUI&lt;/span&gt; is pretty self-explanatory, just make sure to enable the &lt;em&gt;Send &lt;span class="caps"&gt;DNS&lt;/span&gt; requests through this server&lt;/em&gt; checkbox, and select &lt;em&gt;Send all traffic through this server&lt;/em&gt; for the &amp;#8220;Network routes:&amp;#8221; option.&lt;/p&gt;
&lt;h2 id="bugs"&gt;Known Bugs&lt;/h2&gt;
&lt;p&gt;You may see a bunch of &amp;#8220;&lt;strong&gt;warning: closed channel &amp;#8230;&lt;/strong&gt;&amp;#8221; messages when running sshuttle (either on &lt;span class="caps"&gt;STDOUT&lt;/span&gt; or in your system.log), but these warnings are safe to ignore. The developer &lt;a href="http://groups.google.com/group/sshuttle/browse_thread/thread/853316d8e0a90269/4febfe3136aba5df"&gt;knows about the issue&lt;/a&gt; and is thinking of the best way to suppress/eliminate the condition.&lt;/p&gt;
&lt;p&gt;Also, prior to version 0.60 of sshuttle, there was &lt;a href="http://groups.google.com/group/sshuttle/browse_thread/thread/6603f9d17ae8eec4"&gt;a bug in the &lt;span class="caps"&gt;GUI&lt;/span&gt; application&lt;/a&gt; when disconnecting tunnels, where the controlling terminal would disappear before firewall rules could cleaned up. This would leave the network in an odd state and all &lt;span class="caps"&gt;DNS&lt;/span&gt; lookups would fail. It should be fixed now, but if you experience networking trouble after disconnecting a sshuttle tunnel, you can see the current firewall rules using:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;sudo ipfw list
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;#8230;and you can manually flush out those rules to fix connectivity by running:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;sudo ipfw -f flush
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Be aware though, &lt;strong&gt;this will flush out all rules&lt;/strong&gt;, not just the rules set by sshuttle, so it may have unintended consequences. If you&amp;#8217;re unsure, you can always reboot the machine to get connectivity back to normal.&lt;/p&gt;
&lt;h2 id="update"&gt;Update sshuttle&lt;/h2&gt;
&lt;p&gt;Since our installation of sshuttle is managed via git, updating to the latest version is pretty straightforward:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /usr/local/libexec/sshuttle
&lt;span class="nv"&gt;$ &lt;/span&gt;git pull
&lt;span class="nv"&gt;$ &lt;/span&gt;./do all
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Admittedly, sshuttle takes a bit more work than other solutions to get up and running, but the security it provides gives me peace of mind when forced to use insecure Wi-Fi networks.&lt;/p&gt;
&lt;p&gt;If you have any issues, there is an &lt;a href="http://groups.google.com/group/sshuttle"&gt;active mailing list&lt;/a&gt; for the project, or you can always &lt;a href="http://elasticdog.com/about/#contact"&gt;send me a note&lt;/a&gt; and I&amp;#8217;ll see what I can do to help.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=oeyJK6tsjeA:BjA9piu8RKo:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/oeyJK6tsjeA" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2011/12/use-sshuttle-to-keep-safe-on-insecure-wi-fi</feedburner:origLink></entry>
	
	<entry>
		<title>Shelf-Made Standing Desk</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/F7C24ldfUew/shelf-made-standing-desk" />
		<updated>2011-01-25T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2011/01/shelf-made-standing-desk</id>
		<content type="html">&lt;p&gt;Since I started working from home, I&amp;#8217;ve found that I spend even more time sitting at my desk than I did when I worked at the office. I&amp;#8217;ve never had great posture and started noticing that my back and shoulders were pretty achy by the end of the day. Once I got to that point, it was harder to stay focused on work and I was becoming noticably fatigued.&lt;/p&gt;
&lt;p&gt;I started researching alternative workspaces, and found ideas ranging from sitting on an excercise ball to walking on a treadmill desk. Having sat on excercise balls before, I knew that I would quickly regress back to slouching; and the idea of working on a treadmill seemed too impractical. I needed something in between&amp;#8230;&lt;/p&gt;
&lt;h2 id="standing-desk"&gt;A Standing Desk&lt;/h2&gt;
&lt;p&gt;There seems to be a surge of people converting to standing desks recently, and there&amp;#8217;s no shortage of personal stories and information on why they can be beneficial. Some very nice commercially-made standing desks are available, but not knowing if I&amp;#8217;d actually like using one, I didn&amp;#8217;t want to make a big up-front investment.&lt;/p&gt;
&lt;h2 class="old-desk"&gt;My Old Desk&lt;/h2&gt;
&lt;p&gt;For reference, my old desk was simply a cubicle desk surface that had been reclaimed from a dumpster. I always liked the amount of horizontal space it provided, and it was extremely solid, but not completely ideal.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/old-desk.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/old-desk-small.jpg" class="frame" title="My Old Sitting Desk" alt="My Old Sitting Desk" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="new-desk"&gt;My New Desk&lt;/h2&gt;
&lt;p&gt;I decided to convert a cheap shelving unit into a standing desk as a way to test the waters. At 48&amp;quot;W x 24&amp;quot;D x 72&amp;quot;H, &lt;a href="http://www.lowes.com/pd_101933-1281-CR4824_0__?&amp;amp;productId=1000527"&gt;this $80 rack&lt;/a&gt; from Lowes was pretty ideal, and I figured that after a month if I didn&amp;#8217;t like it, the shelf could always be used in my garage.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/muscle-rack.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/muscle-rack-small.jpg" class="frame" title="Muscle Rack" alt="Muscle Rack" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I tried to follow &lt;acronym title="Occupational Safety and Health Administration"&gt;&lt;span class="caps"&gt;OSHA&lt;/span&gt;&lt;/acronym&gt; guidelines as closely as possible when setting up the height of each shelf. The bottom shelf is about 7&amp;quot; above the ground to give my feet ample space below the rack; the upper shelf was placed so the top of the displays are right about eye-level; and the middle shelf was placed just below my elbow height for the keyboard and mouse. I used the extra shelf (which would have been on the very top) as a keyboard &amp;#8220;tray&amp;#8221; by cutting some notches in the corners to create a ledge that sticks out about six inches in the front.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/keyboard-tray.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/keyboard-tray-small.jpg" class="frame" title="Keyboard Tray Wrapped with Contact Paper" alt="Keyboard Tray Wrapped with Contact Paper" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some friends pointed out that &lt;acronym title="Medium-Density Fiberboard"&gt;&lt;span class="caps"&gt;MDF&lt;/span&gt;&lt;/acronym&gt; could potentially contain Formaldehyde in the resin used to bind it together, and that prolonged contact might cause skin irritation. To prevent this, I wrapped the front part of the keyboard tray in faux leather contact paper. It looks nice, and prevents my wrists from getting itchy.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how everything came together&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/complete-desk.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/complete-desk-small.jpg" class="frame" title="Complete Standing Desk" alt="Complete Standing Desk" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So my hands always stay at the proper height, I use &lt;a href="http://synergy-foss.org/"&gt;Synergy&lt;/a&gt; to control both my Linux desktop and my MacBook Pro laptop with the same keyboard and mouse.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/complete-desk-me.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/complete-desk-me-small.jpg" class="frame" title="Complete Standing Desk with Me" alt="Complete Standing Desk with Me" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://elasticdog.com/images/2011/01/complete-desk-footrest.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/complete-desk-footrest-small.jpg" class="frame" title="Complete Standing Desk using Footrest" alt="Complete Standing Desk using Footrest" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The medical community points out that staying in one position for too long (whether that&amp;#8217;s sitting &lt;strong&gt;or&lt;/strong&gt; standing) can be bad for you, so there&amp;#8217;s also a futon in my office where I can switch to using my laptop with a &lt;a href="http://www.logitech.com/en-us/notebook-products/cooling-pads/devices/4841"&gt;Logitech Comfort Lapdesk&lt;/a&gt;. Eventually, I may order a tall stool, so the option to sit at the desk will also be available; although, I do plan on standing for the majority of the time.&lt;/p&gt;
&lt;h3 id="accessories"&gt;Accessories&lt;/h3&gt;
&lt;p&gt;To make the standing desk more ergonomic, I purchased a few accessories:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;A &lt;a href="http://www.raindesigninc.com/mstand.html"&gt;Rain Design mStand&lt;/a&gt; laptop stand to bring my MacBook Pro&amp;#8217;s display up to the proper height&lt;/li&gt;
	&lt;li&gt;A &lt;a href="http://us.kensington.com/html/14801.html"&gt;Kensington SoleMate Plus&lt;/a&gt; adjustable footrest to help facilitate shifting my weight throughout the day&lt;/li&gt;
	&lt;li&gt;A 16&amp;quot; &lt;a href="http://zilotek.com/led_striplight.htm"&gt;Zilotek &lt;acronym title="Light-Emitting Diode"&gt;&lt;span class="caps"&gt;LED&lt;/span&gt;&lt;/acronym&gt; strip light&lt;/a&gt; to help eliminate shadows and illuminiate the shelf with the keyboard and mouse&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;#8217;s an idea of roughly how the keyboard tray looks without the &lt;span class="caps"&gt;LED&lt;/span&gt; strip light installed; and if you mouse over the image, you&amp;#8217;ll see what it looks like with the &lt;span class="caps"&gt;LED&lt;/span&gt; lights turned on&amp;#8230;&lt;/p&gt;
&lt;p class="togglev"&gt;&lt;a href="http://elasticdog.com/images/2011/01/shelf-light.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/shelf-toggle.jpg" class="frame" title="Shelf Lighting" alt="Shelf Lighting" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/01/shelf-leds.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/01/shelf-leds-small.jpg" class="frame" title="Shelf LED Lights" alt="Shelf LED Lights" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="conclusions"&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;My first full day of standing was January 19th, 2011, and so far, I really love the desk. The first week was definitely a little rough, with my feet and back becoming sore by the end of the day, but it&amp;#8217;s getting better. I&amp;#8217;ve read that it takes a couple of weeks to fully adjust, so after I&amp;#8217;ve given the desk a bit more time, I&amp;#8217;ll post another update. At this point, I&amp;#8217;m optimistic that it will be a permanent change to my home office setup.&lt;/p&gt;
&lt;h2 id="update"&gt;Update&lt;/h2&gt;
&lt;p&gt;It has been almost 8 months since I started using the standing desk, and I don&amp;#8217;t think I could go back. My posture has noticeably improved, and I quickly got over the initial soreness. I stand up about 85&amp;#8211;90% of the time, and sit down with my lapboard for the rest (mostly later in the day). I&amp;#8217;ve only made a few changes to my setup so far:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;I switched to an &lt;a href="http://www.kinesis-ergo.com/freestyle_mac.htm"&gt;Kenesis Freestyle ergonomic keyboard&lt;/a&gt; to help improve wrist positioning and limit overreaching when using the mouse&lt;/li&gt;
	&lt;li&gt;I added an &lt;a href="http://www.imprintmats.com/p-16-elite-series-nantucket-basketweave-design.aspx"&gt;Imprint anti-fatigue floor mat&lt;/a&gt; to make standing more comfortable (even though my office is carpeted)&lt;/li&gt;
	&lt;li&gt;I added an &lt;a href="http://www.apple.com/magictrackpad/"&gt;Apple Magic Trackpad&lt;/a&gt; near my mouse pad so I wouldn&amp;#8217;t need to reach to the upper level of the desk to perform multi-touch gestures&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It&amp;#8217;s safe to say that I enjoy utilizing a standing desk, and even though my shelving unit was originally purchased as an inexpensive way to get my feet wet, it has worked out better than expected. For now, it gets the job done and I don&amp;#8217;t see the need to purchase a more expensive standing desk.&lt;/p&gt;
&lt;p&gt;The only other planned improvements I have would be, to finally cut off the extra portion of each of the metal support rails that stick out from the top, and to build small side shelves that could support a pair of &lt;a href="http://www.krksys.com/krk-studio-monitor-speakers/rokit/rokit-5.html"&gt;&lt;span class="caps"&gt;KRK&lt;/span&gt; Rokit 5 studio monitors&lt;/a&gt;. Once I&amp;#8217;ve done those things, I&amp;#8217;ll post an updated photo of how it looks.&lt;/p&gt;
&lt;p&gt;Since posting this original article, I&amp;#8217;ve inspired a handful of friends to try out standing desks, and all of them have stuck with it. If you&amp;#8217;ve been on the fence about trying a standing desk, I can easily say that it&amp;#8217;s worth the effort to give it a shot. I&amp;#8217;d love to &lt;a href="http://elasticdog.com/about/#contact"&gt;hear from you&lt;/a&gt; if you end up taking the plunge!&lt;/p&gt;
&lt;h2 id="update2"&gt;Update&lt;sup&gt;2&lt;/sup&gt;&lt;/h2&gt;
&lt;p&gt;Well, I finished all of my planned improvements and here are the updated pics&amp;#8230;ignore the dust and messy cabling :-)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/09/updated-desk.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/09/updated-desk-small.jpg" class="frame" title="Updated Desk" alt="Updated Desk" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/09/user-input.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/09/user-input-small.jpg" class="frame" title="User Input" alt="User Input" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I found the shelves as a &lt;a href="http://www.knapeandvogt.com/89_Series_Glass_Shelf_Kits_by_Shelf_Made_Images.html?page=products.18.313"&gt;kit from Knape &amp;amp; Vogt&lt;/a&gt; for ~$20 each, but had to purchase some additional hardware (bolts, washers, and locking nuts) since they were originally designed for mounting with wood screws. The shelves can supposedly support up to 50 pounds each; they are stable, but I wouldn&amp;#8217;t be comfortable adding much more than the current 15 pounds on them.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/09/glass-shelf.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/09/glass-shelf-small.jpg" class="frame" title="Glass Shelf" alt="Glass Shelf" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2011/09/shelf-supports.jpg"&gt;&lt;img src="http://elasticdog.com/images/2011/09/shelf-supports-small.jpg" class="frame" title="Shelf Supports" alt="Shelf Supports" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cutting the metal support rails and trimming the shelf mounts to fit took a fair bit of time, a steady hand, and a Dremel. If you try it, the one thing I&amp;#8217;ll say is to definitely wear safety glasses!&lt;/p&gt;
&lt;p&gt;Anyway, I think I&amp;#8217;m finally done tweaking things for a bit, but am incredibly happy with the results. Go forth and stand!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=F7C24ldfUew:WnGPCDfHZRw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/F7C24ldfUew" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2011/01/shelf-made-standing-desk</feedburner:origLink></entry>
	
	<entry>
		<title>Porting a Poker Hand Evaluator from C to Factor</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/u4N1OGB_2Z0/porting-a-poker-hand-evaluator-from-c-to-factor" />
		<updated>2010-11-07T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2010/11/porting-a-poker-hand-evaluator-from-c-to-factor</id>
		<content type="html">&lt;p&gt;To help teach myself &lt;a href="http://factorcode.org/"&gt;Factor&lt;/a&gt;, I started solving a lot of the problems at &lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt; and approached each one, not only as a way to learn a new language, but as a means of exploring unfamiliar programming/mathematical methods, structures, and algorithms. This article explains the process I went through to port a fairly complicated poker hand evaluation algorithm from C to Factor.&lt;/p&gt;
&lt;h2 id="problem54"&gt;Problem 54&lt;/h2&gt;
&lt;p&gt;In order to solve &lt;a href="http://projecteuler.net/index.php?section=problems&amp;amp;id=54"&gt;Problem 54&lt;/a&gt;, I needed to come up with a way to programatically determine the winner when comparing two poker hands. I had recently read an extensive &lt;a href="http://www.codingthewheel.com/archives/poker-hand-evaluator-roundup"&gt;blog post covering various poker hand evaluators&lt;/a&gt;, so I knew that I didn&amp;#8217;t want to bother with a naive solution when there were much better options out there. After reading through the different techniques, one stood out to me in particular; it was a relatively small amount of code, it didn&amp;#8217;t require a ton of storage space, and it was plenty fast&amp;#8230;&lt;/p&gt;
&lt;h3 id="cactuskev"&gt;Cactus Kev&amp;#8217;s Poker Hand Evaluator&lt;/h3&gt;
&lt;p&gt;Through the power of mathematics (&lt;a href="https://secure.wikimedia.org/wikipedia/en/wiki/Combinatorics"&gt;combinatorics&lt;/a&gt; in particular), you can ascertain that out of all 2,598,960 possible poker hands (52 choose 5), there are actually only &lt;a href="http://www.suffecool.net/poker/7462.html"&gt;7462 distinct hand values&lt;/a&gt; that you need to be concerned with. The basic idea behind &lt;a href="http://www.suffecool.net/poker/evaluator.html"&gt;Cactus Kev&amp;#8217;s Poker Hand Evaluator&lt;/a&gt; is that you can take advantage of this fact by storing a card&amp;#8217;s representation in an efficient manner, do some basic bit twiddling, some multiplication (which is computationally cheap), add in a couple lookup tables, and you can determine a hand&amp;#8217;s equivalence class value &lt;em&gt;very&lt;/em&gt; quickly.&lt;/p&gt;
&lt;p&gt;The key concept here is that each of a card&amp;#8217;s possible 13 ranks (deuce through ace) is stored as a different prime number, and by multiplying a hand&amp;#8217;s five prime numbers together, you&amp;#8217;ll get a unique result that can then be used to determine that hand&amp;#8217;s overall value. If you handle the special cases of flushes, straights, and high cards, the rest can be boiled down to a simple binary search. You can read the gory details at &lt;a href="http://www.suffecool.net/poker/evaluator.html"&gt;Kevin Suffecool&amp;#8217;s site&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="porting"&gt;The Porting Process&lt;/h2&gt;
&lt;h3 id="constants"&gt;Bitfield Representation&lt;/h3&gt;
&lt;p&gt;Each card will be stored as a &lt;a href="http://en.wikipedia.org/wiki/Bitfield"&gt;bitfield&lt;/a&gt;, inside of an interger that&amp;#8217;s 4-bytes long:&lt;/p&gt;
&lt;p&gt;&lt;!--
   cyan:   #339999;
   green:  #3A8D35;
   orange: #CB5910;
   tan:    #A9A487;
   yellow: #E2DA6E;
--&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;+-------------------------------------+
| &lt;span style="color:#A9A487"&gt;xxx&lt;/span&gt;&lt;span style="color:#CB5910"&gt;bbbbb bbbbbbbb&lt;/span&gt; &lt;span style="color:#339999"&gt;ssss&lt;/span&gt;&lt;span style="color:#E2DA6E"&gt;rrrr&lt;/span&gt; &lt;span style="color:#A9A487"&gt;xx&lt;/span&gt;&lt;span style="color:#3A8D35"&gt;pppppp&lt;/span&gt; |
+-------------------------------------+
  &lt;span style="color:#A9A487"&gt;xxx&lt;/span&gt;&lt;span style="color:#CB5910"&gt;AKQJT 98765432&lt;/span&gt; &lt;span style="color:#339999"&gt;CDHS&lt;/span&gt;&lt;span style="color:#E2DA6E"&gt;rrrr&lt;/span&gt; &lt;span style="color:#A9A487"&gt;xx&lt;/span&gt;&lt;span style="color:#3A8D35"&gt;pppppp&lt;/span&gt;
  -----------------------------------
  &lt;span style="color:#A9A487"&gt;000&lt;/span&gt;&lt;span style="color:#CB5910"&gt;01000 00000000&lt;/span&gt; &lt;span style="color:#339999"&gt;0100&lt;/span&gt;&lt;span style="color:#E2DA6E"&gt;1011&lt;/span&gt; &lt;span style="color:#A9A487"&gt;00&lt;/span&gt;&lt;span style="color:#3A8D35"&gt;100101&lt;/span&gt;  =  134236965  =  King of Diamonds
  &lt;span style="color:#A9A487"&gt;000&lt;/span&gt;&lt;span style="color:#CB5910"&gt;00000 00001000&lt;/span&gt; &lt;span style="color:#339999"&gt;0001&lt;/span&gt;&lt;span style="color:#E2DA6E"&gt;0011&lt;/span&gt; &lt;span style="color:#A9A487"&gt;00&lt;/span&gt;&lt;span style="color:#3A8D35"&gt;000111&lt;/span&gt;  =     529159  =  Five of Spades
  &lt;span style="color:#A9A487"&gt;000&lt;/span&gt;&lt;span style="color:#CB5910"&gt;00010 00000000&lt;/span&gt; &lt;span style="color:#339999"&gt;1000&lt;/span&gt;&lt;span style="color:#E2DA6E"&gt;1001&lt;/span&gt; &lt;span style="color:#A9A487"&gt;00&lt;/span&gt;&lt;span style="color:#3A8D35"&gt;011101&lt;/span&gt;  =   33589533  =  Jack of Clubs
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;x&lt;/code&gt; = bit turned off, not used&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;b&lt;/code&gt; = bit turned on depending on rank of card&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;s&lt;/code&gt; = bit turned on depending on suit of card&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;r&lt;/code&gt; = rank of card (deuce = 0, trey = 1, four = 2, &amp;#8230;, ace = 12)&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;p&lt;/code&gt; = prime number value of rank (deuce = 2, trey = 3, four = 5, &amp;#8230;, ace = 41)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For now, I&amp;#8217;m going to ignore how we get cards into this particular format, but I&amp;#8217;ll come back to that in a bit.&lt;/p&gt;
&lt;h3 id="constants"&gt;Constants&lt;/h3&gt;
&lt;p&gt;Now that we have an efficient means of representing individual cards, we need to establish some basic constants to align with the above bitfield representation and overall hand values&amp;#8230;&lt;/p&gt;
&lt;h4 id="constants-c"&gt;Constants In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="cp"&gt;#define CLUB     0x8000&lt;/span&gt;
&lt;span class="cp"&gt;#define DIAMOND  0x4000&lt;/span&gt;
&lt;span class="cp"&gt;#define HEART    0x2000&lt;/span&gt;
&lt;span class="cp"&gt;#define SPADE    0x1000&lt;/span&gt;

&lt;span class="cp"&gt;#define Deuce  0&lt;/span&gt;
&lt;span class="cp"&gt;#define Trey   1&lt;/span&gt;
&lt;span class="cp"&gt;#define Four   2&lt;/span&gt;
&lt;span class="cp"&gt;#define Five   3&lt;/span&gt;
&lt;span class="cp"&gt;#define Six    4&lt;/span&gt;
&lt;span class="cp"&gt;#define Seven  5&lt;/span&gt;
&lt;span class="cp"&gt;#define Eight  6&lt;/span&gt;
&lt;span class="cp"&gt;#define Nine   7&lt;/span&gt;
&lt;span class="cp"&gt;#define Ten    8&lt;/span&gt;
&lt;span class="cp"&gt;#define Jack   9&lt;/span&gt;
&lt;span class="cp"&gt;#define Queen  10&lt;/span&gt;
&lt;span class="cp"&gt;#define King   11&lt;/span&gt;
&lt;span class="cp"&gt;#define Ace    12&lt;/span&gt;

&lt;span class="cp"&gt;#define STRAIGHT_FLUSH   1&lt;/span&gt;
&lt;span class="cp"&gt;#define FOUR_OF_A_KIND   2&lt;/span&gt;
&lt;span class="cp"&gt;#define FULL_HOUSE       3&lt;/span&gt;
&lt;span class="cp"&gt;#define FLUSH            4&lt;/span&gt;
&lt;span class="cp"&gt;#define STRAIGHT         5&lt;/span&gt;
&lt;span class="cp"&gt;#define THREE_OF_A_KIND  6&lt;/span&gt;
&lt;span class="cp"&gt;#define TWO_PAIR         7&lt;/span&gt;
&lt;span class="cp"&gt;#define ONE_PAIR         8&lt;/span&gt;
&lt;span class="cp"&gt;#define HIGH_CARD        9&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;value_str&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Straight Flush&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Four of a Kind&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Full House&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Flush&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Straight&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Three of a Kind&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;Two Pair&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;One Pair&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;High Card&amp;quot;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="constants-factor"&gt;Constants In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="no"&gt;CONSTANT: CLUB&lt;/span&gt;     &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: DIAMOND&lt;/span&gt;  &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: HEART&lt;/span&gt;    &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: SPADE&lt;/span&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: DEUCE&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: TREY&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: FOUR&lt;/span&gt;   &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: FIVE&lt;/span&gt;   &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: SIX&lt;/span&gt;    &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: SEVEN&lt;/span&gt;  &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: EIGHT&lt;/span&gt;  &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: NINE&lt;/span&gt;   &lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: TEN&lt;/span&gt;    &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: JACK&lt;/span&gt;   &lt;span class="mi"&gt;9&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: QUEEN&lt;/span&gt;  &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: KING&lt;/span&gt;   &lt;span class="mi"&gt;11&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: ACE&lt;/span&gt;    &lt;span class="mi"&gt;12&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: STRAIGHT_FLUSH&lt;/span&gt;   &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: FOUR_OF_A_KIND&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: FULL_HOUSE&lt;/span&gt;       &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: FLUSH&lt;/span&gt;            &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: STRAIGHT&lt;/span&gt;         &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: THREE_OF_A_KIND&lt;/span&gt;  &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: TWO_PAIR&lt;/span&gt;         &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: ONE_PAIR&lt;/span&gt;         &lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="no"&gt;CONSTANT: HIGH_CARD&lt;/span&gt;        &lt;span class="mi"&gt;8&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: VALUE_STR&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Straight Flush&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Four of a Kind&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Full House&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Flush&amp;quot;&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;Straight&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Three of a Kind&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Two Pair&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;One Pair&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;High Card&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here, the only difference I made in the Factor version was to start the hand value types at 0 instead of 1 to eliminate the empty string at index 0&amp;#8230;it&amp;#8217;s unneccessary.&lt;/p&gt;
&lt;h3 id="prime"&gt;Prime Number Representations&lt;/h3&gt;
&lt;p&gt;As mentioned above, each card rank will be represented by its own prime number, so we&amp;#8217;ll need a way to reference that&amp;#8230;&lt;/p&gt;
&lt;h4 id="prime-c"&gt;Prime Numbers In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="prime-factor"&gt;Prime Numbers In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="no"&gt;CONSTANT: RANK_STR&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;3&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;6&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;7&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;8&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;9&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;T&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;J&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Q&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;K&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;A&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;: card-rank-prime &lt;/span&gt;&lt;span class="kt"&gt;( rank -- n )&lt;/span&gt;
    RANK_STR &lt;span class="k"&gt;index &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;nth &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A minor change I made here was to establish a &lt;code&gt;RANK_STR&lt;/code&gt; constant to make it easier to develop ways to parse and print card representations later (see the &lt;a href="#printing-c"&gt;section on printing&lt;/a&gt; below for the C equivalent). That said, &lt;code&gt;card-rank-prime&lt;/code&gt; in the Factor version has the same purpose as the &lt;code&gt;primes&lt;/code&gt; array in the C version, but it performs the lookup for you.&lt;/p&gt;
&lt;h3 id="initialize-card"&gt;Initializing Cards&lt;/h3&gt;
&lt;p&gt;Now that we have some basic infrastructure in place, we can tackle initializing cards in the desired format. Cactus Kev&amp;#8217;s code glosses over this process and only demonstrates how to generate an entire deck, so I&amp;#8217;ll just cover the Factor code here&amp;#8230;&lt;/p&gt;
&lt;h4 id="initialize-card-factor"&gt;Initializing Cards In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: card-rank &lt;/span&gt;&lt;span class="kt"&gt;( rank -- n )&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; DEUCE &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;3&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; TREY  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; FOUR  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; FIVE  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;6&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; SIX   &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;7&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; SEVEN &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;8&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; EIGHT &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;9&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; NINE  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;T&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; TEN   &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;J&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; JACK  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Q&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; QUEEN &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;K&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; KING  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;A&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; ACE   &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;case &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: card-suit &lt;/span&gt;&lt;span class="kt"&gt;( suit -- n )&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;C&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; CLUB    &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;D&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; DIAMOND &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;H&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; HEART   &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;S&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; SPADE   &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;case &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: card-rank-bit &lt;/span&gt;&lt;span class="kt"&gt;( rank -- n )&lt;/span&gt;
    RANK_STR &lt;span class="k"&gt;index &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;swap shift &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: card-bitfield &lt;/span&gt;&lt;span class="kt"&gt;( rank rank suit rank -- n )&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; card-rank-bit &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; card-suit &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; card-rank &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; card-rank-prime &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; bitfield &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;:: (&amp;gt;ckf) &lt;/span&gt;&lt;span class="kt"&gt;( rank suit -- n )&lt;/span&gt;
    rank rank suit rank card-bitfield &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: &amp;gt;ckf &lt;/span&gt;&lt;span class="kt"&gt;( string -- n )&lt;/span&gt;
    &lt;span class="c"&gt;#! Cactus Kev Format&lt;/span&gt;
    &amp;gt;upper &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;cut &lt;/span&gt;(&amp;gt;ckf) &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: parse-cards &lt;/span&gt;&lt;span class="kt"&gt;( string -- hand )&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot; &amp;quot;&lt;/span&gt; split &lt;span class="p"&gt;[&lt;/span&gt; &amp;gt;ckf &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;map &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To use this code, you&amp;#8217;d start with a string representing a card, like &lt;code&gt;"AS"&lt;/code&gt; for the Ace of Spades or &lt;code&gt;"7H"&lt;/code&gt; for the Seven of Hearts, and then pass it to &lt;code&gt;&amp;gt;ckf&lt;/code&gt; to get its integer representation. The &lt;code&gt;parse-cards&lt;/code&gt; word simply does this conversion for an entire hand; given a string like &lt;code&gt;"7C 5D 4H 3S 2C"&lt;/code&gt;, it will output an array of the proper integers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;7C 5D 4H 3S 2C&amp;quot;&lt;/span&gt; parse-cards .
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2131213&lt;/span&gt; &lt;span class="mi"&gt;541447&lt;/span&gt; &lt;span class="mi"&gt;270853&lt;/span&gt; &lt;span class="mi"&gt;135427&lt;/span&gt; &lt;span class="mi"&gt;98306&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Due to Factor&amp;#8217;s concatenative nature, you tend to write a lot of small words that do one specific thing, and then tie them together. Words are expected to be defined before you reference them (unless they&amp;#8217;ve been &lt;a href="http://docs.factorcode.org/content/article-deferred.html"&gt;deferred&lt;/a&gt;), so when reading code from top to bottom, you&amp;#8217;ll see big-picture words defined after the more-focused words they use. It&amp;#8217;s also a convention to name helper words the same as the word from which they&amp;#8217;re called, but with parentheses around the name.&lt;/p&gt;
&lt;p&gt;One special thing to note is the use of &lt;a href="http://docs.factorcode.org/content/word-__colon____colon__,locals.html"&gt;locals&lt;/a&gt; in the &lt;code&gt;(&amp;gt;ckf)&lt;/code&gt; helper word&amp;#8230;if you start a word definition with &lt;code&gt;::&lt;/code&gt; instead of just &lt;code&gt;:&lt;/code&gt;, Factor will bind the named inputs (from the stack declaration) to lexical variables from left to right. It&amp;#8217;s used in this case because we need to pass these values to the &lt;code&gt;card-bitfield&lt;/code&gt; word in a specific order, and &lt;a href="http://elasticdog.com/2008/12/beginning-factor-shufflers-and-combinators/#caveats"&gt;shufflers would make this a bit more confusing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The last thing to explain is the &lt;code&gt;card-bitfield&lt;/code&gt; word itself&amp;#8230;it looks up the proper bit values for the different parts of our card representation, and then constructs the final 4-byte integer from those values. See the &lt;a href="http://docs.factorcode.org/content/word-bitfield,math.bitwise.html"&gt;bitfield documentation&lt;/a&gt; for more details on its syntax.&lt;/p&gt;
&lt;h3 id="decks"&gt;Shuffling Decks and Printing Hands&lt;/h3&gt;
&lt;p&gt;Initializing and shuffling a deck wasn&amp;#8217;t strictly necessary for solving the Project Euler problem, but it was a useful abstraction and would be expected in a general poker library. Printing out a poker hand falls under this same category, but I&amp;#8217;ve included it here as well since it was part of Cactus Kev&amp;#8217;s original code. This is where the languages start to noticibly deviate in their implementations&amp;#8230;&lt;/p&gt;
&lt;h4 id="init-deck-c"&gt;Initializing a Deck In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="n"&gt;init_deck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;deck&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;deck&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="init-deck-factor"&gt;Initializing a Deck In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: &amp;lt;deck&amp;gt; &lt;/span&gt;&lt;span class="kt"&gt;( -- deck )&lt;/span&gt;
    RANK_STR SUIT_STR &lt;span class="k"&gt;2array &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;concat &lt;/span&gt;&amp;gt;ckf &lt;span class="p"&gt;]&lt;/span&gt; product-map &lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="shuffle-c"&gt;Shuffling a Deck In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="kt"&gt;double&lt;/span&gt;  &lt;span class="n"&gt;drand48&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;shuffle_deck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;deck&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deck&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mf"&gt;51.9999999&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;drand48&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;deck&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="shuffle-factor"&gt;Shuffling a Deck In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;ALIAS: shuffle randomize
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="printing-c"&gt;Printing a Hand In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="n"&gt;print_hand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;suit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;rank&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;23456789TJQKA&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x8000&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x4000&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;&amp;#39;d&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0x2000&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;&amp;#39;h&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;&amp;#39;s&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;%c%c &amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;suit&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;hand&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="printing-factor"&gt;Printing a Hand In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: &amp;gt;card-rank &lt;/span&gt;&lt;span class="kt"&gt;( card -- string )&lt;/span&gt;
    &lt;span class="mi"&gt;-8&lt;/span&gt; &lt;span class="k"&gt;shift &lt;/span&gt;&lt;span class="mh"&gt;HEX: F&lt;/span&gt; &lt;span class="k"&gt;bitand &lt;/span&gt;RANK_STR &lt;span class="k"&gt;nth &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: &amp;gt;card-suit &lt;/span&gt;&lt;span class="kt"&gt;( card -- string )&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="k"&gt;bit? &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;C&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="k"&gt;bit? &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;D&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt; &lt;span class="k"&gt;bit? &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;H&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;S&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;cond &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: card&amp;gt;string &lt;/span&gt;&lt;span class="kt"&gt;( card -- string )&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt; &amp;gt;card-rank &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &amp;gt;card-suit &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi append &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: print-hand &lt;/span&gt;&lt;span class="kt"&gt;( hand -- )&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt; card&amp;gt;string &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;map &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot; &amp;quot;&lt;/span&gt; &lt;span class="k"&gt;join print &lt;/span&gt;flush;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I&amp;#8217;m cheating a bit here with the &lt;code&gt;shuffle&lt;/code&gt; word, as Factor already implements &lt;code&gt;randomize&lt;/code&gt; using the &lt;a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle"&gt;Fisher-Yates algorithm&lt;/a&gt;; so rather than re-inventing the wheel, I just aliased the wheel. With Factor, you&amp;#8217;ll also notice that count-controlled loops are much less common in comparison to using &lt;a href="http://docs.factorcode.org/content/article-sequences.html"&gt;sequence operators&lt;/a&gt; directly on the elements of a data structure.&lt;/p&gt;
&lt;h3 id="lookup"&gt;Lookup Tables&lt;/h3&gt;
&lt;p&gt;We can almost get to the actual evaluation of hands to determine their relative value, but before that, we&amp;#8217;ll need the proper lookup tables. These are all straight-forward arrays, and we have four to consider:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;a table for all flushes (including straight flushes)&lt;/li&gt;
	&lt;li&gt;a table for all non-flush hands consisting of five unique ranks (i.e. either straights or high card hands)&lt;/li&gt;
	&lt;li&gt;a table of the product of prime values associated with a hand&lt;/li&gt;
	&lt;li&gt;a table covering the final hand values of all hands not covered by the flushes/unique5 tables&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A zero means that specific combination is not possible for that type of hand&amp;#8230;&lt;/p&gt;
&lt;h4 id="lookup-c"&gt;Lookup Tables In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="kt"&gt;short&lt;/span&gt; &lt;span class="n"&gt;flushes&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1599&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1598&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1597&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1596&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;short&lt;/span&gt; &lt;span class="n"&gt;unique5&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1608&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7462&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7461&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;7460&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1600&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;72&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;108&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;162&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;176&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;208&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;252&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;264&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;270&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;272&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;280&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;304&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;312&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;368&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;378&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;392&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;396&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;405&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;408&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;420&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;440&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;450&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;464&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;468&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;496&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;520&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;552&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;567&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;588&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;592&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;66737381&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="mi"&gt;71339959&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;73952233&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;76840601&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;79052387&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;81947069&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;85147693&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;87598591&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94352849&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;104553157&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;short&lt;/span&gt;  &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;166&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;322&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;165&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;310&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;164&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2467&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;154&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2466&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;163&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;3325&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;321&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;162&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;3324&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;2464&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;2401&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;161&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;2465&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3314&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2461&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;159&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;320&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="mi"&gt;3323&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;153&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2457&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6185&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2463&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3303&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2452&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;158&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;3322&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;157&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;298&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;1676&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2469&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2468&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1611&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1610&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;179&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;167&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="lookup-factor"&gt;Lookup Tables In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="no"&gt;CONSTANT: flushes-table&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1599&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1598&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1597&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1596&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1595&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1594&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1593&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1592&lt;/span&gt; &lt;span class="mi"&gt;1591&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1590&lt;/span&gt;
...
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: unique5-table&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1608&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7462&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7461&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7460&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7459&lt;/span&gt; &lt;span class="mi"&gt;1607&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7458&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7457&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7456&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;7455&lt;/span&gt; &lt;span class="mi"&gt;7454&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
...
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1600&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: products-table&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt; &lt;span class="mi"&gt;72&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="mi"&gt;108&lt;/span&gt; &lt;span class="mi"&gt;112&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="mi"&gt;162&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt; &lt;span class="mi"&gt;176&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="mi"&gt;208&lt;/span&gt; &lt;span class="mi"&gt;252&lt;/span&gt; &lt;span class="mi"&gt;264&lt;/span&gt; &lt;span class="mi"&gt;270&lt;/span&gt; &lt;span class="mi"&gt;272&lt;/span&gt; &lt;span class="mi"&gt;280&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="mi"&gt;304&lt;/span&gt; &lt;span class="mi"&gt;312&lt;/span&gt;
&lt;span class="mi"&gt;368&lt;/span&gt; &lt;span class="mi"&gt;378&lt;/span&gt; &lt;span class="mi"&gt;392&lt;/span&gt; &lt;span class="mi"&gt;396&lt;/span&gt; &lt;span class="mi"&gt;405&lt;/span&gt; &lt;span class="mi"&gt;408&lt;/span&gt; &lt;span class="mi"&gt;420&lt;/span&gt; &lt;span class="mi"&gt;440&lt;/span&gt; &lt;span class="mi"&gt;450&lt;/span&gt; &lt;span class="mi"&gt;456&lt;/span&gt; &lt;span class="mi"&gt;464&lt;/span&gt; &lt;span class="mi"&gt;468&lt;/span&gt; &lt;span class="mi"&gt;496&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="mi"&gt;520&lt;/span&gt; &lt;span class="mi"&gt;552&lt;/span&gt; &lt;span class="mi"&gt;567&lt;/span&gt; &lt;span class="mi"&gt;588&lt;/span&gt; &lt;span class="mi"&gt;592&lt;/span&gt; &lt;span class="mi"&gt;594&lt;/span&gt;
&lt;span class="mi"&gt;612&lt;/span&gt; &lt;span class="mi"&gt;616&lt;/span&gt; &lt;span class="mi"&gt;630&lt;/span&gt; &lt;span class="mi"&gt;656&lt;/span&gt; &lt;span class="mi"&gt;660&lt;/span&gt; &lt;span class="mi"&gt;675&lt;/span&gt; &lt;span class="mi"&gt;680&lt;/span&gt; &lt;span class="mi"&gt;684&lt;/span&gt; &lt;span class="mi"&gt;696&lt;/span&gt; &lt;span class="mi"&gt;700&lt;/span&gt; &lt;span class="mi"&gt;702&lt;/span&gt; &lt;span class="mi"&gt;728&lt;/span&gt; &lt;span class="mi"&gt;744&lt;/span&gt; &lt;span class="mi"&gt;750&lt;/span&gt; &lt;span class="mi"&gt;760&lt;/span&gt; &lt;span class="mi"&gt;780&lt;/span&gt; &lt;span class="mi"&gt;828&lt;/span&gt; &lt;span class="mi"&gt;882&lt;/span&gt; &lt;span class="mi"&gt;888&lt;/span&gt; &lt;span class="mi"&gt;891&lt;/span&gt;
...
&lt;span class="mi"&gt;64379963&lt;/span&gt; &lt;span class="mi"&gt;64992503&lt;/span&gt; &lt;span class="mi"&gt;66233081&lt;/span&gt; &lt;span class="mi"&gt;66737381&lt;/span&gt; &lt;span class="mi"&gt;71339959&lt;/span&gt; &lt;span class="mi"&gt;73952233&lt;/span&gt; &lt;span class="mi"&gt;76840601&lt;/span&gt; &lt;span class="mi"&gt;79052387&lt;/span&gt;
&lt;span class="mi"&gt;81947069&lt;/span&gt; &lt;span class="mi"&gt;85147693&lt;/span&gt; &lt;span class="mi"&gt;87598591&lt;/span&gt; &lt;span class="mi"&gt;94352849&lt;/span&gt; &lt;span class="mi"&gt;104553157&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;CONSTANT: values-table&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;166&lt;/span&gt; &lt;span class="mi"&gt;322&lt;/span&gt; &lt;span class="mi"&gt;165&lt;/span&gt; &lt;span class="mi"&gt;310&lt;/span&gt; &lt;span class="mi"&gt;164&lt;/span&gt; &lt;span class="mi"&gt;2467&lt;/span&gt; &lt;span class="mi"&gt;154&lt;/span&gt; &lt;span class="mi"&gt;2466&lt;/span&gt; &lt;span class="mi"&gt;163&lt;/span&gt; &lt;span class="mi"&gt;3325&lt;/span&gt; &lt;span class="mi"&gt;321&lt;/span&gt; &lt;span class="mi"&gt;162&lt;/span&gt; &lt;span class="mi"&gt;3324&lt;/span&gt; &lt;span class="mi"&gt;2464&lt;/span&gt; &lt;span class="mi"&gt;2401&lt;/span&gt; &lt;span class="mi"&gt;161&lt;/span&gt; &lt;span class="mi"&gt;2465&lt;/span&gt;
&lt;span class="mi"&gt;3314&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt; &lt;span class="mi"&gt;2461&lt;/span&gt; &lt;span class="mi"&gt;159&lt;/span&gt; &lt;span class="mi"&gt;2400&lt;/span&gt; &lt;span class="mi"&gt;320&lt;/span&gt; &lt;span class="mi"&gt;3323&lt;/span&gt; &lt;span class="mi"&gt;153&lt;/span&gt; &lt;span class="mi"&gt;2457&lt;/span&gt; &lt;span class="mi"&gt;6185&lt;/span&gt; &lt;span class="mi"&gt;2463&lt;/span&gt; &lt;span class="mi"&gt;3303&lt;/span&gt; &lt;span class="mi"&gt;2452&lt;/span&gt; &lt;span class="mi"&gt;158&lt;/span&gt; &lt;span class="mi"&gt;3322&lt;/span&gt; &lt;span class="mi"&gt;157&lt;/span&gt; &lt;span class="mi"&gt;298&lt;/span&gt;
&lt;span class="mi"&gt;2460&lt;/span&gt; &lt;span class="mi"&gt;2446&lt;/span&gt; &lt;span class="mi"&gt;152&lt;/span&gt; &lt;span class="mi"&gt;3292&lt;/span&gt; &lt;span class="mi"&gt;156&lt;/span&gt; &lt;span class="mi"&gt;2398&lt;/span&gt; &lt;span class="mi"&gt;3321&lt;/span&gt; &lt;span class="mi"&gt;2462&lt;/span&gt; &lt;span class="mi"&gt;5965&lt;/span&gt; &lt;span class="mi"&gt;155&lt;/span&gt; &lt;span class="mi"&gt;6184&lt;/span&gt; &lt;span class="mi"&gt;309&lt;/span&gt; &lt;span class="mi"&gt;2456&lt;/span&gt; &lt;span class="mi"&gt;3320&lt;/span&gt; &lt;span class="mi"&gt;2439&lt;/span&gt; &lt;span class="mi"&gt;3313&lt;/span&gt;
...
&lt;span class="mi"&gt;1622&lt;/span&gt; &lt;span class="mi"&gt;191&lt;/span&gt; &lt;span class="mi"&gt;3546&lt;/span&gt; &lt;span class="mi"&gt;2490&lt;/span&gt; &lt;span class="mi"&gt;2470&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="mi"&gt;2600&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt; &lt;span class="mi"&gt;3326&lt;/span&gt; &lt;span class="mi"&gt;169&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="mi"&gt;1612&lt;/span&gt; &lt;span class="mi"&gt;2479&lt;/span&gt; &lt;span class="mi"&gt;1677&lt;/span&gt; &lt;span class="mi"&gt;1621&lt;/span&gt; &lt;span class="mi"&gt;1676&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;
&lt;span class="mi"&gt;2469&lt;/span&gt; &lt;span class="mi"&gt;2468&lt;/span&gt; &lt;span class="mi"&gt;1611&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="mi"&gt;1610&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt; &lt;span class="mi"&gt;179&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="mi"&gt;167&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id="evaluation"&gt;Hand Evaluation&lt;/h3&gt;
&lt;p&gt;Finally, we can get to the actual evaluation of hands&amp;#8230;&lt;/p&gt;
&lt;h4 id="evaluation-c"&gt;Hand Evaluation In C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;findit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;low&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;high&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4887&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;low&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;high&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;high&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;low&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// divide by two&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;high&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;low&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;ERROR:  no match found; key = %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;short&lt;/span&gt;
&lt;span class="nf"&gt;eval_5cards&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c5&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;short&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c2&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c3&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c4&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cm"&gt;/* check for Flushes and StraightFlushes&lt;/span&gt;
&lt;span class="cm"&gt;    */&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c4&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c5&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xF000&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;flushes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="cm"&gt;/* check for Straights and HighCard hands&lt;/span&gt;
&lt;span class="cm"&gt;    */&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unique5&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="cm"&gt;/* let&amp;#39;s do it the hard way&lt;/span&gt;
&lt;span class="cm"&gt;    */&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c2&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c3&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c4&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c5&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;findit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="evaluation-factor"&gt;Hand Evaluation In Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: flush? &lt;/span&gt;&lt;span class="kt"&gt;( hand -- ? )&lt;/span&gt;
    &lt;span class="mh"&gt;HEX: F000&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;bitand &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;reduce &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; = &lt;span class="k"&gt;not &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: rank-bits &lt;/span&gt;&lt;span class="kt"&gt;( hand -- q )&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;bitor &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;reduce &lt;/span&gt;&lt;span class="mi"&gt;-16&lt;/span&gt; &lt;span class="k"&gt;shift &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: lookup &lt;/span&gt;&lt;span class="kt"&gt;( hand table -- value )&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt; rank-bits &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;dip nth &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: prime-bits &lt;/span&gt;&lt;span class="kt"&gt;( hand -- q )&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mh"&gt;HEX: FF&lt;/span&gt; &lt;span class="k"&gt;bitand &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; map-product &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: hand-value &lt;/span&gt;&lt;span class="kt"&gt;( hand -- value )&lt;/span&gt;
    &lt;span class="k"&gt;dup &lt;/span&gt;flush? &lt;span class="p"&gt;[&lt;/span&gt; flushes-table lookup &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="k"&gt;dup &lt;/span&gt;unique5-table lookup &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;nip &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="k"&gt;drop &lt;/span&gt;prime-bits products-table sorted-index
            values-table &lt;span class="k"&gt;nth&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Each language&amp;#8217;s implementation checks for flushes first, then for hands with five unique ranks, and if all else fails, multiplies the primes together, searches for that product in a lookup table, and then uses that index to determine the hand&amp;#8217;s final value. The &lt;code&gt;findit&lt;/code&gt; function in C is the binary search, and once again I used Factor&amp;#8217;s built-in libraries to do the same thing with the &lt;a href="http://docs.factorcode.org/content/word-sorted-index,binary-search.html"&gt;sorted-index&lt;/a&gt; word.&lt;/p&gt;
&lt;h3 id="ranking"&gt;Hand Ranking&lt;/h3&gt;
&lt;p&gt;We&amp;#8217;re basically done at this point&amp;#8230;the hand with the lowest value (from 1 to 7462) wins. If the values are the same, the hands are tied. A simple comparison function can tell you which hand is best.&lt;/p&gt;
&lt;p&gt;One last function that&amp;#8217;s handy though, is the ability to output what that value actually means&amp;#8230;&lt;/p&gt;
&lt;h4 id="ranking-c"&gt;Hand Ranking in C:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;hand_rank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;short&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;6185&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HIGH_CARD&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        &lt;span class="c1"&gt;// 1277 high card&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3325&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ONE_PAIR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         &lt;span class="c1"&gt;// 2860 one pair&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2467&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;TWO_PAIR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         &lt;span class="c1"&gt;//  858 two pair&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1609&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;THREE_OF_A_KIND&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//  858 three-kind&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1599&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;STRAIGHT&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         &lt;span class="c1"&gt;//   10 straights&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;322&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FLUSH&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;            &lt;span class="c1"&gt;// 1277 flushes&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;166&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FULL_HOUSE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;       &lt;span class="c1"&gt;//  156 full house&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FOUR_OF_A_KIND&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;//  156 four-kind&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;STRAIGHT_FLUSH&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                   &lt;span class="c1"&gt;//   10 straight-flushes&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="ranking-factor"&gt;Hand Ranking in Factor:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: value&amp;gt;rank &lt;/span&gt;&lt;span class="kt"&gt;( value -- rank )&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;6185&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;HIGH_CARD &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;        &lt;span class="c"&gt;! 1277 high card&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;3325&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;ONE_PAIR &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;         &lt;span class="c"&gt;! 2860 one pair&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;2467&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;TWO_PAIR &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;         &lt;span class="c"&gt;!  858 two pair&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;1609&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;THREE_OF_A_KIND &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c"&gt;!  858 three-kind&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;1599&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;STRAIGHT &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;         &lt;span class="c"&gt;!   10 straights&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;322&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;FLUSH &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;            &lt;span class="c"&gt;! 1277 flushes&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;166&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;FULL_HOUSE &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;       &lt;span class="c"&gt;!  156 full house&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;dup &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &amp;gt; &lt;span class="p"&gt;]&lt;/span&gt;   &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;FOUR_OF_A_KIND &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c"&gt;!  156 four-kind&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;drop &lt;/span&gt;STRAIGHT_FLUSH &lt;span class="p"&gt;]&lt;/span&gt;                      &lt;span class="c"&gt;!   10 straight-flushes&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;cond &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: string&amp;gt;value &lt;/span&gt;&lt;span class="kt"&gt;( string -- value )&lt;/span&gt;
    parse-cards hand-value &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: hand-rank &lt;/span&gt;&lt;span class="kt"&gt;( string -- string )&lt;/span&gt;
    string&amp;gt;value value&amp;gt;rank VALUE_STR &lt;span class="k"&gt;nth &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Cactus Kev&amp;#8217;s code didn&amp;#8217;t include the code for explicit output of a string, but he did include the &lt;code&gt;value_str&lt;/code&gt; array which could be used for this purpose.&lt;/p&gt;
&lt;h2 id="all-together"&gt;Putting it All Together&lt;/h2&gt;
&lt;p&gt;To use the poker evaluator directly in Factor&amp;#8217;s interactive listener environment, you can enter something like these examples:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;7H 7S 7D AS AC&amp;quot;&lt;/span&gt; hand-rank .
&lt;span class="s2"&gt;&amp;quot;Full House&amp;quot;&lt;/span&gt;

(scratchpad) &lt;span class="s2"&gt;&amp;quot;7C 5D 4H 3S 2C&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;KD QS JC TH 9S&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; string&amp;gt;value &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi@ &lt;/span&gt;&amp;gt; .
&lt;span class="no"&gt;t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id="euler"&gt;Solving Problem 54&lt;/h3&gt;
&lt;p&gt;Getting back to our original goal of solving Project Euler&amp;#8217;s &lt;a href="http://projecteuler.net/index.php?section=problems&amp;amp;id=54"&gt;Problem 54&lt;/a&gt;, we can now quite easily determine how many times &lt;i&gt;Player 1&lt;/i&gt; wins out of 1000 random hands dealt to two players&amp;#8230;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: source-054 &lt;/span&gt;&lt;span class="kt"&gt;( -- seq )&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;resource:extra/project-euler/054/poker.txt&amp;quot;&lt;/span&gt; ascii file-lines
    &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="k"&gt;head-slice &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="k"&gt;tail-slice* &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi 2array &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;map &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: euler054 &lt;/span&gt;&lt;span class="kt"&gt;( -- answer )&lt;/span&gt;
    source-054 &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; string&amp;gt;value &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;map first2 &lt;/span&gt;before? &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;count &lt;/span&gt;&lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;source-054&lt;/code&gt; word simply converts the provided text file into the format our evaluator expects and the hand comparisons are subsequently handled by the &lt;code&gt;euler054&lt;/code&gt; word and counted up! Let&amp;#8217;s just say that &lt;i&gt;Player 2&lt;/i&gt; is much better at poker :-)&lt;/p&gt;
&lt;h2 id="improvements"&gt;Vocabulary Improvements&lt;/h2&gt;
&lt;p&gt;Since porting the initial version of the poker vocabulary, many improvements have been made to generalize the code for use beyond just solving Project Euler problems. I ended up dropping the binary search in favor of using the &lt;a href="http://www.senzee5.com/2006/06/some-perfect-hash.html"&gt;Senzee Perfect Hash Optimization&lt;/a&gt;, and other Factor contributors have added code specifically for Texas Hold&amp;#8217;em and Omaha evaluation. I didn&amp;#8217;t want to cover all of that here, as the focus of this article is the direct comparison between C and Factor, but you can view the &lt;a href="https://github.com/slavapestov/factor/tree/master/extra/poker"&gt;current poker vocabulary&lt;/a&gt; to see all of these enhancements.&lt;/p&gt;
&lt;p&gt;As always, feel free to &lt;a href="http://elasticdog.com/about/#contact"&gt;drop me a line&lt;/a&gt; if you&amp;#8217;d like to discuss things further.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=u4N1OGB_2Z0:ATFn8ai9VgQ:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/u4N1OGB_2Z0" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2010/11/porting-a-poker-hand-evaluator-from-c-to-factor</feedburner:origLink></entry>
	
	<entry>
		<title>Magnetic-Based versus Flash-Based Storage</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/ZYj4-U_1DU4/magnetic-based-versus-flash-based-storage" />
		<updated>2010-11-01T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2010/11/magnetic-based-versus-flash-based-storage</id>
		<content type="html">&lt;p&gt;This article is the answer I wrote to an exam question for a basic cyber forensics course I took back in Feb 2009. I recently ran across this exam in my files and thought others might be interested in a high-level overview of the differences between &lt;a href="https://secure.wikimedia.org/wikipedia/en/wiki/Hard_disk_drive"&gt;magnetic-based&lt;/a&gt; and &lt;a href="https://secure.wikimedia.org/wikipedia/en/wiki/Solid-state_drive"&gt;flash-based&lt;/a&gt; storage technologies&amp;#8230;&lt;/p&gt;
&lt;h2 id="question"&gt;The Question&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;Briefly discuss the differences between magnetic-based storage and flash-based storage. What effect do these differences have on digital evidence investigations?&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="answer"&gt;My Answer&lt;/h2&gt;
&lt;p&gt;Between the two types of disk storage technology of magnetic-based and flash-based hard drives (&lt;acronym title="Hard Disk Drive"&gt;&lt;span class="caps"&gt;HDD&lt;/span&gt;&lt;/acronym&gt;s and &lt;acronym title="Solid-State Drive"&gt;&lt;span class="caps"&gt;SSD&lt;/span&gt;&lt;/acronym&gt;s respectively), magnetic-based drives are more common, with flash-based drives quickly gaining speed in development and adoption rates.&lt;/p&gt;
&lt;p&gt;Magnetic-based drives use a series of stacked metal or glass disks called &amp;#8220;platters&amp;#8221;, which store microscopic magnetic information on concentric rings called &amp;#8220;tracks&amp;#8221;, which are further split into smaller &amp;#8220;sectors&amp;#8221; of 571 bytes each. A sector only holds 512 bytes of actual data and uses the remaining bytes for syncing purposes, a header with a location ID, and error detection via &lt;acronym title="Cyclic Redundancy Check"&gt;&lt;span class="caps"&gt;CRC&lt;/span&gt;&lt;/acronym&gt; checksums. A magnetic read head hovers over the metal platters as they spin, and depending on the electrical impulses that motion creates, you get either a one or zero represented as binary data. A &amp;#8220;cylinder&amp;#8221; is the combined data for a single track on all of the platters in a drive (both sides of each platter). Once the data is read, on-board hardware decodes that information and transmits it to the computer via a standardized interface.&lt;/p&gt;
&lt;p&gt;Flash-based drives are quite different. There are no physically moving parts, and they store data electronically instead of magnetically. Using a pair of transistor gates (a float gate and a control gate), flash-based storage sends electrical impulses to logically segmented areas in memory to store the appropriate ones and zeros in binary format (just like magnetic drives). Because they use only electricity and don&amp;#8217;t have to wait for actuator arms to physically move heads into position for reads and writes, flash-based storage is typically much faster at I/O operations. Like magnetic drives, flash-based drives also have a built-in hardware controller to manage its operation and to convert the data into a standardized format to be read by the computer.&lt;/p&gt;
&lt;p&gt;The effect each one of these has on a digital investigation is wide-spread. First of all, they both retain data for different amounts of time when left sitting. Magnetic data is not very reliable after a year or so, while flash-based data will usually last quite a bit longer. Flash-based memory also has a limited number of erase cycles, after which, whatever data is stored on that segment &lt;em&gt;will not&lt;/em&gt; change. This can actually help in an investigation if you can trick the hardware controller into thinking it can no longer use the memory, you could essentially turn it into a read-only device and preserve evidence. Likewise, magnetic disks often have a residual magnetic signature of previous data, even if it has been overwritten. Sometimes these properties can be exploited by an expert lab with the proper equipment to recover data that was intentionally destroyed.&lt;/p&gt;
&lt;p&gt;Both storage mediums will usually not overwrite data when it is deleted, but will simply update an allocation table to specify that a cluster or segment is free for writing again.&lt;/p&gt;
&lt;p&gt;Keeping in mind how each of these technologies transforms physical properties into a common, logical storage interface can help you to make better decisions on how to preserve data, how to find evidence, and what to expect when doing an investigation. If you don&amp;#8217;t pay attention to how these technologies differ, you have the potential to either miss important information, or in the worst case, destroy the information you do have.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=ZYj4-U_1DU4:SetiwjGSrvk:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/ZYj4-U_1DU4" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2010/11/magnetic-based-versus-flash-based-storage</feedburner:origLink></entry>
	
	<entry>
		<title>Beginning Factor – Shufflers &amp; Combinators</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/5SEOUfhzVKQ/beginning-factor-shufflers-and-combinators" />
		<updated>2008-12-04T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2008/12/beginning-factor-shufflers-and-combinators</id>
		<content type="html">&lt;p&gt;In the &lt;a href="http://elasticdog.com/2008/11/beginning-factor-introduction/"&gt;previous installment&lt;/a&gt; of Beginning Factor, we discussed some of the attributes of stack-based languages and the syntax for defining words in Factor. This time around, I&amp;#8217;d like to introduce stack shufflers, quotations &amp;amp; combinators, and touch on some more basic data types and their properties.&lt;/p&gt;
&lt;p&gt;Up until now, we&amp;#8217;ve essentially been using Factor as an overqualified &lt;acronym title="Reverse Polish Notation"&gt;&lt;span class="caps"&gt;RPN&lt;/span&gt;&lt;/acronym&gt; calculator. I just wanted to make sure that you don&amp;#8217;t underestimate Factor because of these particular examples; Factor is an extremely capable and modern language that can be used for everything from web applications, to game development, to complex text parsing, and so on. I&amp;#8217;m purposefully using over-simplified examples as a means to demonstrate specific points about the language. Stick with me, and I assure you the examples will gradually get more expressive.&lt;/p&gt;
&lt;h2 id="shufflers"&gt;Stack Shufflers&lt;/h2&gt;
&lt;p&gt;Because of Factor&amp;#8217;s stack-based nature, you sometimes need the ability to rearrange or copy items in the stack to ensure that they are in the correct position for future use. The way to go about this is a group of words called &amp;#8220;stack shufflers&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Much like the name implies, stack shufflers are merely words that change the order (or number) of the items on the top of the stack. It is said that shuffle words &amp;#8220;control the flow of data between words that perform actions.&amp;#8221; In fact, you already know one stack shuffler&amp;#8230; &lt;code&gt;drop&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;There are three basic varieties of stack shufflers. Here they are along with the most commonly used word for each type:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Removing Shufflers&lt;/strong&gt;&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;drop&lt;/code&gt; &lt;i&gt;( x &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;removes the top item from the stack and discards it&lt;/dd&gt;
&lt;/dl&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Duplicating Shufflers&lt;/strong&gt;&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;dup&lt;/code&gt; &lt;i&gt;( x &amp;#45;&amp;#45; x x )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;duplicates the top item on the stack&lt;/dd&gt;
&lt;/dl&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Permuting Shufflers&lt;/strong&gt;&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;swap&lt;/code&gt; &lt;i&gt;( x y &amp;#45;&amp;#45; y x )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;exchanges the positions of the first and second items on the top of the stack&lt;/dd&gt;
&lt;/dl&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2008/12/stack-swap.png" title="Swapping Two Items on the Top of a Stack" alt="Swapping Two Items on the Top of a Stack" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;#8230;and here are a couple of word definitions that use these shufflers appropriately:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: sq &lt;/span&gt;&lt;span class="kt"&gt;( x -- y )&lt;/span&gt;
    &lt;span class="k"&gt;dup &lt;/span&gt;* &lt;span class="nf"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;: neg &lt;/span&gt;&lt;span class="kt"&gt;( x -- -x )&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;swap &lt;/span&gt;- &lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="k"&gt;sq &lt;/span&gt;.
&lt;span class="mi"&gt;25&lt;/span&gt;
(scratchpad) &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;neg &lt;/span&gt;.
&lt;span class="mi"&gt;-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id="caveats"&gt;Caveats&lt;/h3&gt;
&lt;p&gt;There are many more &lt;a href="http://docs.factorcode.org/content/article-shuffle-words.html"&gt;shuffle words&lt;/a&gt; that support intricate rearrangements and the duplication/removal of multiple items from differing locations within the stack. The problem is, &lt;em&gt;code that is full of stack shufflers can easily become confusing&lt;/em&gt;. In general, you should try to minimize the use of stack shufflers to keep things understandable.&lt;/p&gt;
&lt;p&gt;Of course there are exceptions to that rule, times when shufflers make the most sense, but the &lt;em&gt;preferred&lt;/em&gt; alternative to complicated stack shufflers is the use of a &amp;#8220;combinator&amp;#8221; that fits your use case. That said, combinators will take a bit of explaining&amp;#8230;&lt;/p&gt;
&lt;h2 id="quotations"&gt;Quotations&lt;/h2&gt;
&lt;p&gt;Before we can get to the idea of combinators, we first have to discuss quotations:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt; &lt;span class="k"&gt;print &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;times&lt;/span&gt;
hello
hello
hello
hello
hello
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this example, &lt;code&gt;[ "hello" print ]&lt;/code&gt; is a quotation.&lt;/p&gt;
&lt;p&gt;In layman&amp;#8217;s terms, a quotation is a way to encapsulate a snippet of code so it doesn&amp;#8217;t get called right away, but can be passed around on the stack and called later. The computer science term for this is an &amp;#8220;anonymous function&amp;#8221;. It&amp;#8217;s referred to as &amp;#8220;anonymous&amp;#8221; because it is fundamentally a word that has no name.&lt;/p&gt;
&lt;p&gt;If we didn&amp;#8217;t have quotations, that same example would get ugly real fast:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt; &lt;span class="k"&gt;dup dup dup dup print print print print print&lt;/span&gt;
hello
hello
hello
hello
hello
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Imagine if you wanted to print &amp;#8220;hello&amp;#8221; 1000 times!&lt;/p&gt;
&lt;p&gt;To create a quotation, you just surround your code snippet with square brackets, and it will be pushed onto the stack: &lt;code&gt;[ ... ]&lt;/code&gt;. In order to do anything useful with that quotation once it&amp;#8217;s on the stack, what you need is a combinator.&lt;/p&gt;
&lt;h2 id="combinators"&gt;What is a Combinator?&lt;/h2&gt;
&lt;p&gt;A combinator is just a fancy name for a word that takes a quotation as one of its inputs. In the example above, &lt;code&gt;times&lt;/code&gt; is a combinator which takes an integer (&lt;i&gt;n&lt;/i&gt;) and a quotation from the stack, and it calls that quotation &lt;i&gt;n&lt;/i&gt; times.&lt;/p&gt;
&lt;p&gt;Factor uses quotations &amp;amp; combinators extensively for conditionals, sequence traversal, namespaces, closures, and more&amp;#8230;but that&amp;#8217;s jumping the gun a bit. Before we dive into all of that, I&amp;#8217;d like to get back to the idea of minimizing the use of stack shufflers by replacing them with appropriate combinators instead.&lt;/p&gt;
&lt;h2 id="intent"&gt;Combinators That Express Intent&lt;/h2&gt;
&lt;p&gt;While our code examples thus far have been easy to follow, when you start tackling more realistic problems, stack shufflers &lt;em&gt;will&lt;/em&gt; begin to obfuscate your code. If we can represent our intentions consistently with a combinator instead, then code becomes cleaner and you can consequently focus more on your problem domain and less on mentally organizing your stack.&lt;/p&gt;
&lt;p&gt;To illustrate this point, I&amp;#8217;d like to introduce a couple of simple combinators:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;dip&lt;/code&gt; &lt;i&gt;( x quot &amp;#45;&amp;#45; x )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;calls a quotation while temporarily hiding the top item on the stack&lt;/dd&gt;
&lt;/dl&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;keep&lt;/code&gt; &lt;i&gt;( x quot &amp;#45;&amp;#45; x )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;calls a quotation with an item on the stack, restoring that item after the quotation returns&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;While both of these combinators have the same stack effect declaration, their usage is a bit different:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; + &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;dip&lt;/span&gt;

--- Data stack:
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;

(scratchpad) &lt;span class="k"&gt;clear&lt;/span&gt;
(scratchpad) &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; + &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;keep&lt;/span&gt;

--- Data stack:
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;These two combinators alone can greatly reduce the number of stack shufflers your code will need. If you&amp;#8217;re curious about how these combinators work, they both secretly take advantage of an auxiliary stack (called the &amp;#8220;retain stack&amp;#8221;) to temporarily store items while the supplied quotation is being executed. There are a few other &lt;a href="http://docs.factorcode.org/content/article-dip-keep-combinators.html"&gt;preserving combinators&lt;/a&gt; that are worth exploring as well.&lt;/p&gt;
&lt;h3 id="cleave"&gt;Cleave, Spread, and Apply&lt;/h3&gt;
&lt;p&gt;The cleave, spread, and apply combinators are your best weapons when trying to reduce the use of stack shufflers while simultaneously expressing intent. The key point being that they &lt;em&gt;should&lt;/em&gt; express intent&amp;#8230;if you find yourself writing code where these combinators don&amp;#8217;t fit logically, then try another option.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cleave Combinators&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These are used when you want to &lt;em&gt;apply multiple quotations to the same set of items&lt;/em&gt; on the top of the stack.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say that you want to find the average of a bunch of numbers in an array. The steps are straightforward, you take the sum of all the numbers and divide that sum by how many numbers you have (the length of the array):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;dup sum swap length &lt;/span&gt;/ .
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can eliminate the need for those stack shufflers and better express our intent by using a cleave combinator to achieve the same thing:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;bi&lt;/code&gt; &lt;i&gt;( x p q &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;applies quotation &lt;b&gt;&lt;i&gt;p&lt;/i&gt;&lt;/b&gt; to &lt;b&gt;&lt;i&gt;x&lt;/i&gt;&lt;/b&gt;, then applies quotation &lt;b&gt;&lt;i&gt;q&lt;/i&gt;&lt;/b&gt; to &lt;b&gt;&lt;i&gt;x&lt;/i&gt;&lt;/b&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2008/12/cleave.png" alt="Cleave Combinator Demonstration" width="510" height="222" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;sum &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;length &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi &lt;/span&gt;/ .
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The different &lt;a href="http://docs.factorcode.org/content/article-cleave-combinators.html"&gt;cleave combinators&lt;/a&gt; change either the number of quotations applied to your items (&lt;code&gt;bi&lt;/code&gt; vs. &lt;code&gt;tri&lt;/code&gt;), or the number of items used as input for your quotations (&lt;code&gt;bi&lt;/code&gt; vs. &lt;code&gt;2bi&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Spread Combinators&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These are used when you want to &lt;em&gt;apply a different quotation to different items&lt;/em&gt; on the top of the stack. The spread combinators are closely related to &lt;code&gt;dip&lt;/code&gt;, but provide a bit more flexibility while also expressing intent.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say that you have two coordinate positions in the form of &lt;code&gt;{ x y }&lt;/code&gt;, and you&amp;#8217;d like to extract the x-coordinate from the first position, and the y-coordinate from the second position to form a new position with those values:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;swap first swap second 2array &lt;/span&gt;.
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can eliminate the need for those stack shufflers and better express our intent by using a spread combinator to achieve the same thing:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;bi*&lt;/code&gt; &lt;i&gt;( x y p q &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;applies quotation &lt;b&gt;&lt;i&gt;p&lt;/i&gt;&lt;/b&gt; to &lt;b&gt;&lt;i&gt;x&lt;/i&gt;&lt;/b&gt;, then applies quotation &lt;b&gt;&lt;i&gt;q&lt;/i&gt;&lt;/b&gt; to &lt;b&gt;&lt;i&gt;y&lt;/i&gt;&lt;/b&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2008/12/spread.png" alt="Spread Combinator Demonstration" width="510" height="222" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;first &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;second &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi* 2array &lt;/span&gt;.
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When you want to do the same thing with more than two quotations/items, then using spread combinators eliminates the need for nested dips or shufflers and the added clarity becomes much more evident.&lt;/p&gt;
&lt;p&gt;The different &lt;a href="http://docs.factorcode.org/content/article-spread-combinators.html"&gt;spread combinators&lt;/a&gt; change the number of quotations applied to the corresponding number of items on the stack (&lt;code&gt;bi*&lt;/code&gt; vs. &lt;code&gt;tri*&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Apply Combinators&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These are used when you want to &lt;em&gt;apply a single quotation to multiple items&lt;/em&gt; on the top of the stack.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say that you have two strings, each containing a name, and you want to see if those names are the same. In order to ignore case when doing the comparison, you decide to convert both strings to upper case before checking for equality:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;john&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;John&amp;quot;&lt;/span&gt; &lt;span class="k"&gt;swap &lt;/span&gt;&amp;gt;upper &lt;span class="k"&gt;swap &lt;/span&gt;&amp;gt;upper = .
&lt;span class="no"&gt;t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can eliminate the need for those stack shufflers and better express our intent by using an apply combinator to achieve the same thing:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;bi@&lt;/code&gt; &lt;i&gt;( x y quot &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;applies the quotation to &lt;b&gt;&lt;i&gt;x&lt;/i&gt;&lt;/b&gt;, then to &lt;b&gt;&lt;i&gt;y&lt;/i&gt;&lt;/b&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2008/12/apply.png" alt="Apply Combinator Demonstration" width="510" height="222" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;john&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;John&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &amp;gt;upper &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;bi@ &lt;/span&gt;= .
&lt;span class="no"&gt;t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The different &lt;a href="http://docs.factorcode.org/content/article-apply-combinators.html"&gt;apply combinators&lt;/a&gt; change the number of items on the stack your quotation is applied to  (&lt;code&gt;bi@&lt;/code&gt; vs. &lt;code&gt;tri@&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The cleave, spread, and apply combinators are all closely related; if you&amp;#8217;re having trouble keeping them apart, try to memorize the naming convention:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;If there is no suffix, it is a &amp;#8220;cleave&amp;#8221;&lt;/li&gt;
	&lt;li&gt;If the suffix is *, it is a &amp;#8220;spread&amp;#8221;&lt;/li&gt;
	&lt;li&gt;If the suffix is @, it is an &amp;#8220;apply&amp;#8221;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you learn these combinators, you should be able to express almost any pattern of complicated stack shufflers. Note that there are also &lt;a href="http://docs.factorcode.org/content/article-combinators.html"&gt;generic forms&lt;/a&gt; for all of these combinators that can take additional inputs from the stack. If you find that you resort to using the generic forms more often then not, that&amp;#8217;s usually a good indication that you should rethink your approach or put your data into a more appropriate structure.&lt;/p&gt;
&lt;h2 id="data"&gt;Data Type Details&lt;/h2&gt;
&lt;p&gt;Before I turn you loose, I wanted to offer a few extra details about some of Factor&amp;#8217;s basic data types&amp;#8230;&lt;/p&gt;
&lt;h3 id="sequences"&gt;Sequences&lt;/h3&gt;
&lt;p&gt;In the cleave and spread examples above, I was sneaky and used sequences without explaining them formally. A sequence is a &lt;em&gt;finite, ordered, collection of elements&lt;/em&gt;. Any data type that implements the sequence mixin class (meaning a data type that knows its length and will let you set/get an element at a specific index) gains the ability to use the powerful built-in &lt;a href="http://docs.factorcode.org/content/article-sequences.html"&gt;sequence operators&lt;/a&gt;. Read through that documentation to get an idea on how to manipulate sequences and their elements.&lt;/p&gt;
&lt;p&gt;Factor has many sequence types that you may already be familiar with, such as &lt;a href="http://docs.factorcode.org/content/article-arrays.html"&gt;arrays&lt;/a&gt; (fixed-size mutable sequences) and &lt;a href="http://docs.factorcode.org/content/article-vectors.html"&gt;vectors&lt;/a&gt; (resizable mutable sequences), but there are also other data types that you might not expect to be sequences, such as strings. In Factor, a string is merely an array of Unicode 5.0 code points.&lt;/p&gt;
&lt;p&gt;Using the sequence operators and combinators together, you can create all sorts of powerful abstractions that I&amp;#8217;ll talk more about next time. Here are a couple of examples to whet your appetite:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="k"&gt;even? &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;filter &lt;/span&gt;.
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
(scratchpad) &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; . &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;each&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
(scratchpad) &lt;span class="s2"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; alpha? &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;all? &lt;/span&gt;.
&lt;span class="no"&gt;t&lt;/span&gt;
(scratchpad) &lt;span class="s2"&gt;&amp;quot;Hello!!!&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; alpha? &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;all? &lt;/span&gt;.
&lt;span class="no"&gt;f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Keep in mind that in Factor, &lt;strong&gt;sequences are zero-based&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id="numbers"&gt;Numbers&lt;/h3&gt;
&lt;p&gt;So far, we have only used integers, but Factor also supports &lt;a href="http://docs.factorcode.org/content/article-rationals.html"&gt;rational numbers&lt;/a&gt; (fractions), &lt;a href="http://docs.factorcode.org/content/article-floats.html"&gt;floats&lt;/a&gt; (decimal approximations of a number), and &lt;a href="http://docs.factorcode.org/content/article-complex-numbers.html"&gt;complex numbers&lt;/a&gt; (imaginary numbers).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="mi"&gt;330&lt;/span&gt; / .
&lt;span class="m"&gt;10/33&lt;/span&gt;
(scratchpad) &lt;span class="m"&gt;5/4&lt;/span&gt; &lt;span class="m"&gt;1/2&lt;/span&gt; + .
&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="m"&gt;+3/4&lt;/span&gt;
(scratchpad) &lt;span class="m"&gt;5/4&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="mf"&gt;.5&lt;/span&gt; + .
&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="mf"&gt;.75&lt;/span&gt;
(scratchpad) &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; rect&amp;gt; .
&lt;span class="p"&gt;C{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id="iota"&gt;Iota&lt;/h4&gt;
&lt;p&gt;One last thing that is going to come in handy, is a word for creating sequences from integers:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;iota&lt;/code&gt; &lt;i&gt;( n &amp;#45;&amp;#45; iota )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;creates a sequence of length &lt;b&gt;&lt;i&gt;n&lt;/i&gt;&lt;/b&gt;, whose elements are its non-negative predecessors (i.e. 0 to &lt;b&gt;&lt;i&gt;n&lt;/i&gt;&lt;/b&gt;-1 inclusive)&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;This word can be very helpful when performing counted loops or other control flow statements. For example, the following two lines are equivalent:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; . &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;each&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="k"&gt;iota &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; . &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;each&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id="next"&gt;Next Time&lt;/h2&gt;
&lt;p&gt;Next time we&amp;#8217;ll stick with a theme of &amp;#8220;flow&amp;#8221; and discuss control flow for your words and after that, the typical work flow when developing code with Factor. Hope you enjoyed this installment!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=5SEOUfhzVKQ:7ZJMzW8QMFo:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/5SEOUfhzVKQ" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/12/beginning-factor-shufflers-and-combinators</feedburner:origLink></entry>
	
	<entry>
		<title>Beginning Factor – Introduction</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/kQkbmoGW6oI/beginning-factor-introduction" />
		<updated>2008-11-29T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2008/11/beginning-factor-introduction</id>
		<content type="html">&lt;p&gt;I&amp;#8217;ve been involved in the &lt;a href="http://factorcode.org/"&gt;Factor programming language&lt;/a&gt; community for about a year now, and am constantly amazed with how productive its contributors are. Large improvements to the language and its libraries are made on a weekly (if not daily) basis, and it&amp;#8217;s finally starting to attract some much-deserved attention from the programming community.&lt;/p&gt;
&lt;p&gt;The problem is, the language is a huge departure from the norm for most developers and it can be overwhelming to someone just getting started. I would like to help ease that transition by posting on various topics that I know have been confusing to me over the past year.&lt;/p&gt;
&lt;p&gt;Note that many topics are covered in &lt;a href="http://concatenative.org/wiki/view/Factor/FAQ"&gt;the official &lt;span class="caps"&gt;FAQ&lt;/span&gt;&lt;/a&gt; &amp;#8212; which is well worth a read &amp;#8212; and I won&amp;#8217;t spend time covering how to install Factor on the 14 or so platforms it supports, but beyond that, I&amp;#8217;ll try to give enough information (from basic to advanced) to get you going.&lt;/p&gt;
&lt;h2 id="basics"&gt;The Basics of the Basics&lt;/h2&gt;
&lt;p&gt;First of all, Factor is a stack-based language, which means that it uses a &lt;a href="http://en.wikipedia.org/wiki/Stack_(data_structure)"&gt;stack&lt;/a&gt; to store all arguments and returned values from functions (called &amp;#8220;words&amp;#8221; in Factor). To put that another way, Factor words don&amp;#8217;t receive arguments in the traditional manner; all input values that your word needs are expected to already exist on the top of the stack.&lt;/p&gt;
&lt;h3 id="what-stack"&gt;What is a Stack?&lt;/h3&gt;
&lt;p&gt;If you&amp;#8217;re unfamiliar with the data structure called a stack, the concept is fairly simple. It centers around the idea of &amp;#8220;Last In First Out&amp;#8221; (&lt;span class="caps"&gt;LIFO&lt;/span&gt;), meaning the last item placed onto the stack is the first item that will you will get when you remove an item from the stack. You cannot get to the lower items until the all of the items above it have been removed.&lt;/p&gt;
&lt;p&gt;I like to picture a stack like a tower of LEGOs. The only thing you can do with it are add another brick to the top (&amp;#8220;push&amp;#8221; an item onto the stack), or take the top brick off to use it for something else (&amp;#8220;pop&amp;#8221; an item off the stack). That&amp;#8217;s all there is to stacks!&lt;/p&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2008/11/stack-push.png" title="Pushing an Item onto a Stack" alt="Pushing an Item onto a Stack" /&gt;&lt;/p&gt;
&lt;h3 id="use-stack"&gt;How to Use the Stack&lt;/h3&gt;
&lt;p&gt;So, now we know that Factor manages its input and output with a stack, but how do we actually use it? Well, when entering data into Factor&amp;#8217;s listener, one of two things is happening:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;You are pushing a literal onto the stack&lt;br /&gt;
  &lt;strong&gt;OR&lt;/strong&gt;&lt;/li&gt;
	&lt;li&gt;You are calling a word which will consume literals from the stack&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Things do get slightly more complicated than that, but for the most part those two rules hold true. The most simple example of this behavior is the ubiquitous hello world program, shown entered directly into Factor&amp;#8217;s interactive listener environment:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(scratchpad) "Hello world!" print
Hello world!&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To understand what is happening, you can just type the string first, and then execute the &lt;code&gt;print&lt;/code&gt; word later:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="s2"&gt;&amp;quot;Hello world!&amp;quot;&lt;/span&gt;

--- Data stack:
&lt;span class="s2"&gt;&amp;quot;Hello world!&amp;quot;&lt;/span&gt;
(scratchpad) &lt;span class="k"&gt;print&lt;/span&gt;
Hello world!
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this particular case, typing the literal string &lt;code&gt;"Hello world!"&lt;/code&gt; will push that value onto the stack; then the word &lt;code&gt;print&lt;/code&gt;, takes a single string off the stack and writes it to the output stream.&lt;/p&gt;
&lt;p&gt;The same idea can be applied to simple arithmetic. Like strings, numbers are also literals, so you just have to type them in (separated by spaces) for them to be pushed onto the stack:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

--- Data stack:
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;i&gt;NOTE: the stack is displayed in the listener upside-down from the way you&amp;#8217;d think, so the bottom number is actually the top of the stack.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&amp;#8230;and if you want to add the top two numbers together, the &lt;code&gt;+&lt;/code&gt; word will simply pop two numbers off the stack, add them together, and push the result back onto the stack:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;--- Data stack:
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
(scratchpad) +

--- Data stack:
&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id="words"&gt;A Few More Words&lt;/h3&gt;
&lt;p&gt;If you start messing around in the listener, odds are your stack is going to grow pretty quickly and become unmanageable. There are a few words that are essential to know in order to keep things under control:&lt;/p&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;drop&lt;/code&gt; &lt;i&gt;( x &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;removes the top item from the stack and discards it&lt;/dd&gt;
&lt;/dl&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;.&lt;/code&gt; &lt;i&gt;( obj &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;takes the top item from the stack and prettyprints it&lt;/dd&gt;
&lt;/dl&gt;
&lt;dl&gt;
	&lt;dt&gt;&lt;code&gt;clear&lt;/code&gt; &lt;i&gt;( &amp;#45;&amp;#45; )&lt;/i&gt;&lt;/dt&gt;
	&lt;dd&gt;removes all items from the stack&lt;/dd&gt;
&lt;/dl&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; -

--- Data stack:
&lt;span class="mi"&gt;-1&lt;/span&gt;
(scratchpad) &lt;span class="k"&gt;drop&lt;/span&gt;
(scratchpad) &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; / .
&lt;span class="mi"&gt;4&lt;/span&gt;
(scratchpad) &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; + &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;

--- Data stack:
&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;
(scratchpad) &lt;span class="k"&gt;clear&lt;/span&gt;
(scratchpad)
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id="stack-ramifications"&gt;Ramifications of Stack-Based Design&lt;/h3&gt;
&lt;p&gt;From these simple examples, we can observe a couple of important things about Factor:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Postfix Notation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When using a stack, passing data becomes implicit and we can assume that all input needed by words already exists on the stack. This naturally lends itself to using &lt;a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation"&gt;postfix notation&lt;/a&gt; because you have to push your data onto the stack before you can use it.&lt;/p&gt;
&lt;p&gt;This also makes words more concise and unambiguous when compared to &lt;em&gt;infix&lt;/em&gt; notation and eliminates the need for copious amounts of parentheses used by &lt;em&gt;prefix&lt;/em&gt; notation languages, like Lisp or Scheme.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;POSTFIX:  6 5 4 * +
INFIX:    6 + 5 * 4 =
PREFIX:   (+ (* 4 5) 6)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the infix example above, you&amp;#8217;d have to know &lt;a href="http://en.wikipedia.org/wiki/Order_of_operations"&gt;order of operations rules&lt;/a&gt; in order to get the correct answer (or use parentheses to force the matter). When using postfix notation, the fact that multiplication is done first becomes explicit. Prefix notation also gets rid of that ambiguity, but becomes messier and harder to type with the more nesting you add.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Calling Words is Implicit&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You don&amp;#8217;t have to specify that you&amp;#8217;re calling a word, you simply use the word. This, combined with postfix syntax, means that you can easily nest words or cut and paste parts of definitions into new words without disrupting the flow of data. This lends to keeping code modular, short, easily testable, and readable.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="first-word"&gt;Your First Word&lt;/h2&gt;
&lt;p&gt;If you&amp;#8217;ve typed in the examples from above and messed around in the listener, then you might want to know how to write your own word rather than just using ones that are predefined. Drawing on what we already know, here&amp;#8217;s how to write your first word:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;: plus-two ( x -- y )
    2 + ;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you copy and paste that into your listener, than you can use the word &lt;code&gt;plus-two&lt;/code&gt; anywhere you would like to add two to a number on the top of the stack:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;(scratchpad) &lt;span class="mi"&gt;15&lt;/span&gt; plus-two .
&lt;span class="mi"&gt;17&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Not very exciting, but it gives us a couple more things to talk about&amp;#8230;&lt;/p&gt;
&lt;h3 id="syntax"&gt;Syntax Specifics&lt;/h3&gt;
&lt;p&gt;If you study the word definition, you&amp;#8217;ll see that it&amp;#8217;s made up of a few elements:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="factor"&gt;&lt;span class="nf"&gt;: plus-two &lt;/span&gt;&lt;span class="kt"&gt;( x -- y )&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt; + &lt;span class="nf"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ol&gt;
	&lt;li&gt;A &lt;strong&gt;colon&lt;/strong&gt; (&lt;code&gt;:&lt;/code&gt;) is used to start the definition of a word. This is required and must have a space after it.&lt;/li&gt;
	&lt;li&gt;Right after the opening colon is the &lt;strong&gt;name&lt;/strong&gt; of your word, also required.&lt;/li&gt;
	&lt;li&gt;Following the name of your word is its &lt;strong&gt;stack effect declaration&lt;/strong&gt;, which is a list of the word&amp;#8217;s inputs and outputs separated by &lt;code&gt;--&lt;/code&gt; and surrounded by parentheses. All words must have a stack effect declaration unless it only pushes literals on the stack. The names of elements in the stack effect declaration don&amp;#8217;t make a difference, only the number of elements. That means that &lt;code&gt;( elt elt -- seq )&lt;/code&gt; and &lt;code&gt;( x y -- z )&lt;/code&gt; are the same thing. There &lt;em&gt;are&lt;/em&gt; some common conventions for these names, but don&amp;#8217;t get caught up by it as I&amp;#8217;ll talk more about them in a later article and it won&amp;#8217;t change how your program runs.&lt;/li&gt;
	&lt;li&gt;Next comes the &lt;strong&gt;word definition&lt;/strong&gt; itself, in this case &lt;code&gt;2 +&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;And the last item is a &lt;strong&gt;semicolon&lt;/strong&gt; (&lt;code&gt;;&lt;/code&gt;), used to end the word definition. This is required and must have a space before it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The reason that everything must be surrounded by spaces is that there aren&amp;#8217;t any syntax-only elements to Factor&amp;#8230;everything is a word! The colon/semicolon, the parentheses, etc. are all just parsing words working together in order to create the syntax.&lt;/p&gt;
&lt;h2 id="next"&gt;Next Time&lt;/h2&gt;
&lt;p&gt;Next time we&amp;#8217;ll talk more about stack shufflers, quotations &amp;amp; combinators, details about more datatypes, and more&amp;#8230;&lt;/p&gt;
&lt;p&gt;If something is unclear or if you&amp;#8217;re having any trouble, let me know and I&amp;#8217;ll try to help out!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=kQkbmoGW6oI:oe2lxHF-vWg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/kQkbmoGW6oI" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/11/beginning-factor-introduction</feedburner:origLink></entry>
	
	<entry>
		<title>Comments Missing in WordPress Dashboard After 2.5.1 Upgrade</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/4PyBL81_1XA/comments-missing-in-wordpress-dashboard-after-251-upgrade" />
		<updated>2008-04-25T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2008/04/comments-missing-in-wordpress-dashboard-after-251-upgrade</id>
		<content type="html">&lt;p&gt;I just upgraded the WordPress installation for ElasticDog to version 2.5.1 and noticed that the Manage Comments page in the administrative Dashboard was not displaying any comments. I only noticed there was a problem when the interface kept telling me there were 9 comments awaiting moderation, yet &lt;a href="http://elasticdog.com/images/2008/04/awaiting-moderation.png"&gt;it would not let me see them&lt;/a&gt;. Everything was displaying correctly on the publicly viewable blog pages, but no comments showed up when trying to access them via the Dashboard.&lt;/p&gt;
&lt;p&gt;After searching for a bit and checking my sever logs, I found that the upgrade script did not add the proper index to the &amp;#8220;comment_date_gmt&amp;#8221; column in the comments table for my WordPress database:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Apr 25 18:22:17 php-cgi: WordPress database error Key 'comment_date_gmt' doesn't exist in table 'wp_comment' for query...&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="solution"&gt;The Solution&lt;/h2&gt;
&lt;p&gt;If you don&amp;#8217;t want to wait until the upgrade script gets fixed in a later WordPress release, you&amp;#8217;ll have to add the missing index to the database table yourself to get things working again. I&amp;#8217;ll demonstrate how to do that using the MySQL command line interface, however, if you&amp;#8217;re more comfortable with using phpMyAdmin, see &lt;a href="http://wordpress.org/support/topic/167450#post-737217"&gt;the steps outlined here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="privileges"&gt;Check for Proper Privileges&lt;/h3&gt;
&lt;p&gt;First of all, you must have the proper privileges on your WordPress database in order to add an index.  To check that, follow these steps:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Log in to MySQL with whatever account credentials you know.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 59202
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&amp;gt;&lt;/code&gt;&lt;/pre&gt;	&lt;/li&gt;
	&lt;li&gt;Specify that you want to access the &amp;#8220;mysql&amp;#8221; database, then ensure that you do have the privileges to add indexes.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;mysql&amp;gt; use mysql
Database changed
mysql&amp;gt; SELECT user, index_priv FROM user;
+------------------+-----------------+
| user       | index_priv |
+------------------+-----------------+
| root       | Y          |
| elasticdog | N          |
+------------------+-----------------+
2 rows in set (0.00 sec)&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As long as you see a &amp;#8216;Y&amp;#8217; next to your username, then you should be good to go.&lt;/p&gt;
&lt;h3 id="cli"&gt;Add the Index to the Comments Table&lt;/h3&gt;
&lt;p&gt;Once you have access to an account that can add indexes, then follow these steps to add the missing index:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Specify that you want to access your WordPress database. If you don&amp;#8217;t know the name of your WordPress database, run &lt;code&gt;show databases;&lt;/code&gt; to see a list of databases you have access to.&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;mysql&amp;gt; use elasticdog_wordpress
Database changed&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
	&lt;li&gt;Add the index. The table names for WordPress are fairly standard, but if you don&amp;#8217;t have one named &amp;#8220;wp_comments&amp;#8221;, run &lt;code&gt;show tables;&lt;/code&gt; to see a list of contenders and it should be easy to figure out.&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;mysql&amp;gt; CREATE INDEX comment_date_gmt ON wp_comments (comment_date_gmt);
Query OK, 458 rows affected (0.14 sec)
Records: 458  Duplicates: 0  Warnings: 0&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
	&lt;li&gt;If want to verify that the index was created, run &lt;br /&gt;&lt;code&gt;SHOW INDEX FROM wp_comments;&lt;/code&gt; to list all indexes, and then you can exit out.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If everything went as planned, all will be right in the world and your comments should be viewable through the dashboard once again!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=4PyBL81_1XA:4_u4RvZnQGM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/4PyBL81_1XA" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/04/comments-missing-in-wordpress-dashboard-after-251-upgrade</feedburner:origLink></entry>
	
	<entry>
		<title>HOWTO: Install WordPress on Nginx</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/Q328y0tbon4/howto-install-wordpress-on-nginx" />
		<updated>2008-02-27T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx</id>
		<content type="html">&lt;p&gt;A few years ago, I moved all of my sites from a cheap shared host to a shiny new &lt;acronym title="Virtual Private Server"&gt;&lt;span class="caps"&gt;VPS&lt;/span&gt;&lt;/acronym&gt;, and have never looked back. As long as you&amp;#8217;re comfortable on the command line, running your own &lt;span class="caps"&gt;VPS&lt;/span&gt; gives you a great amount of flexibility since you have full root access on the server and can configure everything exactly how you want it. That said, it also means that if you want to maintain high performance, you have to keep your resource usage to a minimum.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt; is a very well-establish web server that can handle just about any situation. Unfortunately, that flexibility comes at the cost of size and relatively high demands on server resources. &lt;a href="http://nginx.net/"&gt;Nginx&lt;/a&gt; (&amp;#8220;engine x&amp;#8221;) is a lightweight web server/reverse proxy that is very efficient and perfect for hosting WordPress. Read on to see how that can be done&amp;#8230;&lt;/p&gt;
&lt;h2 id="step-one"&gt;Step One: FastCGI&lt;/h2&gt;
&lt;p&gt;First off, Nginx does not provide FastCGI for you (FastCGI is what your web server uses to interact with WordPress&amp;#8217;s &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; code), so you&amp;#8217;ve got to have a way to spawn your own FastCGI processes. My preferred method is to use the &lt;code&gt;spawn-fcgi&lt;/code&gt; program provided by the &lt;a href="http://www.lighttpd.net/"&gt;lighttpd&lt;/a&gt; project. You &lt;em&gt;can&lt;/em&gt; use PHP&amp;#8217;s built-in FastCGI manager &lt;code&gt;php-cgi&lt;/code&gt; to &lt;a href="http://blog.kovyrin.net/2006/05/30/nginx-php-fastcgi-howto/"&gt;do the same thing&lt;/a&gt;, but it&amp;#8217;s not as straight-forward. Plus, if you learn how to use &lt;code&gt;spawn-fcgi&lt;/code&gt;, you can easily adapt it for use with other non-&lt;span class="caps"&gt;PHP&lt;/span&gt; web applications that require FastCGI.&lt;/p&gt;
&lt;h3&gt;Install spawn-fcgi&lt;/h3&gt;
&lt;p&gt;To download and install &lt;code&gt;spawn-fcgi&lt;/code&gt;, either use your native package manager (this would be the recommended approach), or run the following commands to install the package from source. All of the building happens in your current directory and the binary will be installed under &lt;code&gt;/usr/local/bin/&lt;/code&gt; with a man page under &lt;code&gt;/usr/local/share/man/&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.bz2
&lt;span class="nv"&gt;$ &lt;/span&gt;tar xvjf spawn-fcgi-1.6.3.tar.bz2
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;spawn-fcgi-1.6.3/
&lt;span class="nv"&gt;$ &lt;/span&gt;./configure
&lt;span class="nv"&gt;$ &lt;/span&gt;make
&lt;span class="nv"&gt;$ &lt;/span&gt;sudo make install
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;i&gt;NOTE: If you&amp;#8217;re following the steps above verbatim, you will need to have root privileges in order to perform the final instalation step&amp;#8230;everything else should work fine as a normal user. To gain root privileges, the program &lt;code&gt;sudo&lt;/code&gt; was used in the example above; you may or may not have access to &lt;code&gt;sudo&lt;/code&gt; on your machine.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;After &lt;code&gt;spawn-fcgi&lt;/code&gt; has been installed, you can safely remove the build directory and original source file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;span class="nv"&gt;$ &lt;/span&gt;rm -rf spawn-fcgi-1.6.3/
&lt;span class="nv"&gt;$ &lt;/span&gt;rm spawn-fcgi-1.6.3.tar.bz2
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3&gt;Run spawn-fcgi&lt;/h3&gt;
&lt;p&gt;This part will be fairly distribution-specific, but I&amp;#8217;ll provide the basic command that you&amp;#8217;ll need. What you want to do is find a way to run this command as part of your init scripts so the processes will be spawned automatically when you reboot your server.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 53217 -P /var/run/fastcgi-php.pid -- /usr/bin/php-cgi&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;-a &amp;lt;address&amp;gt;&lt;/code&gt; &amp;rarr; the IP address to bind the processes to; in our case we want the localhost&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;-p &amp;lt;port&amp;gt;&lt;/code&gt; &amp;rarr; the port number to bind the processes to; pick whatever you want that won&amp;#8217;t cause a conflict (technically it would be best to pick a random number between 49152 and 65535), just make sure to remember the number and use that same port for your Nginx configuration file later on&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;-P &amp;lt;path&amp;gt;&lt;/code&gt; &amp;rarr; the location where to save the process id file; you can use this file to easily kill the processes later&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;-- &amp;lt;fcgiapp&amp;gt;&lt;/code&gt; &amp;rarr; the absolute path of the fcgi-application to spawn; in our case we want &amp;#8220;php-cgi&amp;#8221;, which is provided by your distribution&amp;#8217;s &lt;span class="caps"&gt;PHP&lt;/span&gt; package. If you don&amp;#8217;t know where to find it, try running &lt;code&gt;which php-cgi&lt;/code&gt; on the command line.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For better security, you can also spawn the processes as a non-privileged user by specifying the user/group with the &lt;code&gt;-u&lt;/code&gt; and &lt;code&gt;-g&lt;/code&gt; flags respectively. For more information on all the available options, run &lt;code&gt;spawn-fcgi -h&lt;/code&gt; or &lt;code&gt;man spawn-fcgi&lt;/code&gt; on the command line.&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;re interested in seeing a complete example init script that I wrote for use with &lt;a href="http://www.archlinux.org/"&gt;Arch Linux&lt;/a&gt;, you can download it here: &lt;a href="http://elasticdog.com/code/2008/02/fastcgi-php"&gt;fastcgi-php&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="step-two"&gt;Step Two: Complete 83.33% of the Famous 5-Minute Install&lt;/h2&gt;
&lt;p&gt;Next you should download the WordPress files and extract them to their final location on your server. Simply follow steps 1-5 of the &lt;a href="http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install"&gt;Famous 5-Minute Install&lt;/a&gt; (the 6th and final step requires that your web server be up and running properly, so we&amp;#8217;ll do it later). This guide will assume that you extracted the WordPress core files here: &lt;code&gt;/srv/http/nginx/example.com/&lt;/code&gt;&lt;/p&gt;
&lt;h2 id="step-three"&gt;Step Three: Nginx Configuration&lt;/h2&gt;
&lt;p&gt;To get the web server up and running properly, the file you need to edit is called &amp;#8220;nginx.conf&amp;#8221; and is installed in different places depending on your Linux distribution. If you install Nginx from source, the default location is &lt;code&gt;/usr/local/nginx/conf/nginx.conf&lt;/code&gt;, however yours may be somewhere else like &lt;code&gt;/etc/nginx/conf/nginx.conf&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once you find that file, open it with your favorite text editor and add a server declaration that looks something like this (I&amp;#8217;ll cover what each part means after posting the code):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="nginx"&gt;&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt;       &lt;span class="n"&gt;192.0.32.10&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                &lt;span class="c1"&gt;# your server&amp;#39;s public IP address&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt;  &lt;span class="s"&gt;example.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="c1"&gt;# your domain name&lt;/span&gt;
    &lt;span class="kn"&gt;root&lt;/span&gt;         &lt;span class="s"&gt;/srv/http/nginx/example.com/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# absolute path to your WordPress installation&lt;/span&gt;

    &lt;span class="kn"&gt;try_files&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri/&lt;/span&gt; &lt;span class="s"&gt;/index.php&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="p"&gt;~&lt;/span&gt; &lt;span class="sr"&gt;\.php$&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kn"&gt;include&lt;/span&gt;        &lt;span class="s"&gt;fastcgi_params&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;fastcgi_pass&lt;/span&gt;   &lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;53217&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;fastcgi_param&lt;/span&gt;  &lt;span class="s"&gt;SCRIPT_FILENAME&lt;/span&gt;  &lt;span class="nv"&gt;$document_root$fastcgi_script_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class="sourcelink"&gt;Download the Source Code: &lt;a href="http://elasticdog.com/code/2008/02/nginx-conf.txt"&gt;nginx.conf.txt&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;You will need to edit the configuration above using your own information. The first part is merely the server declaration where you define what your server&amp;#8217;s publicly available IP address is, and what domain name that address is associated with. Next we add some default settings which point Nginx to the absolute path of the WordPress installation on your server.&lt;/p&gt;
&lt;p&gt;After that, the &lt;code&gt;try_files&lt;/code&gt; directive automatically checks for the existence of files in order, and returns the first file that is found. The key part here is that WordPress uses the &amp;#8220;Front Controller&amp;#8221; design pattern, meaning that any request for a file that does not exist on the server should be handled by the main index.php file. So that&amp;#8217;s exactly what we do&amp;#8230;if the requested &lt;acronym title="Uniform Resrouce Identifier"&gt;&lt;span class="caps"&gt;URI&lt;/span&gt;&lt;/acronym&gt; exists on our local filesystem (images, stylesheets, etc.), then we&amp;#8217;ll serve it up directly; if the requested &lt;span class="caps"&gt;URI&lt;/span&gt; does not exist on the filesystem, we forward that request on to index.php.&lt;/p&gt;
&lt;p&gt;Last, we add a location block that tells Nginx to dynamically forward &lt;span class="caps"&gt;PHP&lt;/span&gt; requests to the FastCGI processes we &lt;a href="#step-one"&gt;spawned earlier&lt;/a&gt;. You just have to make sure that the port number matches what we did above. That&amp;#8217;s it!&lt;/p&gt;
&lt;h2 id="step-four"&gt;Step Four: Finishing Up&lt;/h2&gt;
&lt;p&gt;Everything should be good to go&amp;#8230;all you need to do now is start your Nginx server process (another distribution specific command), then complete the 6th step of the &lt;a href="http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install"&gt;Famous 5-Minute Install&lt;/a&gt; and you should have WordPress up and running on Nginx!&lt;/p&gt;
&lt;p&gt;If any of this needs further clarification or you&amp;#8217;re just having trouble, drop me a line and I&amp;#8217;ll see what I can do to help&amp;#8230;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=Q328y0tbon4:xSX6156RWHk:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/Q328y0tbon4" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx</feedburner:origLink></entry>
	
	<entry>
		<title>Current Status of the Code Viewer WordPress Plugin</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/zsvqP5WwPg0/current-status-of-the-code-viewer-wordpress-plugin" />
		<updated>2008-02-23T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2008/02/current-status-of-the-code-viewer-wordpress-plugin</id>
		<content type="html">&lt;p&gt;This site has been neglected for a long time, and that negligence has carried over to the development of the &lt;a href="http://elasticdog.com/2004/09/code-viewer/"&gt;Code Viewer&lt;/a&gt; WordPress plugin as well. While I&amp;#8217;ve been away, Code Viewer has been picked up/enhanced by a few other developers &amp;#8212; namely &lt;a href="http://flash.terra.ee/"&gt;AJ&lt;/a&gt; and &lt;a href="http://www.familjencarlstrom.se/WordPress/"&gt;H&amp;aring;kan Carlstr&amp;ouml;m&lt;/a&gt; &amp;#8212; and has gained many new features&amp;#8230;&lt;/p&gt;
&lt;p&gt;Code Viewer now supports syntax highlighting using &lt;a href="http://qbnz.com/highlighter/"&gt;GeSHi&lt;/a&gt;, can display specific line numbers, and has user-configurable scrollbars (among a few other niceties). On top of those changes, the default code path variable can now be configured directly in WordPress&amp;#8217;s admin interface rather than editing the plugin code by hand&amp;#8230;very nice!&lt;/p&gt;
&lt;h2 id="reactions"&gt;Reactions&lt;/h2&gt;
&lt;p&gt;I don&amp;#8217;t agree with all of the design choices they made with the new changes, but my qualms are minor. Specifically, I don&amp;#8217;t like some of the chosen defaults, nor the new format when specifying viewcode tags:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bbcode"&gt;&lt;span class="k"&gt;[viewcode&lt;/span&gt; &lt;span class="k"&gt;]&lt;/span&gt; src=/code/example.txt link=yes&lt;span class="k"&gt;[/viewcode]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;#8230;in comparison to the original:&lt;br /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;/code/example.txt&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;link=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;yes&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That said, it &lt;em&gt;is&lt;/em&gt; a cool feeling to find out that other people appreciate your work and chose to carry on with its development in your absence.&lt;/p&gt;
&lt;h2 id="torch"&gt;Passing the Torch&lt;/h2&gt;
&lt;p&gt;With the latest design incarnation here at ElasticDog, I decided to no longer use Code Viewer for displaying code snippets.  Instead, I went with the plugin &lt;a href="http://www.thunderguy.com/semicolon/wordpress/code-markup-wordpress-plugin/"&gt;Code Markup&lt;/a&gt;, which allows me to easily embed custom markup within code blocks. It&amp;#8217;s a completely different way of going about displaying code in blog entries when compared to Code Viewer, but it does the job well and suits my needs for the time being.&lt;/p&gt;
&lt;p&gt;Although I haven&amp;#8217;t actually worked on the development of Code Viewer since late 2004, I did register to have it hosted at the &lt;a href="http://wordpress.org/extend/plugins/"&gt;WordPress Plugin Repository&lt;/a&gt;. Unfortunately, I never got around to packaging it up for general consumption.&lt;/p&gt;
&lt;p&gt;Trying to not be a slacker anymore, I &lt;em&gt;have&lt;/em&gt; contacted H&amp;aring;kan in hopes of persuading him to take the reins and officially manage the plugin at the centralized WordPress repository. If he agrees, you should be able to download the plugin here very shortly: &lt;a href="http://wordpress.org/extend/plugins/code-viewer/"&gt;http://wordpress.org/extend/plugins/code-viewer/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the mean time, you can find the &lt;a href="http://www.familjencarlstrom.se/WordPress/2006/08/17/code-viewer/"&gt;most up to date version of Code Viewer&lt;/a&gt; at &lt;a href="http://www.familjencarlstrom.se/WordPress/"&gt;H&amp;aring;kan&amp;#8217;s site&lt;/a&gt;. Happy coding!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=zsvqP5WwPg0:XWgkdkgmEmU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/zsvqP5WwPg0" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/02/current-status-of-the-code-viewer-wordpress-plugin</feedburner:origLink></entry>
	
	<entry>
		<title>Optimal Title Functionality Now in WordPress Core</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/54VvmRkLsX0/optimal-title-functionality-now-in-wordpress-core" />
		<updated>2008-02-20T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2008/02/optimal-title-functionality-now-in-wordpress-core</id>
		<content type="html">&lt;p&gt;I wrote &lt;a href="http://elasticdog.com/2004/09/optimal-title/"&gt;Optimal Title&lt;/a&gt; three and a half years ago to help fix a blatant flaw in &lt;a href="http://wordpress.org"&gt;WordPress&amp;#8217;s&lt;/a&gt; default usability and search engine optimization (&lt;span class="caps"&gt;SEO&lt;/span&gt;). Since then, the plugin has been downloaded by tens of thousands of people and written about by hundreds of bloggers. Soon, the plugin will become obsolete&amp;#8230;&lt;/p&gt;
&lt;h2&gt;A Change in WordPress v2.5&lt;/h2&gt;
&lt;p&gt;As of the beginning of this year, a &lt;a href="http://trac.wordpress.org/changeset/6538"&gt;changeset&lt;/a&gt; was checked in to WordPress&amp;#8217;s &lt;acronym title="Subversion"&gt;&lt;span class="caps"&gt;SVN&lt;/span&gt;&lt;/acronym&gt; repository which adds a &amp;#8220;separator location&amp;#8221; argument to the built-in &lt;code&gt;wp_title()&lt;/code&gt; function. What that means, is that when WordPress v2.5 is released around March 10th of this year, users will be able to change the ordering of their &lt;acronym title="Hypertext Markup Language"&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/acronym&gt; title tags without having to use a third-party plugin.&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://trac.wordpress.org/ticket/4407"&gt;developers decided&lt;/a&gt; not to change the default behavior of &lt;code&gt;wp_title()&lt;/code&gt;, and instead added the additional argument to the function in order to prevent breaking existing themes that rely on the current behavior.&lt;/p&gt;
&lt;h2 id="change"&gt;How to Make the Change&lt;/h2&gt;
&lt;p&gt;If you&amp;#8217;re currently using Optimal Title and want to change your template back to using &lt;code&gt;wp_title()&lt;/code&gt; after upgrading to WordPress v2.5 (and you &lt;em&gt;should&lt;/em&gt;), here&amp;#8217;s what you need to do&amp;#8230;&lt;/p&gt;
&lt;p&gt;Using the simplified example from the &lt;a href="http://elasticdog.com/2004/09/optimal-title/#usage"&gt;original Optimal Title article&lt;/a&gt;, you should currently have something like this in your theme&amp;#8217;s &lt;kbd&gt;header.php&lt;/kbd&gt; file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;optimal_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Just replace the function call &lt;code&gt;optimal_title()&lt;/code&gt; with a call to &lt;code&gt;wp_title('&amp;amp;raquo;',TRUE,'right')&lt;/code&gt;, and you&amp;#8217;ll end up with something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;wp_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;amp;raquo;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;right&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#8217;s it!&lt;/p&gt;
&lt;h2 id="parameters"&gt;Parameters&lt;/h2&gt;
&lt;p&gt;The &lt;a href="http://codex.wordpress.org/Template_Tags/wp_title"&gt;wp_title codex page&lt;/a&gt; won&amp;#8217;t be updated until the next release, however, here is how &lt;code&gt;wp_title()&lt;/code&gt; will work after WordPress v2.5 is out:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;wp_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;separator&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;seplocation&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
	&lt;li&gt;&amp;#39;separator&amp;#39; &amp;#8211; &lt;i&gt;string&lt;/i&gt; &amp;#8211; The text to place between portions of the page title, such as the blog name and the category. Defaults to &lt;code&gt;'&amp;amp;raquo;'&lt;/code&gt; (&amp;raquo;).&lt;/li&gt;
	&lt;li&gt;display &amp;#8211; &lt;i&gt;boolean&lt;/i&gt; &amp;#8211; Should the title be displayed (&lt;code&gt;TRUE&lt;/code&gt;) or returned for use in &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; (&lt;code&gt;FALSE&lt;/code&gt;). Defaults to &lt;code&gt;TRUE&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;&amp;#39;seplocation&amp;#39; &amp;#8211; &lt;i&gt;string&lt;/i&gt; &amp;#8211; The location of the separator in relation to the title. All values default to the standard left position, with the exception of &lt;code&gt;'right'&lt;/code&gt;, which will place the separator after the title rather than before.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="glad"&gt;I&amp;#8217;m Glad&lt;/h2&gt;
&lt;p&gt;Even though it took so long to get this done, I&amp;#8217;m glad WordPress finally came around to the idea and added Optimal Title&amp;#8217;s functionality to the core. Regardless of whether or not you were using Optimal Title before, I&amp;#8217;d highly recommend that &lt;strong&gt;all&lt;/strong&gt; users make this simple change to their templates in order to take advantage of the many benefits that a proper title tag has to offer.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=54VvmRkLsX0:D7H4kZo4UWY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/54VvmRkLsX0" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2008/02/optimal-title-functionality-now-in-wordpress-core</feedburner:origLink></entry>
	
	<entry>
		<title>HOWTO: Have Multiple Users Share an iTunes Library on One Machine</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/iysFmtXYnYE/howto-have-multiple-users-share-an-itunes-library-on-one-machine" />
		<updated>2007-04-29T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2007/04/howto-have-multiple-users-share-an-itunes-library-on-one-machine</id>
		<content type="html">&lt;p&gt;I recently purchased a new MacBook (never having owned a Mac before), and have been reading up on keeping things secure. Per one of those security-related suggestions, once everything was set up to my liking, I stopped using the admin account for everyday use and started forcing myself to log in as a regular user. I&amp;#8217;ve also created a user account for my live-in girlfriend so she can go wild customizing her desktop with pictures of flowers, Hugh Jackman, Hugh Jackman laying in a bed of flowers, and so on, without making my eyes bleed.&lt;/p&gt;
&lt;p&gt;The trouble is, we both buy music from iTunes on a regular basis using our own individual Apple ID accounts, and there isn&amp;#8217;t an easy way to share our music seamlessly with one another. We have similar tastes in music and we&amp;#8217;d like it so that when one person buys a new song, it is immediately available for the other person to listen to. Ideally, we&amp;#8217;d also be able to create our own unique playlists and assign ratings to the various songs to reflect our own personal likes/dislikes. This article lays out the details of how I accomplished that goal&amp;#8230;&lt;/p&gt;
&lt;h2 id="problem"&gt;The Problem&lt;/h2&gt;
&lt;p&gt;The main problem with assigning two iTunes Libraries to the same location comes down to permissions. By default, when you download music through iTunes, it assigns permissions based on the user that&amp;#8217;s logged in. It only allows that user and people in the &lt;span class="caps"&gt;UNIX&lt;/span&gt; group &amp;#8220;wheel&amp;#8221; to read the music file (if you&amp;#8217;re &lt;span class="caps"&gt;UNIX&lt;/span&gt;-literate, that means it has 640 file permissions). Since a different user (in this case, my girlfriend) would not fit into those categories, she doesn&amp;#8217;t have the proper permissions to read any of the music I download. To put it simply&amp;#8230;music needs to be world readable.&lt;/p&gt;
&lt;h2 id="solution"&gt;The Solution&lt;/h2&gt;
&lt;p&gt;These permissions can be easily fixed by running a &lt;a href="http://elasticdog.com/code/2007/04/share-itunes"&gt;simple script&lt;/a&gt; that uses the &lt;code&gt;chmod&lt;/code&gt; command to modify your music so anyone can play it. To give you a breakdown, &lt;a href="http://elasticdog.com/code/2007/04/share-itunes"&gt;the script&lt;/a&gt; runs a few safety checks to ensure that you have the proper permissions to modify the files, it then checks that your specified library actually exists, and then it recursively looks at all of your music making sure it is world readable.&lt;/p&gt;
&lt;p&gt;The trick is getting the script to run only when necessary as not to waste resources. You could set up a cron job, but then it would have to run on a fixed time table. Either it would run more often than necessary, or not often enough&amp;#8230;so cron is out. You could set up a launchd/launchctl configuration file and specify it to run when your Library folder is modified, but unfortunately that doesn&amp;#8217;t get triggered when a &lt;em&gt;sub&lt;/em&gt;-folder gets modified&amp;#8230;so launchd is out.&lt;/p&gt;
&lt;p&gt;The key ends up being something called a &amp;#8220;LoginHook&amp;#8221; that is configured in the &lt;code&gt;/etc/ttys&lt;/code&gt; file. Creating a LoginHook will ensure that whenever any user logs in to the machine, the script will be run and proper permissions will be set on the entire library.&lt;/p&gt;
&lt;h2 id="together"&gt;Putting it All Together&lt;/h2&gt;
&lt;p&gt;This should go without saying, but I&amp;#8217;m saying it&amp;#8230;&lt;strong&gt;back up all of your music files before doing anything else&lt;/strong&gt;! Once that&amp;#8217;s done, proceed with the following steps:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;First you must pick a centralized location that all your users have access to and make sure the directory exists. I picked /Users/Shared/Music/iTunes and created it on the command-line using:&lt;br /&gt;&lt;code&gt;mkdir -p /Users/Shared/Music/iTunes&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Next, you must adjust your iTunes settings to point to the new location. You do this by launching iTunes, then navigate to &lt;em&gt;iTunes &amp;raquo; Preferences&amp;#8230; &amp;raquo; Advanced&lt;/em&gt;, and under the &lt;em&gt;General&lt;/em&gt; tab, click the &lt;em&gt;Change&amp;#8230;&lt;/em&gt; button next to the &amp;#8220;iTunes Music folder location&amp;#8221; box. Navigate to your newly-created centralized folder (in my case /Users/Shared/Music/iTunes), and click &lt;em&gt;Choose&lt;/em&gt;.&lt;/li&gt;
	&lt;li&gt;For ease of maintenance and to prevent duplicate files from being generated, make sure the checkbox labeled &amp;#8220;Copy files to iTunes Music folder when adding to library&amp;#8221; is &lt;strong&gt;not&lt;/strong&gt; selected (this is also under the &lt;em&gt;Advanced&lt;/em&gt; section of the Preferences dialog box).&lt;/li&gt;
	&lt;li&gt;Click &lt;em&gt;OK&lt;/em&gt; to accept the changes you made to your preferences.&lt;/li&gt;
	&lt;li&gt;To copy your current library to the new location, navigate to &lt;em&gt;Advanced &amp;raquo; Consolidate Library&amp;#8230;&lt;/em&gt; then proceed by clicking &lt;em&gt;Consolidate&lt;/em&gt;. This step only needs to be performed one time per user to ensure that everything gets moved over to the new location.&lt;/li&gt;
	&lt;li&gt;Repeat these configuration steps for all users that you wish to consolidate libraries for.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At this point, you&amp;#8217;ve done all that is necessary to do within iTunes, and all that is left is fixing the file permissions. To do that, log in as a user with administrator privileges and follow these steps:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Download &lt;a href="http://elasticdog.com/code/2007/04/share-itunes"&gt;the script&lt;/a&gt; and put it anywhere you want. I made another directory called &lt;code&gt;/Users/Shared/bin/&lt;/code&gt; and put the script there, but the location doesn&amp;#8217;t really matter.&lt;/li&gt;
	&lt;li&gt;Modify the script&amp;#8217;s &lt;code&gt;LIBRARY&lt;/code&gt; variable (in the &lt;code&gt;CONSTANTS&lt;/code&gt; section) to point to the centralized music directory you created above.&lt;/li&gt;
	&lt;li&gt;Ensure that the script is executable by running:&lt;br /&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;chmod 755 /Users/Shared/bin/share-itunes
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
	&lt;li&gt;Then edit the &lt;code&gt;/etc/ttys&lt;/code&gt; file with your favorite text editor, and change the line starting with &amp;#8220;console&amp;#8221; to add:&lt;br /&gt;&lt;code&gt;-LoginHook /Users/Shared/bin/share-itunes&lt;/code&gt;&lt;br /&gt;right after the &amp;#8220;loginwindow&amp;#8221; declaration. Make sure you actually point it to the location where you downloaded the script to. The line should have looked something like this before you edited it:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" vt100 on secure onoption="/usr/libexec/getty std.9600"&lt;/code&gt;&lt;/pre&gt;&amp;#8230;and look like this after you edit it:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow -LoginHook /Users/Shared/bin/share-itunes" vt100 on secure onoption="/usr/libexec/getty std.9600"&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
	&lt;li&gt;Save the file, and close your text editor.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&amp;#8217;s it! Everything should be all set to go and your permissions will be checked each time you log in to the computer.&lt;/p&gt;
&lt;h2 id="caveats"&gt;Caveats&lt;/h2&gt;
&lt;p&gt;The only thing I wasn&amp;#8217;t able to automate was adding new music purchased by my girlfriend in to my library so it actually shows up when I launch iTunes. For all I know, there may be an easy way to automate it, but I haven&amp;#8217;t found one at this time. Luckily it&amp;#8217;s a fast/easy procedure to do by hand&amp;#8230;&lt;/p&gt;
&lt;p&gt;To actually have new music purchased by another user show up in your library, all you have to do is launch iTunes, go to &lt;em&gt;File &amp;raquo; Add to Library&amp;#8230;&lt;/em&gt;, then navigate to your shared music folder and click &lt;em&gt;Choose&lt;/em&gt;. It will take a few seconds to parse through your library, but after it&amp;#8217;s done, all of the music should be available for you to play. You will have to do that every time you know that music has been added by another user, but everything else should be automated for you.&lt;/p&gt;
&lt;h2 id="why"&gt;Why it Works&lt;/h2&gt;
&lt;p&gt;Unless you get tricky, iTunes always stores your album artwork, playlists, and song rating information in a file under your home directory (well, in ~/Music/iTunes, to be precise). It also stores a meta file with information regarding what it thinks should be included in your library. These files will be unique to the user even if you choose to share your actual music collections. So when you update your iTunes preferences to move the location of your Library, you still retain the ability to have all your own custom settings regardless of what other users add to the common music folder.&lt;/p&gt;
&lt;p&gt;By periodically telling iTunes to add the common music directory in to your library, you&amp;#8217;re simply forcing it to update the library meta file so it reflects whatever actually exists in that directory&amp;#8230;regardless of whether or not you were the person to purchase the music.&lt;/p&gt;
&lt;p&gt;Hopefully these steps will be able to help someone else out there having a similar issue. When I first started looking in to how to accomplish this configuration, I though surely it would be easy and done before, but alas, things got a bit more complicated than I had hoped. If you know of a better way, please do leave a comment and let us know what works for you. If you have any trouble understanding these procedures or getting it to work, let me know and I&amp;#8217;ll see what I can do to help out&amp;#8230;happy listening!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=iysFmtXYnYE:3iVCSpCSJmA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/iysFmtXYnYE" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2007/04/howto-have-multiple-users-share-an-itunes-library-on-one-machine</feedburner:origLink></entry>
	
	<entry>
		<title>New Flat-Panel Displays using Ceramics</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/tkRELHLLnSM/new-flat-panel-displays-using-ceramics" />
		<updated>2007-03-31T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2007/03/new-flat-panel-displays-using-ceramics</id>
		<content type="html">&lt;p&gt;While waiting for my tax refund, I&amp;#8217;ve been checking out flat panel TVs and I ran across this article on a new ceramic flat panel technology in &lt;a href="http://www.popsci.com"&gt;Popular Science&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;Researcher Steve Yando has invented a ceramic panel that converts video signals into moving pictures. Yando did not have to invent a new way to convert electricity into light; flat electroluminescent panels to do that have been on the market for years. The problem was scanning: how to switch individual points of the panel on and off very rapidly to build up the quick-changing light-and-dark pattern of the TV image. &amp;#8230;Yando solved the problem by pulling a very cute trick with piezoelectric crystals, which are old and long-used electric devices.&lt;/p&gt;
&lt;p&gt;Piezo crystals convert mechanical movement to electricity, or electricity to mechanical movement; they work either way&amp;#8230;.Yando&amp;#8217;s trick was to make a piezo crystal work both ways at the same time &amp;#8212; convert electricity to motion, the motion to electricity &amp;#8212; and combine that with an electroluminescent panel to get light.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2007/04/popsci-diagram.png" title="Ceramic Panel Diagram" alt="Ceramic Panel Diagram" /&gt;&lt;/p&gt;
&lt;p&gt;The dinner-plate picture panel is a flat rectangle of piezo ceramic (lead zirconate-titanate) coated with electroluminescent phosphor (a powder similar to fluorescent-lamp coating). Electrodes at the sides of the ceramic bring scanning voltages that determine which point will light up. Electrodes on the back and face of the panel bring TV picture-signal voltages that determine how bright the point will light up. (The face electrode has to be transparent so you can see the picture that is created.)&lt;/p&gt;
&lt;p&gt;The scanning voltage causes a mechanical vibration to move across the ceramic in a line &amp;#8211; like a long ocean wave. The vibration wave, in turn, generates a piezo voltage in the ceramic. So a line of voltage moves across the panel. But suppose you feed in two scanning voltages simultaneously, one to the top edge of the panel and one to a side edge. This gives you two moving lines of vibration waves and two moving lines of piezo voltage. Where the lines cross, you get a moving point of double piezo voltage. You can control the course of this point &amp;#8211; make it scan across the panel &amp;#8211; by doing things with the circuits in the TV receiver.&lt;/p&gt;
&lt;p&gt;The electroluminescent layer will light up whenever there is a voltage. But you don&amp;#8217;t want the moving lines to show at all, and even the moving spot must adjust it&amp;#8217;s brightness to suit the TV picture signal. So a varying resistance cuts out all voltage at or below the double-strength piezo voltage &amp;#8211; even the moving spot, unaided, won&amp;#8217;t light up. But the additional voltage supplied by the picture signal can make the moving spot glow, changing it from dim to bright to create the entire image.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Though the article is a little old and lacking on display specifications, they did mention that a full-scale prototype has already been built. So I may end up waiting another year or so to see if this develops before looking for a new TV.&lt;/p&gt;
&lt;p&gt;If anybody has any more info on ceramic flat panel TV technology, please drop me a line at &lt;strong&gt;aaron [at] elasticdog dot com&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="update"&gt;Update&lt;/h2&gt;
&lt;p&gt;Whew&amp;#8230;talk about an April Fools Day-spurred adrenaline rush! I think we duped literally &lt;b&gt;&lt;span class="caps"&gt;TENS&lt;/span&gt;&lt;/b&gt; of people with that one (not much response from &lt;a href="http://www.digg.com/"&gt;Digg&lt;/a&gt;, &lt;a href="http://www.fark.com/"&gt;Fark&lt;/a&gt;, or &lt;a href="http://www.shacknews.com/"&gt;Shacknews&lt;/a&gt;). This entry was the brain-child of my diabolical work friend James whom found this article in a 1961 version of Popular Science. Here are scans of the original article: &lt;a href="http://elasticdog.com/images/2007/04/page1.jpg"&gt;page one&lt;/a&gt; and &lt;a href="http://elasticdog.com/images/2007/04/page2.jpg"&gt;page two&lt;/a&gt;. Hopefully next year we can get more traffic coming our way if we want to pull a successful prank on the internets. Live and learn&amp;#8230;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=tkRELHLLnSM:hoFM36-5q9I:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/tkRELHLLnSM" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2007/03/new-flat-panel-displays-using-ceramics</feedburner:origLink></entry>
	
	<entry>
		<title>Upgrade in Progress</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/uop9bcvWCV0/upgrade-in-progress" />
		<updated>2005-06-30T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2005/06/upgrade-in-progress</id>
		<content type="html">&lt;p&gt;I&amp;#8217;m currently in the middle of upgrading my WordPress installation to 1.5.1.3, and thus things might not be working quite right around here for a bit. I&amp;#8217;m not dead, and I will be going back to my original design once I can take to time to develop a theme properly. With all all of the hacking I did to the default installation of WordPress 1.2.1, it could be a little while. Bear with me&amp;#8230;thanks&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=uop9bcvWCV0:4oZxjpYhl5E:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/uop9bcvWCV0" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2005/06/upgrade-in-progress</feedburner:origLink></entry>
	
	<entry>
		<title>WordPress Design Sandbox</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/5Oteo_CTJGQ/wp-design-sandbox" />
		<updated>2004-11-10T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2004/11/wp-design-sandbox</id>
		<content type="html">&lt;p&gt;When creating a website, it&amp;#8217;s best not to make experimental changes to your code directly on your server for the whole world to see. What if you accidentally mess things up beyond all recognition and don&amp;#8217;t remember exactly what you did? It&amp;#8217;s a good idea to test developmental changes in a protected environment where you know they won&amp;#8217;t effect anything that&amp;#8217;s mission critical. Typically this is simple to do as you can just edit the files on your local machine before uploading them. Making a test bed for &lt;a href="http://www.wordpress.org"&gt;WordPress&lt;/a&gt;, however, is a bit more difficult due to the nature of dynamic page generation.&lt;/p&gt;
&lt;p&gt;WordPress uses &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; to pull data from a database, and then subsequently creates the needed &lt;acronym title="Hypertext Markup Language"&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/acronym&gt; based off of that data. Without the &lt;span class="caps"&gt;PHP&lt;/span&gt;, your page would merely render as junk. Thus, in order to see a design change made in your &lt;acronym title="Cascading Style Sheets"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/acronym&gt;, you&amp;#8217;re usually forced to upload the file to your server so WordPress has access to its heart and soul. Not anymore&amp;#8230;&lt;/p&gt;
&lt;h2 id="sandbox"&gt;The Sandbox&lt;/h2&gt;
&lt;p&gt;In an effort to make things easier on WordPress users wanting to customize the default installation, I&amp;#8217;ve created a static version of the default &lt;acronym title="WordPress"&gt;&lt;span class="caps"&gt;WP&lt;/span&gt;&lt;/acronym&gt; template and have placed it in a zip file along with a clean copy of &lt;kbd&gt;wp-layout.css&lt;/kbd&gt; and &lt;kbd&gt;print.css&lt;/kbd&gt;. The template includes a sample entry that utilizes many common &lt;span class="caps"&gt;HTML&lt;/span&gt; elements so you can tell exactly what they would look like on your page.&lt;/p&gt;
&lt;p&gt;In this developmental sandbox, you can make structural code changes, try out new &lt;span class="caps"&gt;CSS&lt;/span&gt; techniques, whatever you want&amp;#8230;all without having to worry about messing up your live site. Once you get things the way you like them, simply update your real files accordingly, and you&amp;#8217;re good to go!&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;ol&gt;
	&lt;li&gt;Download &lt;a href="http://elasticdog.com/code/2004/11/wp-design-sandbox.zip"&gt;wp-design-sandbox.zip&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Create a new directory on your local machine in which you&amp;#8217;d like to place the test files&lt;/li&gt;
	&lt;li&gt;Unzip the three files into the newly created directory&lt;/li&gt;
	&lt;li&gt;Design away&lt;/li&gt;
&lt;/ol&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=5Oteo_CTJGQ:081BIqBZKj8:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/5Oteo_CTJGQ" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/11/wp-design-sandbox</feedburner:origLink></entry>
	
	<entry>
		<title>Design by Fire Cleanup</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/1CN4_svrPwQ/dxf-cleanup" />
		<updated>2004-11-05T00:00:00-08:00</updated>
		<id>http://elasticdog.com/2004/11/dxf-cleanup</id>
		<content type="html">&lt;p&gt;Last week, Andrei Herasimchuk of &lt;a href="http://www.designbyfire.com/"&gt;Design by Fire&lt;/a&gt; announced a contest to see who could take his site&amp;#8217;s current design and &amp;#8220;clean it up, optimizing it for best semantic and structural architecture.&amp;#8221; Having the final code judged by three industry bigwigs (&lt;a href="http://www.mezzoblue.com/"&gt;Dave Shea&lt;/a&gt;, &lt;a href="http://www.w3.org/People/Dean/"&gt;Dean Jackson&lt;/a&gt;, and &lt;a href="http://www.meyerweb.com/"&gt;Eric Meyer&lt;/a&gt;), Andrei is offering the winner their choice of any three &lt;a href="http://www.adobe.com/products/main.html"&gt;Adobe products&lt;/a&gt;. It&amp;#8217;s a widely known fact that software from Adobe is like crack to designers, so I figured I&amp;#8217;d have a go at it.&lt;/p&gt;
&lt;p&gt;I by no means would consider myself an &amp;#8220;expert&amp;#8221; on web standards (at least not in the same league as these guys), but my anal-retentive temperament &lt;em&gt;has&lt;/em&gt; provided me with the abnormal patience to sit down and scour the web for details regarding this subject matter. I&amp;#8217;d like to think that although I may not have a lot of industry experience, I have read tons about web standards and do enough work on my own to offer advice when it&amp;#8217;s needed.&lt;/p&gt;
&lt;p&gt;The contest consisted of cleaning up three different pages of code, and also optimizing the &lt;acronym title="Cascading Style Sheets"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/acronym&gt; involved in creating the look of Andrei&amp;#8217;s site. Initially underestimating the amount of time it would take to complete this cleanup, I immediately downloaded the necessary source code and began hacking away.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://elasticdog.com/images/2004/11/dxf-code.jpg" title="Screenshot of DxF Code" alt="Screenshot of DxF Code" /&gt;&lt;/p&gt;
&lt;h2 id="results"&gt;The Results&lt;/h2&gt;
&lt;p&gt;After about four days of working on the contest, creating three new images, having two bloodshot eyes, and one neglected girlfriend, I decided my pseudo redesign was complete. I&amp;#8217;m sure it&amp;#8217;s not perfect, but I can honestly say that it &lt;em&gt;is&lt;/em&gt; better.&lt;/p&gt;
&lt;p&gt;Overall, my changes make the site much more consistent&amp;#8230;not only in its structure, but in the way it&amp;#8217;s displayed across different browsers and platforms. It&amp;#8217;s also much more accessible, much more semantic, &lt;em&gt;and&lt;/em&gt; it tastes like chicken!&lt;/p&gt;
&lt;p&gt;The final judging for the contest has yet to take place, but I&amp;#8217;m crossing my fingers. Even if I don&amp;#8217;t win the software, it has been a good way for me to flex my design muscles &amp;#8212; plus there&amp;#8217;s the added bonus of three &lt;strong&gt;very&lt;/strong&gt; prominent designers in the industry who will be looking closely at my work.&lt;/p&gt;
&lt;p&gt;If any of my readers are interested in seeing the completed code (yes, I&amp;#8217;m talking to both of you), the three pages can be found here:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://elasticdog.com/dxf/"&gt;DxF Homepage&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://elasticdog.com/dxf/cat_design.html"&gt;DxF Categorical Archive&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://elasticdog.com/dxf/000146.html"&gt;DxF Sample Entry&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;ve also created &lt;a href="http://elasticdog.com/dxf/contest.zip"&gt;a zip file&lt;/a&gt; that contains all of the new code, images, &lt;span class="caps"&gt;CSS&lt;/span&gt;, and source files used in creating my entry. Inside the zip, you&amp;#8217;ll also find a changelog that discusses the improvements I made in more detail.&lt;/p&gt;
&lt;p&gt;Wish me luck!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=1CN4_svrPwQ:qxXLoC1-Gt8:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/1CN4_svrPwQ" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/11/dxf-cleanup</feedburner:origLink></entry>
	
	<entry>
		<title>Faking Multiple Templates in WordPress</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/yIK_CUCQ14o/faking-multiple-templates" />
		<updated>2004-10-07T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2004/10/faking-multiple-templates</id>
		<content type="html">&lt;p&gt;One of the things that surprised me when I first switched from &lt;a href="http://www.movabletype.org/"&gt;Movable Type&lt;/a&gt; to &lt;a href="http://wordpress.org/"&gt;WordPress&lt;/a&gt; was its lack of multiple templates. In &lt;acronym title="Movable Type"&gt;&lt;span class="caps"&gt;MT&lt;/span&gt;&lt;/acronym&gt; you create numerous templates which allow you to change the look of different pages on your site (i.e., the homepage, archive pages, individual entries, etc.). If you want a list of your favorite links to appear on the homepage, but not on the page for an individual entry, you just delete that section of code from the appropriate template.&lt;/p&gt;
&lt;p&gt;WordPress handles its pages a bit differently. Everything is based off of a single template, and through the magic of database queries and dynamic page generation, the right content is always shown according to which type of page you&amp;#8217;re looking at.&lt;/p&gt;
&lt;h2 id="the-problem"&gt;The Problem&lt;/h2&gt;
&lt;p&gt;By using a single template, the default installation of &lt;acronym title="WordPress"&gt;&lt;span class="caps"&gt;WP&lt;/span&gt;&lt;/acronym&gt; will show the exact same sidebar on every page, and likewise, whenever you view an entry listing, it will always look the same. This one-template structure is viewed as a blessing to some, but an over-simplification to others.&lt;/p&gt;
&lt;p&gt;What if you want to show a list of just the entry titles on your archive pages, rather than the entire entry itself? What if you want to hide the sidebar&amp;#8217;s calendar on your individual entry pages? There are countless scenarios like these that require a little more flexibility than the default &lt;kbd&gt;index.php&lt;/kbd&gt; file can give you.&lt;/p&gt;
&lt;p&gt;This issue has been discussed many times on the &lt;a href="http://wordpress.org/support/"&gt;WordPress support forums&lt;/a&gt;, but I&amp;#8217;ve found most of the proposed solutions to be less than ideal. It&amp;#8217;s rumored that the functionality to control these types of things will be built into WordPress 1.3, but for the time being, it seems we&amp;#8217;re on our own.&lt;/p&gt;
&lt;h2 id="common-solution"&gt;A Common Solution&lt;/h2&gt;
&lt;p&gt;Many people suggest using &lt;kbd&gt;.htaccess&lt;/kbd&gt; rules and simply forward visitors to templates other than &lt;kbd&gt;index.php&lt;/kbd&gt;. I feel this method over-complicates things, and here&amp;#8217;s why:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;It creates duplicate code when most of the time you&amp;#8217;ll have the exact same basic page structure in each template. Not only that, but multiple templates aren&amp;#8217;t very easy to maintain if you ever need to change that underlying structure.&lt;/li&gt;
	&lt;li&gt;There&amp;#8217;s no guarantee that all WP users will be able to create, edit, and use &lt;kbd&gt;.htaccess&lt;/kbd&gt; files. Some hosting companies just don&amp;#8217;t allow it.&lt;/li&gt;
	&lt;li&gt;Writing &lt;kbd&gt;.htaccess&lt;/kbd&gt; rules can be downright confusing!&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="my-solution"&gt;My Solution&lt;/h2&gt;
&lt;p&gt;Using some simple &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; and the functionality that&amp;#8217;s already built into WordPress, you can easily control what appears on different page types without having to create multiple templates. The key lies in exploiting a few under appreciated variables&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;var&gt;$single&lt;/var&gt;, &lt;var&gt;$cat&lt;/var&gt;, &lt;var&gt;$m&lt;/var&gt;, and &lt;var&gt;$year&lt;/var&gt; are all built in variables used by WP to determine information about the type of page you&amp;#8217;re looking at. The &lt;var&gt;$single&lt;/var&gt; variable corresponds to individual entry pages, the &lt;var&gt;$cat&lt;/var&gt; variable to categorical listing pages, &lt;var&gt;$m&lt;/var&gt; to monthly listings, and &lt;var&gt;$year&lt;/var&gt; to yearly listings.&lt;/p&gt;
&lt;p&gt;When you&amp;#8217;re viewing each variable&amp;#8217;s corresponding page type, only that variable will be assigned a value. If you&amp;#8217;re viewing the main page of your site, then &lt;em&gt;none&lt;/em&gt; of those variables will be assigned a value. Thus, a simple test of whether or not each variable has a value can be use to control exactly what is displayed and when. Here&amp;#8217;s the basic idea:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$single&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// individual post contents&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// categorical listing contents&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// monthly listing contents&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// yearly listing contents&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// main page contents&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;All you have to do is place the content you want to appear in the appropriate spot. If you don&amp;#8217;t want to do anything different in a particular section from how WP handles it by default, just leave out that variable&amp;#8217;s test.&lt;/p&gt;
&lt;h2 id="apply-it"&gt;How to Apply It&lt;/h2&gt;
&lt;p&gt;Using one of the scenarios from above as an example, let&amp;#8217;s say that you want to show just the entry titles when viewing a categorical listing. All you&amp;#8217;d have to do is change the &lt;code&gt;&amp;lt;div id="content"&amp;gt;&lt;/code&gt; section of your &lt;kbd&gt;index.php&lt;/kbd&gt; file to be something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;div id=&amp;quot;content&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;start_wp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;        &amp;lt;h3 class=&amp;quot;storytitle&amp;quot; id=&amp;quot;post-&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_ID&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_permalink&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot; rel=&amp;quot;bookmark&amp;quot; title=&amp;quot;Permanent Link: &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;        &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;h2&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;/h2&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;

&lt;span class="x"&gt;        &amp;lt;div class=&amp;quot;post&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;            &amp;lt;h3 class=&amp;quot;storytitle&amp;quot; id=&amp;quot;post-&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_ID&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_permalink&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot; rel=&amp;quot;bookmark&amp;quot; title=&amp;quot;Permanent Link: &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;

&lt;span class="x"&gt;            &amp;lt;div class=&amp;quot;meta&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;                &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;_e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Filed under:&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_category&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &amp;amp;#8212; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_author&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; @ &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;edit_post_link&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;            &amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="x"&gt;            &amp;lt;div class=&amp;quot;storycontent&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;                &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;the_content&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;            &amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="x"&gt;            &amp;lt;div class=&amp;quot;feedback&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;                &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;wp_link_pages&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;

&lt;span class="x"&gt;                &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;comments_popup_link&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Comments (0)&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Comments (1)&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Comments (%)&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;            &amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="x"&gt;            &amp;lt;!--&lt;/span&gt;
&lt;span class="x"&gt;            &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;trackback_rdf&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;            --&amp;gt;&lt;/span&gt;

&lt;span class="x"&gt;            &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ABSPATH&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;wp-comments.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;        &amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;endforeach&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;        &amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;_e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Sorry, no posts matched your criteria.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The process would be just as easy to change what appears in the sidebar of your page&amp;#8230;just edit the &lt;code&gt;&amp;lt;div id="menu"&amp;gt;&lt;/code&gt; section. Once you get the hang of it, these variables can be used to manipulate just about anything.&lt;/p&gt;
&lt;h2 id="step-further"&gt;Taking It a Step Further&lt;/h2&gt;
&lt;p&gt;Adding in code for each of these page types can get confusing really fast. With that much information packed in to one file, the scanability of &lt;kbd&gt;index.php&lt;/kbd&gt; drops considerably and it becomes difficult to find what you want when you need it.&lt;/p&gt;
&lt;p&gt;To combat this, I&amp;#8217;ve taken the fake template concept a step further&amp;#8230;rather than listing all of the code directly in &lt;kbd&gt;index.php&lt;/kbd&gt;, I use &lt;span class="caps"&gt;PHP&lt;/span&gt; includes to import each custom section from an external file. Rather than make this tutorial any longer than it already is, here&amp;#8217;s how I set it up:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;div id=&amp;quot;content&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="x"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;start_wp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Faking multiple templates&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$single&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/single.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/category.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/month.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/year.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/main.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;endforeach&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;includes/nomatches.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the external files themselves, simply put what content you want to appear, and that&amp;#8217;s it! I hope this helps some of you guys out.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=yIK_CUCQ14o:E0FOAgYjPRE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/yIK_CUCQ14o" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/10/faking-multiple-templates</feedburner:origLink></entry>
	
	<entry>
		<title>WP Plugin: Code Viewer</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/MLRx8voyS4o/code-viewer" />
		<updated>2004-09-26T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2004/09/code-viewer</id>
		<content type="html">&lt;p&gt;Code Viewer is a &lt;a href="http://wordpress.org/"&gt;WordPress&lt;/a&gt; plugin that pulls source code from an external file and displays it, optionally adding a link to download the code directly. The plugin displays the code with proper indentation, line numbers, and automatic long-line wrapping.&lt;/p&gt;
&lt;p&gt;When using Code Viewer, you no longer have to worry about typing countless entity references in order to make your code &amp;#8220;&lt;acronym title="Hypertext Markup Language"&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/acronym&gt; friendly&amp;#8221; or to simulate tabs&amp;#8230;it&amp;#8217;s all done automatically with &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; and a little &lt;acronym title="Cascading Style Sheets"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/acronym&gt;. By inserting line numbers on your page, the plugin also eliminates the problem of long, non-breaking lines screwing up your layout. In addition, line numbers make convenient reference points when discussing code samples.&lt;/p&gt;
&lt;p&gt;Last, but not least&amp;#8230;because you&amp;#8217;re pulling the source code from an external file (rather than having it embedded directly in your entry), the same code can be repeated on numerous pages, and you only have to type it in once. This not only saves you time, but when you update the code in the centralized file, all instances of that code will be updated along with it.&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;p&gt;&lt;ins datetime="2008-02-24T02:57:54+00:00"&gt;I am no longer maintaining Code Viewer, please see &lt;a href="http://elasticdog.com/2008/02/current-status-of-the-code-viewer-wordpress-plugin/"&gt;Current Status of the Code Viewer Wordpress Plugin&lt;/a&gt; for more details on where to get the latest version.&lt;/ins&gt;&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Download &lt;a href="http://elasticdog.com/code/plugins/code-viewer.txt"&gt;Code Viewer v1.1&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;Open the downloaded file in a text editor and configure the &lt;var&gt;$default_path&lt;/var&gt; variable (found on line 12), setting it equal to the absolute path of your code folder&lt;/li&gt;
	&lt;li&gt;Save the edited file&lt;/li&gt;
	&lt;li&gt;Change the extension of the saved file from &lt;kbd&gt;.txt&lt;/kbd&gt; to &lt;kbd&gt;.php&lt;/kbd&gt;&lt;/li&gt;
	&lt;li&gt;Upload the changed file into your &lt;kbd&gt;wp-content/plugins/&lt;/kbd&gt; directory.&lt;/li&gt;
	&lt;li&gt;Activate the plugin on your &lt;acronym title="WordPress"&gt;&lt;span class="caps"&gt;WP&lt;/span&gt;&lt;/acronym&gt; Admin &amp;raquo; Plugin Management page by clicking the corresponding &amp;ldquo;Activate&amp;rdquo; link under the &lt;b&gt;Action&lt;/b&gt; column.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You&amp;#8217;ll also want to add some new classes to your &lt;span class="caps"&gt;CSS&lt;/span&gt; that will control the look of the code listing. Everything (with the exception of auto-indention) works just fine without the &lt;span class="caps"&gt;CSS&lt;/span&gt;; but adding it in makes a huge difference on readability. Feel free to change these values to whatever you like, but this is how I have mine set up:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="css"&gt;&lt;span class="c"&gt;/* ---( CODE VIEWER FORMATTING )------------------------- */&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;border&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="k"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#DDD&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#C63&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;font-family&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Courier New&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Courier&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="k"&gt;monospace&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;line-height&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;130&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;padding&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt; &lt;span class="m"&gt;45px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5em&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;padding&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;26px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;74px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;98px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;122px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab6&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;146px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.tab7&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;padding-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;170px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.odd&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.even&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#F0F0F0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.sourcelink&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;font&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;115&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;Georgia&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Times New Roman&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="k"&gt;serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;list-style&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;margin-left&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;padding-top&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.85em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;text-align&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt;&lt;span class="nc"&gt;.codelist&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="nt"&gt;code&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#222&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class="sourcelink"&gt;Download Source Code: &lt;a href="http://elasticdog.com/code/2004/09/code-viewer.css"&gt;code-viewer.css&lt;/a&gt;&lt;/div&gt;
&lt;h2 id="usage"&gt;Usage&lt;/h2&gt;
&lt;p&gt;Code Viewer basically searches your entry for a custom &lt;acronym title="Extensible Markup Language"&gt;&lt;span class="caps"&gt;XML&lt;/span&gt;&lt;/acronym&gt; tag named &lt;code&gt;&amp;lt;viewcode /&amp;gt;&lt;/code&gt;, that tells the server to look at an external file and parse it line-by-line into an ordered list. It can be placed anywhere a block-level tag is valid, and like any empty element in &lt;acronym title="Extensible Hypertext Markup Language"&gt;&lt;span class="caps"&gt;XHTML&lt;/span&gt;&lt;/acronym&gt;, &lt;strong&gt;the tag must be properly closed&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;To better illustrate its usage, the tag used in this entry (to show the &lt;kbd&gt;code-viewer.css&lt;/kbd&gt; listing above) was:&lt;br /&gt;
&lt;code&gt;&amp;lt;viewcode src="2004/09/code-viewer.css" link="yes" /&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;h2 id="parameters"&gt;Parameters&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;URL&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;link=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;display&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
	&lt;li&gt;The &lt;code&gt;src&lt;/code&gt; attribute is &lt;strong&gt;required&lt;/strong&gt;.
	&lt;ul&gt;
		&lt;li&gt;&amp;#34;&lt;span class="caps"&gt;URL&lt;/span&gt;&amp;#34; &amp;#8211; &lt;i&gt;string&lt;/i&gt; &amp;#8211; The &lt;acronym title="Uniform Resource Locator"&gt;&lt;span class="caps"&gt;URL&lt;/span&gt;&lt;/acronym&gt; of the code to display. Note that relative paths are in relation to the &lt;var&gt;$default_path&lt;/var&gt; variable set during &lt;a href="#installation"&gt;the installation step&lt;/a&gt;.&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
	&lt;li&gt;The &lt;code&gt;link&lt;/code&gt; attribute is &lt;strong&gt;optional&lt;/strong&gt;.
	&lt;ul&gt;
		&lt;li&gt;&amp;#34;display&amp;#34; &amp;#8211; &lt;i&gt;string&lt;/i&gt; &amp;#8211; Should the link to the code be displayed (&lt;code&gt;"yes"&lt;/code&gt;), or not be displayed (&lt;code&gt;"no"&lt;/code&gt;). If the &lt;code&gt;link&lt;/code&gt; attribute is left out of the tag completely, the value defaults to &lt;code&gt;"no"&lt;/code&gt;.&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are some examples of &lt;em&gt;valid syntax&lt;/em&gt; recognized by Code Viewer&amp;#8230;note that all of these examples point to the same file (assuming the &lt;var&gt;$default_path&lt;/var&gt; variable is set to &amp;#34;&lt;code&gt;http://elasticdog.com/code/&lt;/code&gt;&amp;#34;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://elasticdog.com/code/example.txt&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;link=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;no&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://elasticdog.com/code/example.txt&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;/code/example.txt&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;viewcode&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;example.txt&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Each attribute value &lt;strong&gt;must&lt;/strong&gt; be surrounded with double quotes (&amp;#34;), and &lt;em&gt;not&lt;/em&gt; single quotes (&amp;#39;), or the tag will not be recognized.&lt;/p&gt;
&lt;h2 id="version-history"&gt;Version History&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;v1.1 (10 Oct 2004)&lt;/em&gt; &amp;#8211; Fixed blank line detection; no longer confused by whitespace characters.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;v1.01 (30 Sep 2004)&lt;/em&gt; &amp;#8211; Update to &lt;kbd&gt;code-viewer.css&lt;/kbd&gt;; fixed inconsistent font sizing.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;v1.0 (26 Sep 2004)&lt;/em&gt; &amp;#8211; Initial release to the public.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="credits"&gt;Credits&lt;/h2&gt;
&lt;p&gt;The idea to use ordered lists in &lt;span class="caps"&gt;XHTML&lt;/span&gt; to present code, originated from Simon Willison&amp;#8217;s &lt;a href="http://simon.incutio.com/archive/2002/07/10/numberedCodeListing"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt; Numbered Code Listings&lt;/a&gt; blog entry. The same idea has been used by other designers, and in particular, a fellow WP plugin author named David House&amp;#8230;&lt;/p&gt;
&lt;p&gt;Looking at &lt;a href="http://xmouse.ithium.net/archives/2004/07/19/implementing-a-code-snippet-system"&gt;David&amp;#8217;s code-snippet system&lt;/a&gt;, I fell in love with the idea, but thought his implementation could be improved upon. Code Viewer should be much more efficient in comparison and has the added functionality of optional link inclusion, styling differences for every other line, and better &lt;span class="caps"&gt;URL&lt;/span&gt; &amp;amp; file type support. A big thanks goes out to both David and Simon for their contributions to my latest creation.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=MLRx8voyS4o:re2q3NLeKr8:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/MLRx8voyS4o" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/09/code-viewer</feedburner:origLink></entry>
	
	<entry>
		<title>Workin’ My Backend</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/mYfbWmnws_s/backend" />
		<updated>2004-09-21T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2004/09/backend</id>
		<content type="html">&lt;p&gt;I&amp;#8217;m under no delusions about the number of readers I have, and yet I feel compelled to write an update on how things are progressing. Call it hope for a self-fulfilling prophecy&amp;#8230;after all, if I&amp;#8217;m going to start a blog that I actually expect people to read, I have to write entries in it sooner or later, right?&lt;/p&gt;
&lt;p&gt;It may look as though not much has changed around here over the past couple of weeks, but I assure you things &lt;em&gt;are&lt;/em&gt; moving forward. Admittedly, I have been busy with school and my personal life, and consequently haven&amp;#8217;t had much time to devote toward ElasticDog, but I haven&amp;#8217;t completely ignored it either.&lt;/p&gt;
&lt;p&gt;Not only have I started working on numerous entries, but I&amp;#8217;ve also been teaching myself some &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; in an attempt to customize WordPress even further than I already have. Here&amp;#8217;s a short list of some of the projects I&amp;#8217;ve been tackling:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Convenient Code&lt;/strong&gt;&lt;br /&gt;
		A &lt;acronym title="WordPress"&gt;&lt;span class="caps"&gt;WP&lt;/span&gt;&lt;/acronym&gt; plugin that pulls source code from an external file and displays the associated code with line numbers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Faking Templates with WP&lt;/strong&gt;&lt;br /&gt;
		There are about a billion different ways to do this, and I&amp;#8217;ve come up with one of my own. With my method, I&amp;#8217;m able to control what appears in both the main column and sub column of my site, differing each one for the home page, individual pages, and each of the three archive page types (yearly, monthly, and categorical).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Project JumpDrive&lt;/strong&gt;&lt;br /&gt;
		How I found the road to &lt;acronym title="Universal Serial Bus"&gt;&lt;span class="caps"&gt;USB&lt;/span&gt;&lt;/acronym&gt; flash drive heaven.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Additional &lt;acronym title="Cascading Style Sheets"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/acronym&gt; Inclusion&lt;/strong&gt;&lt;br /&gt;
		A WP plugin that will allow you to include an additional &lt;span class="caps"&gt;CSS&lt;/span&gt; file for a specific entry. That way, you&amp;#8217;re not forced to load a bloated style sheet for all of your pages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Streamlining Code and Planning for Upgradeability&lt;/strong&gt;&lt;br /&gt;
		Although this is a never-ending process, I&amp;#8217;ve been going through my code, commenting important sections, simplifying structure, and adding more flexibility in preparation for inevitable updates.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Text Editor Showdown&lt;/strong&gt;&lt;br /&gt;
		A no holds barred comparison between popular &lt;acronym title="Hypertext Markup Language"&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/acronym&gt; &amp;amp; text editors.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;#8217;s just a sneak peak at what I&amp;#8217;ve got brewing over the next couple of weeks. I&amp;#8217;ll also be adding the rest of the main site pages (about, portfolio, etc.) as soon as humanly possible. Simply put, there&amp;#8217;s much more to come here at ElasticDog, and by the time I&amp;#8217;m finished workin&amp;#8217; my backend, even Jennifer Lopez will have something to be envious of!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=mYfbWmnws_s:YFBszJEjNNM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/mYfbWmnws_s" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/09/backend</feedburner:origLink></entry>
	
	<entry>
		<title>WP Plugin: Optimal Title</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/eAetF1xlnDc/optimal-title" />
		<updated>2004-09-08T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2004/09/optimal-title</id>
		<content type="html">&lt;p&gt;&lt;ins datetime="2008-02-20T07:55:33+00:00"&gt;This plugin is now deprecated&amp;#8230;see &lt;a href="http://elasticdog.com/2008/02/optimal-title-functionality-now-in-wordpress-core/"&gt;Optimal Title Functionality Now in WordPress Core&lt;/a&gt;.&lt;/ins&gt;&lt;/p&gt;
&lt;h2 id="important"&gt;IMPORTANT!!!&lt;/h2&gt;
&lt;p&gt;Due to recent &lt;a href="http://wordpress.org/development/2007/04/wordpress-213-and-2010/"&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt; security issues&lt;/a&gt; fixed in WordPress 2.1.3, the code for Optimal Title also had to change in order to fix the vulnerabilities. It is recommended that &lt;strong&gt;&lt;span class="caps"&gt;ALL&lt;/span&gt;&lt;/strong&gt; users of this plugin upgrade to version 3.0. Due to changes in how Optimal Title works, that should be the last upgrade you will ever need For more details, see the &lt;a href="#update"&gt;update details&lt;/a&gt; section below&amp;#8230;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Optimal Title is a &lt;a href="http://wordpress.org/"&gt;WordPress&lt;/a&gt; plugin that mirrors the function of &lt;code&gt;wp_title()&lt;/code&gt; exactly, but moves the position of the &amp;#39;separator&amp;#39; to after the title rather than before. This allows you to have your blog name tacked on to the end of the page title instead of having it appear first.&lt;/p&gt;
&lt;p&gt;Having your page information appear before your blog name in the title is advantageous because it provides more meaningful search engine results and browser bookmark names The text that appears between your &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tags is used to generate both of these things, and will often be truncated when viewed. Because of this, it is more effective to have words directly relating to the content of your page appear before common markers. Not only will the titles be more meaningful, but the they will also be more scannable when being viewed in a list For more information on this concept, see Dr. Jakob Nielsen&amp;#8217;s article &lt;a href="http://www.useit.com/alertbox/980906.html"&gt;Microcontent: How to Write Headlines, Page Titles, and Subject Lines&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;ol&gt;
	&lt;li&gt;Download &lt;a href="http://downloads.wordpress.org/plugin/optimal-title.3.0.zip"&gt;Optimal Title v3.0&lt;/a&gt; and unzip the archive.&lt;/li&gt;
	&lt;li&gt;Upload &lt;code&gt;optimal-title.php&lt;/code&gt; into your &lt;kbd&gt;wp-content/plugins/&lt;/kbd&gt; directory.&lt;/li&gt;
	&lt;li&gt;Activate the plugin on your &lt;acronym title="WordPress"&gt;&lt;span class="caps"&gt;WP&lt;/span&gt;&lt;/acronym&gt; Admin &amp;raquo; Plugin Management page by clicking the corresponding &amp;ldquo;Activate&amp;rdquo; link under the &lt;b&gt;Action&lt;/b&gt; column.&lt;/li&gt;
	&lt;li&gt;Follow the usage guidelines shown below&amp;#8230;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="usage"&gt;Usage&lt;/h2&gt;
&lt;p&gt;In your &lt;kbd&gt;header.php&lt;/kbd&gt; file, replace the function call &lt;code&gt;wp_title()&lt;/code&gt; with a call to &lt;code&gt;optimal_title()&lt;/code&gt;. You&amp;#8217;ll also want to position your blog name after your usage of Optimal Title in order for this to work as intended. You should end up with a line that looks something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;optimal_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For a more complicated version that checks to make sure the plugin is installed and also includes support for a tagline on the home page, this is actual code I use on this site:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="x"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;optimal_title&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;optimal_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;|&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;wp_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;|&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;is_home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt; | &lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;description&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id="parameters"&gt;Parameters&lt;/h2&gt;
&lt;p&gt;Optimal Title uses the same syntax as &lt;a href="http://codex.wordpress.org/Template_Tags/wp_title"&gt;&lt;code&gt;wp_title&lt;/code&gt;&lt;/a&gt;, from the default WP installation, and thus functions in the exact same way&amp;#8230;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="php"&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nx"&gt;optimal_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;separator&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
	&lt;li&gt;&amp;#39;separator&amp;#39; &amp;#8211; &lt;i&gt;string&lt;/i&gt; &amp;#8211; The text to place between portions of the page title, such as the blog name and the category. Defaults to &lt;code&gt;'&amp;amp;raquo;'&lt;/code&gt; (&amp;raquo;).&lt;/li&gt;
	&lt;li&gt;display &amp;#8211; &lt;i&gt;boolean&lt;/i&gt; &amp;#8211; Should the title be displayed (&lt;code&gt;TRUE&lt;/code&gt;) or returned for use in &lt;acronym title="PHP: Hypertext Preprocessor"&gt;&lt;span class="caps"&gt;PHP&lt;/span&gt;&lt;/acronym&gt; (&lt;code&gt;FALSE&lt;/code&gt;). Defaults to &lt;code&gt;TRUE&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="version-history"&gt;Version History&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;v3.0 (06 Apr 2007)&lt;/em&gt; &amp;#8211; Complete rework on how the plugin works; now should be compatible with all WordPress releases no matter the version.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;v2.0 (26 Mar 2006)&lt;/em&gt; &amp;#8211; Updated to be compatible with the latest WordPress release (including WP 2.x version support).&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;v1.0 (08 Sep 2004)&lt;/em&gt; &amp;#8211; Initial release to the public.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="update"&gt;v3.0 Update Details&lt;/h2&gt;
&lt;p&gt;Upon the suggestion of &lt;a href="http://leekelleher.com/"&gt;Lee Kelleher&lt;/a&gt;, the way in which Optimal Title works was adapted in order to be more efficient, future-proof, and secure. The plugin no longer generates the title text itself, but lets the built-in &lt;code&gt;wp_title()&lt;/code&gt; function handle the generation, then rearranges things afterward. Because of this change, Optimal Title will have the exact same security implications as the default installation of WordPress itself and should never need to be upgraded again&amp;#8230;in other words, if your WordPress installation is up to date, you&amp;#8217;ll never have to worry about the security of using Optimal Title. That also means that the plugin should work for &lt;strong&gt;&lt;span class="caps"&gt;ANY&lt;/span&gt;&lt;/strong&gt; version of WordPress, past, present, and future.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=eAetF1xlnDc:wWQ7hXcOxbY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/eAetF1xlnDc" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/09/optimal-title</feedburner:origLink></entry>
	
	<entry>
		<title>A Fresh Start</title>
		<link href="http://feedproxy.google.com/~r/elasticdog/~3/mH0NWl9fJXo/fresh-start" />
		<updated>2004-09-03T00:00:00-07:00</updated>
		<id>http://elasticdog.com/2004/09/fresh-start</id>
		<content type="html">&lt;p&gt;I started the original ElasticDog about a year ago when I became interested in standards-based&amp;#8212;web-design. The more I read about the subject, the more I wanted to try things out and to create a standards-based site of my own. It had been years since I had even touched &lt;acronym title="Hypertext Markup Language"&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/acronym&gt;, but I was determined to do things right this time around. I stayed up late nights reading, experimenting, repeatedly failing, and eventually, learning&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://elasticdog.com/images/2004/09/edv1.png"&gt;&lt;img src="http://elasticdog.com/images/2004/09/edv1-thumb.png" title="Screen shot of ElsaticDog v1.0" alt="Screen shot of ElsaticDog v1.0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once the initial design had been completed, I was pretty happy with the results, but didn&amp;#8217;t know where to go from there. I had successfully created a functional/accessible site using &lt;acronym title="Extensible Hypertext Markup Language"&gt;&lt;span class="caps"&gt;XHTML&lt;/span&gt;&lt;/acronym&gt; and &lt;acronym title="Cascading Style Sheets"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/acronym&gt;; but they say that &amp;#8220;content is king,&amp;#8221; and I felt that at the time, I had nothing significant to write about.&lt;/p&gt;
&lt;p&gt;And so, I kept researching as much as I could on web design, intermittently writing on what came to mind, and fooling around with different ideas that I ran across. In time, I began to develop my own thoughts on the subjects that I was reading about, rather than just taking what others said at face value. It was quickly becoming apparent to me that ElasticDog needed some major improvements.&lt;/p&gt;
&lt;h2 id="repair-or-rebuild"&gt;Repair or Rebuild?&lt;/h2&gt;
&lt;p&gt;To give you some background info, one of the ideas behind designing with &lt;span class="caps"&gt;XHTML&lt;/span&gt;/&lt;span class="caps"&gt;CSS&lt;/span&gt; is &lt;em&gt;forward compatibility&lt;/em&gt; &lt;del&gt;-&lt;/del&gt; in theory you shouldn&amp;#8217;t have to update your code in order to do a redesign because your content and style are kept completely separate. For a beautiful demonstration of this concept, just check out the &lt;a href="http://www.csszengarden.com/"&gt;css Zen Garden&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With the first version of ElasticDog.com, I had put a lot of thought in to how my code was structured and included many unique features that I really came to like. But on the flip side, I also did some things that were out of the ordinary which prevented me from executing a redesign as easily as I had hoped. For example, instead of having a fixed-width or fluid page, I decided to try my hand at an &lt;a href="http://www.alistapart.com/articles/elastic/"&gt;elastic design&lt;/a&gt;,  which is a combination of the other two. This added unnecessary complexity to my code and limited some of my future design options. Because of limitations, and others like it, I knew that if I started over again, I could do better.&lt;/p&gt;
&lt;p&gt;Around this same time, I was experiencing some reliability issues with my hosting provider, the new licensing structure for &lt;a href="http://www.movabletype.org/"&gt;MovableType&lt;/a&gt; (my former &lt;acronym title="Content Management System"&gt;&lt;span class="caps"&gt;CMS&lt;/span&gt;&lt;/acronym&gt;) was causing &lt;a href="http://www.sixapart.com/log/2004/05/how_are_you_usi.shtml"&gt;a ruckus in the web log community&lt;/a&gt;, and I had pretty much stopped writing entries all together. It was then that I became determined to mix things up in order to turn ElasticDog into the site that I had always envisioned.&lt;/p&gt;
&lt;h2 id="stepping-back"&gt;Stepping Back to Move Forward&lt;/h2&gt;
&lt;p&gt;To kick off this renewal, I went back to the basics by looking at some of my favorite sites and writing down the aspects that made them stand out. How was the site organized? How did the author handle semantics? What characteristics of their design were useful? What features were attractive, or conversely, distracting? Why did the designers make the decisions they made? What things in &lt;em&gt;my&lt;/em&gt; previous design did I do right?&lt;/p&gt;
&lt;p&gt;Keeping all of those things in mind, I began creating a new design from scratch. I completely restructured my &lt;span class="caps"&gt;XHTML&lt;/span&gt;, cleaned up my &lt;span class="caps"&gt;CSS&lt;/span&gt;, and made everything more user friendly. I paid attention to the smallest of details, and made sure to insert a lot more flexibility into my code so future changes wouldn&amp;#8217;t be such a headache.&lt;/p&gt;
&lt;p&gt;Once I had an idea of how things were going to look, I went out and read reviews about hosting providers and ended up switching my site over to &lt;a href="http://icdsoft.com/"&gt;ICDSoft&lt;/a&gt; &amp;#8230;a move that I&amp;#8217;ve been &lt;strong&gt;very&lt;/strong&gt; happy with.&lt;/p&gt;
&lt;p&gt;Now that I had a redesigned look for my site, and a new server to put it on, I needed software to manage it all. Due to a number of reasons, I chose to leave MovableType behind and use the open-source publishing platform &lt;a href="http://wordpress.org/"&gt;WordPress&lt;/a&gt; instead. Once the software was installed, I created templates (based on my design) that would automatically generate my entire site using WordPress&amp;#8230;and the rest is history!&lt;/p&gt;
&lt;h2 id="almost-done"&gt;I Promise, I&amp;#8217;m Almost Done&lt;/h2&gt;
&lt;p&gt;Now that I&amp;#8217;ve bored you to death, I can finally welcome you to the new and improved ElasticDog! Not everything is quite polished yet, but I figured it was good enough to get things going again. For the time being, my old entries will not be imported into the new design. Eventually the ideas will work their way back in the archives, but for now you&amp;#8217;ll have to do without.&lt;/p&gt;
&lt;p&gt;Last, but not least, I&amp;#8217;d like to send thanks out to those who gave me support during my initial learning stages and also to those who offered their insight on my latest design. I realize there&amp;#8217;s not much here yet, but I now have a better idea of what I want ElasticDog to be, and more importantly, how to get it there.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/elasticdog?a=mH0NWl9fJXo:BQUbOZusoBU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/elasticdog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/elasticdog/~4/mH0NWl9fJXo" height="1" width="1"/&gt;</content>
	<feedburner:origLink>http://elasticdog.com/2004/09/fresh-start</feedburner:origLink></entry>
	

</feed>

