<?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>LogikDevelopment &#187; smoreau</title>
	<atom:link href="http://www.logikdev.com/author/smoreau/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logikdev.com</link>
	<description>&#34;Il n&#039;y a pas de problème, il n&#039;y a que des solutions. L&#039;esprit de l&#039;homme invente ensuite le problème.&#34; André Gide</description>
	<lastBuildDate>Tue, 20 Dec 2011 12:25:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Too many open files on Tomcat</title>
		<link>http://www.logikdev.com/2011/12/20/too-many-open-files-on-tomcat/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=too-many-open-files-on-tomcat</link>
		<comments>http://www.logikdev.com/2011/12/20/too-many-open-files-on-tomcat/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 00:24:25 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java.net.SocketException]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[open file descriptors]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[Too many open files]]></category>
		<category><![CDATA[ulimit]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1678</guid>
		<description><![CDATA[The other day, one of my websites was not available anymore. Looking at the log files, I found the following exception: Dec 7, 2011 1:22:39 AM org.apache.jk.common.ChannelSocket acceptConnections WARNING: Exception executing accept java.net.SocketException: Too many open files at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) at java.net.ServerSocket.implAccept(ServerSocket.java:450) at java.net.ServerSocket.accept(ServerSocket.java:421) at org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:307) at org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:661) at org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:872) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) at [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, one of my websites was not available anymore. Looking at the log files, I found the following exception:</p>
<pre>
Dec 7, 2011 1:22:39 AM org.apache.jk.common.ChannelSocket acceptConnections
WARNING: Exception executing accept
java.net.SocketException: Too many open files
	at java.net.PlainSocketImpl.socketAccept(Native Method)
	at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
	at java.net.ServerSocket.implAccept(ServerSocket.java:450)
	at java.net.ServerSocket.accept(ServerSocket.java:421)
	at org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:307)
	at org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:661)
	at org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:872)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
	at java.lang.Thread.run(Thread.java:595)
