<?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>Yuval Baror's Blog</title>
	<atom:link href="http://yuval.bar-or.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://yuval.bar-or.org/blog</link>
	<description></description>
	<lastBuildDate>Sun, 22 Aug 2010 18:01:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sluggish PostgreSQL Databases and Reindexing Indexes</title>
		<link>http://yuval.bar-or.org/blog/2010/08/sluggish-postgresql-databases-and-reindexing-indexes/</link>
		<comments>http://yuval.bar-or.org/blog/2010/08/sluggish-postgresql-databases-and-reindexing-indexes/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 18:01:17 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=134</guid>
		<description><![CDATA[The natural process of erosion affects not only the organic elements of the Earth, but also the hardware we use, the code we write, and the databases we keep. When it comes to maintaining databases, there are several things that can be done to fight the degradation in query run time, and the increase in [...]]]></description>
			<content:encoded><![CDATA[<p>The natural process of erosion affects not only the organic elements of the Earth, but also the hardware we use, the code we write, and the databases we keep. When it comes to maintaining databases, there are several things that can be done to fight the degradation in query run time, and the increase in disk usage. There is one such action that is especially useful in PostgreSQL DBs and this is the command REINDEX INDEX. This command works on a single index and rebuilds it from scratch. Along the way it frees up any unnecessary disk space used by the index, and improves the response time of all queries using the index.</p>
<p>How much can this help? The answer is: a lot. In one example I witnessed reindexing an index improved the run time of a query using that index from several minutes to a few seconds. In another example, reindexing all of the indexes in a DB reduced the disk space used by that DB by over 40%.</p>
<p>So how can it be done? Simple:<br />
REINDEX INDEX &lt;index_name&gt;;</p>
<p>Now assume that you want to reindex all of the indexes related to a list of tables in your database, all you need to do is create a script that extracts the names of the indexes in your DB that are related to these tables and then run the REINDEX command on each of them. Here is an example bash script that does just that:</p>
<blockquote><p>#!/bin/bash</p>
<p>database=mydb<br />
indexes=$(psql -q -t -A -P pager=off -c &#8221;<br />
select<br />
c.relname<br />
from<br />
pg_catalog.pg_class c<br />
join pg_catalog.pg_namespace n on n.oid        = c.relnamespace<br />
join pg_catalog.pg_index i     on i.indexrelid = c.oid<br />
join pg_catalog.pg_class t     on i.indrelid   = t.oid<br />
where<br />
c.relkind = &#8216;i&#8217;<br />
and n.nspname not in (&#8217;pg_catalog&#8217;, &#8216;pg_toast&#8217;)<br />
and pg_catalog.pg_table_is_visible(c.oid)<br />
and t.relname  in (&#8217;table1&#8242;, &#8216;table2&#8242;, &#8216;table3&#8242;)&#8221; $database)</p>
<div dir="ltr">
for index in $indexes<br />
do<br />
echo `date &#8220;+%y-%m-%d %H:%M:%S&#8221;`&#8221; &#8211; Reindexing index $index&#8221;<br />
psql -c &#8220;REINDEX INDEX $index&#8221; $database<br />
done</p>
<p>echo `date &#8220;+%y-%m-%d %H:%M:%S&#8221;`&#8221; &#8211; Done&#8221;</p></div>
<div dir="ltr"></div>
</blockquote>
<div dir="ltr"></div>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2010/08/sluggish-postgresql-databases-and-reindexing-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My fonts look different in Firefox</title>
		<link>http://yuval.bar-or.org/blog/2010/03/my-fonts-look-different-in-firefox/</link>
		<comments>http://yuval.bar-or.org/blog/2010/03/my-fonts-look-different-in-firefox/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 05:33:40 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=106</guid>
		<description><![CDATA[One of the most annoying parts of web development is making sure your website looks the same on all browsers. A few days ago I noticed that on one of my websites the fonts are different in IE and in Firefox. I tried everything I could find on the web to make the fonts look [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most annoying parts of web development is making sure your website looks the same on all browsers. A few days ago I noticed that on one of my websites the fonts are different in IE and in Firefox. I tried everything I could find on the web to make the fonts look the same &#8211; setting the font-family, font-size, font-weight, font-style, font-face, and every other aspect of the font. But the fonts still looked different.</p>
<p>Then I read about <a title="Wikipedia - ClearType" href="http://en.wikipedia.org/wiki/ClearType" target="_blank">ClearType</a> &#8211; Microsoft&#8217;s subpixel rendering technology that is turned off by default in Windows XP, but turned on by default in IE7 and IE8. This means that when using Windows XP, the same font will be rendered differently when viewed in IE and in Firefox.</p>
<p>To enable ClearType go to the Control Panel, then select <em>Display</em>, select the <em>Appearance</em> tab, and click on the <em>Effects </em>button. The second drop-down is labeled &#8220;<em>Use the following method to smooth edges of screen fonts</em>&#8220;. Change the selection from &#8220;<em>Standard</em>&#8221; to <em>&#8220;ClearType</em>&#8220;. Now any web page you load will be rendered using ClearType.</p>
<p>Enabling ClearType will eliminate the difference between the fonts in the different browsers. However, this will also change the way fonts are rendered throughout the whole operating system. To date there is no way to enable ClearType only in specific applications.</p>
<p>Here are some samples of pages before enabling ClearType and after enabling it:</p>
<p><span style="text-decoration: underline;">Before</span></p>
<p><span style="text-decoration: underline;"><br />
</span></p>
<div id="attachment_114" class="wp-caption alignnone" style="width: 334px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE8.jpg"><img class="size-full wp-image-114" title="IE8" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE8.jpg" alt="IE8 - Before ClearType" width="324" height="39" /></a><p class="wp-caption-text">IE8 - Before ClearType</p></div>
<div id="attachment_108" class="wp-caption alignnone" style="width: 328px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Chrome.jpg"><img class="size-full wp-image-108" title="Chrome" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Chrome.jpg" alt="Chrome - Before ClearType" width="318" height="26" /></a><p class="wp-caption-text">Chrome - Before ClearType</p></div>
<div id="attachment_110" class="wp-caption alignnone" style="width: 327px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Firefox.jpg"><img class="size-full wp-image-110" title="Firefox" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Firefox.jpg" alt="Firefox - Before ClearType" width="317" height="31" /></a><p class="wp-caption-text">Firefox - Before ClearType</p></div>
<div id="attachment_112" class="wp-caption alignleft" style="width: 329px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE6.jpg"><img class="size-full wp-image-112" title="IE6" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE6.jpg" alt="IE6 - Before ClearType" width="319" height="30" /></a><p class="wp-caption-text">IE6 - Before ClearType</p></div>
<p><span style="text-decoration: underline;"><br />
</span></p>
<p><span style="color: #ffffff;">_____________________________________</span></p>
<p><span style="text-decoration: underline;">After</span></p>
<div id="attachment_107" class="wp-caption alignleft" style="width: 329px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE8-After.jpg"><img class="size-full wp-image-107" title="IE8-After" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE8-After.jpg" alt="IE8 - After ClearType (No change)" width="319" height="35" /></a><p class="wp-caption-text">IE8 - After ClearType (No change)</p></div>
<div id="attachment_109" class="wp-caption alignleft" style="width: 327px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Chrome-After.jpg"><img class="size-full wp-image-109" title="Chrome-After" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Chrome-After.jpg" alt="Chrome - After ClearType" width="317" height="29" /></a><p class="wp-caption-text">Chrome - After ClearType</p></div>
<div id="attachment_111" class="wp-caption alignleft" style="width: 324px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Firefox-After.jpg"><img class="size-full wp-image-111" title="Firefox-After" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/Firefox-After.jpg" alt="Firefox - After ClearType" width="314" height="25" /></a><p class="wp-caption-text">Firefox - After ClearType</p></div>
<div id="attachment_113" class="wp-caption alignleft" style="width: 330px"><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE6-After.jpg"><img class="size-full wp-image-113" title="IE6-After" src="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/IE6-After.jpg" alt="IE6 - After ClearType" width="320" height="31" /></a><p class="wp-caption-text">IE6 - After ClearType</p></div>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2010/03/my-fonts-look-different-in-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a new Bugzilla version to all products</title>
		<link>http://yuval.bar-or.org/blog/2010/03/adding-a-new-bugzilla-version-to-all-products/</link>
		<comments>http://yuval.bar-or.org/blog/2010/03/adding-a-new-bugzilla-version-to-all-products/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 17:30:27 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=98</guid>
		<description><![CDATA[The Bugzilla GUI doesn&#8217;t support adding a new version to all products. I used to add new versions to each product one by one. This got very tedious and annoying, especially as the number of products grew. I searched online for solutions provided by others and found only one thread on the topic on Nabble [...]]]></description>
			<content:encoded><![CDATA[<p>The Bugzilla GUI doesn&#8217;t support adding a new version to all products. I used to add new versions to each product one by one. This got very tedious and annoying, especially as the number of products grew. I searched online for solutions provided by others and found only one thread on the topic on <a title="Nabble - Bugzilla" href="http://old.nabble.com/How-do-I-add-a-new-version-to-all-products-in-bugzilla--td27456871.html" target="_blank">Nabble</a> and on <a title="Bugzilla Support" href="http://groups.google.com/group/mozilla.support.bugzilla/browse_thread/thread/afcf5a9132ac9424?pli=1" target="_blank">the Bugzilla support forum</a>. In these threads the only suggested solutions were to use SQL on the Bugzilla DB, or to use custom fields instead of the built-in version field.</p>
<p>None of these solutions are satisfactory in my opinion, so I decided to create a better one. I created it in the form of a Perl script using the Bugzilla Perl API. The script can be run on the machine on which Bugzilla in installed and is really easy to use. Just put it in the installation directory of Bugzilla and run:</p>
<blockquote><p>AddBugzillaVersion.pl &lt;version_name&gt;</p></blockquote>
<p>Here is the script itself:</p>
<p><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2010/03/AddBugzillaVersion.pl">AddBugzillaVersion.pl</a></p>
<p>Notes:</p>
<ol>
<li>The script must be in the Bugzilla installation directory in order to work properly. Alternatively &#8211; you can put the script anywhere on the machine and add the Bugzilla installation directory into the Perl library path.</li>
<li>The script uses the Bugzilla API, which requires several Perl modules to be installed. These are usually installed by the <em>install-module.pl</em> script, but if any are missing &#8211; they can be installed from CPAN. Instructions on installing CPAN modules can be found <a title="Installing Perl modules" href="http://perl.about.com/od/packagesmodules/qt/perlcpan.htm" target="_blank">here</a>.</li>
</ol>
<ol></ol>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2010/03/adding-a-new-bugzilla-version-to-all-products/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>&#8216;ERROR: Garbage option.&#8217; when using ps and awk</title>
		<link>http://yuval.bar-or.org/blog/2009/12/error-garbage-option-when-using-ps-and-awk/</link>
		<comments>http://yuval.bar-or.org/blog/2009/12/error-garbage-option-when-using-ps-and-awk/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 17:28:31 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=82</guid>
		<description><![CDATA[The other day I wanted to create a simple bash script that would receive the name of a process and print out its pid. I wanted to run ps and then use awk to filter out the correct process and print out its pid. So I created the following bash script (called getPIDOf):
#! /bin/bash

command=&#8221;ps -o [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wanted to create a simple bash script that would receive the name of a process and print out its pid. I wanted to run <em>ps </em>and then use <em>awk </em>to filter out the correct process and print out its pid. So I created the following bash script (called <em>getPIDOf</em>):</p>
<blockquote><p><em>#! /bin/bash<br />
</em></p>
<p><em>command=&#8221;ps -o pid,command -C $1&#8243;<br />
for (( i=1; i&lt;=$#; i+=1 )); do<br />
curval=${!i}<br />
command=&#8221;$command | grep \&#8221;$curval\&#8221;"<br />
done<br />
command=&#8221;$command | awk &#8216;!/awk/ &amp;&amp; !/getPIDOf/ {print \$1}&#8217;&#8221;</em></p>
<p><em>echo $command<br />
$command<br />
</em></p></blockquote>
<p>I was quite pleased with myself that I had even added in the option to specify multiple identifiers for the process. But when I ran the script I got the following output:</p>
<blockquote><p>yuval@obt:$ ./getPIDOf nc<br />
<em>ps -o pid,command -C nc | grep &#8220;nc&#8221; | awk &#8216;!/awk/ &amp;&amp; !/getPIDOf/ {print $1}&#8217;<br />
ERROR: Garbage option.<br />
********* simple selection *********  ********* selection by list *********<br />
-A all processes                      -C by command name<br />
-N negate selection                   -G by real group ID (supports names)<br />
-a all w/ tty except session leaders  -U by real user ID (supports names)<br />
-d all except session leaders         -g by session OR by effective group name<br />
-e all processes                      -p by process ID<br />
T  all processes on this terminal     -s processes in the sessions given<br />
a  all w/ tty, including other users  -t by tty<br />
g  OBSOLETE &#8212; DO NOT USE             -u by effective user ID (supports names)<br />
r  only running processes             U  processes for specified users<br />
x  processes w/o controlling ttys     t  by tty<br />
*********** output format **********  *********** long options ***********<br />
-o,o user-defined  -f full            &#8211;Group &#8211;User &#8211;pid &#8211;cols &#8211;ppid<br />
-j,j job control   s  signal          &#8211;group &#8211;user &#8211;sid &#8211;rows &#8211;info<br />
-O,O preloaded -o  v  virtual memory  &#8211;cumulative &#8211;format &#8211;deselect<br />
-l,l long          u  user-oriented   &#8211;sort &#8211;tty &#8211;forest &#8211;version<br />
-F   extra full    X  registers       &#8211;heading &#8211;no-heading &#8211;context<br />
********* misc options *********<br />
-V,V  show version      L  list format codes  f  ASCII art forest<br />
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format<br />
-M,Z  security data     c  true command name  -c scheduling class<br />
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy<br />
</em></p></blockquote>
<p>I thought that I must have something wrong with the escaping. But when I ran the command that was printed out, it worked fine:</p>
<blockquote><p>yuval@obt:$ ps -o pid,command -C nc | grep &#8220;nc&#8221; | awk &#8216;!/awk/ &amp;&amp; !/getPIDOf/ {print $1}&#8217;<br />
<em>892</em></p></blockquote>
<p>I even tried the following simplified script:</p>
<blockquote><p><em>#! /bin/bash</em></p>
<p><em>command=&#8221;ps -o pid,command -C $1&#8243;<br />
command2=&#8221;awk &#8216;!/awk/ &amp;&amp; !/getPIDOf/ {print \$1}&#8217;&#8221;</em></p>
<p><em>echo &#8220;$command | $command2&#8243;<br />
$command | $command2<br />
</em></p></blockquote>
<p>And got the following output:</p>
<blockquote><p>yuval@obt:$ ./getPIDOf nc<br />
<em>ps -o pid,command -C nc | awk &#8216;!/awk/ &amp;&amp; !/getPIDOf/ {print $1}&#8217;<br />
awk: 1: unexpected character &#8221;&#8217;</em></p></blockquote>
<p>By this time I was quite puzzled. My simple getPIDOf script had become full of strange behaviors. So I decided to take the quick route out and use Perl instead of awk.</p>
<p>Here is my final version of the getPIDOf script:</p>
<blockquote><p><em>#!/usr/bin/perl -w<br />
use strict;</em></p>
<p><em>die &#8220;Usage: $0 &lt;identifier1&gt; [identifier2] &#8230;\n&#8221; unless (@ARGV);</em></p>
<p><em>my $command = &#8220;/bin/ps -o pid,command -C \&#8221;$ARGV[0]\&#8221;";<br />
my $output = `$command`;<br />
foreach my $line (split(/\n/, $output))<br />
{<br />
if ($line =~ /^\s*(\d+)\s+(.+?)$/)<br />
{<br />
my $pid = $1;<br />
my $command = $2;<br />
my $found_mismatch = 0;<br />
foreach my $filter (@ARGV)<br />
{<br />
if ($command !~ /$filter/)<br />
{<br />
$found_mismatch = 1;<br />
last;<br />
}<br />
}</em></p>
<p><em> if ($found_mismatch){next;<br />
}</em></p>
<p><em>print &#8220;$pid\n&#8221;;<br />
}<br />
}</em></p></blockquote>
<p>And the output, as desired, is:</p>
<blockquote><p>yuval@obt:$ ./getPIDOf nc<br />
<em>892</em></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/12/error-garbage-option-when-using-ps-and-awk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved SWIG C# wrappers for std::vector and std::map</title>
		<link>http://yuval.bar-or.org/blog/2009/11/improved-swig-c-wrappers-for-stdvector-and-stdmap-2/</link>
		<comments>http://yuval.bar-or.org/blog/2009/11/improved-swig-c-wrappers-for-stdvector-and-stdmap-2/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 22:43:25 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=77</guid>
		<description><![CDATA[My previous posts on this topic part 1 and part 2 were posted about half a year ago. Since then SWIG version 1.3.40 has been released and it includes several enhancements in the C# wrapper for std::vector and std::map based on the work that I did, but with several great improvements implemented by William Fulton, [...]]]></description>
			<content:encoded><![CDATA[<p>My previous posts on this topic <a title="Part 1" href="http://yuval.bar-or.org/blog/2009/04/improved-swig-c-wrappers-for-stdvector-and-stdmap/">part 1</a> and <a title="Part 2" href="http://yuval.bar-or.org/blog/2009/05/improved-swig-wrappers-std_vectori-and-std_mapi-part-2/">part 2</a> were posted about half a year ago. Since then SWIG version 1.3.40 has been released and it includes several enhancements in the C# wrapper for std::vector and std::map based on the work that I did, but with several great improvements implemented by William Fulton, the person in charge of the C# wrappers in SWIG.</p>
<p>Since version 1.3.40 wrapping std::vector and std::map in C# is extremely simple. I&#8217;ll give a quick overview:</p>
<p><strong>Wrapping std::vector</strong></p>
<p>Lets assume you have a C++ class called <em>MyClass </em>with a method <em>std::vector&lt;int&gt; GetIntVector();</em> You want to wrap MyClass from  C++ to C# and have the GetIntVector method return an IList&lt;int&gt; in C#. In order to do this, your swig interface file (the .i file) should look something like this:</p>
<blockquote><p>/* File : MyProject.i */<br />
%module MyProject</p>
<p>%{<br />
#include &#8220;MyClass.h&#8221;<br />
%}</p>
<p>%include &#8220;std_vector.i&#8221;<br />
%include &#8220;MyClass.h&#8221;</p>
<p>%template(Int_Vector) std::vector&lt;int&gt;;</p></blockquote>
<p>The C# class <em>Int_Vector</em> will implement the IList&lt;int&gt; interface as desired.</p>
<p>Now lets make things a bit trickier by introducing a new class called MyItem and lets add a method to MyClass with the following signature: <em>std::vector&lt;MyItem&gt; GetItems();</em> In this case you&#8217;ll want the C# method to return an IList&lt;MyItem&gt;. One important issue that should be mentioned here is that any class being used in the IList&lt;&gt; generic must overload the == operator. Otherwise, it is only possible to use the IEnumerable&lt;&gt; generic interface.</p>
<p>So if MyItem doesn&#8217;t overload the == operator, and you&#8217;re content with having the C# method return an IEnumerable&lt;MyItem&gt;, then your swig interface file will look something like this:</p>
<blockquote><p>/* File : MyProject.i */<br />
%module MyProject</p>
<p>%{<br />
#include &#8220;MyClass.h&#8221;<br />
#include &#8220;MyItem.h&#8221;<br />
%}</p>
<p>%include &#8220;std_vector.i&#8221;<br />
%include &#8220;MyClass.h&#8221;<br />
%include &#8220;MyItem.h&#8221;</p>
<p>%template(Int_Vector) std::vector&lt;int&gt;;<br />
%template(Item_Vector) std::vector&lt;MyItem&gt;;</p></blockquote>
<p>The C# class <em>Item_Vector</em> will implement the IEnumerable&lt;MyItem&gt; interface.</p>
<p>If, however, MyItem overloads the == operator, then you can have the C# <em>Item_Vector</em> implement the IList&lt;MyItem&gt; interface. You&#8217;ll need to tell swig that your class can be used with the IList&lt;&gt; interface by using the <em>SWIG_STD_VECTOR_ENHANCED</em> macro. Your swig interface file will look something like this:</p>
<blockquote><p>/* File : MyProject.i */<br />
%module MyProject</p>
<p>%{<br />
#include &#8220;MyClass.h&#8221;<br />
#include &#8220;MyItem.h&#8221;<br />
%}</p>
<p>%include &#8220;std_vector.i&#8221;<br />
%include &#8220;MyClass.h&#8221;<br />
%include &#8220;MyItem.h&#8221;</p>
<p>%template(Int_Vector) std::vector&lt;int&gt;;<br />
SWIG_STD_VECTOR_ENHANCED(MyItem)<br />
%template(Item_Vector) std::vector&lt;MyItem&gt;;</p></blockquote>
<p>Now the C# class <em>Item_Vector</em> will implement the IList&lt;MyItem&gt; interface.</p>
<p><strong>Wrapping std::map</strong></p>
<p>Thanks to some nifty features added to the SWIG core, it is now possible to wrap C++ std::maps into C# IDictionary&lt;&gt; generic classes very easily.</p>
<p>Lets assume you have a C++ class called <em>MyClass </em>with a method <em>std::map&lt;std::string, int&gt; GetMap();</em> You want to wrap MyClass from  C++ to C# and have the GetMap method return an IDictionary&lt;string,int&gt; in C#. In order to do this, your swig interface file should look something like this:</p>
<blockquote><p>/* File : MyProject.i */<br />
%module MyProject</p>
<p>%{<br />
#include &#8220;MyClass.h&#8221;<br />
%}</p>
<p>%include &#8220;std_string.i&#8221;<br />
%include &#8220;std_vector.i&#8221;<br />
%include &#8220;MyClass.h&#8221;</p>
<p>%template(String_Int_Map) std::map&lt;std::string, int&gt;;</p></blockquote>
<p>The C# class <em>String_Int_Map</em> will implement the IDictionary&lt;string,int&gt; interface as desired. It&#8217;s that simple. No need for any specialization macros or anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/11/improved-swig-c-wrappers-for-stdvector-and-stdmap-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Offline installation of PEAR packages</title>
		<link>http://yuval.bar-or.org/blog/2009/11/offline-installation-of-pear-packages/</link>
		<comments>http://yuval.bar-or.org/blog/2009/11/offline-installation-of-pear-packages/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 23:24:13 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=72</guid>
		<description><![CDATA[A few days ago I was trying to set up an offline installation of the FirePHPCore PEAR package on a computer that isn&#8217;t connected to the internet. This task wasn&#8217;t as easy as I thought it would be.
I downloaded the package (on a computer that has an internet connection) using:

pear channel-discover pear.firephp.org
pear download firephp/FirePHPCore

This gave [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I was trying to set up an offline installation of the FirePHPCore PEAR package on a computer that isn&#8217;t connected to the internet. This task wasn&#8217;t as easy as I thought it would be.</p>
<p>I downloaded the package (on a computer that has an internet connection) using:</p>
<ol>
<li><em>pear channel-discover pear.firephp.org</em></li>
<li><em>pear download firephp/FirePHPCore</em></li>
</ol>
<p>This gave me a file called <em>FirePHPCore-0.3.1.tgz</em>. Quite pleased with myself I transferred this file to the target machine and ran:</p>
<p><em>pear install -O FirePHPCore-0.3.1.tgz</em></p>
<p>This gave me the following error:</p>
<blockquote><p>Parsing of package.xml from file &#8220;/tmp/pear/cache/package.xml&#8221; failed<br />
Cannot download non-local package &#8220;FirePHPCore-0.3.1.tgz&#8221;<br />
Package &#8220;FirePHPCore-0.3.1.tgz&#8221; is not valid<br />
install failed</p></blockquote>
<p>That can&#8217;t be good. I tried to fix this problem in several ways. I ended up with the following solution:</p>
<ol>
<li>Extract the contents of the tar file using: <em>tar xzf FirePHPCore-0.3.1.tgz</em>. This creates a file called <em>package.xml</em> and a directory called <em>FirePHPCore-0.3.1</em> with some files in it.</li>
<li>Edit the <em>package.xml</em> file and change the contents of the &#8220;channel&#8221; tag (line 4) from <em>pear.firephp.org</em> to <em>pear.php.net</em></li>
<li>Recreate the tgz file using: <em>tar czf FirePHPCore-0.3.1.tgz package.xml FirePHPCore-0.3.1/*</em></li>
<li>You are now the proud owner of a FirePHPCore-0.3.1.tgz file that can be installed offline.</li>
</ol>
<p>Running <em>pear install -O FirePHPCore-0.3.1.tgz</em> on the new tgz file now results in:</p>
<blockquote><p>install ok: channel://pear.php.net/FirePHPCore-0.3.1</p></blockquote>
<p>Much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/11/offline-installation-of-pear-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building ACE on Windows using Visual Studio</title>
		<link>http://yuval.bar-or.org/blog/2009/11/building-ace-on-windows-using-visual-studio/</link>
		<comments>http://yuval.bar-or.org/blog/2009/11/building-ace-on-windows-using-visual-studio/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 22:53:12 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=55</guid>
		<description><![CDATA[The Adaptive Communication Environment (ACE)  framework is an extensive set of cross-platform tools in C++. In this post I will describe in detail the steps required to set up the ACE framework on Windows using Visual Studio, and to set up a project using the ACE framework. The process is not complicated, but there are [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="ACE" href="http://www.cs.wustl.edu/~schmidt/ACE-overview.html">Adaptive Communication Environment</a> (ACE)  framework is an extensive set of cross-platform tools in C++. In this post I will describe in detail the steps required to set up the ACE framework on Windows using Visual Studio, and to set up a project using the ACE framework. The process is not complicated, but there are several pitfalls that one should be aware of.</p>
<p>Here we go!</p>
<p>Note: Steps 1-6 are partially covered in the <a title="ACE Build Guide" href="http://www.dre.vanderbilt.edu/~schmidt/DOC_ROOT/ACE/ACE-INSTALL.html#msvc">ACE Build Guide</a>. I give them here with some extra hints and tips.</p>
<ol>
<li>Download the ACE framework from <a title="ACE download" href="http://download.dre.vanderbilt.edu/">here</a>. We will be using the full version of ACE.zip (last line under &#8220;Latest Micro Release Kit&#8221;).</li>
<li>Unzip this file into the directory where you want your ACE files to be located. I put my ACE files under C:\Programming\C++. Unzipping the file creates an ACE_Wrappers directory (C:\Programming\C++\ACE_Wrappers in my case). We&#8217;ll call this directory the ACE_ROOT directory.</li>
<li>Go to the ACE_ROOT\ace directory (C:\Programming\C++\ACE_Wrappers\ace in my case) and create a file called &#8220;config.h&#8221;. Edit this file with notepad or any other text editor and put the following text in the file:<br />
#include &#8220;ace/config-win32.h&#8221;</li>
<li>In the ACE_ROOT directory there are several solutions for different versions of Visual Studio and for different types of libraries. In this tutorial I will be using Visual C++ 2008 Express Edition (which is also called vc9) and building ACE as a static library. So the solution I  need is &#8216;ACE_wrappers_vc_9_Static.sln&#8217;. Select the solution that fits your needs.</li>
<li>Select your configuration (Debug or Release) and build the ACE project in your solution. In my case this is &#8216;ACE_vc9_Static&#8217;.<br />
<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/BuildACE.jpg"><img class="alignnone size-full wp-image-56" title="Building the ACE library" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/BuildACE.jpg" alt="Building the ACE library" width="442" height="180" /></a></li>
<li>After a few minutes of building, you should have the ACE library file in your ACE_ROOT\lib directory. I built using the Debug configuration, so the file that was created is c:\Programming\C++\ACE_Wrappers\lib\ACEsd.lib</li>
<li>We are now ready to create our first ACE project! Create an empty C++ solution and then edit the project properties.</li>
<li style="text-align: left;">In <span><span style="font-size: x-small;"><span style="font-size: 10pt;">&#8220;Properties&#8221;&#8211;&#8221;C/C++&#8221;&#8211;&#8221;General&#8221;&#8211;&#8221;Additional Include Directories&#8221; add the ACE_ROOT directory.<br />
<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/AdditionalIncludeDirs.jpg"><img class="alignnone size-full wp-image-57" title="Additional Include Directories" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/AdditionalIncludeDirs.jpg" alt="Additional Include Directories" width="514" height="139" /></a></p>
<p></span></span></span></li>
<li style="text-align: left;"><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;"><span><span style="font-family: Times New Roman; font-size: xx-small;"><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span></span></span><span><span style="font-size: x-small;"><span style="font-size: 10pt;">In &#8220;Properties&#8221;&#8211;&#8221;C/C++&#8221;&#8211;&#8221;Preprocessor&#8221;&#8211;&#8221;Preprocessor Definitions&#8221; set the following:<br />
</span></span></span><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;">ACE_AS_STATIC_LIBS<br />
</span></span><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;">_CRT_SECURE_NO_WARNINGS<br />
</span></span><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;">WIN32</p>
<p><a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/PreprocessorDefs.jpg"><img class="alignnone size-full wp-image-58" title="Preprocessor Definitions" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/PreprocessorDefs.jpg" alt="Preprocessor Definitions" width="355" height="314" /><br />
</a></p>
<p></span></span></li>
<li style="text-align: left;"><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;"> </span></span><span><span style="font-size: x-small;"><span style="font-size: 10pt;">In &#8220;Properties&#8221;&#8211;&#8221;C/C++&#8221;&#8211;&#8221;Code Generation&#8221;&#8211;&#8221;Runtime Library&#8221; set to Multi-Threaded debug (/MTd) for the Debug configuration and Multi-Threaded (/MT) for the Release configuration.<br />
<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/CodeGeneration.jpg"><img class="alignnone size-full wp-image-59" title="Code Generation" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/CodeGeneration.jpg" alt="Code Generation" width="502" height="155" /></a><br />
</span></span></span></li>
<li style="text-align: left;"><span><span style="font-size: x-small;"><span style="font-size: 10pt;">In &#8220;Properties&#8221;&#8211;&#8221;Linker&#8221;&#8211;&#8221;General&#8221;&#8211;&#8221;Additional Library Directories&#8221; add the</span></span></span> ACE_ROOT\lib directory.<br />
<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/AdditionalLibDirs.jpg"><img class="alignnone size-full wp-image-60" title="Additional Library Directories" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/AdditionalLibDirs.jpg" alt="Additional Library Directories" width="499" height="100" /></a></li>
<li><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt;"><span><span style="font-family: Times New Roman; font-size: xx-small;"><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span></span></span><span><span style="font-size: x-small;"><span style="font-size: 10pt;">In &#8220;Properties&#8221;&#8211;&#8221;Linker&#8221;&#8211;&#8221;Input&#8221;&#8211;&#8221;Additional Dependencies&#8221; add ACEsd.lib for the Debug configuration and ACEs.lib for the Release configuration.<br />
<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/LinkerInput.jpg"><img class="alignnone size-full wp-image-61" title="Linker Input" src="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/LinkerInput.jpg" alt="Linker Input" width="503" height="126" /></a><br />
</span></span></span></li>
<li>Your project is now configured to work with ACE. You can create your project code and start using the ACE framework. Following is a simple example program that runs a thread to perform some work.<a href="http://yuval.bar-or.org/blog/wp-content/uploads/2009/11/main.cpp"><br />
ACE Test Program</a></li>
</ol>
<p>That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/11/building-ace-on-windows-using-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading Perl Modules from a Dynamic or Unknown Location</title>
		<link>http://yuval.bar-or.org/blog/2009/11/loading-perl-modules-from-a-dynamic-or-unknown-location/</link>
		<comments>http://yuval.bar-or.org/blog/2009/11/loading-perl-modules-from-a-dynamic-or-unknown-location/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:33:40 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=49</guid>
		<description><![CDATA[Perl modules are sometimes located in non-standard directories. There are several ways to use these modules:

Add the directory to the PERL5LIB environment variable.
Run the script using the perl -l.
Within the script &#8216;use lib&#8216; with the directory name.

These methods are quite common and handle most of the cases perfectly.
For example:
#!/usr/bin/perl -w
use strict;
use lib (&#8221;/home/users/yuval/perl/modules&#8221;);
use MyModule;
 &#8230;
This [...]]]></description>
			<content:encoded><![CDATA[<p>Perl modules are sometimes located in non-standard directories. There are several ways to use these modules:</p>
<ul>
<li>Add the directory to the PERL5LIB environment variable.</li>
<li>Run the script using the perl -l.</li>
<li>Within the script &#8216;<em>use lib</em>&#8216; with the directory name.</li>
</ul>
<p>These methods are quite common and handle most of the cases perfectly.</p>
<p>For example:</p>
<blockquote><p><em>#!/usr/bin/perl -w<br />
use strict;</em></p>
<p><em>use lib (&#8221;/home/users/yuval/perl/modules&#8221;);<br />
use MyModule;</em></p>
<p><em> &#8230;</em></p></blockquote>
<p>This works fine as long as you know that you need to search in /home/users/yuval/perl/modules to find MyModule.</p>
<p><strong>But what happens if you don&#8217;t know the location of the module ahead of time?</strong><br />
None of the methods mentioned above can handle this situation. Consider the following code:</p>
<blockquote><p><em> #!/usr/bin/perl -w<br />
</em><em> </em><em> </em><em>use strict;</em></p>
<p><em> my $user = GetCoolestUser();<br />
use lib (&#8221;/home/users/$user/perl/modules&#8221;);<br />
use MyModule;</em></p>
<p><em> sub GetCoolestUser()<br />
{<br />
return &#8220;yuval&#8221;;<br />
}</em></p>
<p><em> &#8230;</em></p></blockquote>
<p>Running this code gives a bunch of really scary compilation errors.</p>
<p>Yes &#8211; compilation errors. Yes &#8211; in Perl. What gives you ask?</p>
<p>The reason is that the Perl compiler tries to locate all of the modules that are going to be loaded before running the script. It does this before values are given to any variables, and before any functions are evaluated. Therefore the $user variable is undefined when it is evaluated in the parameters to the &#8216;<em>use lib</em>&#8216; statement, and then MyModule isn&#8217;t found in any of the directories that Perl searches.</p>
<p>There are two ways around this:</p>
<p><strong>1. Push the directory name directly into the @INC array in the BEGIN function</strong></p>
<blockquote><p><em> #!/usr/bin/perl -w<br />
</em><em> </em><em> </em><em>use strict;<br />
</em></p>
<p><em> BEGIN<br />
</em><em> {<br />
</em><em> sub GetCoolestUser()<br />
{<br />
return &#8220;yuval&#8221;;<br />
}</em><br />
<em> my $user = GetCoolestUser();<br />
push(@INC, &#8220;/home/users/$user/perl/modules&#8221;);<br />
}<br />
use MyModule;</em></p>
<p><em> &#8230;</em></p></blockquote>
<p>You may notice that this code doesn&#8217;t use the elegant &#8216;<em>use lib</em>&#8216; but rather the tasteless pushing of the directory into the @INC array. Also &#8211; the <em>GetCoolestUser </em>function has to be defined within the BEGIN block in order to be used.</p>
<p><strong>2. Use the eval function</strong></p>
<blockquote><p><em> #!/usr/bin/perl -w<br />
</em><em> </em><em> </em><em>use strict;</em></p>
<p><em> my $user = GetCoolestUser();<br />
eval &#8220;use lib qw(/home/users/$user/perl/modules);<br />
use MyModule;&#8221;;<br />
if ($@) {<br />
die &#8220;Error loading module MyModule:\n$@\n&#8221;;<br />
}</em></p>
<p><em> sub GetCoolestUser()<br />
{<br />
return &#8220;yuval&#8221;;<br />
}</em></p>
<p><em> &#8230;</em></p></blockquote>
<p>This method &#8220;tricks&#8221; Perl compiler and allows loading the module from any location you wish. This method is stronger than the previous method mentioned because the module loading occurs during run time and the location can be calculated dynamically during run time as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/11/loading-perl-modules-from-a-dynamic-or-unknown-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualgos &#8211; The 8-Puzzle</title>
		<link>http://yuval.bar-or.org/blog/2009/09/visualgos-the-8-puzzle/</link>
		<comments>http://yuval.bar-or.org/blog/2009/09/visualgos-the-8-puzzle/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 20:57:01 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=46</guid>
		<description><![CDATA[I&#8217;ve just added a new problem visualization. The visualization is of the 8-Puzzle &#8211; a classic game in which you have a 3 by 3 board with tiles numbered 1 to 8, and one missing tile. Your goal is to bring the board to a state in which the tiles are ordered according to their [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just added a new problem visualization. The visualization is of the 8-Puzzle &#8211; a classic game in which you have a 3 by 3 board with tiles numbered 1 to 8, and one missing tile. Your goal is to bring the board to a state in which the tiles are ordered according to their numbers, and the empty spot is in the bottom right-hand corner. The only movements allowed are taking a tile that is adjacent to the empty spot and sliding it (horizontally or vertically) into the empty spot.</p>
<p>The visualizations added implement the DFS algorithm, the greedy algorithm and the A* algorithm.</p>
<p>You can find the visualization <a title="8-Puzzle Visualization" href="http://yuval.bar-or.org/index.php?item=10">here</a>, along with detailed information about the algorithms.</p>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/09/visualgos-the-8-puzzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing &#8211; Visualgos</title>
		<link>http://yuval.bar-or.org/blog/2009/07/introducing-visualgos/</link>
		<comments>http://yuval.bar-or.org/blog/2009/07/introducing-visualgos/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 18:00:30 +0000</pubDate>
		<dc:creator>yuval</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yuval.bar-or.org/blog/?p=43</guid>
		<description><![CDATA[
Visualgos is a collection of visualizations for algorithms written in Flash.
When I study a new algorithm I usually want to get a feel for it by seeing how it performs. It usually takes hours of programming and debugging in order to get something up and running. The idea of &#8220;Visualgos&#8221; is to supply a collection [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<p>Visualgos is a collection of visualizations for algorithms written in Flash.</p>
<p>When I study a new algorithm I usually want to get a feel for it by seeing how it performs. It usually takes hours of programming and debugging in order to get something up and running. The idea of &#8220;Visualgos&#8221; is to supply a collection of visualizations for different algorithms so that anyone can get a feel for an algorithm without needing to spend hours coding it.</p>
<p>I&#8217;ve already added a visualization of a heuristic search algorithm in the form of a <a title="Tic-Tac-Toe game" href="http://yuval.bar-or.org/index.php?item=8">Tic-Tac-Toe game</a> and a visualization of a heuristic repair algorithm in the form of an <a title="N Queens puzzle solver" href="http://yuval.bar-or.org/index.php?item=9">N Queens puzzle solver</a>.</p>
<p>If you are interested in contributing to this project, please contact me at:</p>
<p>yuval (dot) baror [dot] website {at} gmail (dot) com</p></div>
]]></content:encoded>
			<wfw:commentRss>http://yuval.bar-or.org/blog/2009/07/introducing-visualgos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
