<?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>Saulo Silva&#039;s Blog &#187; How-Tos</title>
	<atom:link href="http://saulosilva.com/category/howtos/feed/" rel="self" type="application/rss+xml" />
	<link>http://saulosilva.com</link>
	<description>On technology, programming, et cetera.</description>
	<lastBuildDate>Wed, 23 Nov 2011 22:43:17 +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>How to load a properties file from a servlet</title>
		<link>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/</link>
		<comments>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 14:48:30 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=433</guid>
		<description><![CDATA[I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to search on the web for a portable solution, but I couldn&#8217;t find anything. Here is the trick: use ServletContext.getRealPath(String). For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-462" title="config.properties" src="http://saulosilva.com/wp-content/uploads/2009/07/config.properties.png" alt="config.properties" /></p>
<p>I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to <a href="http://www.google.ca/search?q=load+properties+file+from+servlet">search on the web</a> for a portable solution, but I couldn&#8217;t find anything.</p>
<p>Here is the trick: use <code><a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)">ServletContext.getRealPath(String)</a></code>. For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:</p>
<pre class="brush: java; title: ; notranslate">
public void init(ServletConfig config) throws ServletException {
	String pathToPropertiesFile =
		config.getServletContext().getRealPath(&quot;&quot;)
		+ &quot;/WEB-INF/config.properties&quot;;
	Properties properties = new Properties();
	properties.load(new FileInputStream(pathToPropertiesFile));
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Applying the Chinese Remainder Theorem</title>
		<link>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/</link>
		<comments>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 13:17:59 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=1</guid>
		<description><![CDATA[In public-key Cryptography, especially with the RSA algorithm, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows x a1 mod m1 x a3 mod m2 x ak mod mk , where m1, m2, &#8230;, mk are coprime, i.e. gcd(m1, m2, &#8230;, mk) = 1. How can we [...]]]></description>
			<content:encoded><![CDATA[<p>In public-key Cryptography, especially with the <a href="http://en.wikipedia.org/wiki/RSA">RSA algorithm</a>, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows</p>
<p>x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>1</sub> mod m<sub>1</sub><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>3</sub> mod m<sub>2</sub><br />
<img class="size-full wp-image-106 noborder alignnone" title="Vertical Ellipsis" src="http://saulosilva.com/wp-content/uploads/2008/08/vertical_ellipsis.png" alt="" width="5" height="20" /><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>k</sub> mod m<sub>k</sub> ,</p>
<p>where m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub> are coprime, i.e. <acronym title="Greatest common divisor">gcd</acronym>(m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub>) = 1.   How can we solve for x? The solution is quite straight forward, but could involve a   fair amount of calculations. I find that breaking down the method into smaller steps   makes it easier to find and fix mistakes. By the Chinese   Remainder Theorem, the solution to that system of equations is</p>
<p style="text-align: center;">x =   (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + &#8230; + a<sub>k</sub>M<sub>k</sub>y<sub>k</sub>) mod M ,</p>
<p>where M<sub>i</sub> is the product of all   m&#8217;s except for m<sub>i</sub></p>
<p style="text-align: center;"><img class="size-full wp-image-107 noborder alignnone" title="How to compute M sub i" src="http://saulosilva.com/wp-content/uploads/2008/08/mi.png" alt="" width="77" height="54" />,</p>
<p>y<sub>i</sub> is the multiplicative inverse of M<sub>i</sub> modulo m<sub>i</sub></p>
<p style="text-align: center;">y<sub>i</sub> <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> M<sub>i</sub><sup>-1</sup> mod m<sub>i</sub> ,</p>
<p style="text-align: center;">and M = m<sub>1</sub> * m<sub>2</sub> * &#8230; * m<sub>k</sub> .</p>
<p>Let us try a numeric example. Here is a system of simultaneous congruences:</p>
<p style="text-align: center;">x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12 mod 25<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9 mod 26<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23 mod 27</p>
<p>We start by calculating M<sub>1</sub> and y<sub>1</sub>:</p>
<p style="text-align: center;">M<sub>1</sub> = m<sub>2</sub> * m<sub>3</sub> = 26 * 27 = 702</p>
<p style="text-align: center;">y<sub>1</sub> = M<sub>1</sub><sup>-1</sup> mod m<sub>1</sub> = 702<sup>-1</sup> mod 25 .</p>
<p>We apply the <a href="http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm">Extended Euclidean Algorithm</a> to find the multiplicative inverse of 702 relative to 25:</p>
<p>702 = 28 * 25 + 2  → 2 = 702 – 28 * 25<br />
25   = 12 * 2 + 1      → 1 = 25 – 12 * <span style="text-decoration: underline;">2</span><br />
= 25 – 12 * (702 – 28 * 25)<br />
= 337 * 25 – 12 * 702</p>
<p>Then y<sub>1</sub> = 702<sup>-1</sup> mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> -12 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 13.</p>
<p>The same calculations can be carried on to find M<sub>2</sub> = 675, y<sub>2</sub> = 25, M<sub>3</sub> = 650 and y<sub>3</sub> = 14. Now it is just a matter of plugging in the values into the equation:</p>
<p>x = (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + a<sub>3</sub>M<sub>3</sub>y<sub>3</sub>) mod  M<br />
= (12*702*13 + 9*675*25 + 23*650*14) mod 17550 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 470687 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 14387</p>
<p>To verify our answer we can plug that number back into the system:</p>
<p style="text-align: center;">470687 mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12<br />
470687 mod 26 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9<br />
470687 mod 27 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to get a c cedilla on Ubuntu</title>
		<link>http://saulosilva.com/2007/02/how-to-get-a-c-cedilla-on-ubuntu/</link>
		<comments>http://saulosilva.com/2007/02/how-to-get-a-c-cedilla-on-ubuntu/#comments</comments>
		<pubDate>Sat, 17 Feb 2007 17:43:32 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=30</guid>
		<description><![CDATA[I was getting really frustrated with the fact that I had to copy and paste the character ç whenever I had a conversation with someone from Brazil. I did a search around the Ubuntu forums to realize that I was not the only one having this problem. The thing is that on Windows, when you [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting really frustrated with the fact that I had to copy and paste the character ç whenever I had a conversation with someone from Brazil. I did a search around the Ubuntu forums to realize that I was not the only one having this problem. The thing is that on Windows, when you type single quote and c, you get a c cedilla (ç). On Ubuntu, you get a c acute (ć).</p>
<p>If you are in the same boat, here is how I solved my problem.</p>
<ol>
<li>Add &#8220;U.S. English International (with dead keys)&#8221; to your list of layouts (System &gt; Preferences &gt; Keyboard).</li>
<li>On the Layout Options tab, make sure the Alt key is a third level chooser.</li>
<li><kbd>Alt</kbd>+<kbd>,</kbd> gives the desired results.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2007/02/how-to-get-a-c-cedilla-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to get a directory listing using batch files</title>
		<link>http://saulosilva.com/2003/12/how-to-get-a-directory-listing-using-batch-files/</link>
		<comments>http://saulosilva.com/2003/12/how-to-get-a-directory-listing-using-batch-files/#comments</comments>
		<pubDate>Mon, 22 Dec 2003 18:48:32 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=79</guid>
		<description><![CDATA[I know there are programs that do the job much better but I like it the dirty way: batch files. It&#8217;s fast, no installation required and does what I want. Enough talk, here is the code: @dir %1 /w /b /o:gn &#62; "_listing.txt" Copy the code to a text file and change its extension to [...]]]></description>
			<content:encoded><![CDATA[<p>I know there are programs that do the job much better but I like it the dirty way: batch files.<br />
It&#8217;s fast, no installation required and does what I want. Enough talk, here is the code:</p>
<p><code>@dir %1 /w /b /o:gn &gt; "_listing.txt"</code></p>
<p>Copy the code to a text file and change its extension to .bat<br />
<strong>/b</strong> &#8211; bare format, remove this for detailed info<br />
<strong>/o:gn &gt; &#8220;_listing.txt&#8221;</strong> &#8211; sends the output to &#8220;_listing.txt&#8221;</p>
<p>For further customization, type <code>dir /?</code> on a command prompt.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2003/12/how-to-get-a-directory-listing-using-batch-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