</pre>
<p><br/>This was the first time I was getting this exception. What is even stranger is that I didn&#8217;t change anything on this application for quite a while!<br />
Anyway, I first did what I usually do with Tomcat: restart it! This fixed the issue but only for a few hours before it crashed again.</p>
<p>After some investigation, it seems that Tomcat was reaching the limit of open file descriptors allowed in this machine (1024 in my case).<br />
To get the maximum number of open file descriptors, simply type the following command:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
ulimit -n
</pre>
<p>It is possible to increase this value by editing the file <code>/etc/security/limits.conf</code> and adding the new limit for the user running Tomcat. However, this is not recommended as 1024 should be sufficient.</p>
<p>The second thing I did was to check the list of open files used by the Tomcat process:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
lsof -p
</pre>
<p>What I found by running this command was a bit odd. It seems that Tomcat was having a multitude of opened connections to one of the web services used by the application. So it looks like the connections between my website and the web service were never closed!  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_neutral.gif' alt=':-|' class='wp-smiley' /><br />
Because I didn&#8217;t change the code on my side, I asked the third party who owns the web service to check their code. I don&#8217;t know what was the root cause of the problem but they fixed it on their side and it is now working fine.</p>
<p><strong>In conclusion, if you get the same exception, try to find where the problem is coming from before increasing the maximum number of open file descriptors.</strong> <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/12/20/too-many-open-files-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Samba access problem with Mac OS X 10.6+</title>
		<link>http://www.logikdev.com/2011/12/13/samba-access-problem-with-mac-os-x-10-6/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=samba-access-problem-with-mac-os-x-10-6</link>
		<comments>http://www.logikdev.com/2011/12/13/samba-access-problem-with-mac-os-x-10-6/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 21:31:15 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[D-Link]]></category>
		<category><![CDATA[DNS-313]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Samba]]></category>
		<category><![CDATA[security mode]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1653</guid>
		<description><![CDATA[This is a problem I encountered when I upgraded Mac OS X from the version 10.5 (Leopard) to 10.6 (Snow Leopard). One of my friend also got a similar problem when she upgraded to the version 10.7 (Lion). This issue was affecting the access to the network shares set up with Samba (version 3.0.24) on [...]]]></description>
			<content:encoded><![CDATA[<p>This is a problem I encountered when I upgraded Mac OS X from the version 10.5 (Leopard) to 10.6 (Snow Leopard). One of my friend also got a similar problem when she upgraded to the version 10.7 (Lion).<br />
This issue was affecting the access to the network shares set up with <strong>Samba</strong> (version 3.0.24) on my D-Link DNS-323. For some reason, I wasn&#8217;t able to authenticate on the shares as soon as I upgraded to Snow Leopard!</p>
<p>Here is the error message I was getting:<br />
<a href="http://www.logikdev.com/wp-content/uploads/2011/12/samba-access-problem.png" rel="lightbox[1653]"><img src="http://www.logikdev.com/wp-content/uploads/2011/12/samba-access-problem-300x271.png" alt="" title="Samba authentication problem on Mac OS X" width="300" height="271" class="alignnone size-medium wp-image-1669" /></a></p>
<p>After browsing a few forums on the web, I finally found a solution. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I simply had to change the security mode in the Samba configuration file (<code>smb.conf</code>) to read:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
security = USER
</pre>
<p>Note that this property can be found under the <code>[global]</code> section.</p>
<p>For more information about the Samba security mode, please read the following article by Jack Wallen:<br />
<a href="http://www.ghacks.net/2010/03/17/understanding-samba-security-modes/" title="Understanding Samba security modes" target="_blank">Understanding Samba security modes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/12/13/samba-access-problem-with-mac-os-x-10-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S3 command failed if the time is not synced</title>
		<link>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=s3-command-failed-if-time-not-synced</link>
		<comments>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 23:11:43 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ntpdate]]></category>
		<category><![CDATA[s3sync]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[system date]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1610</guid>
		<description><![CDATA[This is already the second post about the s3sync ruby program. The first article was focused on monitoring s3sync with Zabbix. I will talk on this one about an error I got when running the S3 synchronisation: S3 command failed: list_bucket prefix /data max-keys 200 delimiter / With result 403 Forbidden S3 ERROR: # s3sync.rb:290:in [...]]]></description>
			<content:encoded><![CDATA[<p>This is already the second post about the <a href="https://forums.aws.amazon.com/thread.jspa?threadID=11975&amp;start=0&amp;tstart=0" target="_blank"><strong>s3sync</strong></a> ruby program. The first article was focused on <a title="Monitor s3sync with Zabbix" href="http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/">monitoring s3sync with Zabbix</a>.</p>
<p>I will talk on this one about an error I got when running the S3 synchronisation:</p>
<pre>
S3 command failed:
list_bucket prefix /data max-keys 200 delimiter /
With result 403 Forbidden
S3 ERROR: #
s3sync.rb:290:in `+': can't convert nil into Array (TypeError)
	from s3sync.rb:290:in `s3TreeRecurse'
	from s3sync.rb:346:in `main'
	from ./thread_generator.rb:79:in `call'
	from ./thread_generator.rb:79:in `initialize'
	from ./thread_generator.rb:76:in `new'
	from ./thread_generator.rb:76:in `initialize'
	from s3sync.rb:267:in `new'
	from s3sync.rb:267:in `main'
	from s3sync.rb:735
</pre>
<p>As you can see, this error is not very human-friendly! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' />  The only thing we know is that the S3 command failed because of the error <code>can't convert nil into Array</code>. It looks to me like an internal error within s3sync&#8230;</p>
<p>But after some investigation, it appears it is simply because the system date on the server is not correct. I cannot tell you how much time I spent on this one!  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /> </p>
<p>Anyway, if you are doing automatic backups as describe on <a href="http://blog.eberly.org/2006/10/09/how-automate-your-backup-to-amazon-s3-using-s3sync/" target="_blank">John Eberly&#8217;s blog</a>, you need to add the following code at the top of your <code>upload.sh</code> script:</p>
<pre class="brush: bash; title: ; notranslate">
# update the system date
/usr/sbin/ntpdate 3.uk.pool.ntp.org 2.uk.pool.ntp.org 1.uk.pool.ntp.org 0.uk.pool.ntp.org
</pre>
<p><br/><strong>NB:</strong> please find below the command lines I use to install <a href="http://www.eecis.udel.edu/~mills/ntp/html/ntpdate.html" target="_blank"><strong>ntpdate</strong></a> on a Debian server:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
apt-get install ntpdate
dpkg-reconfigure tzdata
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitor s3sync with Zabbix</title>
		<link>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitor-s3sync-with-zabbix</link>
		<comments>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 22:28:53 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[s3sync]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[synchronisation]]></category>
		<category><![CDATA[Zabbix]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1566</guid>
		<description><![CDATA[s3sync is a ruby program that easily transfers directories between a local directory and an S3 bucket:prefix. It behaves somewhat, but not precisely, like the rsync program. I am using this tool to automatically backup the important data from Debian servers to Amazon S3. I am not going to explain here how to install s3sync [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://forums.aws.amazon.com/thread.jspa?threadID=11975&#038;start=0&#038;tstart=0" target="_blank"><strong>s3sync</strong></a> is a ruby program that easily transfers directories between a local directory and an S3 bucket:prefix. It behaves somewhat, but not precisely, like the <strong>rsync</strong> program.</p>
<p>I am using this tool to automatically backup the important data from Debian servers to Amazon S3. I am not going to explain here how to install s3sync as it is not the purpose of this article. However, you can read this very useful article from John Eberly&#8217;s blog: <a href="http://blog.eberly.org/2006/10/09/how-automate-your-backup-to-amazon-s3-using-s3sync/" target="_blank">How I automated my backups to Amazon S3 using s3sync</a>.</p>
<p>If you followed the steps from John Eberly&#8217;s post, you should have an <code>upload.sh</code> script and a crontab job which executes this script periodically.</p>
<p>From this point, here is what you need to do to monitor the success of the synchronisation with <a href="http://www.zabbix.com/" target="_blank"><strong>Zabbix</strong></a>:</p>
<ol>
<li>Add the following code at the end of your <code>upload.sh</code> script:
<pre class="brush: bash; title: ; notranslate">
# print the exit code
RETVAL=$?
[ $RETVAL -eq 0 ] &amp;&amp; echo &quot;Synchronization succeed&quot;
[ $RETVAL -ne 0 ] &amp;&amp; echo &quot;Synchronization failed&quot;
</pre>
</li>
<li>Log the output of the cron script as follow:
<pre class="brush: bash; light: true; title: ; notranslate">
30 2 * * sun /path/to/upload.sh &gt; /var/log/s3sync.log 2&gt;&amp;1
</pre>
</li>
<li>On Zabbix, create a new item which will check the existence of the sentence &#8220;Synchronization failed&#8221; in the file <code>/var/log/s3sync.log</code>:<br />
<a href="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item.png" rel="lightbox[1566]"><img src="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item-297x300.png" alt="" title="Create a new item on Zabbix to monitor s3sync" width="297" height="300" class="aligncenter size-medium wp-image-1569" /></a><br />
Item key: <code>vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed]</code><br />
<br/>
</li>
<li>Still on Zabbix, define a new trigger for the previously created item:<br />
<a href="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger.png" rel="lightbox[1566]"><img src="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger-300x160.png" alt="" title="Define a new trigger on Zabbix to monitor s3sync" width="300" height="160" class="aligncenter size-medium wp-image-1570" /></a><br />
Trigger expression: <code>{Template_AmazonCloud_Debian:vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed].last(0)}=1</code>
</li>
</ol>
<p>With these few steps, you should now receive Zabbix alerts when a backup on S3 fails. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refresh GeoIP automatically</title>
		<link>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refresh-geoip-automatically</link>
		<comments>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 22:55:09 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[GeoIP]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[MaxMind]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1440</guid>
		<description><![CDATA[GeoIP is a very useful tool provided by MaxMind. It can determine which country, region, city, postal code, and area code the visitor is coming from in real-time. For more information, visit MaxMind website. This tool is also coming with an Apache module allowing to redirect users depending on their location. For example, we could [...]]]></description>
			<content:encoded><![CDATA[<p><strong>GeoIP</strong> is a very useful tool provided by MaxMind. It can determine which country, region, city, postal code, and area code the visitor is coming from in real-time. For more information, visit <a href="http://www.maxmind.com/app/ip-locate" target="_blank">MaxMind website</a>.</p>
<p>This tool is also coming with an Apache module allowing to redirect users depending on their location. For example, we could redirect all users from France to the French home page of a multi-language website, or we could block the traffic to users from a specific country.</p>
<p>To install this module on a Debian server, you simply need to run the following command:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
apt-get install libapache2-mod-geoip
</pre>
<p><br/>But, how does this module work? How does it know where the user comes from?  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /><br />
It is actually quite simple: GeoIP is using a mapping file of IP address by country. On Debian, this file is stored in the folder <code>/usr/share/GeoIP</code> and is named <code>GeoIP.dat</code>.</p>
<p>However, the IP addresses are something which change all the time. So this file will get out-of-date very quickly. This is why MaxMind provides an updated file at the beginning of each month for free. To read the installation instructions, please click the following link: <a href="http://www.maxmind.com/app/installation" target="_blank">http://www.maxmind.com/app/installation</a></p>
<p>This is good and well, but who will remember or even have the time to update this file every month? And imagine if you have to do this on hundreds of servers?<br />
The solution is to use a shell script which will download, extract and install the updated GeoIP file automatically once a month:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

# Go in the GeoIP folder
cd /usr/share/GeoIP

# Remove the previous GeoIP file (if present)
rm GeoIP.dat.gz

# Download the new GeoIP file
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

# Remove the previous GeoIP backup file
rm GeoIP.dat.bak

# Backup the existing GeoIP file
mv GeoIP.dat GeoIP.dat.bak

# Extract the new GeoIP file
gunzip GeoIP.dat.gz

# Change the permission of the GeoIP file
chmod 644 GeoIP.dat

# Reload Apache
service apache2 reload
</pre>
<p>You can place this file in your root folder and set up the following crontab job:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
0 0 3 * * /root/update_geoip.sh
</pre>
<p>This will execute the script automatically on the third day of every month.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert SQL Server to MySQL</title>
		<link>http://www.logikdev.com/2011/10/17/convert-sql-server-to-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=convert-sql-server-to-mysql</link>
		<comments>http://www.logikdev.com/2011/10/17/convert-sql-server-to-mysql/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 21:51:34 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[mssql2mysql]]></category>
		<category><![CDATA[SQL dump]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1487</guid>
		<description><![CDATA[Some time ago, I had to convert a Microsoft SQL Server database to a MySQL database. The main reason was the cost of the SQL Server license for such a small database. Looking on the web, I found the following open source application: Name: mssql2mysql URL: http://sourceforge.net/projects/mssql2mysql/ Description: mssql2mysql is a python script used to [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I had to convert a Microsoft SQL Server database to a MySQL database. The main reason was the cost of the SQL Server license for such a small database.</p>
<p>Looking on the web, I found the following open source application:</p>
<table style="border:0px;">
<tr>
<td style="border:0px;"><strong>Name:</strong></td>
<td style="border:0px;">mssql2mysql</td>
</tr>
<tr>
<td style="border:0px;"><strong>URL:</strong></td>
<td style="border:0px;"><a href="http://sourceforge.net/projects/mssql2mysql/" target="_blank">http://sourceforge.net/projects/mssql2mysql/</a></td>
</tr>
<tr>
<td style="border:0px;vertical-align:top;"><strong>Description:</strong></td>
<td style="border:0px;">mssql2mysql is a python script used to create a SQL dump from a Microsoft SQL server that is ready to use with MySQL. Supports Schema and data dumping, including Primary Keys for each table, allows to dump all data or just a small portion of it.</td>
</tr>
</table>
<p>To be honest, this tool wasn&#8217;t working as expected but it was a very good start! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Below is the list of changes I&#8217;ve made:</p>
<ul>
<li>Add support for the <code>bool</code> data type;</li>
<li>Add support for the <code>datetime</code> data type;</li>
<li>Only convert tables and views of the &#8216;dbo&#8217; owner;</li>
<li>Add the test <code>columnas[6]==True</code> on the primary key;</li>
<li>Add support for the <code>uniqueidentifier</code> data type;</li>
<li>Add support for the <code>tinyint</code> data type (SQL Server is <code>tinyint unsigned</code> by default, but not in MySQL!);</li>
<li>Add support for the default column values;</li>
<li>Add support for the <code>bit</code> data type (use <code>tinyint</code> instead of <code>bit</code>, go to <a href="http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/" target="_blank">this page</a> for more information).</li>
</ul>
<p>To download the amended script, please click on the following link: <a href="http://www.logikdev.com/wp-content/uploads/2011/10/mssql2mysql.tar.bz2">mssql2mysql.tar.bz2</a></p>
<p>This script worked perfectly fine for me. However, please note that my interest was focused on converting the database structure but not the content!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/10/17/convert-sql-server-to-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make image backgrounds transparent with tolerance</title>
		<link>http://www.logikdev.com/2011/10/05/make-image-backgrounds-transparent-with-tolerance/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=make-image-backgrounds-transparent-with-tolerance</link>
		<comments>http://www.logikdev.com/2011/10/05/make-image-backgrounds-transparent-with-tolerance/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 21:33:48 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[image background]]></category>
		<category><![CDATA[tolerance]]></category>
		<category><![CDATA[transparent]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1435</guid>
		<description><![CDATA[In one of the projects I am working on at the moment, I needed to convert the background colour of an image to be transparent so the image looks better on a non-white background. Looking on the Web, I found the following article from Dustin Marx: Making White Image Backgrounds Transparent with Java 2D/Groovy If [...]]]></description>
			<content:encoded><![CDATA[<p>In one of the projects I am working on at the moment, I needed to convert the background colour of an image to be transparent so the image looks better on a non-white background.</p>
<p>Looking on the Web, I found the following article from Dustin Marx:<br />
<a href="http://www.javaworld.com/community/node/7629" title="Making White Image Backgrounds Transparent with Java 2D/Groovy" target="_blank">Making White Image Backgrounds Transparent with Java 2D/Groovy</a><br />
If the link is broken, please download his code from the following link: <a href="http://www.logikdev.com/wp-content/uploads/2011/10/ImageTransparency.java_.zip">ImageTransparency.java</a></p>
<p>The method which makes the background colour transparent is called <code>makeColorTransparent</code>. This method works pretty well, except in some cases as shown in the example below:</p>
<table style="width:100%;border:0px;">
<tr>
<td style="width:50%;border:0px;">
<img src="http://www.logikdev.com/wp-content/uploads/2011/10/geek-inside-original.jpg" title="Original image" width="100" height="100" class="aligncenter size-full wp-image-1454" />
</td>
<td style="width:50%;border:0px;">
<img src="http://www.logikdev.com/wp-content/uploads/2011/10/geek-inside-0.jpg" alt="" title="Converted image using Dustin's method" width="100" height="100" class="aligncenter size-full wp-image-1457" />
</td>
</tr>
<tr>
<td style="border:0px;text-align:center;vertical-align:top;">
<em>Original image</em>
</td>
<td style="border:0px;text-align:center;vertical-align:top;">
<em>Converted image<br/>using Dustin&#8217;s method</em>
</td>
</tr>
</table>
<p>This is actually quite normal. Indeed, his code is converting a specific colour (#FFFFFF in our case) to be transparent. But what if the background is not homogeneous?</p>
<p>This is the reason why I had to modify his method to add a new parameter called <code>tolerance</code>:</p>
<pre class="brush: java; title: ; notranslate">
private Image makeColorTransparent(final BufferedImage im, final Color color, int tolerance) {
    int temp = 0;
    if (tolerance &lt; 0 || tolerance &gt; 100) {
        System.err.println(&quot;The tolerance is a percentage, so the value has to be between 0 and 100.&quot;);
        temp = 0;
    } else {
        temp = tolerance * (0xFF000000 | 0xFF000000) /100;
    }
    final int toleranceRGB = Math.abs(temp);

    final ImageFilter filter = new RGBImageFilter() {
        // The color we are looking for (white)... Alpha bits are set to opaque
        public int markerRGB = color.getRGB() | 0xFF000000;

        public final int filterRGB(final int x, final int y, final int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF &amp; rgb;
            } else {
                // Nothing to do
                return rgb;
            }
        }
    };

    final ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
</pre>
<p>Such as Photoshop, the tolerance is a percentage value between 0 and 100. The higher the tolerance is, the bigger the range of colours will be.</p>
<p>Let&#8217;s take our previous example and apply a 50% tolerance:</p>
<p><img src="http://www.logikdev.com/wp-content/uploads/2011/10/geek-inside-50.jpg" alt="" title="geek-inside-50" width="100" height="100" class="aligncenter size-full wp-image-1472" /></p>
<p>That looks much better, isn&#8217;t it? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/10/05/make-image-backgrounds-transparent-with-tolerance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AVG function returns 0.9999</title>
		<link>http://www.logikdev.com/2011/09/15/avg-function-returns-09999/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=avg-function-returns-09999</link>
		<comments>http://www.logikdev.com/2011/09/15/avg-function-returns-09999/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 20:32:28 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[0.9999 value]]></category>
		<category><![CDATA[Amazon RDS]]></category>
		<category><![CDATA[AVG function]]></category>
		<category><![CDATA[Bug]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1423</guid>
		<description><![CDATA[This one is a very odd bug! For some reason, the AVG function from MySQL is always returning the value 0.9999 instead of the average value. This has been experienced on MySQL 5.5.12 hosted on Amazon RDS (Relational Database Service). However, the exact same query executed on MySQL 5.1.28 is returning the right values. Why [...]]]></description>
			<content:encoded><![CDATA[<p>This one is a very odd bug! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_neutral.gif' alt=':-|' class='wp-smiley' /> </p>
<p>For some reason, the AVG function from MySQL is always returning the value 0.9999 instead of the average value. This has been experienced on MySQL 5.5.12 hosted on Amazon RDS (Relational Database Service).<br />
However, the exact same query executed on MySQL 5.1.28 is returning the right values.</p>
<p>Why is that? Is it a bug in MySQL 5.5.12?<br />
I did a search on internet and I couldn&#8217;t find anything about it. So to be honest, I am not sure what is this bug or even if MySQL is aware of it.</p>
<p>Anyway, if you encounter the same problem, you can simply replace the AVG function by the combination SUM/COUNT.<br />
For example, the following query:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
SELECT student_name, AVG(test_score)
FROM student
GROUP BY student_name;
</pre>
<p>can be replaced by the one below:</p>
<pre class="brush: sql; light: true; title: ; notranslate">
SELECT student_name, SUM(test_score)/COUNT(test_score)
FROM student
GROUP BY student_name;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/09/15/avg-function-returns-09999/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Send email attachment with PHP</title>
		<link>http://www.logikdev.com/2011/09/01/send-email-attachment-with-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=send-email-attachment-with-php</link>
		<comments>http://www.logikdev.com/2011/09/01/send-email-attachment-with-php/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 20:50:04 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[boundary]]></category>
		<category><![CDATA[email attachment]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1404</guid>
		<description><![CDATA[Everybody probably knows how to send an email using PHP, but do you know how to send an email with an attachment? This is actually not very difficult and you can find examples all over the web. However, it seems that all the examples I found didn&#8217;t work! But after some debugging and testing, I [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody probably knows how to send an email using PHP, but do you know how to send an email with an attachment?</p>
<p>This is actually not very difficult and you can find examples all over the web. However, it seems that all the examples I found didn&#8217;t work! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
But after some debugging and testing, I finally got a working solution. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Please see below the code with comments:</p>
<pre class="brush: php; title: ; notranslate">
// Define some variables
$to = 'test@logikdev.com'
$subject = 'Test email';
// Create a boundary string. It must be unique so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));

// Define the headers
$headers = &quot;From: noreply@logikdev.com\r\n&quot;;
// Add boundary string and mime type specification
$headers .= &quot;Content-Type: multipart/mixed; boundary=\&quot;PHP-mixed-&quot;.$random_hash.&quot;\&quot;&quot;;

// Read the attachment file contents into a string, encode it with MIME base64, and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));

// Define the body of the message
$message = &quot;
--PHP-mixed-$random_hash
Content-Type: text/plain; charset='iso-8859-1'

This is a test email message sent with PHP.

--PHP-mixed-$random_hash
Content-Type: application/zip; name=attachment.zip
Content-Transfer-Encoding: base64
Content-Disposition: attachment

$attachment
--PHP-mixed-$random_hash--&quot;;

// Send the email
if (@mail($to, $subject, $message, $headers)) {
	echo &quot;The mail has been sent.&quot;;
} else {
	echo &quot;The mail has NOT been sent!&quot;;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/09/01/send-email-attachment-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Differences between Amazon instances</title>
		<link>http://www.logikdev.com/2011/07/17/differences-between-amazon-instances/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=differences-between-amazon-instances</link>
		<comments>http://www.logikdev.com/2011/07/17/differences-between-amazon-instances/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 21:36:50 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon Cloud]]></category>
		<category><![CDATA[CPU capacity]]></category>
		<category><![CDATA[cpuinfo]]></category>
		<category><![CDATA[EC2 Compute Units]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1374</guid>
		<description><![CDATA[It has now been more than a year I am using Amazon Cloud for websites hosting. I have to admit that it works pretty well and I am quite happy about their services. However, I got a strange problem a few days ago. I was deploying an application on two different large instances of Amazon [...]]]></description>
			<content:encoded><![CDATA[<p>It has now been more than a year I am using Amazon Cloud for websites hosting. I have to admit that it works pretty well and I am quite happy about their services.<br />
However, I got a strange problem a few days ago.</p>
<p>I was deploying an application on two different large instances of Amazon Cloud, one would be the UAT (User Acceptance Testing) server and the other one would be the Production server.<br />
Strangely enough, the version running on the Production server was running <strong>slower</strong> than on the UAT server! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /> Why?</p>
<p>At first, I thought I missed something with the server configurations. But no, everything was absolutely identical! So where does this difference of speed come from?</p>
<p>After some more investigation, I had the brilliant idea to execute the following command:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
cat /proc/cpuinfo
</pre>
<p>On the Production server, this command was returning the following:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 65
model name	: Dual-Core AMD Opteron(tm) Processor 2218 HE
stepping	: 3
cpu MHz		: 2599.998
cache size	: 1024 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
bogomips	: 5202.40
TLB size	: 1024 4K pages
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc

processor	: 1
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 65
model name	: Dual-Core AMD Opteron(tm) Processor 2218 HE
stepping	: 3
cpu MHz		: 2599.998
cache size	: 1024 KB
physical id	: 1
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow up pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
bogomips	: 5202.40
TLB size	: 1024 4K pages
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc
</pre>
<p>And on the UAT server, it was returning the following:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 23
model name	: Intel(R) Xeon(R) CPU           E5430  @ 2.66GHz
stepping	: 10
cpu MHz		: 2666.762
cache size	: 6144 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu de tsc msr pae cx8 apic sep cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc pni ssse3 cx16 lahf_lm
bogomips	: 5337.55
clflush size	: 64
cache_alignment	: 64
address sizes	: 38 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 23
model name	: Intel(R) Xeon(R) CPU           E5430  @ 2.66GHz
stepping	: 10
cpu MHz		: 2666.762
cache size	: 6144 KB
physical id	: 1
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu de tsc msr pae cx8 apic sep cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc up pni ssse3 cx16 lahf_lm
bogomips	: 5337.55
clflush size	: 64
cache_alignment	: 64
address sizes	: 38 bits physical, 48 bits virtual
power management:
</pre>
<p>As you can see, these two servers actually don&#8217;t have the same CPU model name. But the biggest difference is probably the CPU MHz (2666.762 on UAT and 2599.998 on Production) and the cache size (6MB on UAT and only 1MB on Production).</p>
<p>So what does that mean? Two large instances of Amazon Cloud actually don&#8217;t have the same power?</p>
<p>The answer of this question is actually on the Amazon instance types description (<a href="http://aws.amazon.com/ec2/instance-types/" target="_blank">http://aws.amazon.com/ec2/instance-types/</a>) under the &#8216;Measuring Compute Resources&#8217; chapter:</p>
<blockquote><p>Amazon EC2 uses a variety of measures to provide each instance with a consistent and predictable amount of CPU capacity. In order to make it easy for developers to compare CPU capacity between different instance types, we have defined an Amazon EC2 Compute Unit. The amount of CPU that is allocated to a particular instance is expressed in terms of these EC2 Compute Units. We use several benchmarks and tests to manage the consistency and predictability of the performance of an EC2 Compute Unit. One EC2 Compute Unit provides the equivalent CPU capacity of a 1.0-1.2 GHz 2007 Opteron or 2007 Xeon processor.</p></blockquote>
<p>In conclusion, two identical instance types of Amazon Cloud have the same number of EC2 Compute Units but because a EC2 Compute Unit is equivalent to a CPU capacity between 1.0Ghz and 1.2Ghz, the actual speed of the instance will be slightly different!<br />
<em>Mystery solved.</em> <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/07/17/differences-between-amazon-instances/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

