<?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>solutions.hans-eric.com</title>
	<atom:link href="http://solutions.hans-eric.com/feed" rel="self" type="application/rss+xml" />
	<link>http://solutions.hans-eric.com</link>
	<description>Hans-Eric Grönlund's Log of Solutions to Technical Problems</description>
	<lastBuildDate>Fri, 23 Apr 2010 07:39:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>UNC Paths in Windows Command Shell</title>
		<link>http://solutions.hans-eric.com/unc-paths-in-windows-command-shell</link>
		<comments>http://solutions.hans-eric.com/unc-paths-in-windows-command-shell#comments</comments>
		<pubDate>Fri, 23 Apr 2010 07:39:00 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=39</guid>
		<description><![CDATA[Problem:
Copy and other command shell commands don&#8217;t work with UNC paths, i.e. \\server\dir.
Solution:
Use pushd &#60;path&#62; to temporarily assign a drive letter and map it to the path.
pushd \\server\rootfolder\subfolder
When done, use popd to unmap the letter.
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>Copy and other command shell commands don&#8217;t work with UNC paths, i.e. \\server\dir.</p>
<p><strong>Solution:</strong></p>
<p>Use <em>pushd &lt;path&gt;</em> to temporarily assign a drive letter and map it to the path.</p>
<p><em>pushd \\server\rootfolder\subfolder</em></p>
<p>When done, use <em>popd</em> to unmap the letter.</p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/unc-paths-in-windows-command-shell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting date and time from text using Ruby</title>
		<link>http://solutions.hans-eric.com/extracting-date-and-time-from-text-using-ruby</link>
		<comments>http://solutions.hans-eric.com/extracting-date-and-time-from-text-using-ruby#comments</comments>
		<pubDate>Fri, 19 Mar 2010 16:07:31 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Regular expressions]]></category>
		<category><![CDATA[string handling]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=37</guid>
		<description><![CDATA[Problem:
We want to extract a date and time of the format YYYY-MM-DD MM:SS from a body of text using Ruby.
Solution:
This is extremely easy in ruby, and other languages that features regular expressions.

require "Date"

text = "Some text containing a date and a time, for instance 2010-03-19 17:25."

if text =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/
  dt = DateTime.new($1.to_i, $2.to_i, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong><br />
We want to <em>extract a date and time</em> of the format YYYY-MM-DD MM:SS from a body of text using Ruby.</p>
<p><strong>Solution:</strong><br />
This is extremely easy in ruby, and other languages that features regular expressions.</p>
<pre><code>
require "Date"

text = "Some text containing a date and a time, for instance 2010-03-19 17:25."

if text =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/
  dt = DateTime.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i)
end
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/extracting-date-and-time-from-text-using-ruby/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading a Customized Wordpress Theme</title>
		<link>http://solutions.hans-eric.com/upgrading-a-customized-wordpress-theme</link>
		<comments>http://solutions.hans-eric.com/upgrading-a-customized-wordpress-theme#comments</comments>
		<pubDate>Fri, 13 Nov 2009 15:51:19 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[SubVersion]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=30</guid>
		<description><![CDATA[Problem:
You&#8217;re using a third party wordpress theme but have made changes to customize it for your own needs (changed a picture, added advertising, etc.). When the third party releases an upgrade to the theme you&#8217;d like to upgrade but don&#8217;t want to lose your changes.
Solution:
Let your version management system move your changes over to the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You&#8217;re using a third party wordpress theme but have made changes to customize it for your own needs (changed a picture, added advertising, etc.). When the third party releases an upgrade to the theme you&#8217;d like to upgrade but don&#8217;t want to lose your changes.</p>
<p><strong>Solution:</strong></p>
<p>Let your version management system move your changes over to the new version for you. I use Subversion, but any modern VMS should do fine as well. Here&#8217;s the steps I use to upgrade from, let&#8217;s say Cool Theme 1.0 (that contain my changes) to Cool Theme 1.1.</p>
<ol>
<li>Import the original version of Cool Theme 1.0 (without my changes) to Subversion. I use a repository path like /reposroot/cooltheme/trunk.</li>
<li>Create a tag to freeze the 1.0-version. In Subversion you just copy the above directory, I name the new directory something like /reposroot/cooltheme/tags/1_0.</li>
<li>Create a branch from the 1_0 tag. I&#8217;d name the branch /reposroot/cooltheme/branches/r1_0.</li>
<li>Checkout the r1_0 branch to a local working directory.</li>
<li>Copy the files of the updated version of Cool Theme, the one that contain your changes, to your working directory.</li>
<li>Check in. Now you have the current version in the r1_0 branch.</li>
<li>Delete the working copy if you like, it has served it&#8217;s purpose and the time has come for the actual upgrade.</li>
<li>Checkout the trunk branch (reposroot/cooltheme/trunk in my example) to a working directory.</li>
<li>Copy the files of the upgraded theme to the working directory.</li>
<li>Check in the changes.</li>
<li>Once again, delete the working copy if you wish.</li>
<li>Create a tag for the new version (reposroot/cooltheme/tags/1_1 for example).</li>
<li>Create a branch for the new release (copy the 1_1 tag to reposroot/cooltheme/branches/r1_1)</li>
<li>Merge the changes between r1_0 and r1_1</li>
<li>Handle conflicts</li>
<li>Check in.</li>
<li>Voila! You should now have an upgraded version with your changes in the new release branch (reposroot/cooltheme/branches/r1_1)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/upgrading-a-customized-wordpress-theme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Linebreaks in C#</title>
		<link>http://solutions.hans-eric.com/adding-linebreaks-in-c</link>
		<comments>http://solutions.hans-eric.com/adding-linebreaks-in-c#comments</comments>
		<pubDate>Thu, 03 Sep 2009 12:33:01 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[string handling]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=24</guid>
		<description><![CDATA[Problem:
We want to insert linebreak character sequences into a string in C#. 
Solution:
The platform safe way of doing this is by using the Environment.NewLine property.

msg = "An error occurred: " + Environment.NewLine + e.Message;

Composing a string with more than one line break can become really messy, so using string.Format might be a good idea.

msg = string.Format("{1} An [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>We want to insert linebreak character sequences into a string in C#. </p>
<p><strong>Solution:</strong></p>
<p>The platform safe way of doing this is by using the Environment.NewLine property.</p>
<pre><code>
msg = "An error occurred: " + Environment.NewLine + e.Message;
</code></pre>
<p>Composing a string with more than one line break can become really messy, so using string.Format might be a good idea.</p>
<pre><code>
msg = string.Format("{1} An error occurred!{0}Exception: {0}{2}",
  Environment.NewLine, CurrentTime, e.ToString());
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/adding-linebreaks-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Updating of Action Visibilities</title>
		<link>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities</link>
		<comments>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:38:25 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Updating TAction.Visible]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=18</guid>
		<description><![CDATA[Problem: You want to change an action&#8217;s visible property and does so in its OnUpdate event handler, but it doesn&#8217;t seem to work. Once an action is hidden it can&#8217;t seem to become visible again.   Solution: By design Delphi won&#8217;t invoke OnUpdate event handlers for actions that have their Visible property set to false. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> You want to change an action&#8217;s visible property and does so in its OnUpdate event handler, but it doesn&#8217;t seem to work. Once an action is hidden it can&#8217;t seem to become visible again.   <strong>Solution:</strong> By design Delphi won&#8217;t invoke OnUpdate event handlers for actions that have their Visible property set to false. Instead, one has to override the form&#8217;s UpdateActions method tod do the dynamic checking and setting of Visibility.</p>
<pre><code>type
  TMainForm = class(TForm)
  ...
  protected
  ...
    procedure TMainForm.UpdateActions; override;
  ...
  end;

...

procedure TMainForm.UpdateActions;
begin
  inherited;
  // Those actions are updating their visible
  // properties and must therefore be updated
  // here and not in their respective update
  // event handlers. This is due to the fact
  // that invisible actions are not concidered
  // by the inherited UpdateActions loop.
  // This is by design according to CodeGear.

  CancelAction.Visible := IsRunning;
  StartAction.Visible := not CancelAction.Visible;
end;
</code></pre>
<p>More information can be found on the Delphi forum, here:  <a href="https://forums.embarcadero.com/thread.jspa?threadID=18206&amp;tstart=90">https://forums.embarcadero.com/thread.jspa?threadID=18206&amp;tstart=90</a></p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Create a Tray Icon Controlled Application in Delphi</title>
		<link>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi</link>
		<comments>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi#comments</comments>
		<pubDate>Fri, 07 Aug 2009 08:46:02 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[TTrayIcon]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=9</guid>
		<description><![CDATA[Problem:
We want to create a System Tray Icon featured application that doesn&#8217;t shut down when the user closes the main window. Instead, the form simply hides and is reactivated when the user clicks the associated tray icon.
Solution:
Tested in Delphi 2009.
1. Hide the main form.
Since closing the main form automatically terminates the application we need to [...]]]></description>
			<content:encoded><![CDATA[<h4>Problem:</h4>
<p>We want to create a System Tray Icon featured application that doesn&#8217;t shut down when the user closes the main window. Instead, the form simply hides and is reactivated when the user clicks the associated tray icon.</p>
<h4>Solution:</h4>
<p>Tested in Delphi 2009.</p>
<p>1. Hide the main form.</p>
<p>Since closing the main form automatically terminates the application we need to hide it from the user. This is done by setting Application.ShowMainForm to False in the project settings.</p>
<pre><code>Application.Initialize;
<strong>Application.ShowMainForm := False;</strong>
Application.MainFormOnTaskbar := True;
:
Application.Run;
</code></pre>
<p>2. Add a TTrayIcon to Main Form</p>
<p>Set the Icon property and add an OnClick event handler that displays your real main form (the one that the user will see).</p>
<pre><code>procedure TMainForm.TrayIcon1Click(Sender: TObject);
begin
  MyOtherForm.Show;
end;
</code></pre>
<p>3. Drop a popup menu on the main form and connect it to the tray icon.</p>
<p>Add a close menu item that calls Application.Terminate to kill the application.</p>
<pre><code>procedure TMainForm.Close1Click(Sender: TObject);
begin
  Application.Terminate;
end;
</code></pre>
<p>4. Make the real main form show on start of application</p>
<p>Simply add a OnCreate event handler to the form and invoke Show.</p>
<p>procedure TMyOtherForm.FormCreate(Sender: TObject);<br />
begin<br />
Show;<br />
end;</p>
<p>That&#8217;s it!</p>
<p><strong>Alternative solution 1. </strong></p>
<p><strong>OBSERVE! This solution has the rather big flaw that it stops the computer from shutting down.<br />
</strong></p>
<p>1. Intercept the automatic termination mechanism when the main form is closing</p>
<pre><code>procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  // Minimize application instead of closing
  CanClose := False;
  Application.Minimize;
  // Remove the main form from the Task bar
  Self.Hide;
end;
</code></pre>
<p>2. Clicking on the tray icon restores the application</p>
<pre><code>procedure TMainForm.TrayIcon1Click(Sender: TObject);
begin
  // Restore application from minimized state
  Application.Restore;
  Application.BringToFront;
  // We must invoke Show on the main form, otherwise
  // it won't be able to minimize properly a second time
  // Tested on D2009 Upd 3, and Windows XP
  Self.Show;
end;
</code></pre>
<p>3. Add a popup menu with a close action to the tray icon, and use Application.Terminate in the event handler to kill the application</p>
<pre><code>procedure TMainForm.CloseActionExecute(Sender: TObject);
begin
  Application.Terminate;
end;
</code></pre>
<p><strong>Alternative solution 2</strong></p>
<p>If you want to do it without the TTrayIcon component, this article has what you need: <a href="http://delphi.about.com/od/kbwinshell/l/aa121801a.htm">System Tray Delphi Application &#8211; Quick and Easy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rounding off floating point numbers in Ruby</title>
		<link>http://solutions.hans-eric.com/rounding-off-floating-point-numbers-in-ruby</link>
		<comments>http://solutions.hans-eric.com/rounding-off-floating-point-numbers-in-ruby#comments</comments>
		<pubDate>Tue, 09 Jun 2009 15:15:11 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=8</guid>
		<description><![CDATA[Problem:
If you want to round a floating point number off to two decimals, there is no standard method in Ruby that does it for you.
Solution:
The general solution is
(f * 10**d).round.to_f / 10**d
where f is the floating number and d is the number of decimals.
See my code sample for adding this functionality to the Float class.
Although [...]]]></description>
			<content:encoded><![CDATA[<h4>Problem:</h4>
<p>If you want to round a floating point number off to two decimals, there is no standard method in Ruby that does it for you.</p>
<h4>Solution:</h4>
<p>The general solution is</p>
<pre><code>(f * 10**d).round.to_f / 10**d</code></pre>
<p>where f is the floating number and d is the number of decimals.</p>
<p>See <a title="Floating Point Round off In Ruby" href="http://www.hans-eric.com/code-samples/ruby-floating-point-round-off/">my code sample for adding this functionality to the Float class</a>.</p>
<p>Although the above works you should concider the reason you&#8217;re performing the rounding (or equivalent) operation. If it&#8217;s for presentation reasons only a better way might be to use a format string instead, and leave the original data intact.<br />
Here&#8217;s an example where a representation (rounded_str) of a floating point number (f) is rounded to two decimals.</p>
<pre><code>rounded_str = sprintf('%.2f', f)</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/rounding-off-floating-point-numbers-in-ruby/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turn On ArcSDE Logging</title>
		<link>http://solutions.hans-eric.com/turn-on-arcsde-logging</link>
		<comments>http://solutions.hans-eric.com/turn-on-arcsde-logging#comments</comments>
		<pubDate>Tue, 09 Jun 2009 13:35:37 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[ArcGIS]]></category>
		<category><![CDATA[ArcSDE]]></category>
		<category><![CDATA[SDE Intercept]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=7</guid>
		<description><![CDATA[Problem:
You want to log the traffic between the client (i.e. ArcMap) and an ArcSDE database.
Solution:
In the Command Window, write:
&#62;set SDEINTERCEPTLOC = c:\tempclient
&#62;c:\program files\arcgis\bin\arcmap.exe
It&#8217;s important to start the client (ArcMap in the above example) from the command prompt. ArcMap will intercept the traffic and log it to temp files, named like this:
c:\tempclient.001, c:\tempclient.002, and so on.
]]></description>
			<content:encoded><![CDATA[<h4>Problem:</h4>
<p>You want to log the traffic between the client (i.e. ArcMap) and an ArcSDE database.</p>
<h4>Solution:</h4>
<p>In the Command Window, write:</p>
<pre><code>&gt;set SDEINTERCEPTLOC = c:\tempclient
&gt;c:\program files\arcgis\bin\arcmap.exe</code></pre>
<p>It&#8217;s important to start the client (ArcMap in the above example) from the command prompt. ArcMap will intercept the traffic and log it to temp files, named like this:</p>
<pre><code>c:\tempclient.001, c:\tempclient.002, and so on.</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/turn-on-arcsde-logging/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrations and Environments in Ruby on Rails</title>
		<link>http://solutions.hans-eric.com/ruby-on-rails-migrations-and-environments</link>
		<comments>http://solutions.hans-eric.com/ruby-on-rails-migrations-and-environments#comments</comments>
		<pubDate>Tue, 09 Jun 2009 13:29:38 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Migrations]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=6</guid>
		<description><![CDATA[Problem:
You want to migrate a target environment other than development.
Solution:
For production:
&#62;rake environment RAILS_ENV=production migrate
For test:
&#62;rake environment RAILS_ENV=test migrate
]]></description>
			<content:encoded><![CDATA[<h4>Problem:</h4>
<p>You want to migrate a target environment other than development.</p>
<h4>Solution:</h4>
<p>For production:</p>
<pre>&gt;rake environment RAILS_ENV=production migrate</pre>
<p>For test:</p>
<pre>&gt;rake environment RAILS_ENV=test migrate</pre>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/ruby-on-rails-migrations-and-environments/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect Pages in Wordpress</title>
		<link>http://solutions.hans-eric.com/redirect-pages-in-wordpress</link>
		<comments>http://solutions.hans-eric.com/redirect-pages-in-wordpress#comments</comments>
		<pubDate>Tue, 09 Jun 2009 11:18:17 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Move Pages]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=5</guid>
		<description><![CDATA[Problem
I want to move a page in a WordPress site to a different location, but I still want the old address to be active and instead redirect to the new address.
Solution
Unfortunatelly as per WordPress 2.7 there isn&#8217;t any standard functionallity to accomplish this, so the easiest way to go is to use plugins.
I use Paul [...]]]></description>
			<content:encoded><![CDATA[<h4>Problem</h4>
<p>I want to move a page in a WordPress site to a different location, but I still want the old address to be active and instead redirect to the new address.</p>
<h4>Solution</h4>
<p>Unfortunatelly as per WordPress 2.7 there isn&#8217;t any standard functionallity to accomplish this, so the easiest way to go is to use plugins.</p>
<p>I use <a href="http://wordpress.org/extend/plugins/easyredirect/">Paul Bains EasyRedirect</a> which works for WordPress 2.7 although the description states &#8220;compatible up to: 2.2.0&#8243;. Just install it and add a tag of the form [redirect url time] to your redirecting page.</p>
<p>And we have to make sure the redirecting page is not showing up in the automatically generated page menu. I use &lt;a href=&#8221;http://wordpress.org/extend/plugins/exclude-pages/&#8221;&gt;Simon Wheatley&#8217;s Exclude Pages plugin&lt;/a&gt; for this. This excellent piece of code adds a check box named &#8220;Include this page in user menus&#8221; to your page administration page. Very convenient.</p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/redirect-pages-in-wordpress/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
