<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Three till Seven &#187; Techy</title>
	<atom:link href="http://www.3till7.net/category/techy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3till7.net</link>
	<description>Programming, espresso, and grumbling.</description>
	<lastBuildDate>Tue, 09 Mar 2010 15:23:47 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>got a PS3</title>
		<link>http://www.3till7.net/2010/03/04/got-a-ps3/</link>
		<comments>http://www.3till7.net/2010/03/04/got-a-ps3/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 02:08:42 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Video games]]></category>
		<category><![CDATA[shopping]]></category>
		<category><![CDATA[video games]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=4032</guid>
		<description><![CDATA[Just a quick note to say Best Buy happened to get some 120GB PS3&#8217;s in today and I just happened to call at the right time, squeal &#8220;Omigod, can you hold one?!&#8221;, and buy one.  :)  I couldn&#8217;t find Eternal Sonata at either Best Buy or Gamestop, so I ended up with Bayonetta [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to say Best Buy happened to get some 120GB PS3&#8217;s in today and I just happened to call at the right time, squeal &#8220;Omigod, can you hold one?!&#8221;, and buy one.  :)  I couldn&#8217;t find Eternal Sonata at either Best Buy or Gamestop, so I ended up with Bayonetta instead.  After dying repeatedly in the prologue on Normal setting (the hardest setting there is, for some reason), I realized that using Triangle + Circle does combos a lot better, or something, and I&#8217;ve since progressed to Chapter 3.  I&#8217;m really enjoying it.  Anyone who has a PSN account, my user name is cheshire137, if you want to friend me.  :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/03/04/got-a-ps3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS3&#8217;s hard to find</title>
		<link>http://www.3till7.net/2010/02/27/ps3s-hard-to-find/</link>
		<comments>http://www.3till7.net/2010/02/27/ps3s-hard-to-find/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:55:02 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Video games]]></category>
		<category><![CDATA[shopping]]></category>
		<category><![CDATA[video games]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=4003</guid>
		<description><![CDATA[I just wanted to buy a 120GB Playstation 3 but apparently everyone around here is sold out of them.  I figured the console has been out for a few years and the 120GB version came out in I think September, so I didn&#8217;t even consider that they would be hard to come by.  [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to buy a 120GB Playstation 3 but apparently everyone around here is sold out of them.  I figured the console has been out for a few years and the 120GB version came out in I think September, so I didn&#8217;t even consider that they would be hard to come by.  The Best Buy rep I talked to said he didn&#8217;t know if Sony was intentionally trying to dry out the market or what; some online news I read said they were having manufacturing difficulties.</p>
<p>I found the 120GB version on Toys R Us&#8217;s web site for $299 and it said it was in stock.  Not trusting that to be accurate, since every other store I checked online was out of stock, and stores I called in person were sold out, I decided to call Toys R Us.  I fortunately got stuck with a phone menu that you talk into instead of the kind where you hit different buttons.  I say fortunately because the speak-aloud ones are easy to circumvent:  just wail and squeak and squeal different inhuman noises.  It frustrates the machine and causes it to say things like &#8220;I&#8217;m sorry, I didn&#8217;t get that&#8221; and eventually &#8220;Please hold while I connect you with a representative.&#8221;  Score!  I got a guy who checked for me and said it did indeed appear to be in their warehouse and that there shouldn&#8217;t be a delay in shipping.  We&#8217;ll see.  I went ahead and ordered it from their web site; $299 PS3, $13 shipping, and $18 in taxes later, my PS3 order was placed.</p>
<p>Games I&#8217;m looking forward to playing:</p>
<ul>
<li>Eternal Sonata</li>
<li>Heavy Rain</li>
<li>Katamari Damacy</li>
<li>Dragon Age</li>
<li>Heavenly Sword</li>
<li>Little Big Planet</li>
</ul>
<p>If you have any PS3 game suggestions, let me know.  :)  Also, has anyone else had trouble finding these things?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/02/27/ps3s-hard-to-find/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>convenient file searching with Ruby, grep, and file</title>
		<link>http://www.3till7.net/2010/02/23/convenient-file-searching-with-ruby-grep-and-file/</link>
		<comments>http://www.3till7.net/2010/02/23/convenient-file-searching-with-ruby-grep-and-file/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 18:26:30 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3990</guid>
		<description><![CDATA[For my Linux kernel class, I often know that some struct exists somewhere, or remember seeing a macro defined in some file and it might be useful, but I can't remember where I saw something.  I also end up trying to track down all the places a particular function is called, and don't want [...]]]></description>
			<content:encoded><![CDATA[<p>For my Linux kernel class, I often know that some <code>struct</code> exists somewhere, or remember seeing a macro defined in some file and it might be useful, but I can't remember where I saw something.  I also end up trying to track down all the places a particular function is called, and don't want grep to go digging through every... single... file in the entire kernel directory structure when I only care about .c files.  So, I dug up a lengthy combination of file and grep that limits grep's searching to particular files.  I'm lazy about remembering this and retyping it on different computers, too, though, so I wrote a quick Ruby script to do it for me:</p>
<div class="synthi_code" style="display:block;" id="styled_synthi_4b97a8ffec177">
<h2 class="synthi_header"> Ruby</h2>
<div class="ruby" style="font-family: monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span></p>
<p><span style="color:#9966CC; font-weight:bold;">unless</span> ARGV.<span style="color:#9900CC;">length</span> &gt;= <span style="color:#006666;">2</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Usage:&nbsp; #$0 file_extension query&quot;</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>Example: #$0 '*.h' 'struct list_head'&quot;</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">exit</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></p>
<p><span style="color:#9966CC; font-weight:bold;">unless</span> ARGV.<span style="color:#9900CC;">length</span> == <span style="color:#006666;">2</span><br />
&nbsp; extra_args = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>...<span style="color:#9900CC;">ARGV</span>.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span> ', '<br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Warning:&nbsp; extra arguments ignored: &quot;</span> &lt;&lt; extra_args<br />
<span style="color:#9966CC; font-weight:bold;">end</span></p>
<p>file_extension = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
query = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
command = <span style="color:#996600;">&quot;find . -type f -name '#{file_extension}' -print0 | xargs -0 grep --line-number --color -H -o '#{query}'&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">system</span> 'clear'<br />
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Searching #{file_extension} for <span style="color:#000099;">\&quot;</span>#{query}<span style="color:#000099;">\&quot;</span>...&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">system</span> command</div>
</div>
<p>Here's sample output on my Mac:</p>
<pre>Searching *.rb for "puts"...
./finder.rb:4:puts
./finder.rb:5:puts
./finder.rb:11:puts
./finder.rb:22:puts</pre>
<p>And here's some sample output from a Linux machine:</p>
<pre>Searching *.c for "struct task_struct"...
./fs/fcntl.c:414:struct task_struct
./fs/fcntl.c:423:struct task_struct
./fs/fcntl.c:462:struct task_struct
./fs/fcntl.c:481:struct task_struct
./fs/fcntl.c:490:struct task_struct</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/02/23/convenient-file-searching-with-ruby-grep-and-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>representing rational numbers in Smalltalk</title>
		<link>http://www.3till7.net/2010/02/07/representing-rational-numbers-in-smalltalk/</link>
		<comments>http://www.3till7.net/2010/02/07/representing-rational-numbers-in-smalltalk/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 22:09:20 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3957</guid>
		<description><![CDATA[For my graduate-level programming languages class, I wrote this class that represents a rational number in Smalltalk.  I figured I would share my source code with the interwebs for anyone else trying to learn the language.   I release the code under the GNU General Public License v3.
Note for students: my professor requested [...]]]></description>
			<content:encoded><![CDATA[<p>For my graduate-level programming languages class, I wrote this class that represents a rational number in Smalltalk.  I figured I would share my source code with the interwebs for anyone else trying to learn the language.   I release the code under the <a href="http://www.gnu.org/licenses/gpl-3.0.html">GNU General Public License v3</a>.</p>
<p><em>Note for students:</em> my professor requested I state that, should you be taking his programming languages class CS 655 at the University of Kentucky and you try to use this code, (1) you'll get in trouble for using someone else's work and (2) you have to include the GPL and my copyright notice, which would be a big hint that it's not entirely your work. ;)</p>
<div class="synthi_code" style="display:block;" id="styled_synthi_4b97a9003623f">
<h2 class="synthi_header"> Smalltalk</h2>
<div class="smalltalk" style="font-family: monospace;"><span style="color: #007f00; font-style: italic;">&quot; Copyright 2009 Sarah Vessels<br />
This program is free software: you can redistribute it and/or modify<br />
it under the terms of the GNU General Public License as published by<br />
the Free Software Foundation, either version 3 of the License, or<br />
(at your option) any later version.<br />
This program is distributed in the hope that it will be useful,<br />
but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br />
GNU General Public License for more details.<br />
You should have received a copy of the GNU General Public License<br />
along with this program.&nbsp; If not, see &lt;http://www.gnu.org/licenses/&gt;. &quot;</span><br />
<span style="color: #0000ff;">Object</span> subclass: <span style="color: #7f0000;">#Rational</span>.<br />
<span style="color: #0000ff;">Rational</span> instanceVariableNames: <span style="color: #7f0000;">'numerator denominator'</span>.<br />
<span style="color: #0000ff;">Rational</span> comment: <span style="color: #7f0000;">'I represent a fraction'</span>.</p>
<p><span style="color: #007f00; font-style: italic;">&quot; Thanks to http://en.wikipedia.org/wiki/Euclidean_algorithm &quot;</span><br />
<span style="color: #0000ff;">Rational</span> class extend <span style="">&#91;</span><br />
&nbsp; <span style="color: #00007f;">getGCD</span>: <span style="color: #00007f;">a</span> other: <span style="color: #00007f;">b</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #0000ff;">A</span> <span style="color: #0000ff;">B</span>|<br />
&nbsp; &nbsp; <span style="color: #0000ff;">A</span> := <span style="color: #00007f;">a</span>.<br />
&nbsp; &nbsp; <span style="color: #0000ff;">B</span> := <span style="color: #00007f;">b</span>.<br />
&nbsp; &nbsp; <span style="">&#91;</span><span style="color: #0000ff;">B</span> ~= <span style="color: #00007f;"><span style="color: #7f0000;">0</span></span><span style="">&#93;</span> whileTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; |<span style="color: #00007f;">tmp</span>|<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">tmp</span> := <span style="color: #0000ff;">B</span>.<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">B</span> := <span style="color: #0000ff;">A</span> \\ <span style="color: #0000ff;">B</span>.<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">A</span> := <span style="color: #00007f;">tmp</span>.<br />
&nbsp; &nbsp; <span style="">&#93;</span>.<br />
&nbsp; &nbsp; ^<span style="color: #0000ff;">A</span><br />
&nbsp; <span style="">&#93;</span><br />
<span style="">&#93;</span></p>
<p><span style="color: #007f00; font-style: italic;">&quot; Rational instance methods &quot;</span><br />
<span style="color: #0000ff;">Rational</span> extend <span style="">&#91;</span><br />
&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given a numerator and a non-zero denominator, this will initialize the<br />
&nbsp; &nbsp; Rational. &quot;</span><br />
&nbsp; init: <span style="color: #00007f;">num</span> over: <span style="color: #00007f;">denom</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">gcd</span>|<br />
&nbsp; &nbsp; denom = <span style="color: #00007f;"><span style="color: #7f0000;">0</span></span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Cannot have a 0 denominator'</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">num</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Must have an Integer numerator'</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">denom</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Must have a nonzero Integer denominator'</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">gcd</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> class new<span style="">&#41;</span> getGCD: <span style="color: #00007f;">num</span> other: <span style="color: #00007f;">denom</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;">numerator</span> := <span style="">&#40;</span><span style="color: #00007f;">num</span> / <span style="color: #00007f;">gcd</span><span style="">&#41;</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;">denominator</span> := <span style="">&#40;</span><span style="color: #00007f;">denom</span> / <span style="color: #00007f;">gcd</span><span style="">&#41;</span>.<br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given another Rational instance, this will return the Rational sum of this<br />
&nbsp; &nbsp; instance and the other instance. &quot;</span><br />
&nbsp; add: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">otherRat</span>|<br />
&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherRat</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="">&#40;</span><span style="color: #00007f;">other</span> * <span style="color: #00007f;">denominator</span><span style="">&#41;</span> over: <span style="color: #00007f;">denominator</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Rational</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherRat</span> := <span style="color: #00007f;">other</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Do not know how to add '</span>, <span style="">&#40;</span><span style="">&#40;</span><span style="color: #00007f;">other</span> class<span style="">&#41;</span> printString<span style="">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #7f0000;">' to Rational'</span><span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">denominator</span> = <span style="">&#40;</span><span style="color: #00007f;">otherRat</span> getDenominator<span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="">&#40;</span><span style="color: #00007f;">numerator</span> + <span style="">&#40;</span><span style="color: #00007f;">otherRat</span> getNumerator<span style="">&#41;</span><span style="">&#41;</span> over: <span style="color: #00007f;">denominator</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; |<span style="color: #00007f;">lcd scaledNum1 scaledNum2</span>|<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">lcd</span> := <span style="color: #7f007f;">self</span> getLCD: <span style="color: #00007f;">otherRat</span>.<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">scaledNum1</span> := <span style="color: #7f007f;">self</span> scaleNumerator: <span style="color: #00007f;">lcd</span>.<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">scaledNum2</span> := <span style="color: #00007f;">otherRat</span> scaleNumerator: <span style="color: #00007f;">lcd</span>.<br />
&nbsp; &nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="">&#40;</span><span style="color: #00007f;">scaledNum1</span> + <span style="color: #00007f;">scaledNum2</span><span style="">&#41;</span> over: <span style="color: #00007f;">lcd</span><br />
&nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Will approximate the decimal value of the Rational. &quot;</span><br />
&nbsp; approximate <span style="">&#91;</span> ^<span style="">&#40;</span><span style="color: #00007f;">numerator</span> * <span style="color: #00007f;"><span style="color: #7f0000;">1</span></span>.<span style="color: #00007f;"><span style="color: #7f0000;">0</span></span><span style="">&#41;</span> / <span style="color: #00007f;">denominator</span> <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given a Rational, compareTo compares this instance with the other Rational<br />
&nbsp; &nbsp; instance, returning -1, 0, or 1 depending on whether this instance is less<br />
&nbsp; &nbsp; than, equal to, or greater than the given instance, respectively. &quot;</span><br />
&nbsp; compareTo: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">otherDenom otherNum lcd</span>|<br />
&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> equals: <span style="color: #00007f;">other</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f0000;">0</span> <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> isPositive<span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isNegative<span style="">&#41;</span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f0000;">1</span> <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> isNegative<span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isPositive<span style="">&#41;</span> ifTrue: <span style="">&#91;</span> ^-<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span> <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">otherDenom</span> := <span style="color: #00007f;">other</span> getDenominator.<br />
&nbsp; &nbsp; <span style="color: #00007f;">otherNum</span> := <span style="color: #00007f;">other</span> getNumerator.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">denominator</span> = <span style="color: #00007f;">otherDenom</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">numerator</span> &amp;gt; otherNum ifTrue: <span style="">&#91;</span> ^<span style="color: #7f0000;">1</span> <span style="">&#93;</span><br />
&nbsp; &nbsp; &nbsp; ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">numerator</span> = <span style="color: #00007f;">otherNum</span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f0000;">0</span> <span style="">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ifFalse: <span style="">&#91;</span> ^-<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span> <span style="">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">numerator</span> = <span style="color: #00007f;">otherNum</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">denominator</span> &amp;gt; otherDenom ifTrue: <span style="">&#91;</span> ^-<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span> <span style="">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ifFalse: <span style="">&#91;</span> ^<span style="color: #7f0000;">1</span> <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">lcd</span> := <span style="color: #7f007f;">self</span> getLCD: <span style="color: #00007f;">other</span>.</p>
<p>&nbsp; &nbsp; <span style="">&#40;</span><span style="">&#40;</span><span style="color: #7f007f;">self</span> scaleNumerator: <span style="color: #00007f;">lcd</span><span style="">&#41;</span> &amp;gt; <span style="">&#40;</span><span style="color: #00007f;">other</span> scaleNumerator: <span style="color: #00007f;">lcd</span><span style="">&#41;</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; ^<span style="color: #7f0000;">1</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; ^-<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span><br />
&nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given an Integer or Rational, this will divide this Rational by that<br />
&nbsp; &nbsp; value. &quot;</span><br />
&nbsp; divide: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">otherFrac reciprocal</span>|<br />
&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherFrac</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="color: #00007f;">other</span> over: <span style="color: #00007f;"><span style="color: #7f0000;">1</span></span>.<br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Rational</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherFrac</span> := <span style="color: #00007f;">other</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Do not know how to divide a Ratioanl by '</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="">&#40;</span><span style="color: #00007f;">other</span> class<span style="">&#41;</span> printString<span style="">&#41;</span><span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">reciprocal</span> := <span style="">&#40;</span><span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="">&#40;</span><span style="color: #00007f;">otherFrac</span> getDenominator<span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; over: <span style="">&#40;</span><span style="color: #00007f;">otherFrac</span> getNumerator<span style="">&#41;</span><span style="">&#41;</span>.<br />
&nbsp; &nbsp; ^<span style="color: #7f007f;">self</span> multiply: <span style="color: #00007f;">reciprocal</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns true if the given Rational equals this Rational, either as the same<br />
&nbsp; &nbsp; object or it represents the same fraction. &quot;</span><br />
&nbsp; equals: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #7f007f;">self</span> = <span style="color: #00007f;">other</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; ^<span style="color: #7f007f;">true</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">numerator</span> = <span style="">&#40;</span><span style="color: #00007f;">other</span> getNumerator<span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">denominator</span> = <span style="">&#40;</span><span style="color: #00007f;">other</span> getDenominator<span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^<span style="color: #7f007f;">true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^<span style="color: #7f007f;">false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ^<span style="color: #7f007f;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns the denominator of the Rational. &quot;</span><br />
&nbsp; getDenominator <span style="">&#91;</span> ^denominator <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given another instance of Rational, this will get the least common<br />
&nbsp; &nbsp; denominator (a.k.a. least common multiple) of the two denominators. &quot;</span><br />
&nbsp; getLCD: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">diff denominator2 product gcd</span>|<br />
&nbsp; &nbsp; <span style="color: #00007f;">denominator2</span> := <span style="color: #00007f;">other</span> getDenominator.<br />
&nbsp; &nbsp; <span style="color: #00007f;">diff</span> := <span style="">&#40;</span><span style="color: #00007f;">denominator</span> - <span style="color: #00007f;">denominator2</span><span style="">&#41;</span> abs.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;"><span style="color: #7f0000;">1</span></span> = <span style="color: #00007f;">diff</span> ifTrue: <span style="">&#91;</span> ^denominator * <span style="color: #00007f;">denominator2</span> <span style="">&#93;</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;"><span style="color: #7f0000;">0</span></span> = <span style="color: #00007f;">diff</span> ifTrue: <span style="">&#91;</span> ^denominator <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">product</span> := <span style="">&#40;</span><span style="color: #00007f;">denominator</span> * <span style="color: #00007f;">denominator2</span><span style="">&#41;</span> abs.<br />
&nbsp; &nbsp; <span style="color: #00007f;">gcd</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> class new<span style="">&#41;</span> getGCD: <span style="color: #00007f;">denominator</span> other: <span style="color: #00007f;">denominator2</span>.<br />
&nbsp; &nbsp; ^product / <span style="color: #00007f;">gcd</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns the numerator of the Rational. &quot;</span><br />
&nbsp; getNumerator <span style="">&#91;</span> ^numerator <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns the reciprocal of this Rational. &quot;</span><br />
&nbsp; getReciprocal <span style="">&#91;</span> ^<span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="color: #00007f;">denominator</span> over: <span style="color: #00007f;">numerator</span> <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns true if this Rational is larger than the one given. &quot;</span><br />
&nbsp; greaterThan: <span style="color: #00007f;">other</span> <span style="">&#91;</span> ^<span style="">&#40;</span><span style="color: #7f007f;">self</span> compareTo: <span style="color: #00007f;">other</span><span style="">&#41;</span> = <span style="color: #00007f;"><span style="color: #7f0000;">1</span></span> <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns true if this Rational is larger than the one given, or has the<br />
&nbsp; &nbsp; same value. &quot;</span><br />
&nbsp; greaterThanOrEqualTo: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #7f007f;">self</span> compareTo: <span style="color: #00007f;">other</span><span style="">&#41;</span> &amp;gt; -<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Will return true if this Rational is &amp;lt; 0. &quot;</span><br />
&nbsp; isNegative <span style="">&#91;</span><br />
&nbsp; &nbsp; ^<span style="color: #7f007f;">self</span> isPositive not<br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Will return true if this Rational number is &amp;gt;= 0. &quot;</span><br />
&nbsp; isPositive <span style="">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">numerator</span> &amp;gt; <span style="color: #7f0000;">0</span> ifTrue: <span style="">&#91;</span> <span style="color: #00007f;">denominator</span> &amp;gt; <span style="color: #7f0000;">0</span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f007f;">true</span> <span style="">&#93;</span> <span style="">&#93;</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;">numerator</span> &amp;lt; <span style="color: #7f0000;">0</span> ifTrue: <span style="">&#91;</span> <span style="color: #00007f;">denominator</span> &amp;lt; <span style="color: #7f0000;">0</span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f007f;">true</span> <span style="">&#93;</span> <span style="">&#93;</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;">numerator</span> = <span style="color: #00007f;"><span style="color: #7f0000;">0</span></span> ifTrue: <span style="">&#91;</span> ^<span style="color: #7f007f;">true</span> <span style="">&#93;</span>.<br />
&nbsp; &nbsp; ^<span style="color: #7f007f;">false</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns true if this Rational is smaller than the one given. &quot;</span><br />
&nbsp; lessThan: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #7f007f;">self</span> compareTo: <span style="color: #00007f;">other</span><span style="">&#41;</span> = -<span style="color: #00007f;"><span style="color: #7f0000;">1</span></span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns true if this Rational is smaller than the one given, or has the<br />
&nbsp; &nbsp; same value. &quot;</span><br />
&nbsp; lessThanOrEqualTo: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #7f007f;">self</span> compareTo: <span style="color: #00007f;">other</span><span style="">&#41;</span> &amp;lt; <span style="color: #7f0000;">1</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given an Integer, this will scale the Rational by that amount.&nbsp; Given<br />
&nbsp; &nbsp; another Rational, this will return the product of this Rational and the one<br />
&nbsp; &nbsp; given. &quot;</span><br />
&nbsp; multiply: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">newNum newDenom</span>|<br />
&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">newNum</span> := <span style="color: #00007f;">numerator</span> * <span style="color: #00007f;">other</span>.<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">newDenom</span> := <span style="color: #00007f;">denominator</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Rational</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">newNum</span> := <span style="color: #00007f;">numerator</span> * <span style="">&#40;</span><span style="color: #00007f;">other</span> getNumerator<span style="">&#41;</span>.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">newDenom</span> := <span style="color: #00007f;">denominator</span> * <span style="">&#40;</span><span style="color: #00007f;">other</span> getDenominator<span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Do not know how to multiply by '</span>, <span style="">&#40;</span><span style="">&#40;</span><span style="color: #00007f;">other</span> class<span style="">&#41;</span> printString<span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; ^<span style="">&#40;</span><span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="color: #00007f;">newNum</span> over: <span style="color: #00007f;">newDenom</span><span style="">&#41;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Returns a string representation of the Rational. &quot;</span><br />
&nbsp; printString <span style="">&#91;</span><br />
&nbsp; &nbsp; ^<span style="">&#40;</span><span style="color: #00007f;">numerator</span> printString<span style="">&#41;</span>, <span style="color: #7f0000;">'/'</span>, <span style="">&#40;</span><span style="color: #00007f;">denominator</span> printString<span style="">&#41;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given a least common denominator, this will return the numerator scaled up<br />
&nbsp; &nbsp; such that it pairs with the least common denominator. &quot;</span><br />
&nbsp; scaleNumerator: <span style="color: #00007f;">lcd</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">denominator</span> = <span style="color: #00007f;">lcd</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; ^numerator<br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; |<span style="color: #00007f;">factor</span>|<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">factor</span> := <span style="color: #00007f;">lcd</span> / <span style="color: #00007f;">denominator</span>.<br />
&nbsp; &nbsp; &nbsp; ^numerator * <span style="color: #00007f;">factor</span><br />
&nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; <span style="">&#93;</span></p>
<p>&nbsp; <span style="color: #007f00; font-style: italic;">&quot; Given another Rational, this will subtract the given Rational from this<br />
&nbsp; &nbsp; instance, returning the result as a Rational. &quot;</span><br />
&nbsp; subtract: <span style="color: #00007f;">other</span> <span style="">&#91;</span><br />
&nbsp; &nbsp; |<span style="color: #00007f;">negated negNum otherRat</span>|<br />
&nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Integer</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherRat</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="">&#40;</span><span style="color: #00007f;">denominator</span> * <span style="color: #00007f;">other</span><span style="">&#41;</span> over: <span style="color: #00007f;">denominator</span><br />
&nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #00007f;">other</span> isKindOf: <span style="color: #0000ff;">Rational</span><span style="">&#41;</span> ifTrue: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">otherRat</span> := <span style="color: #00007f;">other</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span> ifFalse: <span style="">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="">&#40;</span><span style="color: #7f007f;">self</span> error: <span style="color: #7f0000;">'Do not know how to subtract '</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="">&#40;</span><span style="">&#40;</span><span style="color: #00007f;">other</span> class<span style="">&#41;</span> printString<span style="">&#41;</span>, <span style="color: #7f0000;">' from Rational'</span><span style="">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="">&#93;</span><br />
&nbsp; &nbsp; <span style="">&#93;</span>.</p>
<p>&nbsp; &nbsp; <span style="color: #00007f;">negNum</span> := <span style="color: #00007f;"><span style="color: #7f0000;">0</span></span> - <span style="">&#40;</span><span style="color: #00007f;">otherRat</span> getNumerator<span style="">&#41;</span>.<br />
&nbsp; &nbsp; <span style="color: #00007f;">negated</span> := <span style="">&#40;</span><span style="color: #0000ff;">Rational</span> new<span style="">&#41;</span> init: <span style="color: #00007f;">negNum</span> over: <span style="">&#40;</span><span style="color: #00007f;">otherRat</span> getDenominator<span style="">&#41;</span>.<br />
&nbsp; &nbsp; ^<span style="color: #7f007f;">self</span> add: <span style="color: #00007f;">negated</span><br />
&nbsp; <span style="">&#93;</span><br />
<span style="">&#93;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/02/07/representing-rational-numbers-in-smalltalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the pain of Facebook application development</title>
		<link>http://www.3till7.net/2010/02/02/the-pain-of-facebook-application-development/</link>
		<comments>http://www.3till7.net/2010/02/02/the-pain-of-facebook-application-development/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 23:19:39 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3867</guid>
		<description><![CDATA[For the past few days, I&#8217;ve been trying to create a Facebook application for interacting with Github.  I hoped to spend my time mainly on the Github portion, figuring out how to post wall posts on Facebook about recent Github activity, etc.  However, I&#8217;ve instead argued with the various Facebook APIs.  I [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few days, I&#8217;ve been trying to create a Facebook application for interacting with Github.  I hoped to spend my time mainly on the Github portion, figuring out how to post wall posts on Facebook about recent Github activity, etc.  However, I&#8217;ve instead argued with the various Facebook APIs.  I started out using PHP with no framework but quickly switched to CakePHP after I realized things were going to get hairy.  CakePHP was okay for a while until I hit the roadblock of not being able to load any page but the index&#8230;  Every sub-page I tried to create produced 404 errors, which no one else seemed to have (or at least document), so I said &#8217;screw it&#8217; and switched to Rails.</p>
<p>I started out using the Facebooker API but got frustrated when I kept getting an error about not being able to convert nil to String.  I don&#8217;t even know now what was causing that.  I tried various ways of accessing Facebooker, via gem or plugin (though one of the developers says in <a href="http://forums.pragprog.com/forums/59/topics/692">this forum</a> that he hadn&#8217;t rebuilt the gem in a while, so use the plugin), with no luck.  So I switched to the older RFacebook and had troubles accessing the magical &#8220;fbsession&#8221; that every tutorial in the history of RFacebook tutorials glosses over like of <em>course</em> it&#8217;s available in your controller and if it&#8217;s not then you&#8217;re obviously retarded and should just write Visual Basic for the rest of your pitiful programming career.  Again, <em>screw that</em>.  Feeling hopeless at the lack of other Ruby APIs out there for Facebook, I went back to Facebooker and proceeded to get <a href="http://tools.ietf.org/html/rfc4918#section-11.2">422 Unprocessable Entity errors</a> (?!) whenever I would submit a POST request.  In my logs, I was seeing the following:</p>
<pre>ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
  facebooker (1.0.61) [v] lib/facebooker.rb:90:in `with_application'</pre>
<p>Lots of googling led to the aforelinked forum post wherein someone said to turn off forgery protection by commenting out the following line in <code>app/controllers/application_controller.rb</code></p>
<div class="synthi_code" style="display:block;" id="styled_synthi_4b97a9006555a">
<h2 class="synthi_header"> Ruby</h2>
<div class="ruby" style="font-family: monospace;">protect_from_forgery <span style="color:#008000; font-style:italic;"># See ActionController::RequestForgeryProtection for details </span></div>
</div>
<p>That doesn&#8217;t sound good, turning off forgery protection, but the forum poster said Facebook already provides it.  No idea if that&#8217;s true, but by damn, I just want to POST two string values to update the database!  Sheesh!  Anyway, so my posts work now and things are proceeding along as I would have expected them to three days ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/02/02/the-pain-of-facebook-application-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>two new programming projects</title>
		<link>http://www.3till7.net/2010/01/30/two-new-programming-projects/</link>
		<comments>http://www.3till7.net/2010/01/30/two-new-programming-projects/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 03:53:54 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Techy]]></category>
		<category><![CDATA[C-sharp]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3865</guid>
		<description><![CDATA[I&#8217;ve gone on a programming project binge today, coding first in C# on a project to add an enforceable Implements attribute to class members, then in PHP to write a Github application for Facebook.  I&#8217;m interested in co-developing the Facebook app, too, and have emailed a few of my programmer friends at UK to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve gone on a programming project binge today, coding first in C# on a project to add an enforceable <a href="http://github.com/moneypenny/ImplementsAttribute">Implements attribute</a> to class members, then in PHP to write a <a href="http://github.com/moneypenny/GithubFacebook">Github application for Facebook</a>.  I&#8217;m interested in co-developing the Facebook app, too, and have emailed a few of my programmer friends at UK to see if they&#8217;d like to participate in coding, testing, or some other part.  If you&#8217;re interested, let me know and I&#8217;ll get you access to the project on Github.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2010/01/30/two-new-programming-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TurboTax fail</title>
		<link>http://www.3till7.net/2009/12/28/turbotax-fail/</link>
		<comments>http://www.3till7.net/2009/12/28/turbotax-fail/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 23:05:43 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Techy]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3787</guid>
		<description><![CDATA[I received in the mail the other day a TurboTax install CD with an offer for free filing of federal and state tax returns.  Neat, I thought, and I was initially under the impression that they were giving me TurboTax for free.  Nope, turns out I still have to pay $60 for it, [...]]]></description>
			<content:encoded><![CDATA[<p>I received in the mail the other day a TurboTax install CD with an offer for free filing of federal and state tax returns.  Neat, I thought, and I was initially under the impression that they were giving me TurboTax for free.  Nope, turns out I still have to pay $60 for it, but whatever, there&#8217;s a $10 mail-in rebate and I&#8217;d pay at least $50 for it or a similar program at Walmart.  So I decided to install it just now and get everything set up for when I file my taxes in a couple/few months.  I&#8217;m under the impression that Mac support for the TurboTax install was tacked on as a last thought, because I couldn&#8217;t get past the fill-in-your-address screen to buy the program.</p>
<p>My first little problem came when I was going to have it create an account for me so I could easily buy TurboTax again in the future.  The labels for &#8220;Password&#8221;, &#8220;Password Again&#8221;, &#8220;Security Question&#8221;, etc. were offset from the form elements they went with.  Not a big deal since I could mostly figure out what went where, but it made me leery of trusting the company with my personal details.  If they can&#8217;t put some polish in their program to, uh, <em>make their forms legible</em>, which is kinda basic, I don&#8217;t exactly trust them to get security and privacy down pat.  So I skipped that step and was just going to do a one-time purchase for my 2009 tax return.  I fully filled out the form with my name, address, and phone number but when I hit the Continue button, it popped up an error:  make sure there are at least two characters in the Customer Billing Address2 field.  Uh, there <em>was</em> no Customer Billing Address2 field.  I had checked the &#8220;Billing address same as shipping address&#8221; checkbox, and there was only one set of address fields available.  Even in that set of address fields, there was only one field for &#8220;Address&#8221;, not a second one labeled &#8220;Address2&#8243;.  I couldn&#8217;t get it to go through, so I&#8217;m thinking I&#8217;ll go with H&amp;R Block&#8217;s tax program again this year, since it worked well for me last year.</p>
<p>On a side note, ever since I updated this blog to Wordpress 2.9, I&#8217;ve been having trouble Publishing posts.  I usually write up an entry in one shot and it auto-saves as I type, which is nice.  However, when I hit the Publish button, it redirects me to a page saying my attempt to edit the entry failed, would I like to try again.  I have to go to Posts &gt; Edit, open the saved draft, add in whatever tags I had tried to publish it with along with the title sometimes, and then Publish.  I hope this is fixed in an update.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/12/28/turbotax-fail/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>heap sort in ML</title>
		<link>http://www.3till7.net/2009/12/23/heap-sort-in-ml/</link>
		<comments>http://www.3till7.net/2009/12/23/heap-sort-in-ml/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 22:24:25 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ML]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3008</guid>
		<description><![CDATA[This past semester for my programming languages class, we had to implement heap sort in Standard ML.  This is my implementation, which I release under the GNU General Public License v3.  I split the code into two separate files:  shared.ml and heap_sort.ml, where shared.ml contains functions that might be of use with [...]]]></description>
			<content:encoded><![CDATA[<p>This past semester for my programming languages class, we had to implement <a href="http://en.wikipedia.org/wiki/Heap_sort">heap sort</a> in <a href="http://en.wikipedia.org/wiki/Standard_ML">Standard ML</a>.  This is my implementation, which I release under the <a href="http://www.gnu.org/licenses/gpl-3.0.html">GNU General Public License v3</a>.  I split the code into two separate files:  shared.ml and heap_sort.ml, where shared.ml contains functions that might be of use with other sorting algorithms and heap_sort.ml contains functions and code specific to heap sort.</p>
<p><em>Note for students:</em>  my professor requested I state that, should you be taking his programming languages class CS 655 at the University of Kentucky and you try to use this code, (1) you'll get in trouble for using someone else's work and (2) you have to include the GPL and my copyright notice, which would be a real big hint that it's not entirely your work.  ;)</p>
<h2>shared.ml</h2>
<div class="synthi_code" style="display:block;" id="styled_synthi_4b97a900a0e8e">
<h2 class="synthi_header"> OCaml</h2>
<div class="ocaml" style="font-family: monospace;"><span style="color: #5d478b; font-style: italic;">(* Copyright 2009 Sarah Vessels<br />
&nbsp; &nbsp; This program is free software: you can redistribute it and/or modify<br />
&nbsp; &nbsp; it under the terms of the GNU General Public License as published by<br />
&nbsp; &nbsp; the Free Software Foundation, either version 3 of the License, or<br />
&nbsp; &nbsp; (at your option) any later version.</p>
<p>&nbsp; &nbsp; This program is distributed in the hope that it will be useful,<br />
&nbsp; &nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
&nbsp; &nbsp; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br />
&nbsp; &nbsp; GNU General Public License for more details.</p>
<p>&nbsp; &nbsp; You should have received a copy of the GNU General Public License<br />
&nbsp; &nbsp; along with this program.&nbsp; If not, see &lt;http://www.gnu.org/licenses/&gt;. *)</span></p>
<p><span style="color: #5d478b; font-style: italic;">(* Define a comparison function for integers that will return -1 if the first<br />
&nbsp;* element is smaller than the second, 0 if they are equal, and 1 if the first<br />
&nbsp;* element is larger than the second. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> int_compare <span style="color: #6c6;">&#40;</span>a:int, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> a &lt; b <span style="color: #06c; font-weight: bold;">then</span> ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> a = b <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Comparison function for reals; see int_compare. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> real_compare <span style="color: #6c6;">&#40;</span>a:real, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> a &lt; b <span style="color: #06c; font-weight: bold;">then</span> ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> a = b <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Comparison function for chars; see int_compare. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> char_compare <span style="color: #6c6;">&#40;</span>a:char, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> a &lt; b <span style="color: #06c; font-weight: bold;">then</span> ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> a = b <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Comparison function for bools; see int_compare.&nbsp; Arbitrarily choosing true to<br />
&nbsp;* be less than false. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> bool_compare <span style="color: #6c6;">&#40;</span>a:bool, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> a=<span style="color: #06c; font-weight: bold;">true</span> andalso b=<span style="color: #06c; font-weight: bold;">false</span> <span style="color: #06c; font-weight: bold;">then</span> ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> a = b <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Comparison function for strings; see int_compare. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> str_compare <span style="color: #6c6;">&#40;</span>a:string, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> a &lt; b <span style="color: #06c; font-weight: bold;">then</span> ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> a = b <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Using the given comparison function, this returns true if a &lt;= b, false<br />
&nbsp;* otherwise. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> leq <span style="color: #6c6;">&#40;</span>&lt;=&gt;, a, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>&lt;=&gt; <span style="color: #6c6;">&#40;</span>a, b<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> &lt; <span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">false</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Using the given comparison function, this returns true if a &gt;= b, false<br />
&nbsp;* otherwise. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> geq <span style="color: #6c6;">&#40;</span>&lt;=&gt;, a, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>&lt;=&gt; <span style="color: #6c6;">&#40;</span>a, b<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> &gt; ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">false</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Using the given comparison function, this returns true if a &lt; b, false<br />
&nbsp;* otherwise. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> lt <span style="color: #6c6;">&#40;</span>&lt;=&gt;, a, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>&lt;=&gt; <span style="color: #6c6;">&#40;</span>a, b<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> = ~<span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">false</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Using the given comparison function, this returns true if a &gt; b, false<br />
&nbsp;* otherwise. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> gt <span style="color: #6c6;">&#40;</span>&lt;=&gt;, a, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>&lt;=&gt; <span style="color: #6c6;">&#40;</span>a, b<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">false</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Using the given comparison function, this returns true if a = b, false<br />
&nbsp;* otherwise. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> eq <span style="color: #6c6;">&#40;</span>&lt;=&gt;, a, b<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span>&lt;=&gt; <span style="color: #6c6;">&#40;</span>a, b<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">false</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Returns a sub-list of the given list from indices i to j, inclusive. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> sub_list <span style="color: #6c6;">&#40;</span>arr, i, j<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* The last valid index in the given list *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> last_index = <span style="color: #6c6;">&#40;</span>length arr<span style="color: #6c6;">&#41;</span> - <span style="color: #c6c;">1</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Ensure the given indices are valid in the given list. *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> i &gt;= <span style="color: #c6c;">0</span> andalso j &gt;= <span style="color: #c6c;">0</span> andalso i &lt;= last_index andalso j &lt;= last_index <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* The first j+1 elements of the list *)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> first_els = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">take</span> <span style="color: #6c6;">&#40;</span>arr, j<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> i &lt; j <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Remove the first i elements of the first j+1 elements and return<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* what's left *)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">drop</span> <span style="color: #6c6;">&#40;</span>first_els, i<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> i = j <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Single-element list *)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#91;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* i &gt; j, so call this method again with the smaller element passed as<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* the first index. *)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_list <span style="color: #6c6;">&#40;</span>arr, j, i<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Invalid indices given, return an empty list/nil. *)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;<br />
&nbsp; &nbsp; &nbsp; <br />
<span style="color: #5d478b; font-style: italic;">(* Given a list arr and indices i and j, this will swap the values in arr found<br />
&nbsp;* at the indices i and j *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> swap <span style="color: #6c6;">&#40;</span>arr, i, j<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get a list of the first elements in the original list, up to the ith<br />
&nbsp; &nbsp; &nbsp;* element *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> first_els = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">take</span> <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span></p>
<p>&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get the ith element *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> i_el = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span></p>
<p>&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get the jth element *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> j_el = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, j<span style="color: #6c6;">&#41;</span></p>
<p>&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get a list of the last elements in the original list, starting at the<br />
&nbsp; &nbsp; &nbsp;* (j+1)th element *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> last_els = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">drop</span> <span style="color: #6c6;">&#40;</span>arr, j<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span></p>
<p>&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get the last valid index in the given list *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> last_index = <span style="color: #6c6;">&#40;</span>length arr<span style="color: #6c6;">&#41;</span> - <span style="color: #c6c;">1</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> i &gt; last_index orelse i &lt; <span style="color: #c6c;">0</span> orelse j &gt; last_index orelse j &lt; <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Error, so just return the original array *)</span><br />
&nbsp; &nbsp; &nbsp; arr<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> i = j<span style="color: #c6c;">-1</span> <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* No elements between i and j, so the swap is easy *)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#40;</span>first_els<span style="color: #6c6;">&#41;</span> @ <span style="color: #6c6;">&#91;</span>j_el<span style="color: #6c6;">&#93;</span> @ <span style="color: #6c6;">&#91;</span>i_el<span style="color: #6c6;">&#93;</span> @ <span style="color: #6c6;">&#40;</span>last_els<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> i &lt; j <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Get a list of the elements strictly between indices i and j in<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* the original array *)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> between_els = sub_list <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #c6c;">+1</span>, j<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#40;</span>first_els<span style="color: #6c6;">&#41;</span> @ <span style="color: #6c6;">&#91;</span>j_el<span style="color: #6c6;">&#93;</span> @ between_els @ <span style="color: #6c6;">&#91;</span>i_el<span style="color: #6c6;">&#93;</span> @ <span style="color: #6c6;">&#40;</span>last_els<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">end</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> i = j <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Same indices given, no swap necessary *)</span><br />
&nbsp; &nbsp; &nbsp; arr<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* i &gt; j, so call this method with the lower index first *)</span><br />
&nbsp; &nbsp; &nbsp; swap <span style="color: #6c6;">&#40;</span>arr, j, i<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given a list, an index, and a value, this will return the same list with the<br />
&nbsp;* value at the given index set to be the given value. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> set_value <span style="color: #6c6;">&#40;</span>arr, index, value<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> size = length arr<br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* If the given index is invalid, just return the original list,<br />
&nbsp; &nbsp; &nbsp;* unmodified. *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> index &lt; <span style="color: #c6c;">0</span> orelse index &gt;= size <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; arr<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Append the value to the end of the original list, then use swap to put<br />
&nbsp; &nbsp; &nbsp; &nbsp;* it at the desired index, then return only as many elements from the<br />
&nbsp; &nbsp; &nbsp; &nbsp;* new list as there were in the original list. *)</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">take</span> <span style="color: #6c6;">&#40;</span>swap <span style="color: #6c6;">&#40;</span>arr @ <span style="color: #6c6;">&#91;</span>value<span style="color: #6c6;">&#93;</span>, index, size<span style="color: #6c6;">&#41;</span>, size<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</div>
</div>
<h2>heap_sort.ml</h2>
<div class="synthi_code" style="display:block;" id="styled_synthi_4b97a900b4714">
<h2 class="synthi_header"> OCaml</h2>
<div class="ocaml" style="font-family: monospace;"><span style="color: #5d478b; font-style: italic;">(* Copyright 2009 Sarah Vessels<br />
&nbsp; &nbsp; This program is free software: you can redistribute it and/or modify<br />
&nbsp; &nbsp; it under the terms of the GNU General Public License as published by<br />
&nbsp; &nbsp; the Free Software Foundation, either version 3 of the License, or<br />
&nbsp; &nbsp; (at your option) any later version.</p>
<p>&nbsp; &nbsp; This program is distributed in the hope that it will be useful,<br />
&nbsp; &nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
&nbsp; &nbsp; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br />
&nbsp; &nbsp; GNU General Public License for more details.</p>
<p>&nbsp; &nbsp; You should have received a copy of the GNU General Public License<br />
&nbsp; &nbsp; along with this program.&nbsp; If not, see &lt;http://www.gnu.org/licenses/&gt;. *)</span><br />
use <span style="color: #3cb371;">&quot;shared.ml&quot;</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given i, this will return the index of i's left child. *)</span><br />
<span style="color: #06c; font-weight: bold;">val</span> left_index = fn i =&gt; <span style="color: #c6c;">2</span>*i;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given i, this will return the value at i's left child. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> left_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span> = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, left_index i<span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given i, this will return the index of i's right child. *)</span><br />
<span style="color: #06c; font-weight: bold;">val</span> right_index = fn i =&gt; <span style="color: #6c6;">&#40;</span><span style="color: #c6c;">2</span>*i<span style="color: #6c6;">&#41;</span> + <span style="color: #c6c;">1</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given i, this will return the value at i's right child. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> right_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span> = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, right_index i<span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Given a list arr, an index i, and the size of the heap contained in the<br />
&nbsp;* given list, this will returns the entire list, modified s.t. the heap rooted<br />
&nbsp;* at i is a max heap.&nbsp; This also requires a comparison function that works with<br />
&nbsp;* the type of elements found in the given list. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i, heap_size<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> l = left_index i&nbsp; <span style="color: #5d478b; font-style: italic;">(* Index of i's left child *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> r = right_index i <span style="color: #5d478b; font-style: italic;">(* Index of i's right child *)</span></p>
<p>&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Value at root i *)</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> value = <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="">List</span></a>.<span style="color: #060;">nth</span> <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; l &lt;= heap_size andalso<br />
&nbsp; &nbsp; &nbsp; gt <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, left_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span>, value<span style="color: #6c6;">&#41;</span> andalso<br />
&nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r &gt; heap_size orelse<br />
&nbsp; &nbsp; &nbsp; &nbsp; leq <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, right_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span>, left_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Largest is left child, so swap left child and root i, then max heapify<br />
&nbsp; &nbsp; &nbsp; &nbsp;* at the left child index. *)</span><br />
&nbsp; &nbsp; &nbsp; max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, swap <span style="color: #6c6;">&#40;</span>arr, i, l<span style="color: #6c6;">&#41;</span>, l, heap_size<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="color: #6c6;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; r &lt;= heap_size andalso<br />
&nbsp; &nbsp; &nbsp; gt <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, right_child <span style="color: #6c6;">&#40;</span>arr, i<span style="color: #6c6;">&#41;</span>, value<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Largest is right child, so swap right child and root i, then max<br />
&nbsp; &nbsp; &nbsp; &nbsp;* heapify at the right child index. *)</span><br />
&nbsp; &nbsp; &nbsp; max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, swap <span style="color: #6c6;">&#40;</span>arr, i, r<span style="color: #6c6;">&#41;</span>, r, heap_size<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Largest is root i, no change necessary, just return the list<br />
&nbsp; &nbsp; &nbsp; &nbsp;* unchanged. *)</span><br />
&nbsp; &nbsp; &nbsp; arr<br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Convenience function for max heapifying a heap in the given list rooted at<br />
&nbsp;* the given i with a fixed heap size (namely, one less than the length of the<br />
&nbsp;* given list).&nbsp; Requires a comparison function for comparing elements in the<br />
&nbsp;* given list. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> max_heapify <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i, <span style="color: #6c6;">&#40;</span>length arr<span style="color: #6c6;">&#41;</span> - <span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Recursive method for turning an entire given list into a max heap.&nbsp; Requires<br />
&nbsp;* the initial root for max_heapify be given as a parameter.&nbsp; Requires a<br />
&nbsp;* comparison function for comparing elements in the given list. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> build_max_heap_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, <span style="color: #c6c;">0</span><span style="color: #6c6;">&#41;</span> = max_heapify <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, <span style="color: #c6c;">0</span><span style="color: #6c6;">&#41;</span><br />
&nbsp; | build_max_heap_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; &nbsp; &nbsp; build_max_heap_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, max_heapify <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i<span style="color: #6c6;">&#41;</span>, i<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Convenience function for turning an entire given list into a max heap.&nbsp; Makes<br />
&nbsp;* use of the build_max_heap_rec function by passing in an initial root to<br />
&nbsp;* max_heapify.&nbsp; Requires a comparison function to compare elements in the given<br />
&nbsp;* list. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> build_max_heap <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> heap_size = <span style="color: #6c6;">&#40;</span>length arr<span style="color: #6c6;">&#41;</span> - <span style="color: #c6c;">1</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> initial_i = heap_size div <span style="color: #c6c;">2</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; build_max_heap_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, initial_i<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* A recursive heap_sort implementation taking a list, an initial index, and a<br />
&nbsp;* heap size for the given list.&nbsp; Requires a comparison function to compare<br />
&nbsp;* elements in the given list. *)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> heap_sort_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, <span style="color: #c6c;">1</span>, heap_size<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Max heapify the list at root 0 after swapping the values at indices 0 and<br />
&nbsp; &nbsp; &nbsp;* 1 in the given list. *)</span><br />
&nbsp; &nbsp; max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, swap <span style="color: #6c6;">&#40;</span>arr, <span style="color: #c6c;">0</span>, <span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span>, <span style="color: #c6c;">0</span>, heap_size<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span><br />
&nbsp; | heap_sort_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr, i, heap_size<span style="color: #6c6;">&#41;</span> =<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Decrement the heap size we're looking at by 1 each time *)</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> dec_heap_size = heap_size<span style="color: #c6c;">-1</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">(* Swap the values at indices 0 and i, then recursively heap_sort the<br />
&nbsp; &nbsp; &nbsp; &nbsp;* modified list by looking at the next value for i and looking at a<br />
&nbsp; &nbsp; &nbsp; &nbsp;* smaller heap *)</span><br />
&nbsp; &nbsp; &nbsp; heap_sort_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, max_heapify_w_size <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, swap <span style="color: #6c6;">&#40;</span>arr, <span style="color: #c6c;">0</span>, i<span style="color: #6c6;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c6c;">0</span>, dec_heap_size<span style="color: #6c6;">&#41;</span>, i<span style="color: #c6c;">-1</span>, dec_heap_size<span style="color: #6c6;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Convenience function for sorting a given list with heap_sort.&nbsp; Makes use of<br />
&nbsp;* heap_sort_rec by passing in an initial index and initial heap size.<br />
&nbsp;* Initially converts the given list into a max heap, which is necessary for<br />
&nbsp;* heap_sort.&nbsp; Requires a comparison function for comparing the elements in the<br />
&nbsp;* given list.<br />
&nbsp;*)</span><br />
<span style="color: #06c; font-weight: bold;">fun</span> heap_sort <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr<span style="color: #6c6;">&#41;</span> = <br />
&nbsp; <span style="color: #06c; font-weight: bold;">let</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> heap_size = <span style="color: #6c6;">&#40;</span>length arr<span style="color: #6c6;">&#41;</span> - <span style="color: #c6c;">1</span><br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">val</span> max_heap = build_max_heap <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, arr<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">in</span><br />
&nbsp; &nbsp; heap_sort_rec <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALcompare"><span style="">compare</span></a>, max_heap, heap_size, heap_size<span style="color: #6c6;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">end</span>;</p>
<p><span style="color: #5d478b; font-style: italic;">(* Example unsorted lists and the results of heap-sorting them.&nbsp; I don't print<br />
&nbsp;* these out because mosml shows the results when you run this file. *)</span><br />
print <span style="color: #3cb371;">&quot;Sorting integers:\n&quot;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #c6c;">16</span>, <span style="color: #c6c;">4</span>, <span style="color: #c6c;">10</span>, <span style="color: #c6c;">14</span>, <span style="color: #c6c;">7</span>, <span style="color: #c6c;">9</span>, <span style="color: #c6c;">3</span>, <span style="color: #c6c;">2</span>, <span style="color: #c6c;">8</span>, <span style="color: #c6c;">1</span><span style="color: #6c6;">&#93;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>int_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #c6c;">5</span>, <span style="color: #c6c;">4</span>, <span style="color: #c6c;">3</span>, <span style="color: #c6c;">2</span>, <span style="color: #c6c;">1</span>, <span style="color: #c6c;">0</span>, ~<span style="color: #c6c;">1</span>, ~<span style="color: #c6c;">2</span>, ~<span style="color: #c6c;">3</span>, ~<span style="color: #c6c;">4</span>, ~<span style="color: #c6c;">5</span><span style="color: #6c6;">&#93;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>int_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p>print <span style="color: #3cb371;">&quot;Sorting strings:\n&quot;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #3cb371;">&quot;my&quot;</span>, <span style="color: #3cb371;">&quot;mother&quot;</span>, <span style="color: #3cb371;">&quot;told&quot;</span>, <span style="color: #3cb371;">&quot;me&quot;</span>, <span style="color: #3cb371;">&quot;to&quot;</span>, <span style="color: #3cb371;">&quot;pick&quot;</span>, <span style="color: #3cb371;">&quot;the&quot;</span>, <span style="color: #3cb371;">&quot;very&quot;</span><span style="color: #6c6;">&#93;</span><br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>str_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p><span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #3cb371;">&quot;best&quot;</span>, <span style="color: #3cb371;">&quot;one&quot;</span>, <span style="color: #3cb371;">&quot;and&quot;</span>, <span style="color: #3cb371;">&quot;you&quot;</span>, <span style="color: #3cb371;">&quot;are&quot;</span>, <span style="color: #3cb371;">&quot;not&quot;</span>, <span style="color: #3cb371;">&quot;not&quot;</span>, <span style="color: #3cb371;">&quot;it&quot;</span><span style="color: #6c6;">&#93;</span><br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>str_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p>print <span style="color: #3cb371;">&quot;Sorting Booleans:\n&quot;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #06c; font-weight: bold;">false</span>, <span style="color: #06c; font-weight: bold;">true</span><span style="color: #6c6;">&#93;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>bool_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p>print <span style="color: #3cb371;">&quot;Sorting characters:\n&quot;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span>#<span style="color: #3cb371;">&quot;z&quot;</span>, #<span style="color: #3cb371;">&quot;k&quot;</span>, #<span style="color: #3cb371;">&quot;b&quot;</span>, #<span style="color: #3cb371;">&quot;c&quot;</span>, #<span style="color: #3cb371;">&quot;f&quot;</span><span style="color: #6c6;">&#93;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>char_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</p>
<p>print <span style="color: #3cb371;">&quot;Sorting reals:\n&quot;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> unsorted_list = <span style="color: #6c6;">&#91;</span><span style="color: #c6c;">1.3</span>, ~<span style="color: #c6c;">0.225</span>, <span style="color: #c6c;">3.1415</span>, <span style="color: #c6c;">87.5</span><span style="color: #6c6;">&#93;</span>;<br />
<span style="color: #06c; font-weight: bold;">val</span> sorted = heap_sort <span style="color: #6c6;">&#40;</span>real_compare, unsorted_list<span style="color: #6c6;">&#41;</span>;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/12/23/heap-sort-in-ml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>inflexible Adobe</title>
		<link>http://www.3till7.net/2009/12/08/inflexible-adobe/</link>
		<comments>http://www.3till7.net/2009/12/08/inflexible-adobe/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 20:49:47 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Techy]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[shopping]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3740</guid>
		<description><![CDATA[Wow, Adobe doesn&#8217;t make things convenient for you.  I just called about their $199 offer for Photoshop CS4 for students, hoping that I could use it on my Mac or in Windows and perhaps be restricted to using only one at a time, but no.  I can download it for Mac or Windows, [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, Adobe doesn&#8217;t make things convenient for you.  I just called about their $199 offer for Photoshop CS4 for students, hoping that I could use it on my Mac or in Windows and perhaps be restricted to using only one at a time, but no.  I can download it for Mac <em>or</em> Windows, but I can&#8217;t have both.  I don&#8217;t even have the option of buying a second license (not that I would want to do that, because $199 is a lot to begin with) because with the student edition, you&#8217;re only allowed one license.  Honestly, what do they care which operating system I use it on?  It seems like they could do some kind of check to ensure the registration key is not currently active on some other computer at the time, allowing me to work on either my Mac laptop or my Windows desktop PC.  I paid once for <a href="http://www.artrage.com/">ArtRage</a> and now have the option to install it in Windows or Mac using one license.</p>
<p>Another question I had was if I had to pay the $199 all at once or if they offered some kind of installment plan.  I just figured a big company like Adobe would offer such conveniences, considering that Apple and other companies do.  Hell, I can buy an iMac for $28/month, and its total cost is <em>way</em> more than the student Photoshop at $199.  *rolls eyes*  Way to be inflexible and lose a sale, Adobe.  Guess I&#8217;ll continue with <a href="http://www.gimp.org/">GIMP</a> and ArtRage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/12/08/inflexible-adobe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sims 3 World Adventures arrived</title>
		<link>http://www.3till7.net/2009/11/17/sims-3-world-adventures-arrived/</link>
		<comments>http://www.3till7.net/2009/11/17/sims-3-world-adventures-arrived/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 20:54:10 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Video games]]></category>
		<category><![CDATA[Sims]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3116</guid>
		<description><![CDATA[Whoo, The Sims 3:  World Adventures arrived today!  I had preordered it on EA&#8217;s site but was dubious about it 1) arriving the day it was released (i.e. today) and 2) actually being left on my doorstep/mailbox versus being stashed in some package center for me to go and pick up with my [...]]]></description>
			<content:encoded><![CDATA[<p>Whoo, <a href="http://en.wikipedia.org/wiki/The_Sims_3:_World_Adventures">The Sims 3:  World Adventures</a> arrived today!  I had preordered it on EA&#8217;s site but was dubious about it 1) arriving the day it was released (i.e. today) and 2) actually being left on my doorstep/mailbox versus being stashed in some package center for me to go and pick up with my little paper slip in hand.  EA and UPS teamed up to make me happy, though, and I found the package left by my door this afternoon.  Yay, no driving across town to pick it up myself from UPS or FedEx!</p>
<p>I got it installed with no trouble, though it took a while (maybe 10-15 minutes).  There was a little silliness when I went to run it, surprisingly.  I thought &#8220;do I run the usual Sims 3, or should I run the specific Sims 3 World Adventures program?&#8221;.  Well, so I tried running the World Adventures launcher, and it prompted me to update with a game patch.  Already?  Fine fine, go ahead.  So I got that installed and it shut down my launcher.  Whatevs, I figured I&#8217;d try opening the regular Sims 3 launcher this time.  So I did, and it prompted me for an update&#8230;  Wait, didn&#8217;t it just do this?  Seems like the right hand doesn&#8217;t know what the left is doing.  I was concerned that it would somehow be undoing whatever the World Adventures update had just done.  When it finished installing, I opened the World Adventures launcher to have it <em>bing!</em> at me and say it couldn&#8217;t do anything with the Sims 3 because some other Sims 3 thing was already open.  Er&#8230;  So I closed that and opened&#8230;  Well, I can&#8217;t remember which one I opened next, but I opened one of the two launchers and started playing the game.  *shrug*</p>
<p>Though I&#8217;ve been playing with one family for some time, all its members are old and near death (and actually they live with three ghosts currently; how&#8217;s that for foreshadowing?) and it just doesn&#8217;t seem right to drag them out to a desert or to learn martial arts when really they should be relaxing at home growing Death Flower Bushes, just in case.  So I made a new family and got to try out some of the new traits.  I have a girl that&#8217;s Adventurous, Snobby, a Natural Cook, and she just happens to be dressed in the Sims&#8217; version of Parisian attire.  I made a husband for her that&#8217;s <a href="http://alllooksame.com/">some kind of Asian</a>, and he&#8217;s Disciplined and Brave, and I plan to martial arts it up with him.  Sooo, now I&#8217;m building a house for them with a nice basement for storing Nectar (way to skirt that higher ESRB rating, Maxis!).  I&#8217;m tickled with the fact that basements are finally an easy thing to make in the Sims, since always before you had to manually dig in the ground to a certain depth and it was always a bit wonky.  I&#8217;ll be sure to post some screenshots once I have my Sims doing craaaazy foreign and adventurous things.  I was pleased to note that the guide for World Adventures noted highly skilled martial artists will be able to teleport, as in The Sims 2 Bon Voyage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/11/17/sims-3-world-adventures-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PC hard drive dying</title>
		<link>http://www.3till7.net/2009/11/08/pc-hard-drive-dying/</link>
		<comments>http://www.3till7.net/2009/11/08/pc-hard-drive-dying/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 17:02:14 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Video games]]></category>
		<category><![CDATA[boyfriend]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[Sims]]></category>
		<category><![CDATA[video games]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3078</guid>
		<description><![CDATA[I don&#8217;t know if I blogged about it, but I certainly complained on Twitter about my Macbook hard drive eating itself at the beginning of the semester.  Well, just this morning my Windows hard drive in my PC started acting up.  When I booted the computer, I got a &#8220;DISK READ ERROR INSERT [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if I blogged about it, but I certainly complained on Twitter about my Macbook hard drive eating itself at the beginning of the semester.  Well, just this morning my Windows hard drive in my PC started acting up.  When I booted the computer, I got a &#8220;DISK READ ERROR INSERT SYSTEM DISC&#8221; message.  I unplugged and replugged my hard drive, both data and power, and it booted.  However, when burning a backup CD of some Sims 3 data, it crashed.  Jon unplugged and replugged the hard drive and it booted again afterward.  I played The Sims 3 for a while as a test and it was fine for maybe half an hour, but it crashed again, first to desktop and then I got the Blue Screen of Death.  (In Windows 7, no less!)  Jon&#8217;s poking around in there now, trying out a different hard drive cable (it&#8217;s an old, old IDE hard drive that I wouldn&#8217;t mind replacing) and unplugging/replugging from the motherboard instead of just the back of the hard drive.  If this doesn&#8217;t work, I think we&#8217;ll go to Best Buy today and get me a new, fast SATA drive because, seriously, I don&#8217;t know how old this 70GB IDE is, I just know I&#8217;ve had it forever as my Windows drive.</p>
<p><strong>Update:</strong>  Jon switched out the IDE cable for the one that was hooked to my CDROM drive, so I can&#8217;t currently use my CDROM drive but the hard drive so far has been fine.  He plugged it into a different port on the motherboard, so I don&#8217;t know yet if the problem is 1) the hard drive, 2) the port on the motherboard, or 3) the first IDE cable.  I&#8217;ve been playing The Sims 3 and nothing has crashed or acted up, so maybe it was the motherboard port or the IDE cable, and my hard drive is actually fine.</p>
<p>Here&#8217;s what I&#8217;ve been doing with my Sims:</p>
<div class="photo" style="width:500px"><a href="http://www.flickr.com/photos/cheshire137/4086885886/"><img src="http://farm3.static.flickr.com/2612/4086885886_d223ed9cb3.jpg" alt="ghost Sim" width="500" height="312" /></a><br />
Right, so one of my [normal, living] Sims got an Opportunity to take the remains of a loved one to the science lab so they could be brought back to life. I didn&#8217;t have any dead loved ones, so I had my other Sim, a kleptomaniac, go steal something from the graveyard. What she stole was Vernon Carpenter&#8217;s remains. So my first Sim took them to the science lab, but the experiment didn&#8217;t go fully as planned, and I ended up with Vernon Carpenter as a ghost, but part of my family. He&#8217;s completely controllable and is just another family member. I designed for him this snazzy bedroom shown here.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/11/08/pc-hard-drive-dying/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the wily C# shuffle</title>
		<link>http://www.3till7.net/2009/11/07/the-wily-c-shuffle/</link>
		<comments>http://www.3till7.net/2009/11/07/the-wily-c-shuffle/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 16:46:40 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Class]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[academia]]></category>
		<category><![CDATA[C-sharp]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3074</guid>
		<description><![CDATA[My programming languages professor is quite the wily one.  For our last programming assignment in there, we&#8217;re to write a fraction class in both Java and Smalltalk, as part of our coverage of object-oriented languages.  I asked if I could do C# and Smalltalk, since I really like C# and, darn it, everyone [...]]]></description>
			<content:encoded><![CDATA[<p>My programming languages professor is quite the wily one.  For our last programming assignment in there, we&#8217;re to write a fraction class in both Java and Smalltalk, as part of our coverage of object-oriented languages.  I asked if I could do C# and Smalltalk, since I really like C# and, darn it, everyone says they&#8217;re pretty much the same language.  For my professor&#8217;s purposes, i.e. teaching us different OO styles, substituting C# in for Java should accomplish the same purpose.  (&#8220;Accomplish the same purpose&#8221; sounds weird to me now, but &#8220;accomplish the same effect&#8221; did, too.  Suggestions on rephrasing?)  I sent him a list via email of all the reasons he should let me write it in C#, including:</p>
<ol>
<li>The Ph. D. student we had as a substitute mentioned that my professor is his advisor, the student is doing C# stuff, and my professor is not all that familar with C#.  This would give my professor more experience with it, and in a case where he already knows what the expected result of the program is.</li>
<li>The same Ph. D. student pointed out that if you know C++ and you know Java (which my professor certainly does), you can read C# fine.</li>
<li>You can use Mono in Linux to run C#&#8211;there&#8217;s no need to have .NET or use Windows.  This point stems from the fact that my prof is a big Linux person and either dislikes Windows/Microsoft or perhaps just GUI interfaces&#8230;  He has brought his laptop to class before to show code examples and he&#8217;s so hardcore that his window manager, <a href="http://www.fvwm.org/">fvwm2</a>, doesn&#8217;t even have <em>title bars</em> on the windows, by his configuration, so to move a window you have to hold down some key combination and drag it with the mouse.</li>
<li>For our first program, he let me work in Ruby instead of Python.  Ruby is to Python as C# is to Java.</li>
<li>Recently on <a href="http://stackoverflow.com">StackOverflow</a>, I was reading someone&#8217;s response about learning a new programming language, and I thought he had a good point.  He said that if you already know Java, there&#8217;s not much point in learning C#, but instead perhaps learn ML or C because those are different kinds of languages.  If this programming project is intended to teach us about object-oriented programming, then it doesn&#8217;t seem like it would matter whether we wrote in Java or C# because they&#8217;re so similar.</li>
</ol>
<p>He told me in class he had been considering my request, but had decided that since I code in C# all day at work, it wouldn&#8217;t be helpful for me to write the assignment in C#, too, so I should do it in Java since I&#8217;ve barely worked in Java before.  Then he went on to say that anyone else, however, that isn&#8217;t familiar with C# can use that over Java.  My classmates started laughing and I had to say &#8220;Damnit, that&#8217;s not what I intended at all!&#8221;  Grumble grumble.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/11/07/the-wily-c-shuffle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RAM installed</title>
		<link>http://www.3till7.net/2009/10/21/ram-installed/</link>
		<comments>http://www.3till7.net/2009/10/21/ram-installed/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 21:01:41 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Techy]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3034</guid>
		<description><![CDATA[Whoo, got my 2GB of RAM yesterday and got it installed.  Now to enjoy my 4GB RAM (3GB usable&#8211;thanks Windows 7 32-bit) to play The Sims 3.
Also, having your apartment building&#8217;s roof replaced sucks.  I think they&#8217;re dancing up there.
]]></description>
			<content:encoded><![CDATA[<p>Whoo, got my 2GB of RAM yesterday and got it installed.  Now to enjoy my 4GB RAM (3GB usable&#8211;thanks Windows 7 32-bit) to play The Sims 3.</p>
<p>Also, having your apartment building&#8217;s roof replaced sucks.  I think they&#8217;re dancing up there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/10/21/ram-installed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>stupid Adobe pop-up</title>
		<link>http://www.3till7.net/2009/10/13/stupid-adobe-pop-up/</link>
		<comments>http://www.3till7.net/2009/10/13/stupid-adobe-pop-up/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 19:29:47 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Techy]]></category>
		<category><![CDATA[screenshots]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=3002</guid>
		<description><![CDATA[Adobe Reader, I heart your verbosity:

]]></description>
			<content:encoded><![CDATA[<p>Adobe Reader, I heart your verbosity:</p>
<p><a href="/wp-content/uploads/2009/10/reader_blank_scr.png"><img src="/wp-content/uploads/2009/10/reader_blank_scr-300x103.png" alt="Adobe Reader blank message" title="Adobe Reader blank message" width="300" height="103" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/10/13/stupid-adobe-pop-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grub Error 13 and 17 together</title>
		<link>http://www.3till7.net/2009/10/12/grub-error-13-and-17-together/</link>
		<comments>http://www.3till7.net/2009/10/12/grub-error-13-and-17-together/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 00:24:47 +0000</pubDate>
		<dc:creator>Sarah</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Grub]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.3till7.net/?p=2991</guid>
		<description><![CDATA[I just encountered a Grub Error 13 and a Grub Error 17 all for seemingly no reason.  I fixed the problem, but thought I could save others undue headache.
The Setup
I have Ubuntu Linux installed on one hard drive which fdisk calls /dev/hda and Windows XP installed on a second hard drive called /dev/hdb.  [...]]]></description>
			<content:encoded><![CDATA[<p>I just encountered a Grub Error 13 and a Grub Error 17 all for seemingly no reason.  I fixed the problem, but thought I could save others undue headache.</p>
<h2>The Setup</h2>
<p>I have Ubuntu Linux installed on one hard drive which <code>fdisk</code> calls <code>/dev/hda</code> and Windows XP installed on a second hard drive called <code>/dev/hdb</code>.  To Grub, the mapping is as follows:</p>
<ul>
<li><code>/dev/hda1</code> = <code>(hd0, 0)</code></li>
<li><code>/dev/hdb1</code> = <code>(hd1, 0)</code></li>
</ul>
<p>This works because my BIOS agrees on this mapping.</p>
<h2>The Mistake</h2>
<p>After shutting down my computer, I unplugged <em>only</em> my Linux drive, which both my BIOS and Grub agreed was the main/first/primary drive, hoping I would somehow still be able to boot into Windows even though Grub is on my Linux drive.  Alas, that didn&#8217;t work and I got some kind of &#8220;Grub configuration error&#8221; screen without seeing my Grub boot menu.  I figured &#8220;oh well, I&#8217;ll just plug my Linux drive back in and boot into Windows&#8221;.</p>
<p>I shut down my computer, plugged my Linux drive back in, and powered on the computer.  The Grub boot menu loaded again, as expected.  When I tried to boot into Windows, however, it gave me a Grub Error 13.  This was weird, since I hadn&#8217;t done anything to the Grub configuration.  Exiting back to the Grub boot menu, I tried to load Linux.  No luck, but this time it gave me a Grub Error 17.  I tried following <a href="/2007/10/25/grub-error-17/">my own tutorial about error 17</a>, but <code>fdisk</code> reported that <code>/dev/hda1</code> was a Linux partition, as it should.  What was going on?</p>
<h2>The Explanation</h2>
<p>Reading on the <a href="http://ubuntuforums.org/showthread.php?t=442945">Ubuntu Forums</a>, <a href="http://ubuntuforums.org/member.php?u=31200">mbwardle</a> wrote the following:</p>
<blockquote cite="mbwardle"><p>The error usually happens because Linux and your BIOS detect your hard disks in different orders. GRUB tries to translate between the two using the device.map file in /boot/grub/device.map, which is automatically generated. Chances are, it guessed wrong.</p>
<p>In my case, I have three SATA hard disks.</p>
<p>My BIOS sees them as:<br />
HDD1 &#8211; 80 GB &#8211; Windows<br />
HDD2 &#8211; 80 GB &#8211; Linux<br />
HDD3 &#8211; 250 GB &#8211; Media</p>
<p>Linux sees them as:<br />
/dev/sda &#8211; 80 GB &#8211; Windows<br />
/dev/sdb &#8211; 250 GB &#8211; Media<br />
/dev/sdc &#8211; 80 GB &#8211; Linux<br />
&mdash; <a href="http://ubuntuforums.org/showthread.php?t=442945">mbwardle</a></p></blockquote>
<p>Aha, your BIOS and Grub are not necessarily talking about the same thing!  This was what happened in my case.  When I unplugged the Linux drive (which Grub and my BIOS thought of as the first drive) and left only the Windows drive (which Grub and my BIOS thought of as the second drive), I was left with only the second drive, but my BIOS started thinking of that as the <em>first</em> drive since that was the only drive plugged in.  Then when I plugged the Linux drive back in, it was thought of as the second drive.  Just because my BIOS changed the order, though, doesn&#8217;t mean Grub did:  it still thought of Linux as #1 and Windows as #2.</p>
<h2>The Solution</h2>
<p>I shut down my computer, unplugged the Windows drive (the one Grub thinks of as #2), and left the Linux drive (the one Grub thinks of as #1) plugged in.  I started my computer, thus making my BIOS think of the Linux drive as #1 again.  I was able to boot Linux just fine from the Grub boot screen, though of course Windows was inaccessible because the drive was unplugged.</p>
<p>I shut down my computer again, plugged the Windows drive back in, and kept the Linux drive plugged in too.  I started my computer, and then the BIOS saw the Windows drive and began thinking of it as #2, just like Grub does.  Now I can boot both Windows and Linux because, once again, Grub and my BIOS agree about what order the drives are in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.3till7.net/2009/10/12/grub-error-13-and-17-together/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
