<?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>( f o o b a r . l u ) &#187; Coding Voodoo</title>
	<atom:link href="http://foobar.lu/wp/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://foobar.lu/wp</link>
	<description>coding should be fun</description>
	<lastBuildDate>Thu, 09 Jun 2011 15:20:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>JScript to query scheduled tasks</title>
		<link>http://foobar.lu/wp/2011/06/09/jscript-to-query-scheduled-tasks/</link>
		<comments>http://foobar.lu/wp/2011/06/09/jscript-to-query-scheduled-tasks/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 15:19:47 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=211</guid>
		<description><![CDATA[Soon, we will need to send out notifications as soon something bad happens with a scheduled task on Windows. The following JScript file runs natively on Windows and is capable of just that. It uses the command line tool &#8220;schtasks&#8221; to query the information and wraps the result into a list of usable object instances. [...]]]></description>
			<content:encoded><![CDATA[<p>Soon, we will need to send out notifications as soon something bad happens with a scheduled task on Windows. The following JScript file runs natively on Windows and is capable of just that. It uses the command line tool &#8220;schtasks&#8221; to query the information and wraps the result into a list of usable object instances.</p>
<p>It&#8217;s possible to use this list to react to important events in the job executions. For example, you could loop through the list and send emails to the appropriate people if the variable &#8220;lastResult&#8221; is non-zero.</p>
<div id="gist-1016899" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Naive CSV splitter</span></div><div class='line' id='LC3'><span class="cm"> *</span></div><div class='line' id='LC4'><span class="cm"> * This splitter is *very* simplistic and may result in errors when parsing</span></div><div class='line' id='LC5'><span class="cm"> * unknown CSV sources. This works well in the current problem domain.</span></div><div class='line' id='LC6'><span class="cm"> *</span></div><div class='line' id='LC7'><span class="cm"> * As we have well defined data, with no escaped quotes inside the fields, we</span></div><div class='line' id='LC8'><span class="cm"> * can sefaly assume that this will work.</span></div><div class='line' id='LC9'><span class="cm"> */</span></div><div class='line' id='LC10'><span class="kd">function</span> <span class="nx">simpleCsvSplit</span><span class="p">(</span><span class="nx">lineText</span><span class="p">){</span></div><div class='line' id='LC11'>	<span class="kd">var</span> <span class="nx">columns</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC12'>	<span class="kd">var</span> <span class="nx">inside_quote</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC13'>	<span class="kd">var</span> <span class="nx">current_data</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">;</span></div><div class='line' id='LC14'>	<span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span></div><div class='line' id='LC15'>	<span class="k">for</span><span class="p">(</span><span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">lineText</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">){</span></div><div class='line' id='LC16'>		<span class="kd">var</span> <span class="nx">chr</span> <span class="o">=</span> <span class="nx">lineText</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span></div><div class='line' id='LC17'>		<span class="k">if</span> <span class="p">(</span><span class="nx">chr</span> <span class="o">===</span> <span class="s2">&quot;\&quot;&quot;</span><span class="p">){</span></div><div class='line' id='LC18'>			<span class="nx">inside_quote</span> <span class="o">=</span> <span class="o">!</span><span class="nx">inside_quote</span><span class="p">;</span></div><div class='line' id='LC19'>			<span class="k">continue</span><span class="p">;</span></div><div class='line' id='LC20'>		<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">chr</span> <span class="o">===</span> <span class="s2">&quot;,&quot;</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">inside_quote</span><span class="p">){</span></div><div class='line' id='LC21'>			<span class="nx">columns</span><span class="p">[</span><span class="nx">columns</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span> <span class="o">=</span> <span class="nx">current_data</span><span class="p">;</span></div><div class='line' id='LC22'>			<span class="nx">current_data</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">;</span></div><div class='line' id='LC23'>		<span class="p">}</span></div><div class='line' id='LC24'>		<span class="k">if</span> <span class="p">(</span><span class="nx">inside_quote</span><span class="p">){</span></div><div class='line' id='LC25'>			<span class="nx">current_data</span> <span class="o">+=</span> <span class="nx">chr</span><span class="p">;</span></div><div class='line' id='LC26'>		<span class="p">}</span></div><div class='line' id='LC27'>	<span class="p">}</span></div><div class='line' id='LC28'>	<span class="nx">columns</span><span class="p">[</span><span class="nx">columns</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span> <span class="o">=</span> <span class="nx">current_data</span><span class="p">;</span></div><div class='line' id='LC29'>	<span class="k">return</span> <span class="nx">columns</span><span class="p">;</span></div><div class='line' id='LC30'><span class="p">}</span></div><div class='line' id='LC31'><br/></div><div class='line' id='LC32'><span class="cm">/**</span></div><div class='line' id='LC33'><span class="cm"> * A container object for the task metadata</span></div><div class='line' id='LC34'><span class="cm"> * This makes further processing with the data a lot more expressive.</span></div><div class='line' id='LC35'><span class="cm"> *</span></div><div class='line' id='LC36'><span class="cm"> * @param lineText A string taken from the CSV output representing one line</span></div><div class='line' id='LC37'><span class="cm"> */</span></div><div class='line' id='LC38'><span class="kd">var</span> <span class="nx">Task</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">lineText</span><span class="p">){</span></div><div class='line' id='LC39'>	<span class="c1">// parse the CSV data</span></div><div class='line' id='LC40'>	<span class="nx">columns</span> <span class="o">=</span> <span class="nx">simpleCsvSplit</span><span class="p">(</span><span class="nx">lineText</span><span class="p">);</span></div><div class='line' id='LC41'><br/></div><div class='line' id='LC42'>	<span class="c1">// put everything into explicitly named variables</span></div><div class='line' id='LC43'>	<span class="k">this</span><span class="p">.</span><span class="nx">hostName</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span></div><div class='line' id='LC44'>	<span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span></div><div class='line' id='LC45'>	<span class="k">this</span><span class="p">.</span><span class="nx">nextRun</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span></div><div class='line' id='LC46'>	<span class="k">this</span><span class="p">.</span><span class="nx">status</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span></div><div class='line' id='LC47'>	<span class="k">this</span><span class="p">.</span><span class="nx">lastRun</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">4</span><span class="p">];</span></div><div class='line' id='LC48'>	<span class="k">this</span><span class="p">.</span><span class="nx">lastResult</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">5</span><span class="p">];</span></div><div class='line' id='LC49'>	<span class="k">this</span><span class="p">.</span><span class="nx">creator</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">6</span><span class="p">];</span></div><div class='line' id='LC50'>	<span class="k">this</span><span class="p">.</span><span class="nx">schedule</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">7</span><span class="p">];</span></div><div class='line' id='LC51'>	<span class="k">this</span><span class="p">.</span><span class="nx">command</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">8</span><span class="p">];</span></div><div class='line' id='LC52'>	<span class="k">this</span><span class="p">.</span><span class="nx">startIn</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">9</span><span class="p">];</span></div><div class='line' id='LC53'>	<span class="k">this</span><span class="p">.</span><span class="nx">comment</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span></div><div class='line' id='LC54'>	<span class="k">this</span><span class="p">.</span><span class="nx">scheduledState</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">11</span><span class="p">];</span></div><div class='line' id='LC55'>	<span class="k">this</span><span class="p">.</span><span class="nx">scheduledType</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">12</span><span class="p">];</span></div><div class='line' id='LC56'>	<span class="k">this</span><span class="p">.</span><span class="nx">startTime</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">13</span><span class="p">];</span></div><div class='line' id='LC57'>	<span class="k">this</span><span class="p">.</span><span class="nx">startDate</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">14</span><span class="p">];</span></div><div class='line' id='LC58'>	<span class="k">this</span><span class="p">.</span><span class="nx">endDate</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">15</span><span class="p">];</span></div><div class='line' id='LC59'>	<span class="k">this</span><span class="p">.</span><span class="nx">days</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">16</span><span class="p">];</span></div><div class='line' id='LC60'>	<span class="k">this</span><span class="p">.</span><span class="nx">months</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">17</span><span class="p">];</span></div><div class='line' id='LC61'>	<span class="k">this</span><span class="p">.</span><span class="nx">runAs</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">18</span><span class="p">];</span></div><div class='line' id='LC62'>	<span class="k">this</span><span class="p">.</span><span class="nx">deleteIfNotRescheduled</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">19</span><span class="p">];</span></div><div class='line' id='LC63'>	<span class="k">this</span><span class="p">.</span><span class="nx">stopIf</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span></div><div class='line' id='LC64'>	<span class="k">this</span><span class="p">.</span><span class="nx">repeatEvery</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">21</span><span class="p">];</span></div><div class='line' id='LC65'>	<span class="k">this</span><span class="p">.</span><span class="nx">repeatUntilTime</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">22</span><span class="p">];</span></div><div class='line' id='LC66'>	<span class="k">this</span><span class="p">.</span><span class="nx">repeatUntilDuration</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">23</span><span class="p">];</span></div><div class='line' id='LC67'>	<span class="k">this</span><span class="p">.</span><span class="nx">repeatStopIfRunning</span> <span class="o">=</span><span class="nx">columns</span><span class="p">[</span><span class="mi">24</span><span class="p">];</span></div><div class='line' id='LC68'>	<span class="k">this</span><span class="p">.</span><span class="nx">idleTime</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">25</span><span class="p">];</span></div><div class='line' id='LC69'>	<span class="k">this</span><span class="p">.</span><span class="nx">powerManagement</span> <span class="o">=</span> <span class="nx">columns</span><span class="p">[</span><span class="mi">26</span><span class="p">];</span></div><div class='line' id='LC70'><span class="p">};</span></div><div class='line' id='LC71'><br/></div><div class='line' id='LC72'><span class="c1">// execute the shell command to retrieve the scheduled tasks</span></div><div class='line' id='LC73'><span class="kd">var</span> <span class="nx">WshShell</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ActiveXObject</span><span class="p">(</span><span class="s2">&quot;WScript.Shell&quot;</span><span class="p">);</span></div><div class='line' id='LC74'><span class="kd">var</span> <span class="nx">oExec</span> <span class="o">=</span> <span class="nx">WshShell</span><span class="p">.</span><span class="nx">Exec</span><span class="p">(</span><span class="s2">&quot;schtasks /Query /FO CSV /V&quot;</span><span class="p">);</span></div><div class='line' id='LC75'><br/></div><div class='line' id='LC76'><span class="c1">// retrieve the lines from stdout and save them as tasks</span></div><div class='line' id='LC77'><span class="kd">var</span> <span class="nx">tasks</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC78'><span class="k">while</span><span class="p">(</span> <span class="o">!</span><span class="nx">oExec</span><span class="p">.</span><span class="nx">StdOut</span><span class="p">.</span><span class="nx">AtEndOfStream</span><span class="p">){</span></div><div class='line' id='LC79'>&nbsp;&nbsp;&nbsp;<span class="nx">tasks</span><span class="p">[</span><span class="nx">tasks</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span> <span class="o">=</span> <span class="nx">oExec</span><span class="p">.</span><span class="nx">StdOut</span><span class="p">.</span><span class="nx">ReadLine</span><span class="p">();</span></div><div class='line' id='LC80'><span class="p">}</span></div><div class='line' id='LC81'><br/></div><div class='line' id='LC82'><span class="c1">// now do something with the tasks</span></div><div class='line' id='LC83'><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span><span class="nx">tasks</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">){</span></div><div class='line' id='LC84'>	<span class="kd">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Task</span><span class="p">(</span><span class="nx">tasks</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span></div><div class='line' id='LC85'>	<span class="nx">WScript</span><span class="p">.</span><span class="nx">Echo</span><span class="p">(</span><span class="nx">tmp</span><span class="p">.</span><span class="nx">lastResult</span> <span class="o">+</span> <span class="s2">&quot; - &quot;</span> <span class="o">+</span> <span class="nx">tmp</span><span class="p">.</span><span class="nx">status</span><span class="p">);</span></div><div class='line' id='LC86'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1016899/6ca6bcea3da4909c690654e4355d6231db6bc1aa/inspectJobs.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1016899#file_inspect_jobs.js" style="float:right;margin-right:10px;color:#666">inspectJobs.js</a>
            <a href="https://gist.github.com/1016899">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2011/06/09/jscript-to-query-scheduled-tasks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows script to remove old files</title>
		<link>http://foobar.lu/wp/2011/06/08/windows-script-to-remove-old-files/</link>
		<comments>http://foobar.lu/wp/2011/06/08/windows-script-to-remove-old-files/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 09:42:16 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=206</guid>
		<description><![CDATA[Simple script&#8230; still, I thought I&#8217;d share&#8230;]]></description>
			<content:encoded><![CDATA[<p>Simple script&#8230; still, I thought I&#8217;d share&#8230;</p>
<div id="gist-1014084" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cm">/**</span></div><div class='line' id='LC2'><span class="cm"> * Remove all files and folders that are older than a set number of days.</span></div><div class='line' id='LC3'><span class="cm"> *</span></div><div class='line' id='LC4'><span class="cm"> * @param rootURI The URI of the root folder. All old files and folders in this</span></div><div class='line' id='LC5'><span class="cm"> *                folder are removed.</span></div><div class='line' id='LC6'><span class="cm"> * @param days Files older than this number of days are deleted</span></div><div class='line' id='LC7'><span class="cm"> */</span></div><div class='line' id='LC8'><span class="kd">function</span> <span class="nx">purgeFiles</span><span class="p">(</span><span class="nx">rootURI</span><span class="p">,</span> <span class="nx">days</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">fso</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ActiveXObject</span><span class="p">(</span><span class="s2">&quot;Scripting.FileSystemObject&quot;</span><span class="p">);</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">rootFolder</span> <span class="o">=</span> <span class="nx">fso</span><span class="p">.</span><span class="nx">GetFolder</span><span class="p">(</span><span class="nx">rootURI</span><span class="p">);</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">subFolders</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Enumerator</span><span class="p">(</span><span class="nx">rootFolder</span><span class="p">.</span><span class="nx">SubFolders</span><span class="p">);</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="c1">// create a date before which files are considered &quot;old&quot;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">threshold_date</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="nx">threshold_date</span><span class="p">.</span><span class="nx">setDate</span><span class="p">(</span><span class="nx">threshold_date</span><span class="p">.</span><span class="nx">getDate</span><span class="p">()</span><span class="o">-</span><span class="nx">days</span><span class="p">);</span></div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="c1">// loop over each file</span></div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="nx">subFolders</span><span class="p">.</span><span class="nx">moveFirst</span><span class="p">();</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="k">for</span><span class="p">(;</span><span class="o">!</span><span class="nx">subFolders</span><span class="p">.</span><span class="nx">atEnd</span><span class="p">();</span> <span class="nx">subFolders</span><span class="p">.</span><span class="nx">moveNext</span><span class="p">()){</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="nx">subFolders</span><span class="p">.</span><span class="nx">item</span><span class="p">();</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span><span class="p">(</span><span class="nx">f</span><span class="p">.</span><span class="nx">DateCreated</span> <span class="o">&lt;</span> <span class="nx">threshold_date</span> <span class="p">){</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">//WScript.Echo(&quot;Deleting &quot;+f.Name+&quot;  last accessed on: &quot;+f.DateCreated);</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">f</span><span class="p">.</span><span class="nx">Delete</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC26'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC27'><br/></div><div class='line' id='LC28'><span class="p">}</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'><span class="nx">purgeFiles</span><span class="p">(</span><span class="s2">&quot;C:/path/to/folder&quot;</span><span class="p">,</span> <span class="mi">300</span><span class="p">);</span></div><div class='line' id='LC31'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1014084/6f3aa6a391862d52f8d3a374e38a0f473190b66a/purgeFiles.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1014084#file_purge_files.js" style="float:right;margin-right:10px;color:#666">purgeFiles.js</a>
            <a href="https://gist.github.com/1014084">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2011/06/08/windows-script-to-remove-old-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change JPA EntityManager connection properties at Runtime</title>
		<link>http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/</link>
		<comments>http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 10:18:25 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=119</guid>
		<description><![CDATA[There are many times you want to be able to use different connection options for a JPA EntityManager. The most obvious is different user-credentials (think of a user login-screen and re-using these credentials to connect to the DB), or to make the distinction between development/testing/production environment. However, if you let Netbeans create the persistence configuration, [...]]]></description>
			<content:encoded><![CDATA[<p>There are many times you want to be able to use different connection options for a JPA EntityManager. The most obvious is different user-credentials (think of a user login-screen and re-using these credentials to connect to the DB), or to make the distinction between development/testing/production environment.</p>
<p>However, if you let Netbeans create the persistence configuration, it will hardcode all connection parameters into the persistence.xml file. When retrieving an EntityManager instance, it will use this information to connect.</p>
<p>If, instead you would like to do this at runtime, you can do the following:</p>
<ol>
<li>Remove the &#8220;properties&#8221; tag from the persistence.xml. This may not be necessary, but this will make it clear, that the properties are set inside the code.</li>
<li>Create a &#8220;Map&lt;String, String&gt;&#8221; which will contain the properties. A list of standard properties can be found <a href="http://cds-esd.sun.com/ESD5/JSCDL/persistence/2.0-final/persistence-2_0-final-spec.pdf?AuthParam=1293702814_a2cf5b707c37421faf9eb75521cc9550&#038;TicketId=B/w4kR2JTFNCShJDPlBekAPj&#038;GroupName=CDS&#038;FilePath=/ESD5/JSCDL/persistence/2.0-final/persistence-2_0-final-spec.pdf&#038;File=persistence-2_0-final-spec.pdf">in the specs in section 8.2.1.10</a>.</li>
<li>Use this map to create an EntityManagerFactory and use this to create your EntityManager</li>
</ol>
<p>An example persistence.xml without properties</p>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;persistence</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> xsi:schemaLo</span><br />
<span style="color: #009900;"> &nbsp;<span style="color: #000000; font-weight: bold;">&lt;persistence-unit</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myTestPU&quot;</span> <span style="color: #000066;">transaction-type</span>=<span style="color: #ff0000;">&quot;RESOURCE_LOCAL&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.persistence.jpa.PersistenceProvider<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/provider<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>my.package.Entity1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>my.package.Entity2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistence-unit<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>In case Netbeans created a method &#8220;getEntityManager&#8221;, you can safely replace this. Here is an example I currently have in use. The &#8220;appConf&#8221; instance is a singleton I use to store configuration data in the user&#8217;s home folder, and yes, the password is stored in plain-text, but for this test-case I did not need to go any further:</p>
<div class="codecolorer-container java twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> EntityManager getEntityManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> dbProps <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;eclipselink.logging.level&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;eclipselink.logging.level&quot;</span>, <span style="color: #0000ff;">&quot;INFO&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// On linux, the GSSAPI is not available. Use a default user/password &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// pair to connect &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Linux&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;os.name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.url&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:jtds:sqlserver://%s/%s&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.host&quot;</span>, <span style="color: #0000ff;">&quot;my-default-host&quot;</span><span style="color: #009900;">&#41;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.database&quot;</span>, <span style="color: #0000ff;">&quot;my-default-db&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.driver&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;net.sourceforge.jtds.jdbc.Driver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.password&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.password&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.user&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.user&quot;</span>, <span style="color: #0000ff;">&quot;my-default-username&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.url&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:sqlserver://%s;databaseName=%s;integratedSecurity=true&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.host&quot;</span>, <span style="color: #0000ff;">&quot;my-default-host&quot;</span><span style="color: #009900;">&#41;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db.database&quot;</span>, <span style="color: #0000ff;">&quot;my-default-db&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbProps.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.persistence.jdbc.driver&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; appConf.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; EntityManagerFactory fact <span style="color: #339933;">=</span> Persistence.<span style="color: #006633;">createEntityManagerFactory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myTestPU&quot;</span>, dbProps<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> fact.<span style="color: #006633;">createEntityManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span></div></div>
<p>This example uses eclipselink. All available properties can be found it the <a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)">EclipseLink Wiki</a></p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPSS, MS-SQL2008 &amp; bigint</title>
		<link>http://foobar.lu/wp/2010/03/31/spss-ms-sql2008-bigint/</link>
		<comments>http://foobar.lu/wp/2010/03/31/spss-ms-sql2008-bigint/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:39:08 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=97</guid>
		<description><![CDATA[There seems to be an issue with SPSS while reading data from an MS-SQL-Server instance. Notably with the SQL datatype &#8220;bigint&#8221;. Assume the following SPSS syntax: GET DATA &#160; &#160;/TYPE=ODBC &#160; &#160;/CONNECT='DSN=my_dsn;SERVER=server_name;Trusted_Connection=yes;DATABASE=db_name' &#160; &#160;/SQL = 'SELECT year FROM &#160;my_table' . EXECUTE. If the field in question (in this case: &#8220;year&#8221;) is of SQL-type &#8220;bigint&#8221; then [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be an issue with SPSS while reading data from an MS-SQL-Server instance. Notably with the SQL datatype &#8220;bigint&#8221;. Assume the following SPSS syntax:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">GET DATA<br />
&nbsp; &nbsp;/TYPE=ODBC<br />
&nbsp; &nbsp;/CONNECT='DSN=my_dsn;SERVER=server_name;Trusted_Connection=yes;DATABASE=db_name'<br />
&nbsp; &nbsp;/SQL = 'SELECT year FROM &nbsp;my_table'<br />
.<br />
EXECUTE.</div></div>
<p>If the field in question (in this case: &#8220;year&#8221;) is of SQL-type &#8220;bigint&#8221; then SPSS will show these values in the majority of the cases as &#8220;MISSING&#8221;. Sporadically some values appear, but they are completely wrong.</p>
<p>Once the cause is known (problem with the &#8220;biging&#8221; type), the solution is straight-forward: Cast the type to another appropriate type which is understood by SPSS. Which type you choose obviously depends on the values stored in the affected fields. Casting blindly to &#8220;int&#8221; <strong>may</strong> (I haven&#8217;t tested this!) resolve in strange results if the values lie outside of the &#8220;int&#8221; range (-2^31 to 2^31-1). In this case you may need to cast it to something alphanumeric like &#8220;varchar&#8221; and re-cast it in SPSS into &#8220;Numeric&#8221;. As said, I haven&#8217;t tested this but I thought it might be worth mentioning!</p>
<p>So, here&#8217;s the above query with the appropriate cast:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">GET DATA<br />
&nbsp; &nbsp;/TYPE=ODBC<br />
&nbsp; &nbsp;/CONNECT='DSN=my_dsn;SERVER=server_name;Trusted_Connection=yes;DATABASE=db_name'<br />
&nbsp; &nbsp;/SQL = 'SELECT CONVERT(int, year) AS year FROM &nbsp;my_table'<br />
.<br />
EXECUTE.</div></div>
<p>Note also that in this case you need to add an alias for the column ( &#8220;&#8230; AS year&#8221; ). Otherwise SPSS will return it as &#8220;VXXX&#8221; (where XXX is a sequential number).</p>
<p>I have tested this solution on all combinations of SPSS 11.5, SPSS 18, SQL-Server 2008 64bit, SQL-Server 2008 Express 32bit. And casting the value worked every time.</p>
<p>Depending on your use, it may be helpful to create views which do the casting. I have not yet tried this, but I don&#8217;t see a reason why it shouldn&#8217;t work. Additionally, it might be noteworthy that I have only encountered this problem with &#8220;bigint&#8221; so far. There <strong>may</strong> be problems with other types as well. I expect, casting them to something else should work there too.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2010/03/31/spss-ms-sql2008-bigint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dialog buttons not responding in Eclipse under KDE/GNOME</title>
		<link>http://foobar.lu/wp/2010/02/01/dialog-buttons-not-responding-in-eclipse-under-kdegnome/</link>
		<comments>http://foobar.lu/wp/2010/02/01/dialog-buttons-not-responding-in-eclipse-under-kdegnome/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 09:50:01 +0000</pubDate>
		<dc:creator>wickeddoc</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2010/02/01/dialog-buttons-not-responding-in-eclipse-under-kdegnome/</guid>
		<description><![CDATA[In case you&#8217;re running into the same trouble as me, that dialog buttons are not &#8220;clickable&#8221; anymore under Eclipse, just add the following line to one of your linux startup scripts to fix the problem: export GDK_NATIVE_WINDOWS=1]]></description>
			<content:encoded><![CDATA[<p>In case you&#8217;re running into the same trouble as me, that dialog buttons are not &#8220;clickable&#8221; anymore under Eclipse, just add the following line to one of your linux startup scripts to fix the problem:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">export GDK_NATIVE_WINDOWS=1</div></div>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2010/02/01/dialog-buttons-not-responding-in-eclipse-under-kdegnome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mayflower Zend Framework Cheatsheet</title>
		<link>http://foobar.lu/wp/2009/12/31/mayflower-zend-framework-cheatsheet/</link>
		<comments>http://foobar.lu/wp/2009/12/31/mayflower-zend-framework-cheatsheet/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 11:14:33 +0000</pubDate>
		<dc:creator>wickeddoc</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=75</guid>
		<description><![CDATA[Several weeks ago I was scouting the Internet for a Zend Framework cheatsheet and I found a blog entry somewhere about a Zend Framework Cheatsheet Poster, created by a German company called Mayflower. On their blog they say, if you&#8217;re an eager Zend Framework developer and want to get your copy of their Cheatsheet poster, [...]]]></description>
			<content:encoded><![CDATA[<p>Several weeks ago I was scouting the Internet for a Zend Framework cheatsheet and I found a blog entry somewhere about a <strong>Zend Framework Cheatsheet Poster</strong>, created by a German company called <strong><a href="http://www.mayflower.de">Mayflower</a></strong>.</p>
<p>On their blog they say, if you&#8217;re an eager Zend Framework developer and want to get your copy of their Cheatsheet poster, you&#8217;ll just have to send them an email and you&#8217;ll get this great Poster delivered to your office or home or whatever, <strong>free of charge</strong>. So that&#8217;s what I did and guess what, a week later I received this very useful poster in the mail.<br />
So if you are a Zend Framework developer yourself and want to own this cool poster, don&#8217;t be shy, just send an email to Björn Schotte over at Mayflower.</p>
<p>Here&#8217;s a photo of the poster in our office @ <strong><a href="http://www.vo.lu">Visual Online, Luxembourg</a></strong></p>
<p><img src="http://www.foobar.lu/mayflower.jpg" alt="Mayflower Zend Framework Cheatsheet Poster" /></p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2009/12/31/mayflower-zend-framework-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unable to easy_install psycopg2 on debian</title>
		<link>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/</link>
		<comments>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 15:18:30 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=66</guid>
		<description><![CDATA[Problem: $ easy_install psycopg2 Searching for psycopg2 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<h3>Problem:</h3>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ easy_install psycopg2<br />
Searching for psycopg2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Reading http://pypi.python.org/simple/psycopg2/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Reading http://initd.org/projects/psycopg2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Reading http://initd.org/pub/software/psycopg/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Best match: psycopg2 2.0.13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Downloading http://initd.org/pub/software/psycopg/psycopg2-2.0.13.tar.gz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Processing psycopg2-2.0.13.tar.gz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Running psycopg2-2.0.13/setup.py -q bdist_egg --dist-dir /tmp/easy_install-cHE0C_/psycopg2-2.0.13/egg-dist-tmp-x-CxRS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
error: Setup script exited with error: No such file or directory</div></div>
<h3>Solution:</h3>
<p>This most likely indicates that you are missing the &#8220;libpq&#8221; headers:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo aptitude install libpq-dev</div></div>
<p>should solve the problem</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Studio forgetting about your ZF Project</title>
		<link>http://foobar.lu/wp/2009/06/16/zend-studio-forgetting-about-your-zf-project/</link>
		<comments>http://foobar.lu/wp/2009/06/16/zend-studio-forgetting-about-your-zf-project/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 14:40:21 +0000</pubDate>
		<dc:creator>wickeddoc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=56</guid>
		<description><![CDATA[as a php developer i&#8217;m using zend studio for eclipse on a daily basis. sometimes zend studio forgets about my zend framework projects, especially projects which are hosted on a SVN repository. i close my project, reopen it, and for no obvious reasons zend studio no longer recognizes it as a zend framework project. huch!? [...]]]></description>
			<content:encoded><![CDATA[<p>as a php developer i&#8217;m using zend studio for eclipse on a daily basis. sometimes zend studio forgets about my zend framework projects, especially projects which are hosted on a SVN repository. i close my project, reopen it, and for no obvious reasons zend studio no longer recognizes it as a zend framework project. huch!?</p>
<p>until now i was unable to find a real solution to my problem, but here&#8217;s a little workaround which should get you up and running again, in case you&#8217;re running into the same problem.</p>
<p>close the project, then just open the .project file at the root of your project in your favourite text editor and check the &#8216;natures&#8217; section, make sure it contains the following line:</p>
<div class="codecolorer-container xml twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.zend.php.framework.ZendFrameworkNature<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>that should do the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2009/06/16/zend-studio-forgetting-about-your-zf-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Add creation and modification timestamps to an Excel worksheet</title>
		<link>http://foobar.lu/wp/2009/02/19/add-creation-and-modification-timestamps-to-an-excel-worksheet/</link>
		<comments>http://foobar.lu/wp/2009/02/19/add-creation-and-modification-timestamps-to-an-excel-worksheet/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 14:14:47 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Coding Voodoo]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=45</guid>
		<description><![CDATA[Please, for the love of $deity do not hit me&#8230;.. This is going to be a post about excel! Excel is a horrid solution for data entry, and even worse for data archival. And yet, it&#8217;s one of the most commonly used solutions. One of the most useful information in any given data-set is the [...]]]></description>
			<content:encoded><![CDATA[<p>Please, for the love of $deity do not hit me&#8230;.. This is going to be a post about excel!</p>
<p>Excel is a horrid solution for data entry, and even worse for data archival. And yet, it&#8217;s one of the most commonly used solutions. One of the most useful information in any given data-set is the information about <em>when</em> the information was <em>created</em> and <em>when</em> it was <em>last modified</em>. This is something that any decent developer in charge of a data collection (let&#8217;s just call it that for now) will add to each data record.</p>
<p>Alas, a lot of non-it people manage and store their data in excel worksheets. And that is OK with me as long as they pay attention to data archival. In it&#8217;s most simple form, data archival can be achieved by storing the data as a CSV file <strong>and</strong> <strong>including</strong> the following metadata:</p>
<ul>
<li>Which column represents which value (the name of the variable)</li>
<li>The data type (number, text, date, &#8230;) of each column</li>
<li>If a column is &#8220;coded&#8221;, please also include the meaning of each code.<br />
For example a &#8220;Yes&#8221;, &#8220;No&#8221;, &#8220;Maybe&#8221; column might be stored as &#8220;1&#8243;, &#8220;2&#8243; and &#8220;3&#8243;. Which means in it&#8217;s most basic nature it&#8217;s a numeric variable, but the different values have a meaning attached to them. So: Add this list in your metadata description.</li>
<li>If any computations or checks are performed on the values, please add them to the metadata document as well!</li>
</ul>
<p>Even if the timestamp values might seem superflous at first, it will be of <strong>great</strong> help to anyone tracing errors in the data. Imagine that you would at some point need to fix some values that were entered/modified during a specific time period for whatever reason. Without this most basic bit of information you will be up for a treat. However, if it&#8217;s been rigurously implemented since the beginning, you&#8217;ll have the problem solved in no time.</p>
<p>Now, each halfway serious database system will offer you this kind of functionality out-of-the-box. But Excel <strong>is no database system</strong> (I intentionally left out the word &#8220;management&#8221; as this issue is a bit more general!). So it does not offer you a straight-forward way to solve this. But even if it&#8217;s not straight-forward, it&#8217;s simple enough for about anyone using Excel do add this bit of information.</p>
<p>Assuming that you use the first two columns (numbered 1 and 2 in excel) of your worksheet to add creation- and modification timestamps simply open up the Visual Basic editor (found in Tools-&gt;Macro or somesuch), next, in your project tree (in the top left of the screen) select your workbook (the .xls file), and in it&#8217;s sub-tree double-click the Worksheet that should have the timestamps set automatically.</p>
<p>Then copy/paste the following text into the just opened code editor and you&#8217;re done. I hope the comments will give some insight as to what happens. Note that in this case I will ignore the first row of the sheet, and obviously, the first two columns. If that does not suit your needs, feel free to change this script to your liking.</p>
<div class="codecolorer-container vb twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">'<br />
</span><span style="color: #008000;">' Callback which is called when a cell in a workbook changes<br />
</span><span style="color: #008000;">' @param Target: The cell that changed it's value<br />
</span><span style="color: #008000;">'<br />
</span><span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #E56717; font-weight: bold;">Sub</span> Worksheet_Change(<span style="color: #151B8D; font-weight: bold;">ByVal</span> Target <span style="color: #151B8D; font-weight: bold;">As</span> Range)<br />
&nbsp; &nbsp;<span style="color: #008000;">' We will ignore any changes in the first row, as it contains header labels<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Target.Row = 1 <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Sub</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #008000;">' As we set the values of column 1 and 2 we won't need to capture changes in these either<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Target.Column = 1 <span style="color: #8D38C9; font-weight: bold;">Or</span> Target.Column = 2 <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Sub</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #008000;">' We will update the timestamp in column 2 *always* (last changed time)<br />
</span> &nbsp; Cells(Target.Row, 2) = Now<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #008000;">' We will update the timestamp in column 1 only if it is empty (creation time)<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> IsEmpty(Cells(Target.Row, 1)) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp;Cells(Target.Row, 1) = Now<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2009/02/19/add-creation-and-modification-timestamps-to-an-excel-worksheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python startup (command completion &amp; history)</title>
		<link>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/</link>
		<comments>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:18:17 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/</guid>
		<description><![CDATA[If you want command completion and a history in your python shell, export the PYTHONSTARTUP env var (export PYTHONSTARTUP=$HOME/.pystartup) in your bashrc and create a file ~/.pystartup with the following contents: import atexit import os import readline import rlcompleter historyPath = os.path.expanduser&#40;&#34;~/.pyhistory&#34;&#41; def save_history&#40;historyPath=historyPath&#41;: import readline readline.write_history_file&#40;historyPath&#41; if os.path.exists&#40;historyPath&#41;: readline.read_history_file&#40;historyPath&#41; readline.parse_and_bind&#40;'tab: complete'&#41; atexit.register&#40;save_history&#41; del os, [...]]]></description>
			<content:encoded><![CDATA[<p>If you want command completion and a history in your python shell, export the <em>PYTHONSTARTUP</em> env var (<em>export PYTHONSTARTUP=$HOME/.pystartup) </em>in your bashrc and create a file ~/.pystartup with the following contents:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">atexit</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">readline</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">rlcompleter</span><br />
<br />
historyPath <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;~/.pyhistory&quot;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> save_history<span style="color: black;">&#40;</span>historyPath<span style="color: #66cc66;">=</span>historyPath<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">readline</span><br />
<span style="color: #dc143c;">readline</span>.<span style="color: black;">write_history_file</span><span style="color: black;">&#40;</span>historyPath<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>historyPath<span style="color: black;">&#41;</span>:<br />
<span style="color: #dc143c;">readline</span>.<span style="color: black;">read_history_file</span><span style="color: black;">&#40;</span>historyPath<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #dc143c;">readline</span>.<span style="color: black;">parse_and_bind</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tab: complete'</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #dc143c;">atexit</span>.<span style="color: black;">register</span><span style="color: black;">&#40;</span>save_history<span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">del</span> <span style="color: #dc143c;">os</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">atexit</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">readline</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">rlcompleter</span><span style="color: #66cc66;">,</span> save_history<span style="color: #66cc66;">,</span> historyPath</div></div>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

