<?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>philihp.com</title>
	<atom:link href="http://philihp.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://philihp.com/blog</link>
	<description>I do things, and then I tell the internet about them.</description>
	<lastBuildDate>Tue, 18 Jun 2013 04:50:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Mining Bitcoin in the Eligius pool using Phoenix2</title>
		<link>http://philihp.com/blog/2013/mining-bitcoin-in-the-eligius-pool-using-phoenix2/</link>
		<comments>http://philihp.com/blog/2013/mining-bitcoin-in-the-eligius-pool-using-phoenix2/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 22:43:35 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[bitcoin]]></category>
		<category><![CDATA[eligius]]></category>
		<category><![CDATA[phoenix2]]></category>
		<category><![CDATA[pool]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://philihp.com/blog/?p=1232</guid>
		<description><![CDATA[I prefer to use the Eligius bitcoin mining pool because the pool takes no cut (compared to the larger, more popular BTC Guild, which takes 3-5%). The &#8220;getting started&#8221; for the Eligius Bitcoin mining pool doesn&#8217;t show how to configure Phoenix2, which is faster than, and supports more features over the older Phoenix 1.xx miner.&#8230; <a href="http://philihp.com/blog/2013/mining-bitcoin-in-the-eligius-pool-using-phoenix2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I prefer to use the <a href="http://eligius.st/">Eligius</a> bitcoin mining pool because the pool takes no cut (compared to the larger, more popular <a href="http://www.btcguild.com/">BTC Guild</a>, which takes 3-5%). The &#8220;<a href="http://eligius.st/wiki/index.php/Getting_Started">getting started</a>&#8221; for the Eligius Bitcoin mining pool doesn&#8217;t show how to configure Phoenix2, which is faster than, and supports more features over the older Phoenix 1.xx miner. Here&#8217;s a quick/dirty tutorial of how I set them up to work together on my machine.</p>
<blockquote><p>NOTE: It&#8217;s cheaper to buy bitcoin on an exchange than to mine it. The cost of a dedicated machine will probably take 1-2 years to recoup.</p></blockquote>
<h2>Step 1: Download <a href="https://github.com/downloads/phoenix2/phoenix/phoenix-2.0.0.zip">Phoenix 2</a></h2>
<p>Extract it to a folder on your hard drive, like <code>c:\phoenix\</code>. Anywhere. Doesn&#8217;t really matter.</p>
<h2>Step 2: Create phoenix.cfg</h2>
<p>Create it in that same folder. It should contain something like this. Once running you can play around with some of the parameters.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cfg" style="font-family:monospace;">[general]
    autodetect = +cl -cpu
    verbose = False
    backend = http://1PhiLHuzbozkqVkWYZEUiptKNGYNfne9Hb:x@mining.eligius.st:8337
    backups = http://rpcuser:rpcpassword@localhost:8332/
    failback = 600
    queuesize = 1
    ratesamples = 100
    logfile = False
[cl:0:0]
    name = GPU 0
    kernel = phatk2
    aggression = 1
    bfi_int = True
    fastloop = False
    goffset = True
    vectors = True
    vectors4 = False
    worksize = 128</pre></td></tr></table></div>

<p>Once running, you can tinker around with these last parameters to get the highest Mhash/s rate.  You will want to change the username to be the backend property to be where you want your rewards to be sent when the pool finds a new block (ideally yourself). You will also need some luck for the pool to start finding Bitcoin. You can generate a higher chance of that happening by donating bitcoin to <code>1PhiLHuzbozkqVkWYZEUiptKNGYNfne9Hb</code></p>
<p>Step 3: There is no step 3. Just run <code>phoenix.exe</code> from that folder. Go find something to do while your computer makes you money.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2013/mining-bitcoin-in-the-eligius-pool-using-phoenix2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Base SAS Library Assignments</title>
		<link>http://philihp.com/blog/2013/automatic-base-sas-library-assignments/</link>
		<comments>http://philihp.com/blog/2013/automatic-base-sas-library-assignments/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 19:19:16 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[8.2]]></category>
		<category><![CDATA[9.1.3]]></category>
		<category><![CDATA[9.2]]></category>
		<category><![CDATA[9.3]]></category>
		<category><![CDATA[autoexec]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[SAS]]></category>

		<guid isPermaLink="false">http://philihp.com/blog/?p=1227</guid>
		<description><![CDATA[If you stick a file named autoexec.sas in the directory where SAS is installed, it will run automatically when SAS starts up. By default, this place is C:\Program Files\SASHome\SASFoundation\9.3. This has worked since at least SAS 8.2, probably before. I like to use my Windows desktop as a temporary staging area, so I have my&#8230; <a href="http://philihp.com/blog/2013/automatic-base-sas-library-assignments/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you stick a file named <code>autoexec.sas</code> in the directory where SAS is installed, it will run automatically when SAS starts up. By default, this place is <code>C:\Program Files\SASHome\SASFoundation\9.3</code>. This has worked since <i>at least</i> SAS 8.2, probably before.</p>
<p>I like to use my Windows desktop as a temporary staging area, so I have my <code>autoexec.sas</code> automatically assign a &#8220;DESKTOP&#8221; library with this code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;"><span style="color: #0000ff;">%let</span> USERPROFILE=<span style="color: #0000ff;">%sysget</span><span style="color: #66cc66;">&#40;</span>USERPROFILE<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">libname</span> desktop <span style="color: #a020f0;">&quot;&amp;USERPROFILE<span style="color: #000099; font-weight: bold;">\D</span>esktop<span style="color: #000099; font-weight: bold;">\&quot;</span>;</span></pre></td></tr></table></div>

<p>So when SAS starts up, the library is assigned and my log says this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">NOTE: Copyright (c) 2002-2010 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.3 (TS1M2)
      Licensed to Microsoft Windows for x64 All Compatible Non-Plann, Site  XXXXXXX.
NOTE: This session is executing on the X64_7PRO  platform.
&nbsp;
&nbsp;
&nbsp;
NOTE: Enhanced analytical products:
&nbsp;
SAS/STAT 12.1, SAS/ETS 12.1, SAS/OR 12.2, SAS/IML 12.1, SAS/QC 12.1
&nbsp;
NOTE: SAS initialization used:
      real time           0.65 seconds
      cpu time            0.63 seconds
&nbsp;
&nbsp;
NOTE: AUTOEXEC processing beginning; file is C:\Program
      Files\SASHome\SASFoundation\9.3\autoexec.sas.
&nbsp;
NOTE: Libref DESKTOP was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\Users\philihp\Desktop
&nbsp;
NOTE: AUTOEXEC processing completed.</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2013/automatic-base-sas-library-assignments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding the Center of US Counties in SAS</title>
		<link>http://philihp.com/blog/2013/finding-the-center-of-us-counties-in-sas/</link>
		<comments>http://philihp.com/blog/2013/finding-the-center-of-us-counties-in-sas/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 20:53:43 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[centroid]]></category>
		<category><![CDATA[data step]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[proc sql]]></category>
		<category><![CDATA[SAS]]></category>

		<guid isPermaLink="false">http://philihp.com/blog/?p=1208</guid>
		<description><![CDATA[I had a problem where I needed the center longitude and latitude of each US county. SAS comes with some datasets containing map data in the format of tables that trace a line around the borders of counties. I was interested in the MAPSGFK.US_COUNTIES dataset, which has data that looks like this: The State and&#8230; <a href="http://philihp.com/blog/2013/finding-the-center-of-us-counties-in-sas/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I had a problem where I needed the center longitude and latitude of each US county. <a href="http://support.sas.com/documentation/cdl/en/graphref/65389/HTML/default/viewer.htm#n0i4k2s0dkf6n8n15222j3gi07o8.htm">SAS comes with some datasets containing map data</a> in the format of tables that trace a line around the borders of counties. I was interested in the <a href="http://support.sas.com/documentation/cdl/en/graphref/65389/HTML/default/viewer.htm#n17k5bnax0zd6qn1p4qvzgd8uz2d.htm">MAPSGFK.US_COUNTIES</a> dataset, which has data that looks like this:</p>
<p><img src="http://philihp.com/blog/wp-content/uploads/2013/03/uscounties.png" alt="" title="US Counties Table" width="500" class="alignnone size-full wp-image-1209" /></p>
<p>The State and County numbers were <a href="http://en.wikipedia.org/wiki/FIPS_county_code">FIPS codes</a>, which were also stored in the US_COUNTIES_ATTR table, so those are easy enough to figure out. Segment <i>seemed</i> to be always 1. Resolution and Density were numbers that I figured had to do with how much detail the drawing would have if these points were used in a line drawing.</p>
<p>The longitude and latitude here are all points along the border. The simplest, and most incorrect way of getting the center of the county would be to take an average of them, which would be fine for rectangular counties, but for territories where one side is flat (and has few waypoints) and one side is jagged (such as a coastal border), the midpoint will be weighted to that side. So instead, use geometry.</p>
<p>In geometry, there&#8217;s a formula for the <a href="http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon">Centroid of a polygon</a>. This is a magic formula that I just trust is correct, because everything on Wikipedia is true, without exception. Here was my first pass at an implementation of it in SAS:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;"><span style="color: #000080; font-weight: bold;">proc sort</span> <span style="color: #000080; font-weight: bold;">data</span>=mapsgfk.us_counties out=centroids;
  <span style="color: #0000ff;">by</span> state county;
<span style="color: #000080; font-weight: bold;">run</span>;
<span style="color: #000080; font-weight: bold;">data</span> centroids<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">keep</span>=cx cy county state<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0000ff;">retain</span> yi yj xi xj a cx cy x0 y0 <span style="color: #2e8b57; font-weight: bold;">0</span>;
  <span style="color: #0000ff;">set</span> centroids<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">keep</span>=state county lat long <span style="color: #0000ff;">rename</span>=<span style="color: #66cc66;">&#40;</span>lat=yj long=xj<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0000ff;">by</span> state county;
  <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span>first.county<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    cx = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    cy = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    a = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    x0 = xj;
    y0 = yj;
  <span style="color: #0000ff;">end</span>;
  <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">not</span> first.county<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    ta = <span style="color: #66cc66;">&#40;</span>xi<span style="color: #006400; font-style: italic;">*yj - xj*yi);</span>
    cx + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xi+xj<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    cy + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>yi+yj<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    a + ta;
  <span style="color: #0000ff;">end</span>;
  <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span>last.county<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    ta = <span style="color: #66cc66;">&#40;</span>xj<span style="color: #006400; font-style: italic;">*y0 - x0*yj);</span>
    cx + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xj+x0<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    cy + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>yj+y0<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    a  = ta + a <span style="color: #006400; font-style: italic;">* 0.5;</span>
    cx = cx / <span style="color: #66cc66;">&#40;</span><span style="color: #2e8b57; font-weight: bold;">6</span><span style="color: #006400; font-style: italic;">*a);</span>
    cy = cy / <span style="color: #66cc66;">&#40;</span><span style="color: #2e8b57; font-weight: bold;">6</span><span style="color: #006400; font-style: italic;">*a);</span>
    <span style="color: #0000ff;">output</span>;
  <span style="color: #0000ff;">end</span>;
  xi = xj;
  yi = yj;
<span style="color: #000080; font-weight: bold;">run</span>;</pre></td></tr></table></div>

<p>Here, <i>xi</i> and <i>yi</i> are always the coordinates from the previous point, and &#8220;<code>if not first.county</code>&#8221;  prevents processing of the first point of a county because it didn&#8217;t have a previous point. The variables <i>a</i>, <i>cx</i>, and <i>cy</i> accumulate for every point. The variable <i>ta</i> is the area of the rectangle defined by the two points. Once all the points have been accumulated, the area is halfed so it&#8217;s the actual area, and the area is used in calculating the centroid (<i>cx</i> and <i>cy</i>).</p>
<p><img src="http://philihp.com/blog/wp-content/uploads/2013/03/pass1.png" alt="" title="pass1" width="440" height="173" class="aligncenter size-full wp-image-1215" /></p>
<p>But then I noticed the 2nd county was positioned somewhere in the mid-Atlantic. Something had to be up. Looking closer, this was <a href="http://en.wikipedia.org/wiki/Baldwin_County,_Alabama">Baldwin County</a>, which had an island. Looking at the source data, this segment was drawn in two segments, which caused the centroid formula to choke, as it assumed contiguous shapes. So instead, in my second pass, I compute the centroid of every segment, then average them weighted by their areas.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;"><span style="color: #000080; font-weight: bold;">proc sort</span> <span style="color: #000080; font-weight: bold;">data</span>=mapsgfk.us_counties out=centroids;
  <span style="color: #0000ff;">by</span> state county segment;
<span style="color: #000080; font-weight: bold;">run</span>;
<span style="color: #000080; font-weight: bold;">data</span> centroids_temp;
  <span style="color: #0000ff;">retain</span> yi yj xi xj a cx cy x0 y0 <span style="color: #2e8b57; font-weight: bold;">0</span>;
  <span style="color: #0000ff;">set</span> centroids<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">keep</span>=state county segment lat long <span style="color: #0000ff;">rename</span>=<span style="color: #66cc66;">&#40;</span>lat=yj long=xj<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0000ff;">by</span> state county segment;
  <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span>first.segment<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    cx = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    cy = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    a = <span style="color: #2e8b57; font-weight: bold;">0</span>;
    x0 = xj;
    y0 = yj;
  <span style="color: #0000ff;">end</span>;
  <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">not</span> first.segment<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    ta = <span style="color: #66cc66;">&#40;</span>xi<span style="color: #006400; font-style: italic;">*yj - xj*yi);</span>
    cx + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xi+xj<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    cy + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>yi+yj<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    a + ta;
  <span style="color: #0000ff;">end</span>;
  <span style="color: #0000ff;">if</span><span style="color: #66cc66;">&#40;</span>last.segment<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;
    ta = <span style="color: #66cc66;">&#40;</span>xj<span style="color: #006400; font-style: italic;">*y0 - x0*yj);</span>
    cx + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>xj+x0<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    cy + <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>yj+y0<span style="color: #66cc66;">&#41;</span><span style="color: #006400; font-style: italic;">*ta);</span>
    a  = ta + a <span style="color: #006400; font-style: italic;">* 0.5;</span>
    cx = cx / <span style="color: #66cc66;">&#40;</span><span style="color: #2e8b57; font-weight: bold;">6</span><span style="color: #006400; font-style: italic;">*a);</span>
    cy = cy / <span style="color: #66cc66;">&#40;</span><span style="color: #2e8b57; font-weight: bold;">6</span><span style="color: #006400; font-style: italic;">*a);</span>
    <span style="color: #0000ff;">output</span>;
  <span style="color: #0000ff;">end</span>;
  xi = xj;
  yi = yj;
<span style="color: #000080; font-weight: bold;">run</span>;
<span style="color: #000080; font-weight: bold;">proc sql</span>;
  <span style="color: #0000ff;">create</span> <span style="color: #0000ff;">table</span> centroid_weight <span style="color: #0000ff;">as</span>
  <span style="color: #0000ff;">select</span>
    state, county, <span style="color: #0000ff;">sum</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">as</span> <span style="color: #0000ff;">sum</span>
  <span style="color: #0000ff;">from</span> centroids_temp
    <span style="color: #0000ff;">group</span> <span style="color: #0000ff;">by</span> state, county;
<span style="color: #000080; font-weight: bold;">quit</span>;
<span style="color: #000080; font-weight: bold;">proc sql</span>;
  <span style="color: #0000ff;">create</span> <span style="color: #0000ff;">table</span> centroids <span style="color: #0000ff;">as</span>
  <span style="color: #0000ff;">select</span> a.state, a.county,
         <span style="color: #0000ff;">sum</span><span style="color: #66cc66;">&#40;</span>cx<span style="color: #006400; font-style: italic;">*(a / sum)) as lat,
         sum(cy*(a / sum)) as long
    from centroids_temp a
    inner join centroid_weight b
      on (a.state = b.state and a.county = b.county)
    group by a.state, a.county;</span>
<span style="color: #000080; font-weight: bold;">quit</span>;
<span style="color: #000080; font-weight: bold;">proc sql</span>;
  <span style="color: #0000ff;">drop</span> <span style="color: #0000ff;">table</span> centroids_temp;
  <span style="color: #0000ff;">drop</span> <span style="color: #0000ff;">table</span> centroid_weight;
<span style="color: #000080; font-weight: bold;">quit</span>;</pre></td></tr></table></div>

<p>Here, I add two more steps. The first proc SQL block sums up the total area of each county, which is used in the second block to find the average centroid of each county&#8217;s centroids, weighted by the total area that centroid represents, which gives us correct centroids for counties drawn in multiple segments.</p>
<p><img src="http://philihp.com/blog/wp-content/uploads/2013/03/pass2.png" alt="" title="pass2" width="438" height="284" class="alignnone size-full wp-image-1219" /></p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2013/finding-the-center-of-us-counties-in-sas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bayesian Averaging in SAS</title>
		<link>http://philihp.com/blog/2013/bayesian-averaging-in-sas/</link>
		<comments>http://philihp.com/blog/2013/bayesian-averaging-in-sas/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 22:53:46 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[average]]></category>
		<category><![CDATA[bayesian]]></category>
		<category><![CDATA[rank]]></category>
		<category><![CDATA[rating]]></category>
		<category><![CDATA[SAS]]></category>

		<guid isPermaLink="false">http://philihp.com/blog/?p=1184</guid>
		<description><![CDATA[Hypothetical situation, lets say you&#8217;ve got a list of movies that you want to rank in a website or a report or something, and you have user-submitted ratings for them, but some are more popular than others, so your data looks like this: data ratings; input name $ rating; datalines; Lincoln 9 Lincoln 8 Lincoln&#8230; <a href="http://philihp.com/blog/2013/bayesian-averaging-in-sas/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Hypothetical situation, lets say you&#8217;ve got a list of movies that you want to rank in a website or a report or something, and you have user-submitted ratings for them, but some are more popular than others, so your data looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;">  <span style="color: #000080; font-weight: bold;">data</span> ratings;
    <span style="color: #0000ff;">input</span> name $ rating;
    datalines;
  Lincoln <span style="color: #2e8b57; font-weight: bold;">9</span>
  Lincoln <span style="color: #2e8b57; font-weight: bold;">8</span>
  Lincoln <span style="color: #2e8b57; font-weight: bold;">9</span>
  Amour <span style="color: #2e8b57; font-weight: bold;">9</span>
  Argo <span style="color: #2e8b57; font-weight: bold;">5</span>
  Argo <span style="color: #2e8b57; font-weight: bold;">10</span>
  ;
  <span style="color: #000080; font-weight: bold;">run</span>;</pre></td></tr></table></div>

<table class="data">
<colgroup>
<col /></colgroup>
<colgroup>
<col />
<col /></colgroup>
<thead>
<tr>
<th scope="col">Obs</th>
<th scope="col">name</th>
<th scope="col">rating</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Lincoln</td>
<td>9</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Lincoln</td>
<td>8</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Lincoln</td>
<td>9</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Amour</td>
<td>9</td>
</tr>
<tr>
<th scope="row">5</th>
<td>Argo</td>
<td>5</td>
</tr>
<tr>
<th scope="row">6</th>
<td>Argo</td>
<td>10</td>
</tr>
</tbody>
</table>
<p>The easiest thing to do would be to calculate an average rating for each movie like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;">  <span style="color: #000080; font-weight: bold;">proc sql</span>;
    <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">distinct</span> name, avg<span style="color: #66cc66;">&#40;</span>rating<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">as</span> average
      <span style="color: #0000ff;">from</span> ratings
      <span style="color: #0000ff;">group</span> <span style="color: #0000ff;">by</span> name
      <span style="color: #0000ff;">order</span> <span style="color: #0000ff;">by</span> average desc;
  <span style="color: #000080; font-weight: bold;">run</span>;</pre></td></tr></table></div>

<table class="data">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">average</th>
</tr>
</thead>
<tbody>
<tr>
<td>Amour</td>
<td>9.00</td>
</tr>
<tr>
<td>Lincoln</td>
<td>8.67</td>
</tr>
<tr>
<td>Argo</td>
<td>7.50</td>
</tr>
</tbody>
</table>
<p>But hey! That&#8217;s not cool. It looks like Amour wins, because its average rating is 9. Maybe we want to consider Lincoln as better because 3 people think it&#8217;s very high. A good way to deal with this is by instead taking a <a href="http://en.wikipedia.org/wiki/Bayesian_average" target="_blank">Bayesian Average</a>.</p>
<p>This means we&#8217;re going to add in some &#8220;dummy&#8221; votes for each movie, who give each movie the average rating a movie gets. How many (C) is a judgement call, the more we add, the harder we make it for an obscure movie to be near the top. Likewise, if a movie&#8217;s first rating is low, it keeps it from suddenly dropping to the bottom of the list. If we expect thousands of ratings for each movie, a C=1000 might be appropriate. In this example, I use a small C of 10.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;">  <span style="color: #000080; font-weight: bold;">proc sql</span>;
    <span style="color: #0000ff;">select</span> avg<span style="color: #66cc66;">&#40;</span>rating<span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">into</span> :average
      <span style="color: #0000ff;">from</span> ratings;
    <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">distinct</span>
        name,
        <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">sum</span><span style="color: #66cc66;">&#40;</span>rating<span style="color: #66cc66;">&#41;</span> + <span style="color: #0000ff; font-weight: bold;">&amp;average</span> <span style="color: #006400; font-style: italic;">* 10) / (count(*) + 10) as b_average
      from ratings
      group by name
      order by b_average;</span>
  <span style="color: #000080; font-weight: bold;">quit</span>;</pre></td></tr></table></div>

<table class="data">
<colgroup>
<col />
<col /></colgroup>
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">b_average</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lincoln</td>
<td>8.41</td>
</tr>
<tr>
<td>Amour</td>
<td>8.39</td>
</tr>
<tr>
<td>Argo</td>
<td>8.19</td>
</tr>
</tbody>
</table>
<p>And look! Lincoln is back on top, since its bayesian average more closely reflects a product of the number of ratings it has and what those ratings are.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2013/bayesian-averaging-in-sas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Save Struts Messages After a Redirect</title>
		<link>http://philihp.com/blog/2012/how-to-save-struts-messages-after-a-redirect/</link>
		<comments>http://philihp.com/blog/2012/how-to-save-struts-messages-after-a-redirect/#comments</comments>
		<pubDate>Tue, 18 Dec 2012 10:34:41 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionerror]]></category>
		<category><![CDATA[actionmessage]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[Struts]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1177</guid>
		<description><![CDATA[If you&#8217;ve got an Action in Struts 1 that leaves an error or message for the view, it does it somewhere in the class like this: ActionMessages messages = getMessages&#40;request&#41;; messages.add&#40;ActionMessages.GLOBAL_MESSAGE, new ActionMessage&#40;&#34;message.detail&#34;, &#34;Normality has been restored.&#34;&#41;&#41;; saveMessages&#40;request, messages&#41;; However if your Action later selects an ActionForward that redirects (possibly unbeknownst to the Action, since&#8230; <a href="http://philihp.com/blog/2012/how-to-save-struts-messages-after-a-redirect/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve got an Action in Struts 1 that leaves an error or message for the view, it does it somewhere in the class like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">ActionMessages messages <span style="color: #339933;">=</span> getMessages<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
messages.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>ActionMessages.<span style="color: #006633;">GLOBAL_MESSAGE</span>, <span style="color: #000000; font-weight: bold;">new</span> ActionMessage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message.detail&quot;</span>, <span style="color: #0000ff;">&quot;Normality has been restored.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
saveMessages<span style="color: #009900;">&#40;</span>request, messages<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>However if your Action later selects an ActionForward that redirects (possibly unbeknownst to the Action, since that is configured elsewhere), the Controller will redirect the browser to that new location and Struts will see that redirected call as an entirely new request, having lost anything in the request attributes (such as the message you just saved).</p>
<p>There are some <a href="http://struts.1045723.n5.nabble.com/Showing-messages-after-a-redirect-td3481980.html">other</a> ways to do it, but here&#8217;s a really simple way to do it:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">saveMessages<span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, messages<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once they&#8217;re displayed in the view once they will automatically be removed from the session. In this fashion, it behaves like a <a href="http://mkblog.exadel.com/2010/07/learning-jsf2-using-flash-scope/">Flash</a> scoped variable in JSF, except you can be sure it&#8217;s displayed even if the next request fails, which is probably a good thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/how-to-save-struts-messages-after-a-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WARNING: Form &#8216;myForm&#8217; not found for locale &#8216;en_US&#8217;</title>
		<link>http://philihp.com/blog/2012/warning-form-myform-not-found-for-locale-en_us/</link>
		<comments>http://philihp.com/blog/2012/warning-form-myform-not-found-for-locale-en_us/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 07:14:30 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1164</guid>
		<description><![CDATA[It looks like someone had this error in 2006, and it was never resolved. I am posting this, hoping that in 2018 someone will have the same issue again, and the wisdom of the ancients will not fail him. Dec 10, 2012 1:41:05 AM org.apache.commons.validator.ValidatorResources getForm WARNING: Form 'myFormBean' not found for locale 'en_US' In&#8230; <a href="http://philihp.com/blog/2012/warning-form-myform-not-found-for-locale-en_us/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>It looks like <a href="http://www.servlets.com/archive/servlet/BrowseList?listName=struts-user&#038;by=thread&#038;from=96820">someone</a> had this error in 2006, and it was never resolved. I am posting this, hoping that in 2018 someone will have the same issue again, and the <a href="http://xkcd.com/979/">wisdom of the ancients</a> will not fail him.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">Dec 10, 2012 1:41:05 AM org.apache.commons.validator.ValidatorResources getForm
WARNING: Form 'myFormBean' not found for locale 'en_US'</pre></td></tr></table></div>

<p>In Struts 1.3, when you see this error in your code, it&#8217;s because you have a ValidatorForm specified in your struts-config, and Struts is trying to instantiate it, and wondering what validator rules it follows. The validator is looking in your validation.xml file (the thing specified in the plug-in element in your struts-config.xml file), and not seeing any mention of your form. The bit about the locale is a red herring; <b>every Form bean that extends ValidatorForm listed in struts-config.xml must have a corresponding form element in validation.xml</b>. It doesn&#8217;t matter if your ValidatorForm does all of its own validation in <a href="http://struts.apache.org/1.3.10/apidocs/org/apache/struts/validator/ValidatorForm.html#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)">validate()</a>. Everything will work, but if that empty element isn&#8217;t in validation.xml, you will get this annoying warning, and if you <a href="http://visualstudiotips.wordpress.com/2006/04/16/tip-treat-warnings-as-errors/">treat warnings as errors</a>, then you&#8217;re probably wondering how to fix it.</p>
<p>To fix it, add an empty form element to validation.xml, like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-validation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;formset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myFormBean&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/formset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-validation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Please use this knowledge to save us from the Ko-dan armada.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/warning-form-myform-not-found-for-locale-en_us/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting the last element in an array in JSF and JSTL</title>
		<link>http://philihp.com/blog/2012/getting-the-last-element-in-an-array-in-jsp-with-jstl/</link>
		<comments>http://philihp.com/blog/2012/getting-the-last-element-in-an-array-in-jsp-with-jstl/#comments</comments>
		<pubDate>Sun, 09 Dec 2012 19:15:45 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[el]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[jstl]]></category>
		<category><![CDATA[last]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1155</guid>
		<description><![CDATA[I&#8217;d love it if JSTL had some sort of way to get the last element in an array. Ruby conveniently makes negative indexes start from the end of the array: myarray&#91;-1&#93; For some reason, lists and arrays in Java have &#8220;.length&#8221; and &#8220;.size()&#8221; accessors, instead of either getLength() or getSize(), and there isn&#8217;t a convenience&#8230; <a href="http://philihp.com/blog/2012/getting-the-last-element-in-an-array-in-jsp-with-jstl/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;d love it if JSTL had some sort of way to get the last element in an array. Ruby conveniently makes negative indexes start from the end of the array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">myarray<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>For some reason, lists and arrays in Java have &#8220;.length&#8221; and &#8220;.size()&#8221; accessors, instead of either getLength() or getSize(), and there isn&#8217;t a convenience method for this. And for some reason, this has never been corrected, and the old way deprecated. Who knows? Bad decisions from the start have a way of growing like cancer. In JSTL and JSF, which relies heavily on getters for property accessing, there&#8217;s a helper function for this: <a href="http://docs.oracle.com/javaee/5/tutorial/doc/bnalg.html">fn:length()</a>. Using this, you can get the last element of an array like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">$<span style="color: #009900;">&#123;</span>myArray<span style="color: #009900;">&#91;</span>fn<span style="color: #339933;">:</span>length<span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>or in JSF</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">#<span style="color: #009900;">&#123;</span>myArray<span style="color: #009900;">&#91;</span>fn<span style="color: #339933;">:</span>length<span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Maybe someone at <s>Sun</s> Oracle will see this and add it to Java 9?</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/getting-the-last-element-in-an-array-in-jsp-with-jstl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting Rows from the Last 5 Years in SAS</title>
		<link>http://philihp.com/blog/2012/selecting-rows-from-the-last-5-years-in-sas/</link>
		<comments>http://philihp.com/blog/2012/selecting-rows-from-the-last-5-years-in-sas/#comments</comments>
		<pubDate>Thu, 06 Dec 2012 05:01:06 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[intck]]></category>
		<category><![CDATA[interval]]></category>
		<category><![CDATA[intnx]]></category>
		<category><![CDATA[SAS]]></category>
		<category><![CDATA[window]]></category>
		<category><![CDATA[year]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1144</guid>
		<description><![CDATA[I was asked recently in a Q&#38;A, &#8220;how to select the last 5 years worth of data from a table in SAS?&#8221; One way of doing it is by selecting the data with a Proc SQL query similar to the following, and something similar could also be done in a data step: PROC SQL; create&#8230; <a href="http://philihp.com/blog/2012/selecting-rows-from-the-last-5-years-in-sas/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I was asked recently in a Q&amp;A, &#8220;how to select the last 5 years worth of data from a table in SAS?&#8221; One way of doing it is by selecting the data with a Proc SQL query similar to the following, and something similar could also be done in a data step:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sas" style="font-family:monospace;"><span style="color: #000080; font-weight: bold;">PROC SQL</span>;
  <span style="color: #0000ff;">create</span> <span style="color: #0000ff;">table</span> mywindow <span style="color: #0000ff;">as</span>
  <span style="color: #0000ff;">select</span> ...myvariables...
    <span style="color: #0000ff;">from</span> mylib.mytable
    <span style="color: #0000ff;">where</span> <span style="color: #0000ff;">year</span><span style="color: #66cc66;">&#40;</span>mydate<span style="color: #66cc66;">&#41;</span> between <span style="color: #0000ff;">year</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">today</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>-<span style="color: #2e8b57; font-weight: bold;">5</span> <span style="color: #0000ff;">and</span> <span style="color: #0000ff;">year</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">today</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000080; font-weight: bold;">QUIT</span>;</pre></td></tr></table></div>

<p><i>Caveat emptor</i>, this is really only going to include the last 4 complete years and whatever portion of the current year is in the dataset. This is because year() truncates out the month and day of the date.</p>
<p>Of course, this is just one way to do it. By using the intnx function, more advanced intervals can be done.</p>
<p>SAS Documentation:</p>
<ul>
<li><a href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p13eycdrmfb0l8n1492z3wocpt3s.htm">YEAR function</a></li>
<li><a href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0hm9egy8s7mokn1mz0yxng80ax5.htm">TODAY function</a></li>
<li><a href="http://support.sas.com/documentation/cdl/en/etsug/65545/HTML/default/viewer.htm#etsug_tsdata_sect047.htm">Interval Functions INTNX and INTCK</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/selecting-rows-from-the-last-5-years-in-sas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two Common Struts Null Pointer Exceptions</title>
		<link>http://philihp.com/blog/2012/struts-form-nullpointerexception/</link>
		<comments>http://philihp.com/blog/2012/struts-form-nullpointerexception/#comments</comments>
		<pubDate>Mon, 03 Dec 2012 03:38:04 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[null pointer]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[Struts 1.3]]></category>
		<category><![CDATA[validatior]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1137</guid>
		<description><![CDATA[The First Problem I have come across this problem at 2 times this weekend. Since I came across it twice, I assume a high likelihood that others will as well. Hopefully the people of the future will be able to Google the stack trace and find this post. The problem is that after mucking around&#8230; <a href="http://philihp.com/blog/2012/struts-form-nullpointerexception/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h1>The First Problem</h1>
<p>I have come across this problem at 2 times this weekend. Since I came across it twice, I assume a high likelihood that others will as well. Hopefully the people of the future will be able to Google the stack trace and find this post. The problem is that after mucking around with my struts-config.xml file&#8217;s hooks, I got this error when trying to visit a page:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="plain" style="font-family:monospace;">javax.servlet.ServletException: java.lang.NullPointerException
	org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.philihp.weblabora.util.EntityManagerFilter.doFilter(EntityManagerFilter.java:32)
&nbsp;
java.lang.NullPointerException
	org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
	org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:357)
	org.apache.struts.chain.commands.CreateActionForm.execute(CreateActionForm.java:92)
	org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
	org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
	org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.philihp.weblabora.util.EntityManagerFilter.doFilter(EntityManagerFilter.java:32)</pre></td></tr></table></div>

<p>The problem was that the type of my form-bean couldn&#8217;t be instantiated, because it didn&#8217;t exist. My config looked like:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginForm&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.struts.action.DynaValidatorForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The problem was <code>org.apache.struts.action.DynaValidatorForm</code> does not exist (or wasn&#8217;t found on the classpath). Instead, the correct line was</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginForm&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.struts.validator.DynaValidatorForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In another case, I typed &#8220;com.apache&#8230;&#8221; instead of &#8220;org.apache&#8230;&#8221;.</p>
<h1>The Second Problem</h1>
<p>This problem&#8217;s symptom was a stack trace like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="plain" style="font-family:monospace;">java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null
	org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:70)
	org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
	org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
	org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
	org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)</pre></td></tr></table></div>

<p>The problem is that an Action with a ValidatorForm form was validating with errors, and didn&#8217;t know where to send the client back to. This can happen if both the validate and input attributes of the Action are omitted. It can be remedied by setting validate=&#8221;false&#8221; (if you don&#8217;t want it to validate) or input=&#8221;<i>some path</i>&#8221; (if you do want it to validate).</p>
<p>Struts needs to know where to send the user if there are errors in validation.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/struts-form-nullpointerexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Farmville 2 Profit/Experience Maximization Spreadsheet</title>
		<link>http://philihp.com/blog/2012/a-farmville-2-profitexperience-maximization-spreadsheet/</link>
		<comments>http://philihp.com/blog/2012/a-farmville-2-profitexperience-maximization-spreadsheet/#comments</comments>
		<pubDate>Sat, 24 Nov 2012 19:36:09 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Video Games]]></category>
		<category><![CDATA[farmville 2]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[spreadsheet]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=1130</guid>
		<description><![CDATA[I&#8217;ve been playing Farmville 2 since launch. At first it started out as a mix of nostalgia and curiosity, but after reaching level 5 and opening up the cookhouse, I discovered there was a fun supply-chain management problem in it, and I made this Google Docs spreadsheet. It glosses over a few things like the&#8230; <a href="http://philihp.com/blog/2012/a-farmville-2-profitexperience-maximization-spreadsheet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been playing Farmville 2 since launch. At first it started out as a mix of nostalgia and curiosity, but after reaching level 5 and opening up the cookhouse, I discovered there was a fun supply-chain management problem in it, and I made this Google Docs spreadsheet. It glosses over a few things like the average number of fruit a tree produces, and the costs involved in farming livestock.</p>
<p><iframe width='500' height='300' frameborder='0' src='https://docs.google.com/spreadsheet/pub?key=0AmcSLQePfpMkdHZqVjcwU1NTRkRIWUw1bEQ5am16cHc&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe><br />
<i><a href="http://goo.gl/5oOAq">http://goo.gl/5oOAq</a></i></p>
<p>If you have any data or corrections you&#8217;d like to contribute, please email me.</p>
]]></content:encoded>
			<wfw:commentRss>http://philihp.com/blog/2012/a-farmville-2-profitexperience-maximization-spreadsheet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
