<?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>Dev Corner &#187; Software Development</title>
	<atom:link href="http://devcorner.georgievi.net/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://devcorner.georgievi.net</link>
	<description>Software Developer's Notepad</description>
	<lastBuildDate>Fri, 12 Aug 2011 20:03:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Data Expressions or Backus-Naur Form (BNF)</title>
		<link>http://devcorner.georgievi.net/pages/programming/data-expressions-bnf</link>
		<comments>http://devcorner.georgievi.net/pages/programming/data-expressions-bnf#comments</comments>
		<pubDate>Wed, 02 Dec 2009 13:20:59 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=328</guid>
		<description><![CDATA[Data expressions can be used to describe structure of data.
Example: Data Expression with plus as concatenator

booking request = guest data + period + room type

guest data = guest name + address + paymethod
           + [passport number]

passport number = letter + {digit}*8

room state = {free &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Data expressions can be used to describe structure of data.<span id="more-328"></span></p>
<p><strong>Example: Data Expression with plus as concatenator</strong></p>
<pre>
booking request = guest data + period + room type

guest data = guest name + address + paymethod
           + [passport number]

passport number = letter + {digit}*8

room state = {free | booked | occupied | repair}

account data = transfer + {account record}* + done
</pre>
<p><strong>Example: Data Expression with implicit concatenation</strong></p>
<pre>
guestData = guestName, address, paymethod
         [, passportNumber]

if_statement = 'if' condition 'Then' statement
              ['Else:' statement 'End If']
</pre>
<ul>
<li>+    Shows the sequence of data. What comes after what.</li>
<li>[ ]  Shows that something is optional. <br />
                [optional-expression]</li>
<li>{ }* Shows that something is repeated a number of times.<br />
                {expression}* <br />
                {expression}*8 <br />
                {expression}*(0:8) <br />
                {expression}*(4:*)</li>
<li>{ | | } Shows a choice between several possibilities.</li>
<li>B = C Shows that the composite data structure B is composed as shown by C.</li>
<li>&#8216;free&#8217;   Shows a literal value.</li>
<li>If we want a comma to separate the data parts, we<br />
show a comma in the formula.</li>
</ul>
<p>Software Requirements &#8211; Styles and Techniques</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/data-expressions-bnf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decode UTF-8 Encoded String in PHP (utf8_decode)</title>
		<link>http://devcorner.georgievi.net/pages/programming/php/utf8-decode-php</link>
		<comments>http://devcorner.georgievi.net/pages/programming/php/utf8-decode-php#comments</comments>
		<pubDate>Sun, 01 Nov 2009 09:31:55 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php howto]]></category>
		<category><![CDATA[php recipe]]></category>
		<category><![CDATA[php tip]]></category>
		<category><![CDATA[php utf]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=191</guid>
		<description><![CDATA[Problem: You have a string encoded in UTF-8 and you need to convert it to two byte UTF encoded string. For example, you might want to display convert the string to CP1251 (Windows-1251) encoding using standard encoding tables.
Solution:
Here is a simple procedure in PHP that can convert UTF-8 string to corresponding full UTF representation. The [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: You have a string encoded in UTF-8 and you need to convert it to two byte UTF encoded string. For example, you might want to display convert the string to CP1251 (Windows-1251) encoding using standard encoding tables.<span id="more-191"></span></p>
<p><strong>Solution:</strong><br />
Here is a simple procedure in PHP that can convert UTF-8 string to corresponding full UTF representation. The function was constructed to solve specific problem and is not complete. It supports only 1, 2 and 3 octet (byte) UTF-8 entries. It also doesn&#8217;t support BOM.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Decode UTF8 without BOM string to UTF string.
 * 
 * @param $string string Original UTF-8 encoded string we need to decode.
 * @param $strip_zeroes Remove trailing zeroes from converted UTF entry points. Default is false.
 * @return string UTF representation of the original UTF8 encoded string.
 *
 * @todo Add support for four byte characters.
 * @author Ivan Georgiev
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$strip_zeroes</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$len</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$code1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0x80</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0xE0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Two byte</span>
			<span style="color: #000088;">$code1</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x1F</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$code1</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$code2</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x3F</span> <span style="color: #339933;">&amp;</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$res_code1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$code1</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res_code1</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$strip_zeroes</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res_code1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #000088;">$code2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0xF0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Three byte</span>
			<span style="color: #000088;">$code1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$code1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// No need to mask</span>
			<span style="color: #000088;">$code2</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x3F</span> <span style="color: #339933;">&amp;</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$code3</span> <span style="color: #339933;">=</span> <span style="color: #208080;">0x3F</span> <span style="color: #339933;">&amp;</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$res_code1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code2</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$res_code1</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$strip_zeroes</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res_code1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code2</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #000088;">$code3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>See also: <a href="input-file-stream" title="PHP Class for Sequential (Stream) Input from a File">Generic File Input Stream in PHP with UTF-8 Support</a><br />
Back to: <a href="../../../category/programming/php">PHP Tips and Recipes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/php/utf8-decode-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Hexadecimal String to Binary (hex2bin) PHP Function</title>
		<link>http://devcorner.georgievi.net/pages/programming/php/hex2bin-php</link>
		<comments>http://devcorner.georgievi.net/pages/programming/php/hex2bin-php#comments</comments>
		<pubDate>Sat, 31 Oct 2009 21:18:36 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php howto]]></category>
		<category><![CDATA[php recipe]]></category>
		<category><![CDATA[php tip]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=183</guid>
		<description><![CDATA[PHP implements a bin2hex function that converts given binary string to hexadecimal string. Sometimes you need to solve the reverse task. You are given hexadecimal string and you need a PHP function that converts it to a binary string.
The following PHP function converts a hexadecimal string to a binary string. The function is byte-based which [...]]]></description>
			<content:encoded><![CDATA[<p>PHP implements a bin2hex function that converts given binary string to hexadecimal string. Sometimes you need to solve the reverse task. You are given hexadecimal string and you need a PHP function that converts it to a binary string.<span id="more-183"></span></p>
<p>The following PHP function converts a hexadecimal string to a binary string. The function is byte-based which means that it interprets consecutive pairs of hexadecimal digits and converts them to binary characters using the standard PHP function chr(). White-spaces are skipped.</p>
<p>A good extension point would be to implement word-based function that works in Big-Endian and Little-Endian modes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEX2BIN_WS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> hex2bin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hex_string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hex_string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span>HEX2BIN_WS<span style="color: #339933;">,</span> <span style="color: #000088;">$hex_string</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$pos</span><span style="color: #339933;">++;</span>
	  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hexdec</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hex_string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pos</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pos</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
	    <span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	  <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Back to: <a href="../../../category/programming/php">PHP Tips and Recipes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/php/hex2bin-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic File Input Stream in PHP with UTF-8 Support</title>
		<link>http://devcorner.georgievi.net/pages/programming/php/input-file-stream</link>
		<comments>http://devcorner.georgievi.net/pages/programming/php/input-file-stream#comments</comments>
		<pubDate>Sat, 31 Oct 2009 21:09:22 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php class]]></category>
		<category><![CDATA[php recpie]]></category>
		<category><![CDATA[php utf]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=181</guid>
		<description><![CDATA[Input stream are useful as they encapsulate concrete implementation of a data source. You can change the data source without changing the application code. For example, you application reads data from a file. One day your boss decides that you need to retrieve information from a server located 1000 miles away. You just implement another [...]]]></description>
			<content:encoded><![CDATA[<p>Input stream are useful as they encapsulate concrete implementation of a data source. You can change the data source without changing the application code. For example, you application reads data from a file. One day your boss decides that you need to retrieve information from a server located 1000 miles away. You just implement another class that implements the same input stream interface. The new class retrieves data from network instead of a local file.<span id="more-181"></span> That&#8217;s it. No more changes are required to your code.</p>
<p><strong>Solution:</strong></p>
<p>The following class implements simple Input Stream functionality in PHP. It provides a handy function for retrieving complete UTF-8 chars. At this time it supports only 1, 2 or 3 &#8211; octet (byte) characters.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FileInputStream <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$fn</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file_name</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fh</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchUtf8Char<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$code1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0x80</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Single byte</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0xE0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Two byte</span>
			<span style="color: #000088;">$ch</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchByte</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: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code1</span> <span style="color: #339933;">&lt;</span> <span style="color: #208080;">0xF0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Tree byte</span>
			<span style="color: #000088;">$ch</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchByte</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: #b1b100;">return</span> <span style="color: #000088;">$ch</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasMore<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fh</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
		       <span style="color: #009900;">&#40;</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fh</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>I kept the functionality of the Input File Stream class to the bare minimum. I haven&#8217;t implemented any features that were not necessary for the solving the particular problem the Input Stream was designed for. You can implement methods that solve your problems. For example, you can implement a readLine method.</p>
<p>Useful concrete Input Stream could be a StringInputStream that implements same stream operations as File Input Stream, but for sequential read from string.</p>
<p>Programming patterns require that you create a interface class, for example InputStream. Concrete classes should implement the InputStream interface. PHP allows for replacing types without checking inheritance. Because of performance considerations I decided not to create an abstract interface.</p>
<p>See Also: <a href="utf8-decode-php" title="PHP function to encode UTF8 strings">utf8_decode: Decode UTF-8 Encoded String in PHP</a><br />
Back to: <strong><a href="../../../category/programming/php">PHP Tips and Recipes</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/php/input-file-stream/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Join (concatenate) strings in JavaScript</title>
		<link>http://devcorner.georgievi.net/pages/programming/javascript/join-concatenate-strings-in-javascript</link>
		<comments>http://devcorner.georgievi.net/pages/programming/javascript/join-concatenate-strings-in-javascript#comments</comments>
		<pubDate>Wed, 07 Oct 2009 15:54:35 +0000</pubDate>
		<dc:creator>bateto</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=87</guid>
		<description><![CDATA[Problem
How to join together two strings and how to make one long string from numerous pieces?

Solution
For the purpose of a single statement, use the plus (+) operator to concatenate multiple strings.

var longString = &#34;One piece &#34; + &#34;plus one more &#34;;

To compose a string value in multiple statements, use the operator +=

var sentence = &#34;&#34;;
sentence [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong></p>
<p>How to join together two strings and how to make one long string from numerous pieces?<br />
<span id="more-87"></span><br />
<strong>Solution</strong></p>
<p>For the purpose of a single statement, use the plus (+) operator to concatenate multiple strings.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> longString <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;One piece &quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;plus one more &quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To compose a string value in multiple statements, use the operator +=</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sentence <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
sentence <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;word1 &quot;</span><span style="color: #339933;">;</span>
sentence <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;word2 &quot;</span><span style="color: #339933;">;</span>
sentence <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;word3&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can also use and the plus for this operation, but its less elegant:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sentence <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;word1 word2 word3&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/javascript/join-concatenate-strings-in-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the type of an element in JavaScript</title>
		<link>http://devcorner.georgievi.net/pages/programming/javascript/how-to-get-the-type-of-a-element</link>
		<comments>http://devcorner.georgievi.net/pages/programming/javascript/how-to-get-the-type-of-a-element#comments</comments>
		<pubDate>Sun, 04 Oct 2009 21:43:54 +0000</pubDate>
		<dc:creator>bateto</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=53</guid>
		<description><![CDATA[Sometimes we should find what the is the type of a given variable. In JavaScript there is a simple way to solve this problem - using the operator typeof. This operator returns as result of the check a string, which could have one of the listed values:

number
string
boolean
object
function
undefined

Example #1

typeof&#40;123&#41;;			//This will return number
typeof&#40;&#34;abd&#34;&#41;;			//This will return string
typeof&#40;false&#41;;			//This will [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we should find what the is the type of a given variable. In JavaScript there is a simple way to solve this problem <span id="more-53"></span>- using the operator <em>typeof</em>. This operator returns as result of the check a string, which could have one of the listed values:</p>
<ul>
<li>number</li>
<li>string</li>
<li>boolean</li>
<li>object</li>
<li>function</li>
<li>undefined</li>
</ul>
<p><strong>Example #1</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//This will return number</span>
<span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;abd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//This will return string</span>
<span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//This will return boolean</span>
&nbsp;
&nbsp;
<span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
<span style="color: #006600; font-style: italic;">//This will return string - no matter what the type of var is</span></pre></div></div>

<p>Sometimes it is possible that IE thinks that a function is actually an object.</p>
<p><strong>Example #2</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			
<span style="color: #006600; font-style: italic;">//The possible result for this operation is object, instead of function</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/javascript/how-to-get-the-type-of-a-element/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if variable is a number in PHP</title>
		<link>http://devcorner.georgievi.net/pages/programming/php/how-to-check-the-type-of-variable</link>
		<comments>http://devcorner.georgievi.net/pages/programming/php/how-to-check-the-type-of-variable#comments</comments>
		<pubDate>Sun, 04 Oct 2009 21:08:51 +0000</pubDate>
		<dc:creator>bateto</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=31</guid>
		<description><![CDATA[It is useful to know the type of the variables, with which you are operating. But in PHP there are not declarations, in which we point out what the type of the variable to be. So if we say that we have a input form and we have to operate only with numbers, how do [...]]]></description>
			<content:encoded><![CDATA[<p>It is useful to know the type of the variables, with which you are operating. But in PHP there are not declarations, in which we point out what the type of the variable to be. <span id="more-31"></span>So if we say that we have a input form and we have to operate only with numbers, how do we know that the user inputs a number? He can actually enter everything, including strings, empty space and etc.</p>
<p>There are a bunch of functions, which see what actually the variable contains.</p>
<p><em>bool</em> <strong>is_numeric</strong>($<em>var</em>) &#8211; this function checks if var is a number or a numeric string. It returns <strong>TRUE</strong> if <em>var</em> is a numeric string or <strong>FALSE</strong> otherwise.</p>
<p><strong>Example #1</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">345</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;">// Returns true</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;456&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 		<span style="color: #666666; font-style: italic;">// Returns true	</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;adf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>             	<span style="color: #666666; font-style: italic;">// Returns false	</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;345dffds&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     	<span style="color: #666666; font-style: italic;">// Returns false</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><em>bool</em> <strong>is_int</strong>($<em>var</em>) &#8211; this function checks if var is a integer. It returns <strong>TRUE</strong> if <em>var</em> is a integer or <strong>FALSE</strong> otherwise.</p>
<p><strong>Example #2</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">345</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;">// Returns true</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">345.345</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;">// Returns false</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;456&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 		<span style="color: #666666; font-style: italic;">// Returns false	</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><em>bool</em> <strong>is_double</strong>($<em>var</em>) &#8211; this function checks if var is a double. It returns <strong>TRUE</strong> if <em>var</em> is a integer or <strong>FALSE</strong> otherwise.</p>
<p><strong>Example #3</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">345.345</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;">// Returns true</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">345</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #666666; font-style: italic;">// Returns false</span>
	<span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;456.68&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 		<span style="color: #666666; font-style: italic;">// Returns false	</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This three functions are enough to see if the variable is a number. There are also another functions for checking what the type of a variable is, such <strong>is_bool() </strong>, <strong>is_array()</strong> , <strong>is_string() </strong>, <strong>is_object()</strong> etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/php/how-to-check-the-type-of-variable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shuffle 2D Array Java Algorithm</title>
		<link>http://devcorner.georgievi.net/pages/programming/java/shuffle-2d-array-java-algorithm</link>
		<comments>http://devcorner.georgievi.net/pages/programming/java/shuffle-2d-array-java-algorithm#comments</comments>
		<pubDate>Tue, 31 Mar 2009 11:01:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java array]]></category>
		<category><![CDATA[java recipe]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=7</guid>
		<description><![CDATA[Problem
You are given a Java array. You need Java Code to shuffle array elements in random order.
Solution
To shuffle array elements, traverse the array and swap the current array element with another element, selected randomly.

/**
 * Shuffle array Java class
 *
 * @author: Ivan Georgiev
 */
public class ArrayShuffler
&#123;
	public static void shuffle&#40;int&#91;&#93; targetArray&#41;
	&#123;
		int targetIndex;
		int swapBuffer;
		int maxInd = [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong></p>
<p>You are given a Java array. You need Java Code to shuffle array elements in random order.<span id="more-7"></span></p>
<p><strong>Solution</strong></p>
<p>To shuffle array elements, traverse the array and swap the current array element with another element, selected randomly.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Shuffle array Java class
 *
 * @author: Ivan Georgiev
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ArrayShuffler
<span style="color: #009900;">&#123;</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;">void</span> shuffle<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> targetArray<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> targetIndex<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> swapBuffer<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> maxInd <span style="color: #339933;">=</span> targetArray.<span style="color: #006633;">length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> curIndex<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> curIndex <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> targetArray.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> curIndex<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			targetIndex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">Math</span>.<span style="color: #006633;">round</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> maxInd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			swapBuffer <span style="color: #339933;">=</span> targetArray<span style="color: #009900;">&#91;</span>curIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			targetArray<span style="color: #009900;">&#91;</span>curIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> targetArray<span style="color: #009900;">&#91;</span>targetIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			targetArray<span style="color: #009900;">&#91;</span>targetIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> swapBuffer<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Discussion</strong></p>
<p>The array is traversed position-by-position. For each position we swap the element into that position with randomly selected element from the array. The random selection is done using the <code>Math.random</code> method. By traversing all the array elements we ensure that it is &#8220;well&#8221; shuffled.</p>
<p>Usually we shuffle an array to produce a random selection of array elements. If the number of elements in an array is big the time necessary for shuffling the array would be significant. It would also be impossible or at least undesirable to load all the elements into memory. For that purpose it would be better to generate a list of array indexes to represent array elements.</p>
<p><strong>Sample client code</strong></p>
<p>Here is a simple Java application to demonstrate how the random array shuffler works.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ArrayShufflerTest
<span style="color: #009900;">&#123;</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;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Define and initialize array of integers 0, 1, ..., 99</span>
		<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>arr.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Display initial array</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initial array: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printArray<span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Invoke the shuffler method to shuffle the array.</span>
		ArrayShuffler.<span style="color: #006633;">shuffle</span><span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Display shuffled array</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Shuffled array: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		printArray<span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> printArray<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arr<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> el<span style="color: #339933;">:</span> arr<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>el <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</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>

]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/java/shuffle-2d-array-java-algorithm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello JavaScript!</title>
		<link>http://devcorner.georgievi.net/pages/programming/javascript/hello-javascript</link>
		<comments>http://devcorner.georgievi.net/pages/programming/javascript/hello-javascript#comments</comments>
		<pubDate>Tue, 31 Mar 2009 07:50:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dummy]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=3</guid>
		<description><![CDATA[How to implement the simplest JavaScript code ?  &#8211; the explorer to alert with &#8220;Hello JavaScript!&#8221;
For this purpose we use the function alert(), which opens up a box with a message. In our example it&#8217;s &#8220;Hello JavaScript!&#8221;, but it could be everything.

&#60;script type=&#34;text/javascript&#34;&#62;
	window.alert&#40;&#34;Hello JavaScript!&#34;&#41;;
&#60;/script&#62;

This function is very handy when there is a debugging process [...]]]></description>
			<content:encoded><![CDATA[<p>How to implement the simplest JavaScript code ? <span id="more-3"></span> &#8211; the explorer to alert with &#8220;Hello JavaScript!&#8221;</p>
<p>For this purpose we use the function <strong>alert()</strong>, which opens up a box with a message. In our example it&#8217;s &#8220;Hello JavaScript!&#8221;, but it could be everything.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	window.<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello JavaScript!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This function is very handy when there is a debugging process for a JavaScript. But be beware not to place it in a loop. Otherwise there would be a nasty alert for a lot of times, which could make you angry and you probably will have to press the &#8220;OK&#8221; button for a thousand times.</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/programming/javascript/hello-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

