<?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>Nepherte (dot) be &#187; Programming</title>
	<atom:link href="http://www.nepherte.be/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nepherte.be</link>
	<description>About Nepherte, Mosiah and the person behind</description>
	<lastBuildDate>Sun, 30 May 2010 18:20:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Regular expression for Belgian phone numbers</title>
		<link>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/</link>
		<comments>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 22:02:15 +0000</pubDate>
		<dc:creator>Nepherte</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Belgian Phone Number]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Regular Expression]]></category>

		<guid isPermaLink="false">http://www.nepherte.be/?p=608</guid>
		<description><![CDATA[I needed a regular expression for Belgian phone numbers for a program I am writing. At first sight regular expressions can be quite difficult for people to understand but luckily I have a course at University that studies the mathematics behind regular expressions and the languages they define. A nice but easy exercise. Belgian phone [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a regular expression for Belgian phone numbers for a program I am writing. At first sight regular expressions can be quite difficult for people to understand but luckily I have a course at University that studies the mathematics behind regular expressions and the languages they define. A nice but easy exercise.</p>
<p>Belgian phone numbers have the following format: 01 234 56 78 or 012 34 56 78. The first 3 digits, the zone number, always starts with a zero. The total numbers of zeros should always be 9. There exist multiple other notations like 012/34.56.78 and 012/34.56.78. The strenght of a regular expression is that it can describe all these notations in one line. This easy regular expression will do the necessary, though will also accept 10 digit numbers: [0](?:\\d{1,2})[/. ]?(?:\\d{2,3})[/. ]?(?:\\d{2})[/. ]?(?:\\d{2}). You could however use a logical or between two expressions to make sure only 9 digit phone numbers are accepted: [0](?:\\d{1})[/. ]?(?:\\d{3})[/. ]?(?:\\d{2})[/. ]?(?:\\d{2})|[0](?:\\d{2})[/. ]?(?:\\d{2})[/. ]?(?:\\d{2})[/. ]?(?:\\d{2})</p>
<p>Belgian cellular phones on the other hand have a slightly different format so another expression is necessary. The used format is 0412 34 56 67. The first 2 digits should always start with 04. The total number of digits should always be 10. Again multiple notations exist to write down cellular phone numbers. An expression that only accepts this format with the commonly used notations is: 0][4](?:\\d{2})[/. ]?(?:\\d{2,3})[/. ]?(?:\\d{2})[/. ]?(?:\\d{2})</p>
<p>A small program in java that uses this regular expressions could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Matcher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> InputValidator <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Check for valid Belgian phone numbers</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValidPhoneNumber<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[0](?:<span style="color: #000099; font-weight: bold;">\\</span>d{1,2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2,3})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})&quot;</span><span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Matcher m <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Check for valid Belgian cell phone numbers</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValidCellPhoneNumber<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[0][4](?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2,3})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Matcher m <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Lego Mindstorms</title>
		<link>http://www.nepherte.be/lego-mindstorms/</link>
		<comments>http://www.nepherte.be/lego-mindstorms/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 20:46:53 +0000</pubDate>
		<dc:creator>Nepherte</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lego]]></category>
		<category><![CDATA[mindstorms]]></category>
		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://www.nepherte.be/?p=151</guid>
		<description><![CDATA[The academic first semester&#8217;s just finished and the exams are coming closer and closer (January, that is). That basically means studying and, once more, studying. So absolutely no holiday mood for me. How weird it may sound, this also means I&#8217;ll probably post here more often because the time I spend the time to relax, [...]]]></description>
			<content:encoded><![CDATA[<p>The academic first semester&#8217;s just finished and the exams are coming closer and closer (January, that is). That basically means studying and, once more, studying. So absolutely no holiday mood for me. How weird it may sound, this also means I&#8217;ll probably post here more often because the time I spend the time to relax, goes to writing articles for this blog.</p>
<p>A lof of time during this first semester went to programming a Lego Mindstorms robot. I&#8221;ll explain the assignment briefly: There&#8217;s a board divided into square cells and filled with obstacles. Somewhere on that board is a small white circle, the so-called &#8220;parking spot&#8221;. The robot has to find its way to that parking spot and park itself on the center of this circle.</p>
<p>At the end of the semester, a final demonstration was held where all the teams could demonstrate their work. Several setups where constructed to test the capabilities of the robot. All of this was filmed and put on youtube. This was the fourth and most interesting path that had to be taken by the robot of my team (GREEN):</p>
<p><object width="425" height="344" data="http://www.youtube.com/v/yVit8xneFC0&amp;hl=nl&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/yVit8xneFC0&amp;hl=nl&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>You can find other movies of this project <a title="Lego Mindstorms Demonstations" href="http://www.youtube.com/profile?user=Yteven&amp;view=videos">here</a>.</p>
<p>The code is written in Java, using the <a href="http://lejos.sourceforge.net/" title="Lejos Runtime Environment">Lejos Runtime</a> replacing the default firmware of the Lego Mindstorms robot. The communication between robot and computer is through bluetooth. I&#8217;ll make the source code available for downloading as soon as this university course ends (june, 2009).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nepherte.be/lego-mindstorms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto: Send Mail Over SMTPS In Java</title>
		<link>http://www.nepherte.be/send-mail-over-smtps-in-java/</link>
		<comments>http://www.nepherte.be/send-mail-over-smtps-in-java/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 16:00:28 +0000</pubDate>
		<dc:creator>Nepherte</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[smtps]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nepherte.be/?p=72</guid>
		<description><![CDATA[Introduction This tutorial will show you, with an example, how to send mail in Java over SMTPS. Nowadays, providers try to use the extended version of smtp: smtps, where the s stands for the SSL protocol. SMTP, or Simple Mail Transfer Protocol, is the de facto standard for email transmissions across the internet where the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
This tutorial will show you, with an example, how to send mail in Java over SMTPS. Nowadays, providers try to use the extended version of smtp: smtps, where the s stands for the SSL protocol. SMTP, or Simple Mail Transfer Protocol, is the de facto standard for email transmissions across the internet where the SSL protocol, or Secure Socket Layer, provides an encrypted, secure connection.</p>
<p><strong>Example code</strong><br />
In the example given, we will use the smtps server of Google. To use this server, you will need a Gmail account. We will assume the fictive email &#8216;mail@gmail.com&#8217; as mail account with &#8216;password&#8217; as password. We will also use the <a href="http://java.sun.com/products/javamail/">JavaMail</a> library.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Message</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Multipart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.InternetAddress</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeBodyPart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMultipart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.mail.smtp.SMTPSSLTransport</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sendMail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> to, <span style="color: #003399;">String</span> from, <span style="color: #003399;">String</span> subject, Multipart content<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// create properties</span>
<span style="color: #003399;">Properties</span> props <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- authorization, i.e. account &amp;amp; password is required --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.auth&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- it is important you use the correct port. smtp uses 25, smtps 465 --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.port&quot;</span>, <span style="color: #0000ff;">&quot;465&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- put the smtps server host address here --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.host&quot;</span>, <span style="color: #0000ff;">&quot;smtp.gmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create session</span>
Session session <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getDefaultInstance</span><span style="color: #009900;">&#40;</span>props<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
session.<span style="color: #006633;">setDebug</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create content</span>
MimeMultipart msgContent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMultipart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;alternative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Text Mail</span>
MimeBodyPart html <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeBodyPart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- we will send plain text, &quot;text/html&quot; is possible as well --&gt;</span>
html.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span>content, <span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
html.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MIME-Version&quot;</span>, <span style="color: #0000ff;">&quot;1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
html.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;text/plain; charset=iso-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msgContent.<span style="color: #006633;">addBodyPart</span><span style="color: #009900;">&#40;</span>html<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
MimeMessage msg <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMessage<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// set sender and recipient</span>
msg.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">addRecipient</span><span style="color: #009900;">&#40;</span>Message.<span style="color: #006633;">RecipientType</span>.<span style="color: #006633;">TO</span>, <span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>to<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// transport the message</span>
<span style="color: #666666; font-style: italic;">// &lt; -- we will send the message over smtps --&gt;</span>
SMTPSSLTransport transport <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SMTPSSLTransport<span style="color: #009900;">&#41;</span>session.<span style="color: #006633;">getTransport</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;smtps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to server</span>
<span style="color: #666666; font-style: italic;">// &lt; -- fill in gmail email address and password --&gt;</span>
transport.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;smtp.gmail.com&quot;</span>, <span style="color: #0000ff;">&quot;mail@gmail.com&quot;</span>, <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// send the message</span>
transport.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg, msg.<span style="color: #006633;">getAllRecipients</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// close the connection</span>
transport.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nepherte.be/send-mail-over-smtps-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
