<?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>Labrat&#039;s Blog</title>
	<atom:link href="http://blog.labrat.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.labrat.info</link>
	<description>Rants, raves and stuff from this dude&#039;s brain</description>
	<lastBuildDate>Mon, 20 Jun 2011 14:00:30 +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>2 day Tahoe trip to Josh&#8217;s Bachelor Party</title>
		<link>http://blog.labrat.info/20110620/2-day-tahoe-trip-to-joshs-bachelor-party/</link>
		<comments>http://blog.labrat.info/20110620/2-day-tahoe-trip-to-joshs-bachelor-party/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 14:00:30 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Motorcycles]]></category>
		<category><![CDATA[Motorcycle]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=365</guid>
		<description><![CDATA[This was a 2 day trip up to South Tahoe. Went up on Saturday and came back Sunday. The map of the total trip with all stops taken out. A bit of stats: Trip Odometer: 480 miles Moving Time: 8 hours 4 minutes Stopped Time: 1 hour 44 minutes]]></description>
			<content:encoded><![CDATA[<p>This was a 2 day trip up to South Tahoe.  Went up on Saturday and came back Sunday.  The map of the total trip with all stops taken out.  </p>
<p>A bit of stats:<br />
Trip Odometer: 480 miles<br />
Moving Time: 8 hours 4 minutes<br />
Stopped Time: 1 hour 44 minutes</p>
<div  style="text-align: left;"  class="xmlgmdiv" id="xmlgmdiv_11"><iframe class="xmlgm" id="xmlgm_11" src="http://blog.labrat.info/wp-content/plugins/xml-google-maps/xmlgooglemaps_show.php?gpxid=11" style="border: 0px; width: 550px; height: 400px;" name="Google_Gpx_Maps" frameborder="0"></iframe></div>
<p><img class="xmlgmele" id="xmlgmele_11"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Elevation Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.14285714285714,FFFFFF,0.14285714285714&#038;chxt=x,y&#038;chxl=0:|0 mi|120 mi|240 mi|360 mi|480 mi|1:|0 ft|1000 ft|2000 ft|3000 ft|4000 ft|5000 ft|6000 ft|7000 ft&#038;chd=s:AACDEBAABBAAAACJOYgfs65442125xqcUPGCBAAABBAABEDCAA&#038;chs=550x200&#038;chco=008000&#038;chtt=Elevation+Profile&#038;chts=555555,12" /><br /><img class="xmlgmspeed" id="xmlgmspeed_11"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Speed Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.2,FFFFFF,0.2&#038;chxt=x,y&#038;chxl=0:|0 mi|120 mi|240 mi|360 mi|480 mi|1:|0 mph|25 mph|50 mph|75 mph|100 mph|125 mph&#038;chd=s:Wgjjlliiklkhmlnkigiad2WPTSZdjgkkjmmdjXikhklmnongjT&#038;chs=550x200&#038;chco=0000FF&#038;chtt=Speed+Profile&#038;chts=555555,12" /><br /><a href='http://blog.labrat.info/wp-content/uploads/2011/06/Track-2011-06-19-22-30-41.gpx'></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110620/2-day-tahoe-trip-to-joshs-bachelor-party/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making an analogue gauge with Processing</title>
		<link>http://blog.labrat.info/20110505/making-an-analogue-gauge-with-processing/</link>
		<comments>http://blog.labrat.info/20110505/making-an-analogue-gauge-with-processing/#comments</comments>
		<pubDate>Thu, 05 May 2011 14:00:50 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[analogue-gauge]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=358</guid>
		<description><![CDATA[I&#8217;ve been looking around the internet for an easy way to make an &#8220;analog gauge&#8221; in Processing to help me get a better handle on an IMU I got from Sparkfun. Looking at numbers go by on the serial terminals was making me more motion sick than anything else. Step one was to try to ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking around the internet for an easy way to make an &#8220;analog gauge&#8221; in <a href="http://processing.org/" target="_blank">Processing</a> to help me get a better handle on an <a href="http://www.sparkfun.com/products/10010" target="_blank">IMU</a> I got from <a href="http://www.sparkfun.com/" target="_blank">Sparkfun</a>.  Looking at numbers go by on the serial terminals was making me more motion sick than anything else.</p>
<p>Step one was to try to make an arrow.  Luckily the internet came to the rescue and I found <a href="http://processing.org/discourse/yabb2/YaBB.pl?num=1219607845" target="_blank">this</a> in one of the Processing <a href="http://processing.org/discourse/yabb2/YaBB.pl" target="_blank">forums</a>.  The function is :</p>
<pre class="brush: plain; title: ; notranslate">
void arrow(int x1, int y1, int x2, int y2) {
  line(x1, y1, x2, y2);
  pushMatrix();
  translate(x2, y2);
  float a = atan2(x1-x2, y2-y1);
  rotate(a);
  line(0, 0, -10, -10);
  line(0, 0, 10, -10);
  popMatrix();
}
</pre>
<p>With that knowledge I needed to find a way to take the angle I&#8217;m getting back form the IMU and tell Processing to draw me the gauge.  Somewhere in the back of my mind I remembered there was something that I could give an angle and a radius and I could get X and Y position of the tip of that Radius.  Another quick internet search and I found <a href="http://en.wikipedia.org/wiki/Polar_coordinate_system" target="_blank">Polar Coordinates</a> and then found there as already a <a href="http://processing.org/learning/basics/polartocartesian.html" target="_blank">tutorial</a> on that on the Processing website.  Quick re-factor of that code and I got this:</p>
<pre class="brush: plain; title: ; notranslate">
void guage(float r, float angle) {
  // Conver from Degree -&gt; Rad
  angle = -angle*(PI/180) ;
    // Convert Polar -&gt; Cartesian
  float x = r * cos(angle);
  float y = r * sin(angle);

  arrow(0,0, (int)x, (int)y) ;
}
</pre>
<p>And now to make it look like a guage just add a circle around it!</p>
<pre class="brush: plain; title: ; notranslate">
ellipse(0, 0, height/2, height/2) ;
guage(height/2, angleX) ;
</pre>
<p>So now that I can draw a cool guage-looking thing on the screen I made my <a href="http://www.arduino.cc/">Arduino</a> print out to serial a tab-separated list of X and Y values that are read by the Processing sketch and the gauges now tell me the angle of the IMU!</p>
<pre class="brush: plain; title: ; notranslate">
import processing.serial.*; 

Serial arduino;

float angleX = 0 ;
float angleY = 0 ;

float minX=0 ;
float maxX=0 ;
float minY=0 ;
float maxY=0 ;

void setup() {
  size(800,600) ;

  arduino = new Serial(this, Serial.list()[0], 9600);
  arduino.bufferUntil('\n');

}

void draw() {
  background(255);

  translate(width/4, height/2);

  stroke(0,0,0) ;
  ellipse(0, 0, height/2, height/2) ;
  strokeWeight(2);
  stroke(255,0,0) ;
  guage(height/4, angleX) ;

  translate(width/2, 0);
  stroke(0,0,0) ;
  ellipse(0, 0, height/2, height/2) ;
  stroke(0,255,0) ;
  guage(height/4, angleY) ;

  if (minX &gt; angleX) minX = angleX ;
  if (minY &gt; angleY) minY = angleY ;
  if (maxX &lt; angleX) maxX = angleX ;
  if (maxY &lt; angleY) maxY = angleY ;

  println(minX + &quot;\t&quot; + maxX + &quot;\t&quot; + minY + &quot;\t&quot; + maxY) ;

}

void serialEvent (Serial arduino)
{
 //get the ASCII strings:
 angleX = float(trim(arduino.readStringUntil('\t'))) ;
 angleY = float(trim(arduino.readStringUntil('\t'))) ;

}

void guage(float r, float angle) {
  // Conver from Degree -&gt; Rad
  angle = -angle*(PI/180) ;
    // Convert Polar -&gt; Cartesian
  float x = r * cos(angle);
  float y = r * sin(angle);

  arrow(0,0, (int)x, (int)y) ;
}

void arrow(int x1, int y1, int x2, int y2) {
  line(x1, y1, x2, y2);
  pushMatrix();
  translate(x2, y2);
  float a = atan2(x1-x2, y2-y1);
  rotate(a);
  line(0, 0, -10, -10);
  line(0, 0, 10, -10);
  popMatrix();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110505/making-an-analogue-gauge-with-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RawHyde and Calmoto off-road class</title>
		<link>http://blog.labrat.info/20110502/rawhyde-and-calmoto-off-road-class/</link>
		<comments>http://blog.labrat.info/20110502/rawhyde-and-calmoto-off-road-class/#comments</comments>
		<pubDate>Tue, 03 May 2011 04:17:16 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Motorcycles]]></category>
		<category><![CDATA[Calmoto]]></category>
		<category><![CDATA[off-road]]></category>
		<category><![CDATA[RawHyde]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=348</guid>
		<description><![CDATA[This was a great ride setup by the guys from Calmoto and taught by the guys from RawHyde. Much fun]]></description>
			<content:encoded><![CDATA[<p>This was a great ride setup by the guys from <a href="http://www.calmoto.com/" target="_blank">Calmoto</a> and taught by the guys from <a href="http://www.rawhyde-offroad.com/" target="_blank">RawHyde</a>.  Much fun.</p>
<div  style="text-align: left;"  class="xmlgmdiv" id="xmlgmdiv_10"><iframe class="xmlgm" id="xmlgm_10" src="http://blog.labrat.info/wp-content/plugins/xml-google-maps/xmlgooglemaps_show.php?gpxid=10" style="border: 0px; width: 550px; height: 400px;" name="Google_Gpx_Maps" frameborder="0"></iframe></div>
<p><img class="xmlgmele" id="xmlgmele_10"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Elevation Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.16666666666667,FFFFFF,0.16666666666667&#038;chxt=x,y&#038;chxl=0:|0 mi|29 mi|58 mi|87 mi|116 mi|1:|0 ft|800 ft|1600 ft|2400 ft|3200 ft|4000 ft|4800 ft&#038;chd=s:FFGHIIHGHIKSXaacehigbcTPPRabaacaZfszqfcWVHCBBBCCCB&#038;chs=550x200&#038;chco=008000&#038;chtt=Elevation+Profile&#038;chts=555555,12" /><br /><img class="xmlgmspeed" id="xmlgmspeed_10"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Speed Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.14285714285714,FFFFFF,0.14285714285714&#038;chxt=x,y&#038;chxl=0:|0 mi|29 mi|58 mi|87 mi|116 mi|1:|0 mph|10 mph|20 mph|30 mph|40 mph|50 mph|60 mph|70 mph&#038;chd=s:WfcixnoelrjefbcfaffcggdaRgglusikhbZZYbaddedn2558fa&#038;chs=550x200&#038;chco=0000FF&#038;chtt=Speed+Profile&#038;chts=555555,12" /><br /><a href='http://blog.labrat.info/wp-content/uploads/2011/05/Track-2011-05-02-21-05-53.gpx'></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110502/rawhyde-and-calmoto-off-road-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Playing with colors</title>
		<link>http://blog.labrat.info/20110428/playing-with-colors/</link>
		<comments>http://blog.labrat.info/20110428/playing-with-colors/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 14:00:37 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=322</guid>
		<description><![CDATA[I&#8217;ve been looking around the internet lately for interesting ways to calculate colors. More than anything I was looking for functions that I could use to make a strip of 3-color LEDs change from one color to another. I started with a brute-force 3-loop approach where I just did and inner most look though 0-255 ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking around the internet lately for interesting ways to calculate colors.  More than anything I was looking for functions that I could use to make a strip of 3-color LEDs  change from one color to another.  I started with a brute-force 3-loop approach where I just did and inner most look though 0-255 for Red, then a loop around that from 0-255 for Green and then the outer-most loop from 0-255 for Blue.  Something like this:</p>
<pre class="brush: plain; title: ; notranslate">
for (b=0; b &lt; 255; b++) {
  for (g=0; g &lt; 255; g++) {
    for (r=0; r &lt; 255; r++) {
      draw_rectangle(r,g,b) ;
    }
  }
}
</pre>
<p>I have to say, the colors produced were not pleasing to the eye at all.  </p>
<p>The I came accross <a href="http://www.krazydad.com/makecolors.php">this page</a> describing how to make a rainbow.  It has a great explanation on how to use a wave function, in this case sin(), to make colors.  I&#8217;m not going to get into all the theory an implementation of the algorithm because the other page does it so well.  I just made a little processing sketch where I can play with some of the parameters (frequency, amplitude, and center) to see what will happen to the color sequence.  </p>
<p>The sketch was cobbled together in a couple of minutes so I&#8217;m sorry it doesn&#8217;t look very nice.  Here is the <a href="http://blog.labrat.info/wp-content/uploads/2011/04/Graph.zip">Processing sketch</a> and applet so it can be modified to look better <img src='http://blog.labrat.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . (BTW, if you don&#8217;t know about <a href="http://processing.org/">Processing</a>, go check it out.  It&#8217;s pretty amazing.)</p>
<p><div class="processing_embed" id="Graph_container"><p><a href="#" onclick="deployJava.addAppletTo('Graph', 'http://blog.labrat.info/wp-content/uploads/2011/04/guicomponents.jar,http://blog.labrat.info/wp-content/uploads/2011/04/Graph.jar', 670, 600, 'http://blog.labrat.info/wp-content/plugins/wordpress-processing-embed', 'Graph_container'); return false;">Here&#8217;s the applet.</a></p></div>  It will mess up the formatting of the blog because the theme is not wide-enough.  Again, please excuse the ugly.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110428/playing-with-colors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trip to Clovis, CA</title>
		<link>http://blog.labrat.info/20110314/trip-to-clovis-ca/</link>
		<comments>http://blog.labrat.info/20110314/trip-to-clovis-ca/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 15:00:09 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Clovis]]></category>
		<category><![CDATA[Jimmy John's]]></category>
		<category><![CDATA[Motorcycle]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=300</guid>
		<description><![CDATA[I found out there was a Jimmy John&#8217;s in Clovis, CA so it sounded like a great idea to get me a #7!]]></description>
			<content:encoded><![CDATA[<p>I found out there was a<a href="http://www.jimmyjohns.com/"> Jimmy John&#8217;s</a> in Clovis, CA so it sounded like a great idea to get me a #7! </p>
<div  style="text-align: left;"  class="xmlgmdiv" id="xmlgmdiv_9"><iframe class="xmlgm" id="xmlgm_9" src="http://blog.labrat.info/wp-content/plugins/xml-google-maps/xmlgooglemaps_show.php?gpxid=9" style="border: 0px; width: 550px; height: 400px;" name="Google_Gpx_Maps" frameborder="0"></iframe></div>
<p><img class="xmlgmele" id="xmlgmele_9"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Elevation Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.16666666666667,FFFFFF,0.16666666666667&#038;chxt=x,y&#038;chxl=0:|0 mi|82.5 mi|165 mi|247.5 mi|330 mi|1:|0 ft|200 ft|400 ft|600 ft|800 ft|1000 ft|1200 ft&#038;chd=s:BBIMRMIHOcuUGEDEGJKNOOPOPQPNNMLGEDDFIRd0SMHKPPJCBD&#038;chs=550x200&#038;chco=008000&#038;chtt=Elevation+Profile&#038;chts=555555,12" /><br /><img class="xmlgmspeed" id="xmlgmspeed_9"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Speed Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.2,FFFFFF,0.2&#038;chxt=x,y&#038;chxl=0:|0 mi|82.5 mi|165 mi|247.5 mi|330 mi|1:|0 mph|20 mph|40 mph|60 mph|80 mph|100 mph&#038;chd=s:YksvvsgirssuskvvuwtxrvnstaZqtvsvvvukqtuuunfouxxwnU&#038;chs=550x200&#038;chco=0000FF&#038;chtt=Speed+Profile&#038;chts=555555,12" /><br /><a href='http://blog.labrat.info/wp-content/uploads/2011/03/Track-2011-03-14-07-28-54-2.gpx'></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110314/trip-to-clovis-ca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Firewall example for Linux</title>
		<link>http://blog.labrat.info/20110202/simple-firewall-example-for-linux/</link>
		<comments>http://blog.labrat.info/20110202/simple-firewall-example-for-linux/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 15:00:22 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=276</guid>
		<description><![CDATA[After posting about how to make a simple firewall on a BSD system I&#8217;ve been asked to do the same for Linux.  In Linux the command you&#8217;ll want to look at is iptables. Here&#8217;s the script I use to get a basic web server protected: We can go by this line by line. Line 4 ]]></description>
			<content:encoded><![CDATA[<p>After posting about how to make a <a href="http://blog.labrat.info/20100422/simple-firewall-example-ipfilter/" target="_blank">simple firewall on a BSD</a> system I&#8217;ve been asked to do the same for Linux.  In Linux the command you&#8217;ll want to look at is <em><a href="http://www.netfilter.org/" target="_blank">iptables</a></em>.</p>
<p>Here&#8217;s the script I use to get a basic web server protected:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# Flush all chains
/sbin/iptables --flush

# Allow unlimited traffic on the loopback interface
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

# Set default policies are set to Drop
/sbin/iptables --policy INPUT DROP
/sbin/iptables --policy OUTPUT DROP
/sbin/iptables --policy FORWARD DROP

# Previously initiated and accepted exchanges bypass rule checking
# Allow unlimited outbound traffic
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# Allow incoming (tcp) SSH traffic
/sbin/iptables -A INPUT -p tcp --dport ssh -m state --state NEW -j ACCEPT

# Allow incoming (udp) DHCP
/sbin/iptables -A INPUT -p udp --dport bootpc -j ACCEPT

# Allow incoming (tcp) WWW request
/sbin/iptables -A INPUT -p tcp --dport www -m state --state NEW -j ACCEPT

# Drop all other traffic
/sbin/iptables -A INPUT -j DROP
</pre>
<p>We can go by this line by line.</p>
<ul>
<li>Line 4 flushes all previous IPTable rules to we can make sure we have a clean slate to start.</li>
<li>Lines 7 &#8211; 8 disable any filtering on the loopback device.  You&#8217;ll most likely use this to make connections inside of the machine which are assumed to be secure.</li>
<li>Lines 11 &#8211; 13 set the default policy to be &#8220;Drop&#8221;.  This means that if a connection doesn&#8217;t match any of the rules that we are going to create, it will be dropped.  Basically, nothing can connect unless we explicitly punch a hole.</li>
<li>Lines 17 &#8211; 18 are just for performance.  If a connection has already been established it&#8217;s not worth checking again to see if it should be filtered or not.</li>
<li>Line 21 is the first rule.  We are letting <a href="http://www.openssh.com/" target="_blank">SSH</a> connections make it though the firewall so they can connect to the SSH server running on the machine.</li>
<li>Line 24 is a hole in the firewall in case the machine is using DHCP to setup it&#8217;s network.  If the machine has a static IP, this rule is not necessary and can be removed/commented out.</li>
<li>Line 27 punches another hole though the firewall so traffic can get to the webserver on port 80.</li>
<li>Line 30 makes sure that if no rule was satisfied the connection will be dropped.</li>
</ul>
<p>I think at this point there is one clarification to be made.  In the example I used <em>&#8211;dport</em> with with a name for a service and not a port number.  So how did I know the names that match up to the port I&#8217;m interested in?  IPTables uses the <em>/etc/services</em> file to match up a name to a port number.  If this makes you uncomfortable you can give <em>&#8211;dport</em> a port number and it will work just as well.</p>
<p>For example if you want to open a port for Tomcat on the default port (8080) the line would look something like this:</p>
<pre class="brush: bash; title: ; notranslate">
# Allow incoming (tcp) traffic to Tomcat on port 8080
sbin/iptables -A INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110202/simple-firewall-example-for-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Image Tools plugin for Grails</title>
		<link>http://blog.labrat.info/20110127/installing-image-tools-plugin-for-grails/</link>
		<comments>http://blog.labrat.info/20110127/installing-image-tools-plugin-for-grails/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 15:00:48 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Image Tool]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=287</guid>
		<description><![CDATA[After getting the upload part up and running so quick and easily, I&#8217;ve had a nasty time trying to get the Image Tools plugin for Grails to work with my application.  I tried using the version that&#8217;s mentioned in the Grails documentation for the file but kept getting the following error: After looking around for ]]></description>
			<content:encoded><![CDATA[<p>After getting the <a href="http://blog.labrat.info/20110113/uploading-files-in-grails/" target="_blank">upload part</a> up and running so quick and easily, I&#8217;ve had a nasty time trying to get the <a href="http://grails.org/ImageTools+plugin" target="_blank">Image Tools plugin</a> for Grails to work with my application.  I tried using the version that&#8217;s mentioned in the Grails documentation for the file but kept getting the following error:</p>
<pre class="brush: groovy; title: ; notranslate">
[groovyc] /Users/test/Documents/Proj-test/grails-app/controllers/ProjController.groovy: 192: unable to resolve class ImageTool
[groovyc]  @ line 192, column 21.
[groovyc]    				def imageTool = new ImageTool()
[groovyc]                        ^
</pre>
<p>After looking around for a bit I found the code on the <a href="https://github.com/ricardojmendez/grails-imagetools/" target="_blank">project&#8217;s Github</a> seemed correct but I still couldn&#8217;t get the plugin installed.  Kept getting errors that files were missing and the structure was incorrect.  I found out I had to build my own version of the plugin with the code I had checked out.  Once I did this everything started to work.</p>
<p>To save other people from this work I&#8217;ve created a <a href="http://blog.labrat.info/wp-content/uploads/2011/01/grails-image-tools-1.0.5.zip" target="_blank">ZIP file</a> for the plugin and put it online.  To install the plugin run the following command:</p>
<pre class="brush: bash; title: ; notranslate">
grails install-plugin http://blog.labrat.info/wp-content/uploads/2011/01/grails-image-tools-1.0.5.zip
</pre>
<p>Once that is done don&#8217;t forget to import the library before you use it:</p>
<pre class="brush: groovy; title: ; notranslate">
import org.grails.plugins.imagetools.*
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110127/installing-image-tools-plugin-for-grails/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ride around Brookdale</title>
		<link>http://blog.labrat.info/20110118/ride-around-brookdale/</link>
		<comments>http://blog.labrat.info/20110118/ride-around-brookdale/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 15:00:16 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Motorcycles]]></category>
		<category><![CDATA[Brookdale]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[Ride]]></category>
		<category><![CDATA[Santa Cruz Mountains]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=255</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div  style="text-align: left;"  class="xmlgmdiv" id="xmlgmdiv_7"><iframe class="xmlgm" id="xmlgm_7" src="http://blog.labrat.info/wp-content/plugins/xml-google-maps/xmlgooglemaps_show.php?gpxid=7" style="border: 0px; width: 550px; height: 400px;" name="Google_Gpx_Maps" frameborder="0"></iframe></div>
<p><img class="xmlgmele" id="xmlgmele_7"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Elevation Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.16666666666667,FFFFFF,0.16666666666667&#038;chxt=x,y&#038;chxl=0:|0 mi|19.3 mi|38.5 mi|57.8 mi|77 mi|1:|0 ft|500 ft|1000 ft|1500 ft|2000 ft|2500 ft|3000 ft&#038;chd=s:CDEFHJMTdp1xqfWQMLKKIGGINJDFKLOUYdkfVOJGGEDDCDDDCC&#038;chs=550x200&#038;chco=008000&#038;chtt=Elevation+Profile&#038;chts=555555,12" /><br /><img class="xmlgmspeed" id="xmlgmspeed_7"  style="text-align: left; margin: 0px; padding: 0px; max-width: 100%;"  alt="Speed Profile" src="http://chart.apis.google.com/chart?cht=lc&#038;chls=5,0,0&#038;chf=c,ls,90,CCCCCC,0.2,FFFFFF,0.2&#038;chxt=x,y&#038;chxl=0:|0 mi|19.3 mi|38.5 mi|57.8 mi|77 mi|1:|0 mph|20 mph|40 mph|60 mph|80 mph|100 mph&#038;chd=s:PXXWWSWbjWXabXVlZcVWVTUaebbrotslllqiknloqtwoo0xZWP&#038;chs=550x200&#038;chco=0000FF&#038;chtt=Speed+Profile&#038;chts=555555,12" /><br /><a href='http://blog.labrat.info/wp-content/uploads/2011/01/Track-2011-01-16-13-22-15.gpx'></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110118/ride-around-brookdale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading Files in Grails</title>
		<link>http://blog.labrat.info/20110113/uploading-files-in-grails/</link>
		<comments>http://blog.labrat.info/20110113/uploading-files-in-grails/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 14:00:16 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[LinkedIn]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=214</guid>
		<description><![CDATA[I&#8217;ve been playing with Grails for a bit and I was trying to find out how I can upload images to what I&#8217;ve been playing with. Sure there&#8217;s a couple plugins out there. But I wanted something simple and something I could mess around with. After some searching I found Valum&#8217;s AJAX Uploader page. I ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with <a href="http://www.grails.org/">Grail</a>s for a bit and I was trying to find out how I can upload images to what I&#8217;ve been playing with.  Sure there&#8217;s a <a href="http://www.grails.org/plugin/super-file-upload">couple</a> <a href="http://www.grails.org/plugin/file-uploader">plugins</a> out there. But I wanted something simple and something I could mess around with.  </p>
<p>After some searching I found Valum&#8217;s AJAX Uploader<a href="http://valums.com/ajax-upload/"> page</a>. I was impressed in just how simple his solution was yet so powerful.  It also seemed quite simple to add this to Grails.</p>
<p>The first thing to do is to go his <a href="http://github.com/valums/ajax-upload">Git page</a> on <a href="http://github.com/">Github</a> and download his files.  This should have created a new directory with everything in there.</p>
<p>Copy the client files from the Git checkout into the correct places in the Grails project.  This is to make your life easier when deploying as you can let Grails do all the magic of changing paths as you mode from development to production.</p>
<p>The files get moved like this:</p>
<pre>valums-file-uploader/client/fileuploader.css -&gt; web-app/css/
valums-file-uploader/client/fileuploader.js -&gt; web-app/js/
valums-file-uploader/client/loading.gif -&gt; web-app/images/</pre>
<p>I wanted to have flexibility to embed the upload facility into any class to I created a view <strong>grails-app/views/_uploader.gsp</strong>.  Here I use a lot of the gsp facilities to get the correct files we moved into the project to load once the view has loaded.  One thing I didn&#8217;t find a good clean way to do was to change the CSS so it would point to the correct animated GIF.  The hacky way I did it is to just overwrite the entire CSS line inside the view.  You&#8217;ll probably want to change <em>${domainInstance?.id}</em> to match your Domain&#8217;s name.</p>
<pre class="brush: jscript; html-script: true; title: ; notranslate">
&lt;link href=&quot;${resource(dir:'css',file:'fileuploader.css')}&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;

&lt;div id=&quot;image-uploader&quot;&gt;
    &lt;noscript&gt;
        &lt;p&gt;Please enable JavaScript to use file uploader.&lt;/p&gt;
        &lt;!-- or put a simple form for upload here --&gt;
    &lt;/noscript&gt;
&lt;/div&gt;

&lt;script src=&quot;${resource(dir:'js',file:'fileuploader.js')}&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;%-- Override the style in the file with the correct pathname --%&gt;
&lt;style type=&quot;text/css&quot;&gt;
    .qq-upload-spinner {
      display:inline-block;
      background: url(&quot;${resource(dir:'images',file:'loading.gif')}&quot;);
      width:15px;
      height:15px;
      vertical-align:text-bottom;
    }
&lt;/style&gt;
&lt;script&gt;
    function createUploader(){
        var uploader = new qq.FileUploader({
            element: document.getElementById('image-uploader'),
            action: '&lt;g:createLink action=&quot;upload&quot; id=&quot;${domainInstance?.id}&quot; /&gt;',
            sizeLimit: 3145728, // 3 MB
            allowedExtensions: ['jpg', 'jpeg'],
            debug: false
        });
    }

    // in your app create uploader as soon as the DOM is ready
    // don't wait for the window to load
    window.onload = createUploader;
&lt;/script&gt;
</pre>
<p>Now it&#8217;s pretty amazing just how little you have to add to your Domain Controller to support the upload. I just added one more definition that looks like this:</p>
<pre class="brush: groovy; title: ; notranslate">
def upload = {
    File file = new File(&quot;/tmp/&quot; +  request.getHeader('x-file-name'))
    try {
        InputStream inputStream = request.getInputStream();

        OutputStream out=new FileOutputStream (file.getAbsolutePath())
        byte[] buf = new byte [1024]
        int len
        while((len=inputStream.read(buf))&amp;gt;0) {
            out.write(buf,0,len)
        }
        out.close()
        inputStream.close()
    } catch (all) {
        file.delete()
        render(status: response.SC_INTERNAL_SERVER_ERROR, text:&quot;{success: false}&quot;)
    }
    render(status: response.SC_OK, text:&quot;{success: true}&quot;)
}
</pre>
<p>And that&#8217;s all that needs to be done.  Now go to whatever view you like, in my case I decided you can only upload once you&#8217;ve created an object so I just added the following into the grails-app/view/edit.gst:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;g:render template=&quot;uploader&quot; model=&quot;['domainInstance':domainInstance]&quot; /&gt;
</pre>
<p>And again please change <em>domainInstance</em> to match your Domain.</p>
<p>I&#8217;m amazed at just how simple this was.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20110113/uploading-files-in-grails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Grails ConnectionPool error with MySQL on FreeBSD</title>
		<link>http://blog.labrat.info/20101111/grails-connectionpool-error-with-mysql-on-freebsd/</link>
		<comments>http://blog.labrat.info/20101111/grails-connectionpool-error-with-mysql-on-freebsd/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 17:00:21 +0000</pubDate>
		<dc:creator>labrat</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.labrat.info/?p=169</guid>
		<description><![CDATA[When trying to get Grails to work on one of my machines I kept getting the following error when I tried to deploy the production WAR file. nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'test_user'@'127.0.0.1' (using password: YES)) This had me really confused ]]></description>
			<content:encoded><![CDATA[<p>When trying to get Grails to work on one of my machines I kept getting the following error when I tried to deploy the production WAR file.</p>
<pre>nested exception is org.springframework.jdbc.support.MetaDataAccessException:
 Error while extracting DatabaseMetaData;
 nested exception is org.apache.commons.dbcp.SQLNestedException:
   Cannot create PoolableConnectionFactory (Access denied for user 'test_user'@'127.0.0.1' (using password: YES))</pre>
<p>This had me really confused because I had changed nothing except where the database was.  In the dev and testing environment I&#8217;m using a remote database while in production environment the database is on the same machine as the code.  I took the same WAR file and moved it over to a Linux machine and everything seems to work with no problems there.  This got me even more confused.</p>
<p>After staring at the error for a little while I narrowed the problem down to how I was setting up the user&#8217;s permissions in MySQL.  They way I created the user&#8217;s permissions on all machines was this:</p>
<pre>GRANT ALL PRIVILEGES ON appdb.* to 'appuser'@'localhost' IDENTIFIED BY 'super-secret-pass' ;</pre>
<p>Turns out MySQL on FreeBSD really doesn&#8217;t like this when you have the DB setup in Grails as &#8220;localhost&#8221;.  For some reason I still don&#8217;t quite understand it uses the IP and not the DNS alias when authenticating.  I can see how this might be faster.  No need to do name resolution, but still, just makes thing harder.</p>
<p>The fix was to just create the user with the host set to 127.0.0.1.</p>
<pre>GRANT ALL PRIVILEGES ON appdb.* to 'appuser'@'127.0.0.1' IDENTIFIED BY 'super-secret-pass' ;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.labrat.info/20101111/grails-connectionpool-error-with-mysql-on-freebsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

