<?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>n3wt0n! &#187; General Programming</title>
	<atom:link href="http://n3wt0n.com/blog/category/general-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://n3wt0n.com/blog</link>
	<description>Student4Life</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:40:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Serialize and Deserialize series of strings</title>
		<link>http://n3wt0n.com/blog/serialize-and-deserialize-series-of-strings/</link>
		<comments>http://n3wt0n.com/blog/serialize-and-deserialize-series-of-strings/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 21:25:12 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=1029</guid>
		<description><![CDATA[Just a quick example of serializing and deserializing a series of strings. import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Arrays; import java.util.LinkedList; import java.util.List; public class GEncode { String serialize(List strings) throws UnsupportedEncodingException { String serialized = ""; for (String s : strings) { serialized += URLEncoder.encode(s, "UTF-8") + "&#38;"; } return serialized; } @SuppressWarnings("deprecation") [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick example of serializing and deserializing a series of strings.</p>
<pre>import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class GEncode {

	String serialize(List strings) throws UnsupportedEncodingException {
		String serialized = "";
		for (String s : strings) {
			serialized += URLEncoder.encode(s, "UTF-8") + "&amp;";
		}
		return serialized;
	}

	@SuppressWarnings("deprecation")
	List deserialize(String serialized) {
		String[] strings = serialized.split("&amp;");
		for (int i = 0; i &lt; strings.length; i++) {
			strings[i] = URLDecoder.decode(strings[i]);
		}
		List list = Arrays.asList(strings);
		return list;
	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		List strings = new LinkedList();
		strings.add("Old &amp; New");
		strings.add("Once upon a time!");
		strings.add("Yes, there is a monster in the closet");
		strings.add("Another string? Why, I don't mind if I do!");
		strings.add("She said \"Yes\"");

		for (String s : strings) {
			System.out.println (s);
		}

		GEncode g = new GEncode();
		String s = g.serialize(strings);

		System.out.println ("\nSerialized:\n" + s + "\n\nDeserialized:");

		List newStrings = g.deserialize(s);

		int i = 1;
		for (String ns : newStrings) {
			System.out.println (i + ": " + ns);
			i++;
		}
	}
}</pre>
<p>Output:</p>
<pre>Old &amp; New
Once upon a time!
Yes, there is a monster in the closet
Another string? Why, I don't mind if I do!
She said "Yes"

Serialized:
Old+%26+New&amp;Once+upon+a+time%21&amp;Yes%2C+there+is+a+monster+in+the+closet&amp;Another+string%3F+Why%2C+I+don%27t+mind+if+I+do%21&amp;She+said+%22Yes%22&amp;

Deserialized:
1: Old &amp; New
2: Once upon a time!
3: Yes, there is a monster in the closet
4: Another string? Why, I don't mind if I do!
5: She said "Yes"</pre>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/serialize-and-deserialize-series-of-strings/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/serialize-and-deserialize-series-of-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Points and Line of Sight</title>
		<link>http://n3wt0n.com/blog/points-and-line-of-sight/</link>
		<comments>http://n3wt0n.com/blog/points-and-line-of-sight/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 04:13:18 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[Game Dev]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=967</guid>
		<description><![CDATA[A very minor update, barely worth mention. You&#8217;ll notice the entire wall segment is enclosed in the radius around the &#8216;player&#8217;, that yellow circle at the center. The significance here is that the top-left point of the wall segment isn&#8217;t included in the list of accessible nodes! Why not? Because, the player can&#8217;t see that [...]]]></description>
			<content:encoded><![CDATA[<p>A very minor update, barely worth mention.</p>
<p><a href="http://n3wt0n.com/blog/wp-content/uploads/2011/04/6.png"><img class="alignnone size-full wp-image-968" title="line of sight" src="http://n3wt0n.com/blog/wp-content/uploads/2011/04/6.png" alt="" width="145" height="145" /></a></p>
<p>You&#8217;ll notice the entire wall segment is enclosed in the radius around the &#8216;player&#8217;, that yellow circle at the center. The significance here is that the top-left point of the wall segment isn&#8217;t included in the list of accessible nodes! Why not? Because, the player can&#8217;t see that node (it&#8217;s on the other side of the wall segment). Another good thing in the image above, the yellow dot is flush with the two red nodes meaning it has the same x-axis as the node to its left and same y-axis as the node above.</p>
<p>It&#8217;s all theory, but I believe I&#8217;m close to achieving my goal. A little recursion to jump from one point to every other point in its line of sight, adding together all the places that the orange &#8216;light&#8217; can shine on, and I should finally have my map of accessible areas. Remember, it&#8217;s the idea of having a string anchored to a location, and then mapping out only the locations that the tethered string can reach.</p>
<p>It&#8217;ll all become clearer when I get it working. You&#8217;ll see.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/points-and-line-of-sight/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/points-and-line-of-sight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Points, Comparators, and Thread</title>
		<link>http://n3wt0n.com/blog/points-comparators-and-thread/</link>
		<comments>http://n3wt0n.com/blog/points-comparators-and-thread/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 09:02:28 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[Game Dev]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[area]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=952</guid>
		<description><![CDATA[Trying hard to figure out an efficient way to do the following: And so far, only coming up with something like this: Imagine a thread of fixed length N stuck to a location on your desk. Now picture a coffee cup in the path of that thread. Now fill in only the area that the [...]]]></description>
			<content:encoded><![CDATA[<p>Trying hard to figure out an efficient way to do the following:</p>
<p><a href="http://n3wt0n.com/blog/wp-content/uploads/2011/04/ThePath.png"><img class="alignnone size-full wp-image-953" title="Limiting Accessible Area" src="http://n3wt0n.com/blog/wp-content/uploads/2011/04/ThePath.png" alt="Limiting Accessible Area" width="512" height="512" /></a></p>
<p>And so far, only coming up with something like this:</p>
<p><a href="http://n3wt0n.com/blog/wp-content/uploads/2011/04/Screenshot-4.png"><img class="alignnone size-full wp-image-955" title="Remaining thread from points" src="http://n3wt0n.com/blog/wp-content/uploads/2011/04/Screenshot-4.png" alt="Remaining thread from points" width="110" height="110" /></a></p>
<p>Imagine a thread of fixed length N stuck to a location on your desk. Now picture a coffee cup in the path of that thread. Now fill in only the area that the thread can reach.</p>
<p>I&#8217;ve tried to work it out on a whiteboard but that was only getting me so far with the subject. Now I&#8217;ve got a hunch that if I iterate (and recurse) the points within the line-of-sight from the closest to furthest points from the player that I can calculate the accessible region based on the player&#8217;s position, and how far the player can move (the length of the thread).</p>
<p>That brings me to Comparators. In PHP there&#8217;s a handy function called usort. It takes an array for the first argument, and the name of a function as the second argument. The function as a second argument is one usually written by you, the developer, to tell usort how to compare two elements in the array.</p>
<p>In Java you can accomplish usort via the Comparator interface which usually works out to something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span>a, b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a <span style="color: #339933;">==</span> b<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>a <span style="color: #339933;">&lt;</span> b<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case I&#8217;d compare Point objects and sort them from closest to most distant locations from the player. For reference, <a href="http://www.javadeveloper.co.in/java-example/java-comparator-example.html">this page</a> was informative enough to show how to create and use your own Comparator.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/points-comparators-and-thread/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/points-comparators-and-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LOTRO Craft Update</title>
		<link>http://n3wt0n.com/blog/lotro-craft-update/</link>
		<comments>http://n3wt0n.com/blog/lotro-craft-update/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 00:56:10 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[lotro]]></category>
		<category><![CDATA[lotrocraft]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=943</guid>
		<description><![CDATA[This weekend I finished version 2 of the LOTRO Craft Assist. Changes include: Recipe list filter Full stack button Reduced AJAX The filter, as you expect, narrows the list of recipes down to whatever you&#8217;ve typed in the filter box. Typing &#8220;cup&#8221; will shrink the list down to: Cup of Red Tea, Cup of Spring [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I finished version 2 of the <a title="LOTRO Craft Assist" href="http://n3wt0n.com/lotro-craft/" target="_blank">LOTRO Craft Assist</a>. Changes include:</p>
<ul>
<li>Recipe list filter</li>
<li>Full stack button</li>
<li>Reduced AJAX</li>
</ul>
<p>The filter, as you expect, narrows the list of recipes down to whatever you&#8217;ve typed in the filter box. Typing &#8220;cup&#8221; will shrink the list down to: Cup of Red Tea, Cup of Spring Barley Flour, etc, cutting out the items that don&#8217;t have the &#8220;cup&#8221; in its name.</p>
<p>The quantity box, used to find the cost of a specified number of items, now loads with the value 50 which is usually the size of the stack when dealing with cooked food. Likewise, a &#8220;Full Stack&#8221; button is present which, when clicked, resets the quantity box back to 50. I&#8217;ll be storing the actual stack size of items in a future release so it&#8217;ll no longer default to 50 but rather whatever the actual stack size is.</p>
<p>The first version was written from the ground up in Javascript. That was all fine, and a fun exercise, but it was impractical. When your local internet connection was slow, sometimes the recipe list or individual recipes failed to load. Now the entire catalog is loaded once, reducing bandwidth limitations.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/lotro-craft-update/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/lotro-craft-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lord of the Rings Online: Craft Assistant</title>
		<link>http://n3wt0n.com/blog/lord-of-the-rings-online-craft-assistant/</link>
		<comments>http://n3wt0n.com/blog/lord-of-the-rings-online-craft-assistant/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 08:57:45 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[craft]]></category>
		<category><![CDATA[crafting]]></category>
		<category><![CDATA[lord of the rings]]></category>
		<category><![CDATA[lotro]]></category>
		<category><![CDATA[online]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=940</guid>
		<description><![CDATA[I&#8217;ve been working on what I call the LOTRO Craft Assistant. You can find it here. It is intended to show you the base cost of a crafted item, with a focus on items crafted by Farmers and Cooks at the moment. I see potential to expand the app to cover recipes and ingredients for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on what I call the LOTRO Craft Assistant. You can find it <a href="http://n3wt0n.com/lotro-craft/" target="_blank">here</a>. It is intended to show you the base cost of a crafted item, with a focus on items crafted by Farmers and Cooks at the moment. I see potential to expand the app to cover recipes and ingredients for Tailors, Jewelers, etc. It might even be possible to cover crafting costs in other MMOs, too.</p>
<p>Like the majority of the things I do, I did it with selfish intent. It&#8217;s an app to help me price items for auction in The Lord of the Rings Online. I hope others find it useful, too.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/lord-of-the-rings-online-craft-assistant/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/lord-of-the-rings-online-craft-assistant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Sweet) Chili</title>
		<link>http://n3wt0n.com/blog/sweet-chili/</link>
		<comments>http://n3wt0n.com/blog/sweet-chili/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 18:24:34 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[chili]]></category>
		<category><![CDATA[dinner]]></category>
		<category><![CDATA[foood]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[recipe]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=835</guid>
		<description><![CDATA[Who doesn&#8217;t like chili? Perhaps vegetarians, but that doesn&#8217;t matter. Cook this. It takes less than an hour to throw it all in a pot. The hardest part is not eating it when it starts smelling delicious. Ingredients 1 package of ground beef 6 chipotle (or other spicy) sausage 1 bulb of garlic 1 medium [...]]]></description>
			<content:encoded><![CDATA[<p>Who doesn&#8217;t like chili? Perhaps vegetarians, but that doesn&#8217;t matter. Cook this. It takes less than an hour to throw it all in a pot. The hardest part is not eating it when it starts smelling delicious.</p>
<h3>Ingredients</h3>
<p>1 package of ground beef<br />
6 chipotle (or other spicy) sausage<br />
1 bulb of garlic<br />
1 medium sized white onion<br />
2 tablespoons (at least) of chili powder for a mild sensation<br />
1 can of red kidney beans<br />
2 cans of beans in molasses<br />
2 680mL cans of tomato sauce<br />
4 heaping tablespoons of brown sugar (optional)</p>
<h3>Instructions</h3>
<ol>
<li>Eat some breakfast or lunch. Whichever is closer.</li>
<li>Heat pot to medium heat. Cook a package of ground beef. I used extra lean.</li>
<li>Cut up 6 spicy sausages. Add when beef is cooked.</li>
<li>From one bulb of garlic, remove skins of all cloves. Leave whole. Add when all inedible bits are removed.</li>
<li>Peel and slice one medium sized white onion. Add to the pot. And stir while you&#8217;ve been adding stuff.</li>
<li>Add 2 tablespoons (the big one) of hot chili powder.</li>
<li>Cover and reduce the heat to low (2 on a scale of 10). Let sit a few minutes.</li>
<li>While the pot is sitting, strain <strong>and rinse</strong> 1 can of red kidney beans. Add.</li>
<li>Add 2 cans of beans with molasses.</li>
<li>Add 2 cans of tomato sauce.</li>
<li>Let sit a few minutes and then taste it. Add more chili powder as required.</li>
<li>If it fits, you can add more of your favorite ingredient now.</li>
<li>Optional: Add 4 heaping tablespoons of brown sugar.</li>
<li>Let it cook at low heat until you&#8217;re hungry again.</li>
</ol>
<p>I&#8217;m hungry again writing down these instructions.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/sweet-chili/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/sweet-chili/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FizzBuzz and a false coin</title>
		<link>http://n3wt0n.com/blog/fizzbuzz-and-a-false-coin/</link>
		<comments>http://n3wt0n.com/blog/fizzbuzz-and-a-false-coin/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 16:56:53 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[skill]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=759</guid>
		<description><![CDATA[I just had my co-worker visit me at home. We all work remotely so we don&#8217;t see each other on a daily basis, but he was passing through town. He brought up an interesting topic; a programming &#8220;test&#8221; called &#8220;FizzBuzz&#8221;. The rules: Print out all values between 1 and 100. When a number is divisible [...]]]></description>
			<content:encoded><![CDATA[<p>I just had my co-worker visit me at home. We all work remotely so we don&#8217;t see each other on a daily basis, but he was passing through town. He brought up an interesting topic; a programming &#8220;test&#8221; called &#8220;FizzBuzz&#8221;.</p>
<p>The rules: Print out all values between 1 and 100. When a number is divisible by 3 print &#8220;FIZZ&#8221; and when divisible by 5 print &#8220;BUZZ&#8221;. When the number is divisible by both, print &#8220;FIZZ BUZZ&#8221;.</p>
<p>My simple solution to it (a Perl script) is as follows:</p>
<pre>for ($i = 1; $i &lt;= 100; $i++) {
 print "$i:\t";
 if ($i%3==0) { print "FIZZ "; }
 if ($i%5==0) { print "BUZZ "; }
 print "\n";
}</pre>
<p>This meets the criteria, though I don&#8217;t check if a number is specifically divisible by both within a condition.</p>
<p>This brought back a memory of an &#8220;Algorithm Analysis&#8221; exam from University. I call it &#8220;The False Coin&#8221; problem, though it probably has many names.</p>
<p>You have a pile of coins. All of the coins are equal, except one, which is lighter than the other coins. This is the false coin. You also have a scale which allows you to compare two weights against each other. Using the scale, what is the most efficient way to find the false coin?</p>
<p>The other students insisted you split the pile of coins into two equal piles, weigh the two against each other and find the lighter pile, then split the lighter pile into two piles, and so on.</p>
<p>Close. But wrong. There is a better way and it involves splitting the first pile into three equal piles. Compare two piles, identify which of the three is the lightest pile and split that into three more equal piles, and so on. With every weighing you get rid of 66% of the remaining coins, compared to only 50% when splitting the piles by half.</p>
<p>So keep that in mind before your next programming interview.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/fizzbuzz-and-a-false-coin/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/fizzbuzz-and-a-false-coin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java String Validation and Scrubbing</title>
		<link>http://n3wt0n.com/blog/java-string-validation-and-scrubbing/</link>
		<comments>http://n3wt0n.com/blog/java-string-validation-and-scrubbing/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 17:48:41 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[matcher]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=739</guid>
		<description><![CDATA[I find myself more and more needing to validate user input, checking for illegal characters and empty Strings. import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; &#160; public class ScrubTest &#123; &#160; public String scrubText&#40;String dirty&#41; &#123; dirty = scrub&#40;&#34;\\s+&#34;, dirty, &#34; &#34;&#41;; return scrub&#40;&#34;^\\s?&#124;\\s?$&#34;, dirty, &#34;&#34;&#41;; &#125; &#160; public String scrub&#40;String pattern, String text, String replace&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>I find myself more and more needing to validate user input, checking for illegal characters and empty Strings.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.LinkedList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Matcher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ScrubTest <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> scrubText<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> dirty<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		dirty <span style="color: #339933;">=</span> scrub<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>s+&quot;</span>, dirty, <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> scrub<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>s?|<span style="color: #000099; font-weight: bold;">\\</span>s?$&quot;</span>, dirty, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> scrub<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pattern, <span style="color: #003399;">String</span> text, <span style="color: #003399;">String</span> replace<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span>pattern<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Matcher matcher <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> matcher.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span>replace<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		ScrubTest st <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ScrubTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		LinkedList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> list <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s <span style="color: #339933;">:</span> list<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Testing string: <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> s <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>---------------&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				s <span style="color: #339933;">=</span> st.<span style="color: #006633;">scrubText</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;null:  &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;empty: &quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>n:    &quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR:&quot;</span> <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003399;">String</span> scrubbed <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>   This   is       just a  test            <span style="color: #000099; font-weight: bold;">\n</span>    &quot;</span><span style="color: #339933;">;</span>
		scrubbed <span style="color: #339933;">=</span> st.<span style="color: #006633;">scrubText</span><span style="color: #009900;">&#40;</span>scrubbed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span> <span style="color: #009900;">&#40;</span>scrubbed <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Produces:</p>
<pre>Testing string: "test"
---------------
null:  false
empty: false
\n:    false

Testing string: "null"
---------------
ERROR:java.lang.NullPointerException

Testing string: ""
---------------
null:  false
empty: true
\n:    false

Testing string: " "
---------------
null:  false
empty: true
\n:    false

Testing string: "
"
---------------
null:  false
empty: true
\n:    false
This is just a test.
</pre>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/java-string-validation-and-scrubbing/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/java-string-validation-and-scrubbing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Slick, Phys2D, LWJGL, and Eclipse</title>
		<link>http://n3wt0n.com/blog/slick-phys2d-lwjgl-and-eclipse/</link>
		<comments>http://n3wt0n.com/blog/slick-phys2d-lwjgl-and-eclipse/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 19:22:57 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lwjgl]]></category>
		<category><![CDATA[phys2d]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[slick]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=658</guid>
		<description><![CDATA[This guide will be as straight-to-the-point as can be. Please note, I make an example of the Linux version in this setup, but you can substitute the instructions for Windows or Mac if that is what you use. Purpose Create an Eclipse project that uses Slick, Phys2D and LWJGL. Requirements Slick &#8211; website &#8211; Download [...]]]></description>
			<content:encoded><![CDATA[<p>This guide will be as straight-to-the-point as can be. Please note, I make an example of the <strong>Linux</strong> version in this setup, but you can substitute the instructions for Windows or Mac if that is what you use.</p>
<h4>Purpose</h4>
<p>Create an Eclipse project that uses Slick, Phys2D and LWJGL.</p>
<h4>Requirements</h4>
<ol>
<li>Slick &#8211; <a href="http://slick.cokeandcode.com/" target="_blank">website</a> &#8211; Download the &#8220;full distribution&#8221; <a href="http://slick.cokeandcode.com/downloads/slick.zip">slick.zip</a> (~ 9.8 MB)</li>
<li>LWJGL &#8211; <a href="http://www.lwjgl.org/" target="_blank">website</a> &#8211; I prefer to use the &#8220;<a href="https://www.newdawnsoftware.com/hudson/view/LWJGL/job/LWJGL/lastStableBuild/" target="_blank">last stable build</a>&#8221; from the project repository (currently 2.2.0, ~ 3.6 MB)</li>
<li>Phys2D &#8211; <a href="http://www.cokeandcode.com/phys2d/" target="_blank">website</a> &#8211; Download the <a href="http://www.cokeandcode.com/phys2d/source/builds/phys2d-060408.jar">latest build</a> (current build 2008-04-06, ~ 100 KB)</li>
</ol>
<h4>Procedure</h4>
<p>This is a personal preference, but I rename the Phys2D download. It downloads as <strong>phys2d-060408.jar</strong>, so I rename it <strong>phys2d.jar</strong>.</p>
<p>Next, extract/unzip the <strong>slick.zip</strong> file, it doesn&#8217;t matter where. We will import the files into the Eclipse workspace later anyway.</p>
<p>Open up Eclipse and start a new project.</p>
<pre>File &gt;&gt; New &gt;&gt; Java Project</pre>
<p>Presumably, you know your way around Eclipse so I will not help with the specifics of creating a project.</p>
<p>Now that the project is created, create a new folder called <strong>lib</strong> in the project.</p>
<pre>File &gt;&gt; New &gt;&gt; Folder
Click the project name
Folder name: lib</pre>
<p>Next, we import Slick and Phys2D into the project.</p>
<pre>Right click lib &gt;&gt; Left click Import &gt;&gt; General &gt;&gt; File System &gt;&gt; Next
Browse to the unzipped slick directory and find the slick/lib folder &gt;&gt; OK
Select the following jar files</pre>
<ul>
<li> jogg-0.0.7.jar</li>
<li> jorbis-0.0.15.jar</li>
<li> lwjgl.jar</li>
<li> slick.jar</li>
</ul>
<pre>Click Finish</pre>
<p>You&#8217;ve imported Slick, now we import Phys2D.</p>
<pre>Right click lib &gt;&gt; Import &gt;&gt; General &gt;&gt; File System &gt;&gt; Next
Browse to the location you put phys2d.jar &gt;&gt; OK
Select phys2d.jar &gt;&gt; Finish</pre>
<p>Now your lib folder should have those five jar files in them. Just about done.</p>
<p>We need to add the jar files into the project build path.</p>
<pre>Right click the Project &gt;&gt; Properties
On the left, make sure <strong>Java Build Path</strong> is selected.
Click the <strong>Libraries</strong> tab &gt;&gt; Add JARs
Expand the Project
Expand lib
Select all of the jar files in the lib directory &gt;&gt; OK &gt;&gt; OK</pre>
<p>You should now see a new directory in the Package Explorer called <strong>Referenced Libraries</strong>. The project is incomplete without first attaching the native libraries to lwjgl.jar. To do that, we first import those native libraries into the project.</p>
<pre>Right click lib &gt;&gt; Import &gt;&gt; General &gt;&gt; Archive File
Browse to the unzipped slick directory and
select slick/lib/natives-linux.jar &gt;&gt; OK &gt;&gt; Finish
Do the same for natives-win32.jar and natives-mac.jar
(if you wish to support those operating systems)</pre>
<p>Next, we attach those native libraries to the lwjgl.jar file.</p>
<pre>Expand <strong>Referenced Libraries</strong>
Right click lwjgl.jar &gt;&gt; Properties
Select <strong>Native Library</strong> at the left of that window
Location path: &gt;&gt; Workspace
Expand the Project
Select lib &gt;&gt; OK &gt;&gt; Apply &gt;&gt; OK</pre>
<p>Now you are ready to build your awesome game.</p>
<pre>But wait, what about using the latest version of lwjgl? We skipped that step.</pre>
<p>Right. We did. As of right now, we&#8217;re using the the version of LWJGL that came packaged with Slick. However, some users might run into a problem with LWJGL, particularly if you&#8217;re using Ubuntu 9.04 (like I am). At this point, if I were to try to compile a Slick program, I would end up with this error:</p>
<pre>Failed to initialise the LWJGL display</pre>
<p>The solution to which is to use the latest LWJGL native Linux libraries.</p>
<pre>Extract that <strong>last stable build</strong> of LWJGL that you downloaded (lwjgl-2.2.0.zip).
In Eclipse, Right click lib &gt;&gt; Import &gt;&gt; File System &gt;&gt; Next
Browse to the unzipped lwjgl-2.2.0 directory, to lwjgl-2.2.0/native/linux &gt;&gt; OK
Select all of the .so files (all of the files in the directory) &gt;&gt; Finish
<strong>Yes To All</strong> when asked to overwrite files</pre>
<p>Not entirely done yet. Trying to compile now would result in the following error:</p>
<pre>Version mismatch: jar version is '16', native libary version is '17'</pre>
<p>So we replace the old lwjgl.jar with the new. Find it at <strong>lwjgl-2.2.0/jar/lwjgl.jar</strong>. Import it into the lib folder of the project. You know how to do that by now. Compile and run again and all should be well.</p>
<p>P.S. You are done with all the extra unzipped directories and zip files, etc. Everything needed to run your project has been imported into Eclipse. They can be deleted if you so choose.</p>
<p><strong>Update</strong>: It seems that now there is an additional problem, as follows.</p>
<pre>java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path</pre>
<p>The solution was found at the <a href="http://www.jmonkeyengine.com/forum/index.php?topic=10669.msg81127#msg81127" target="_blank">jMonkeyEngine forums</a>. You need to tell the lwjgl.jar where it can find the native libraries so it can run. Basically it calls for</p>
<pre>Right click the project &gt;&gt; Properties &gt;&gt; Java Build Path &gt;&gt; Libraries
Expand <strong>lwjgl.jar</strong>
Select <strong>Native Library</strong> &gt;&gt; Edit
Click <strong>Workspace</strong>
Expand the project
Click <strong>lib</strong> &gt;&gt; OK &gt;&gt; OK</pre>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/slick-phys2d-lwjgl-and-eclipse/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/slick-phys2d-lwjgl-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Backing up your Database (with GoDaddy and Cron)</title>
		<link>http://n3wt0n.com/blog/backing-up-your-database-with-godaddy-and-cron/</link>
		<comments>http://n3wt0n.com/blog/backing-up-your-database-with-godaddy-and-cron/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 00:23:09 +0000</pubDate>
		<dc:creator>kyle</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[godaddy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://n3wt0n.com/blog/?p=271</guid>
		<description><![CDATA[In short, this is  a guide to setting up a cron job in GoDaddy so that your databases can be backed up (and later restored). It&#8217;s generally a good idea to regularly backup your databases, whether you think you need to or not. This guide assumes that you are using the Linux hosting of GoDaddy. [...]]]></description>
			<content:encoded><![CDATA[<p>In short, this is  a guide to setting up a cron job in GoDaddy so that your databases can be backed up (and later restored). It&#8217;s generally a <a href="http://lunduke.com/?p=3" target="_blank">good idea</a> to regularly backup your databases, whether you think you need to or not.</p>
<p>This guide assumes that you are using the Linux hosting of GoDaddy.</p>
<p>First, get familiar with <strong>mysqldump</strong>. It&#8217;s the utility we&#8217;re going to use to do the backing up. Do you have access to your sites shell? It&#8217;s that thing you get when you log into <strong>yourdomain.com</strong> through <strong>SSH</strong>. I&#8217;ll assume you&#8217;ve got access to the command line to try this yourself and if you don&#8217;t then just follow along and trust me.</p>
<p>I&#8217;ll paste a facsimile of the <strong>mysqldump</strong> command that I use in my account, and then explain what it does. Keep in mind, the following command is continuous, all on one line, but I&#8217;ve broken it down to fit on this page.</p>
<pre>mysqldump
-h <strong>DBHOSTADDRESS</strong>
-u <strong>DBNAME</strong>
-p<strong>DBPASSWORD
</strong><strong>DBNAME</strong> |
gzip &gt;
$HOME/html/somefolder/<strong>DBNAME</strong>_`date '+%m-%d-%Y_%H-%M'`.sql.gz</pre>
<p>I&#8217;d like to point out the workings of that &#8220;date&#8221; thing first. Simply put, that gives the backup a name like &#8220;MyDB_03-18-2009_02-15.sql.gz&#8221; which tells us that the database, MyDB, was backed up March 18, 2009 at 2:15am.</p>
<p><strong>DBNAME</strong> is whatever you named the database. As we all know by now, GoDaddy shares the database name and the database username, which is why it shows up so often.</p>
<p><strong>DBPASSWORD</strong> is worth noting. There is <strong>no space</strong> between the <strong>-p</strong> and the <strong>password</strong>. That is not a typo. Just keep it as -pNoSpace or it will not work (of course, use the database password in place of &#8220;NoSpace&#8221;).</p>
<p><strong>DBHOSTADDRESS</strong> can be found in the GoDaddy control panel. The control panel is found at</p>
<p>GoDaddy.com &gt;&gt; Hosting &gt;&gt; My Hosting Account &gt;&gt; Manage Account &gt;&gt; Databases &gt;&gt; MySQL</p>
<p>Then click the &#8220;Edit/View Details&#8221; <strong>Action</strong> for the database you want. The host address can be found in the <strong>Host Name</strong> row of the <strong>MySQL Database Information</strong>.</p>
<p><strong>GZIP</strong> is what zips up the backup for us. It keeps the backup small (or at least smaller than the raw backup file).</p>
<p><strong>$HOME</strong> is the <strong>full path</strong> to the backup directory. You do not need to worry about the path, just keep $HOME as it is.</p>
<p>And now for the easy part.</p>
<p>Create a file and write <strong>#!/bin/bash</strong> for the first line. Then on the second line, paste in the <strong>mysqldump</strong> command for your database. Remember to change the variables in the command to suit your account and database configuration.</p>
<p>Now change the permission of the script you just created to be executable by you. From the command line the command is</p>
<pre>chmod 744 WhateverTheScriptIsCalled</pre>
<p>You could probably change the permission from within an FTP program, like FileZilla, by right clicking and changing the permission.</p>
<p>Next, open <strong>Cron Manager</strong>. It is located in the <strong>Control Panel</strong> under the <strong>Content</strong> tab.</p>
<p>Give the cron job a name and set the frequency. Next, in the <strong>command</strong> box, browse to the location of the script you just created. Select it. Save. Done.</p>
<div class="plus-one-wrap"><g:plusone href="http://n3wt0n.com/blog/backing-up-your-database-with-godaddy-and-cron/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://n3wt0n.com/blog/backing-up-your-database-with-godaddy-and-cron/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

