<?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>the cosmotron &#187; howto</title>
	<atom:link href="http://thecosmotron.com/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecosmotron.com</link>
	<description>the blog of ryan lewis</description>
	<lastBuildDate>Mon, 14 Nov 2011 02:22:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Basic Emacs Tutorial</title>
		<link>http://thecosmotron.com/2009/04/25/basic-emacs/</link>
		<comments>http://thecosmotron.com/2009/04/25/basic-emacs/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 19:43:38 +0000</pubDate>
		<dc:creator>Ryan Lewis</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Planet COSI]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://thecosmotron.com/?p=146</guid>
		<description><![CDATA[In my last post, I wrote about how I had to write a guide to using a piece of software for a class. Well, I had to do another one, but this time it was individually rather than in a group. So, I wrote a guide on how to do some basic tasks in emacs. [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I wrote about how I had to write a guide to using a piece of software for a class.  Well, I had to do another one, but this time it was individually rather than in a group.</p>
<p>So, I wrote a <a href="http://thecosmotron.com/basic-emacs.html">guide on how to do some basic tasks in emacs</a>.</p>
<p>Let me know of any mistakes/improvements that you can think of in the comments!</p>
<p>P.S. I&#8217;m pretty fond of the mock terminal that I made with CSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecosmotron.com/2009/04/25/basic-emacs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fedora 10, Subversion, and WebSVN</title>
		<link>http://thecosmotron.com/2009/04/17/fedora-10-subversion-and-websvn/</link>
		<comments>http://thecosmotron.com/2009/04/17/fedora-10-subversion-and-websvn/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 04:59:21 +0000</pubDate>
		<dc:creator>Ryan Lewis</dc:creator>
				<category><![CDATA[Planet COSI]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://thecosmotron.com/?p=141</guid>
		<description><![CDATA[Justin and I recently wrote a guide to installing Subversion for a class that we&#8217;re taking. It&#8217;s a pretty simple process and we&#8217;ve tested it twice now, but if you try it and something it unclear/doesn&#8217;t work, let us know.]]></description>
			<content:encoded><![CDATA[<p><a href="http://jmbennett.org/">Justin</a> and I recently wrote a <a href="http://jmbennett.org/svn-setup/">guide to installing Subversion</a> for a class that we&#8217;re taking.  It&#8217;s a pretty simple process and we&#8217;ve tested it twice now, but if you try it and something it unclear/doesn&#8217;t work, let us know.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecosmotron.com/2009/04/17/fedora-10-subversion-and-websvn/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fix &#8220;Unexpected clusters per mft record (-127)&#8221;</title>
		<link>http://thecosmotron.com/2009/03/15/fix-unexpected-clusters-per-mft-record-127/</link>
		<comments>http://thecosmotron.com/2009/03/15/fix-unexpected-clusters-per-mft-record-127/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:44:07 +0000</pubDate>
		<dc:creator>Ryan Lewis</dc:creator>
				<category><![CDATA[Planet COSI]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mft]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[ntfs]]></category>
		<category><![CDATA[testdisk]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://thecosmotron.com/?p=132</guid>
		<description><![CDATA[I encountered this error yesterday after trying to fix some Windows bootloader issues in Ubuntu with ms-sys. Needless to say, I just created more issues and eventually couldn&#8217;t even mount my Windows partition from Ubuntu, as this would happen: # mount -t ntfs-3g -o force /dev/sda1 /mnt/win Unexpected clusters per mft record (-127). Failed to [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered this error yesterday after trying to fix some Windows bootloader issues in Ubuntu with <code>ms-sys</code>.  Needless to say, I just created more issues and eventually couldn&#8217;t even mount my Windows partition from Ubuntu, as this would happen:</p>
<pre>
# mount -t ntfs-3g -o force /dev/sda1 /mnt/win
Unexpected clusters per mft record (-127).
Failed to mount '/dev/sda1': Invalid argument
The device '/dev/sda1' doesn't have a valid NTFS.
</pre>
<p>I tried to recover it using a Windows XP disk, but that didn&#8217;t work because it wouldn&#8217;t recognize my <code>C:\WINDOWS</code> folder!  At this point, I was getting pretty worried.</p>
<p>So, back in Ubuntu, I do a bit more reading and find out about the <code>testdisk</code> command (<code>apt-get install testdisk</code>) and a nice <a href="http://ubuntuforums.org/showpost.php?p=6612068&#038;postcount=11">post about how to use it</a> on the Ubuntu forums.  To summarize, this is what I took out of that post to get <code>mount</code> to actually work after:</p>
<blockquote><p>
After starting testdisk, choose &#8220;No log&#8221;, choose the correct HDD and &#8220;Proceed&#8221;, choose &#8220;Intel&#8221;, choose &#8220;Advanced&#8221;, select the Windows partition, choose &#8220;Boot&#8221;, then choose &#8220;Rebuild BS&#8221;.</p>
<p>If testdisk gives you a warning that the &#8220;Extrapolated boot sector and current boot sector are different&#8221;, then choose &#8220;Write&#8221;.
</p></blockquote>
<p>Sure enough, something was messed and it was able to fix it after I selected &#8220;Write&#8221;.</p>
<p>After all this, <code>mount</code> worked, and when I rebooted, the Windows XP disk detected the installation and I was able to fix my MBR like I wanted.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecosmotron.com/2009/03/15/fix-unexpected-clusters-per-mft-record-127/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Basic CouchDB w/ PHP Tutorial</title>
		<link>http://thecosmotron.com/2008/08/11/basic-couchdb-w-php/</link>
		<comments>http://thecosmotron.com/2008/08/11/basic-couchdb-w-php/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 18:20:59 +0000</pubDate>
		<dc:creator>Ryan Lewis</dc:creator>
				<category><![CDATA[Planet COSI]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[couchdb]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://thecosmotron.com/?p=49</guid>
		<description><![CDATA[I mentioned CouchDB in my last post, but didn&#8217;t really elaborate on what it was. Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine [...]]]></description>
			<content:encoded><![CDATA[<p>I mentioned <a href="http://incubator.apache.org/couchdb/">CouchDB</a> in my last post, but didn&#8217;t really elaborate on what it was.</p>
<blockquote><p>Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language.</p></blockquote>
<p>I&#8217;m gonna show you some really basic ways to use CouchDB using a <a href='http://thecosmotron.com/wp-content/uploads/2008/08/CouchDB.php'>PHP class</a> found on their <a href="http://wiki.apache.org/couchdb/GettingStartedWithPhp">website</a> and assume that you have PHP 5.1 or greater and CouchDB 0.8 installed successfully.</p>
<p>The first thing that we need to do is create a sample database for us to play eventually play with using PHP.  To manage your databases and documents, you can use Futon, CouchDB&#8217;s administrative frontend.  It can be accessed at <a href="http://localhost:5984/_utils">http://localhost:5984/_utils</a>.  Create a database called &#8220;people&#8221; with two documents in it with random IDs that each have two fields in them: &#8220;name&#8221; and &#8220;age&#8221;.  Also, be sure to enter in some values for those.</p>
<p>Let&#8217;s look at this PHP file:</p>
<pre style="font-size:8pt; color:#005577;">
&lt;?php
include_once "CouchDB.php";

$couchdb = new CouchDB("people", "localhost");
$view = '{ "map": "function(doc) { emit(null, doc); }" }';

try {
  $all = $couchdb-&gt;send("/_temp_view", "post", $view)-&gt;getBody(true);
}
catch (CouchDBException $e) {
  die("[ERROR]".$e-&gt;getMessage()."\n");
}

foreach ($all-&gt;rows as $k =&gt; $row) {
  echo "Name: ".$row-&gt;value-&gt;name." / Age: ".$row-&gt;value-&gt;age."&lt;br/&gt;";
}
?&gt;</pre>
<p>This code is using a temporary view to query the database and then simply looping through the returned JSON and printing data from it.&nbsp; If you set up your database as I mentioned above, <code>$all</code> should be structured like this:</p>
<pre style="font-size:8pt; color:#005577;">
stdClass Object
(
  [total_rows] =&gt; 2
  [offset] =&gt; 0
  [rows] =&gt; Array
  (
    [0] =&gt; stdClass Object
    (
      [id] =&gt; 4144833052c61ab553875737b88ef91a
      [key] =&gt;
      [value] =&gt; stdClass Object
      (
        [_id] =&gt; 4144833052c61ab553875737b88ef91a
        [_rev] =&gt; 3595404992
        [name] =&gt; Ryan
        [age] =&gt; 20
      )
    )
    [1] =&gt; stdClass Object
    (
      [id] =&gt; ff3f20d54772b92aad43c36d6ed4abd1
      [key] =&gt;
      [value] =&gt; stdClass Object
      (
        [_id] =&gt; ff3f20d54772b92aad43c36d6ed4abd1
        [_rev] =&gt; 994830077
        [name] =&gt; Bob
        [age] =&gt; 40
      )
    )
  )
)</pre>
<p>When I visit the page running the script, it will therefore output this:</p>
<pre style="font-size:8pt; color:#005577;">
Name: Ryan / Age: 20
Name: Bob / Age: 40</pre>
<p>If anyone wants to see how to do something, just post a comment and I&#8217;ll try to whip something up.  Also, the <a href="http://wiki.apache.org/couchdb/FrontPage">CouchDB Wiki</a> has a lot more information if you&#8217;re interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecosmotron.com/2008/08/11/basic-couchdb-w-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic jQuery Form</title>
		<link>http://thecosmotron.com/2008/08/05/basic-jquery-form/</link>
		<comments>http://thecosmotron.com/2008/08/05/basic-jquery-form/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 18:25:50 +0000</pubDate>
		<dc:creator>Ryan Lewis</dc:creator>
				<category><![CDATA[Planet COSI]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://thecosmotron.com/?p=41</guid>
		<description><![CDATA[I have been working on a web project at work for the past month and used it as an opportunity to learn jQuery and CouchDB. jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. While learning it, I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a web project at work for the past month and used it as an opportunity to learn <a href="http://jquery.com/">jQuery</a> and <a href="http://incubator.apache.org/couchdb/">CouchDB</a>.</p>
<blockquote><p>jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages.</p></blockquote>
<p>While learning it, I found that there wasn&#8217;t a simple tutorial on how to make an ajax form, so here is one:</p>
<p>First, <a href="http://docs.jquery.com/Downloading_jQuery">download jQuery</a> from their website and rename the file to &#8220;jquery.js&#8221; (minus quotes).</p>
<p>Let&#8217;s create a file called form.html in the same folder as jquery.js:</p>
<pre style="font-size:8pt; color:#005577;">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Contact Form&lt;/title&gt;
    &lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
        $("#contact").submit(function(event) {
          event.preventDefault();
          $.ajax({
            type: "POST",
            url: "process_form.php",
            data: $(this).serialize(),
            success: function(html) {
              $("#info").html(html);
            },
            error: function() {
              alert("[ERROR] submit");
            }
          });
        });
      });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form id="contact" action="process_form.php" method="POST"&gt;
      Name &lt;input type="text" name="name" /&gt;&lt;br /&gt;&lt;br /&gt;
      Email &lt;input type="text" name="email" /&gt;&lt;br /&gt;
      Message &lt;textarea name="msg"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;

      &lt;input type="submit" name="submit" value="submit" /&gt;
    &lt;/form&gt;
    &lt;p id="info"&gt;&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Next, lets have a file called process_form.php, again in the same folder:</p>
<pre style="font-size:8pt; color:#005577;">&lt;?php
echo "Name: ".$_POST['name']."&lt;br /&gt;";
echo "Email: ".$_POST['email']."&lt;br /&gt;";
echo "Message: ".$_POST['msg'];
?&gt;
</pre>
<p>If you load up your pages via a working installation of a webserver with PHP installed, it should return what you entered into the form upon clicking submit. Now that it works, how about an explanation?</p>
<p>This is selecting the element with the id contact and binding to it&#8217;s submit event the proceeding function which is being passed event.data by jQuery</p>
<pre style="font-size:8pt; color:#005577;">$("#contact").submit(function(event) {</pre>
<p>Because event was passed to the function, we are now preventing the normal submit actions from being performed. So now when you click the submit button, the page wont refresh and the browser wont call the action script specified in the form tag.</p>
<pre style="font-size:8pt; color:#005577;">  event.preventDefault();</pre>
<p>This is how jQuery loads a page using HTTP request.  We specify that we want it use POST and the url to request.</p>
<pre style="font-size:8pt; color:#005577;">  $.ajax({
    type: "POST",
    url: "process_form.php",</pre>
<p>This is how we can send the data collected from the form to file being requested. <code>$(this)</code> is referring to the element with an id of contact and serialize is going to do just that: serialize the collected data into a string that can be sent in the request.</p>
<pre style="font-size:8pt; color:#005577;">    data: $(this).serialize(),</pre>
<p>This is the function to be called if the request succeeds. In our case, we are going to have it print all returned html into the element with id of info.</p>
<pre style="font-size:8pt; color:#005577;">    success: function(html) {
      $("#info").html(html);
    },</pre>
<p>This is called if the request fails for some reason.  In our case, an alert will pop up.</p>
<pre style="font-size:8pt; color:#005577;">    error: function() {
      alert("[ERROR] submit");
    }
  });
});</pre>
<p>That concludes this tutorial, if you want to read more about jQuery, there are <a href="http://docs.jquery.com/">tons of docs</a> on their official website.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecosmotron.com/2008/08/05/basic-jquery-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

