<?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>Tech Notes &#187; Examples</title>
	<atom:link href="http://www.ryannitz.org/tech-notes/category/examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryannitz.org/tech-notes</link>
	<description>Miscellaneous technology examples and notes</description>
	<lastBuildDate>Mon, 10 Aug 2009 18:29:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.ryannitz.org/tech-notes</link>
  <url>http://ryan-nitz/favicon.ico</url>
  <title>Tech Notes</title>
</image>
		<item>
		<title>MongoDB Wildcard Query</title>
		<link>http://www.ryannitz.org/tech-notes/2009/08/10/mongodb-wildcard-query/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/08/10/mongodb-wildcard-query/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 18:29:58 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://ryan-nitz.com/tech-notes/?p=211</guid>
		<description><![CDATA[MongoDB uses regex in certain parts of their query syntax. The following is an example of how to perform a wildcard query: db.collectionName.find( { fieldName : /.*cnn.*/ } ); This example searches the collection for all documents with a field that contains, &#8220;%cnn%&#8221;. Of course in your query you need to replace &#8220;collectionName&#8221; with the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-189" title="icon" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2009/07/icon.png" alt="icon" width="42" height="42" /></p>
<p><a href="http://www.mongodb.org/" target="_blank">MongoDB</a> uses <a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">regex</a> in certain parts of their query syntax. The following is an example of how to perform a wildcard query:</p>
<pre>db.collectionName.find( { fieldName : /.*cnn.*/ } );</pre>
<p>This example searches the collection for all documents with a field that contains, &#8220;%cnn%&#8221;. Of course in your query you need to replace &#8220;collectionName&#8221; with the name of your collection and &#8220;fieldName&#8221; with the field you are interested in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/08/10/mongodb-wildcard-query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create Amazon EC2 AMI</title>
		<link>http://www.ryannitz.org/tech-notes/2009/08/09/create-amazon-ec2-ami/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/08/09/create-amazon-ec2-ami/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:36:10 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[EC2]]></category>

		<guid isPermaLink="false">http://ryan-nitz.com/tech-notes/?p=202</guid>
		<description><![CDATA[Creating an Amazon EC2 AMI from an existing image seems like a challenging process however, it is actually fairly simple. Before looking at the steps to create the image, first have the following AWS information/files handy: Access key Secret Key Account Number Private key (e.g., pk-37BKCPZ2AVHVSYBK2WZXUQ9D4GQZEB4Q.pem) Certificate (e.g., cert-38BKCPZ1BOHVSYBK4WZXUQ4D4GQZEB2Q.pem) Next, login to your instance and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-92" title="aws" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2008/12/aws.gif" alt="aws" width="150" height="60" /></p>
<p>Creating an Amazon EC2 AMI from an existing image seems like a challenging process however, it is actually fairly simple. Before looking at the steps to create the image, first have the following AWS information/files handy:</p>
<ul>
<li>Access key</li>
<li>Secret Key</li>
<li>Account Number</li>
<li>Private key (e.g., pk-37BKCPZ2AVHVSYBK2WZXUQ9D4GQZEB4Q.pem)</li>
<li>Certificate (e.g., cert-38BKCPZ1BOHVSYBK4WZXUQ4D4GQZEB2Q.pem)</li>
</ul>
<p>Next, login to your instance and make sure you have the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368" target="_blank">Amazon AMI</a> and <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&amp;categoryID=88" target="_blank">EC2 API</a> tools installed and available in your PATH. Also, upload your private key and certificate to the server.</p>
<p>Now you are ready to create your image file. First create a directory to store this image in.</p>
<p>E.g.</p>
<pre>mkdir /mnt/ami</pre>
<p>The actual AMI bundle is created by running:</p>
<pre>ec2-bundle-vol -d /mnt/ami -k YOUR_PRIVATE_KEY -c YOUR_CERTIFICATE -u YOUR_ACCOUNT_NUMBER</pre>
<p><strong>note:</strong> The account number should not contain any dashes (&#8216;-&#8217;).</p>
<p>Creating the bundle takes a few minutes. After the bundle has been created, it is time to upload it to S3. This is done by running:</p>
<pre>ec2-upload-bundle -b YOUR_BUNDLE_NAME -m /mnt/ami/image.manifest.xml -a YOUR_ACCESS_KEY -s YOUR_SECRET_KEY</pre>
<p>This walks through the files generated by the bundle command and inserts them into S3.</p>
<p>After your files have been uploaded, it is time to register the AMI using the following command:</p>
<pre>ec2-register YOUR_BUNDLE_NAME/image.manifest.xml</pre>
<p>The result of running this command is your AMI id.</p>
<p>E.g.</p>
<pre>ami-323FEA</pre>
<p>Finally, your AMI has been created, uploaded and registered and you are able to launch a new instance of your AMI.</p>
<p>If you need more help, there is <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=938" target="_blank">a good video</a> available from an Amazon employee. Additionally, take a look at the <a href="http://docs.amazonwebservices.com/AmazonEC2/dg/2006-06-26/bundling-an-ami.html" target="_blank">Amazon docs</a> on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/08/09/create-amazon-ec2-ami/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB &#8211; Find Documents Missing Fields</title>
		<link>http://www.ryannitz.org/tech-notes/2009/07/29/monogodb-document-missing-field/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/07/29/monogodb-document-missing-field/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 17:59:10 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://ryan-nitz.com/tech-notes/?p=188</guid>
		<description><![CDATA[In MongoDB it is possible that some documents will not contain fields other documents have. The following code shows how to find these documents using the mongo shell. db.collectionName.find("function() { return this.fieldName == null }") db.collectionName.find("function() { return this.fieldName == null }").count() The second example shows how to only get the count. In this example. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-189" title="icon" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2009/07/icon.png" alt="icon" width="42" height="42" /></p>
<p>In <a href="http://www.mongodb.org/" target="_blank">MongoDB</a> it is possible that some documents will not contain fields other documents have. The following code shows how to find these documents using the mongo shell.</p>
<pre>db.collectionName.find("function() { return this.fieldName == null }")
db.collectionName.find("function() { return this.fieldName == null }").count()</pre>
<p>The second example shows how to only get the count. </p>
<p>In this example. you would replace &#8220;collectionName&#8221; with the name of the collection you are interested in querying. Additionally, you would change &#8220;fieldName&#8221; to the name of the field that interests you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/07/29/monogodb-document-missing-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash &#8211; Write A Sequential For Loop</title>
		<link>http://www.ryannitz.org/tech-notes/2009/03/30/bash-for-loop/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/03/30/bash-for-loop/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 02:10:36 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=156</guid>
		<description><![CDATA[A sequential for loop in bash script is accomplished in the following example: for i in {1..100} do # Do something here echo "${i}" done This example iterates from 1 to 100 (inclusive) and prints the index number. Note: This only works in modern versions of bash (3.x+).]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-157" title="bashterm" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2009/03/bashterm.png" alt="bashterm" width="180" height="100" /></p>
<p>A sequential <em>for</em> loop in bash script is accomplished in the following example:</p>
<pre>for i in {1..100}
do
    # Do something here
    echo "${i}"
done</pre>
<p>This example iterates from 1 to 100 (inclusive) and prints the index number.</p>
<p>Note: This only works in modern versions of <a href="http://en.wikipedia.org/wiki/Bash" target="_blank">bash</a> (3.x+).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/03/30/bash-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OS X &#8211; Empty Trash Command Line</title>
		<link>http://www.ryannitz.org/tech-notes/2009/03/23/os-x-empty-trash-command-line/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/03/23/os-x-empty-trash-command-line/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 13:35:10 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=152</guid>
		<description><![CDATA[It is possible to empty the trash in OS X from the command line by running the following command in the terminal: rm -Rf ~/.Trash/* This command permanently removes all the files you have placed in your OS X trash bin.]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-153" title="apple-logo" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2009/03/apple-logo.jpg" alt="apple-logo" width="80" height="93" /></p>
<p>It is possible to empty the trash in OS X from the command line by running the following command in the terminal:</p>
<pre>rm -Rf ~/.Trash/*</pre>
<p>This command <em>permanently</em> removes all the files you have placed in your OS X trash bin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/03/23/os-x-empty-trash-command-line/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash Find On A Large Dataset &#8211; Write The Results To A File</title>
		<link>http://www.ryannitz.org/tech-notes/2009/03/14/bash-find-dataset-write-file/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/03/14/bash-find-dataset-write-file/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 18:20:26 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Find]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=148</guid>
		<description><![CDATA[A fast bash based solution for executing a find on a directory with a lot of files that you want to log to a file: find /my/data/  -name '*.xml' -type f -fprint my_xml_files.txt This example looks in the /my/data/ directory for all files with the xml extension and then writes the results to the my_xml_files.txt [...]]]></description>
			<content:encoded><![CDATA[<p>A fast <a href="http://en.wikipedia.org/wiki/Bash" target="_blank">bash</a> based solution for executing a <a href="http://www.gnu.org/software/findutils/" target="_blank">find</a> on a directory with a lot of files that you want to log to a file:</p>
<pre>find /my/data/  -name '*.xml' -type f -fprint my_xml_files.txt</pre>
<p>This example looks in the <em>/my/data/</em> directory for all files with the <em>xml</em> extension and then writes the results to the <em>my_xml_files.txt</em> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/03/14/bash-find-dataset-write-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Wildcard Query</title>
		<link>http://www.ryannitz.org/tech-notes/2009/02/03/hibernate-wildcard-query/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/02/03/hibernate-wildcard-query/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 02:28:36 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=131</guid>
		<description><![CDATA[Creating a wildcard query in Hibernate (HQL) is similar to how SQL handles the same funciton. The query is accomplished by using the, like keyword. The example below searches for people with a name that contains Mik &#8211; an obvious match would be Mike. Query query = getEntityManager().createQuery("SELECT p FROM Person p WHERE p.name like [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-16" title="hibernate_icon" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2008/06/hibernate_icon.gif" alt="hibernate_icon" width="120" height="120" /></p>
<p>Creating a wildcard query in Hibernate (HQL) is similar to how SQL handles the same funciton. The query is accomplished by using the, <em>like</em> keyword.</p>
<p>The example below searches for people with a name that contains <em>Mik</em> &#8211; an obvious match would be <em>Mike</em>.</p>
<pre>Query query
= getEntityManager().createQuery("SELECT p FROM Person p WHERE p.name like :name");
 query.setParameter("name", 'Mik");
 query.getResultList(); // Returns a list of People.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/02/03/hibernate-wildcard-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Not A Number Gotcha</title>
		<link>http://www.ryannitz.org/tech-notes/2009/01/25/java-not-a-number-gotcha/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/01/25/java-not-a-number-gotcha/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 16:06:38 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=122</guid>
		<description><![CDATA[There are always subtle nuances to every computer language. Recently, I found the following NaN (not a number) nuance in Java: Bad: if (value == Double.NaN)     // Do something... Good: if (Double.isNaN(value))     // Do something....]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-124" title="java" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2009/01/java.jpg" alt="java" width="150" height="150" /></p>
<p>There are always subtle nuances to every computer language. Recently, I found the following NaN (not a number) nuance in Java:</p>
<p><strong>Bad:</strong></p>
<pre>if (value == Double.NaN)
    // Do something...</pre>
<p><strong>Good:</strong></p>
<pre>if (Double.isNaN(value))

    // Do something....</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/01/25/java-not-a-number-gotcha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL and Negative Infinity</title>
		<link>http://www.ryannitz.org/tech-notes/2009/01/19/mysql-and-negative-infinity/</link>
		<comments>http://www.ryannitz.org/tech-notes/2009/01/19/mysql-and-negative-infinity/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 02:12:09 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=118</guid>
		<description><![CDATA[Storing and retrieving negative infinity in a MySQL database is accomplished by inserting an arbitrarily large negative number.  Negative infinity is handy when storing default values in a database. The following SQL statement is an example of inserting negative infinity: INSERT INTO test(negative_infinity) VALUES('-1e500'); Here is the test table: CREATE TABLE test (      negative_infinity [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-15" title="mysql" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2008/06/mysql.jpeg" alt="mysql" width="124" height="90" /></p>
<p>Storing and retrieving <a href="http://en.wiktionary.org/wiki/infinity" target="_blank">negative infinity</a> in a MySQL database is accomplished by inserting an arbitrarily large negative number.  Negative infinity is handy when storing default values in a database.</p>
<p>The following SQL statement is an example of inserting negative infinity:</p>
<pre>INSERT INTO test(negative_infinity) VALUES('-1e500');</pre>
<p>Here is the test table:</p>
<pre>CREATE TABLE test (
     negative_infinity DOUBLE NOT NULL
) ENGINE=INNODB character set utf8;</pre>
<p>The value in the database is stored as the maximum negative value for the data type, double (-1.79769313486232e+308).</p>
<pre>mysql&gt; select * from test;
+------------------------+
| negative_infinity      |
+------------------------+
| -1.79769313486232e+308 |
+------------------------+
1 row in set (0.00 sec)</pre>
<p>In Java, the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html" target="_blank">Double contsant</a> for max infinity, directly correlates to the value stored by MySQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2009/01/19/mysql-and-negative-infinity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Create XML Document</title>
		<link>http://www.ryannitz.org/tech-notes/2008/12/30/python-create-xml-document/</link>
		<comments>http://www.ryannitz.org/tech-notes/2008/12/30/python-create-xml-document/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 16:51:26 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://leisuremech.com/?p=109</guid>
		<description><![CDATA[Creating an XML document in Python can be accomplished by executing: from xml.dom import minidom doc = minidom.Document() testElem = doc.createElement("test") testElem.setAttribute('id', '1234') doc.appendChild(testElem) print doc.toxml() The  example above creates an XML document, creates a child element, sets an attribute and then appends the child element to the document. The XML document in the above [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-107" title="python_logo2" src="http://ryan-nitz.com/tech-notes/wp-content/uploads/2008/12/python_logo2.png" alt="python_logo2" width="188" height="60" /></p>
<p>Creating an XML document in Python can be accomplished by executing:</p>
<pre>from xml.dom import minidom
doc = minidom.Document()
testElem = doc.createElement("test")
testElem.setAttribute('id', '1234')
doc.appendChild(testElem)
print doc.toxml()</pre>
<p>The  example above creates an XML document, creates a child element, sets an attribute and then appends the child element to the document.</p>
<p>The XML document in the above example looks like:</p>
<pre>&lt;?xml version="1.0" ?&gt;&lt;test id="1234"/&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannitz.org/tech-notes/2008/12/30/python-create-xml-document/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
