<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>array &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/array/</link>
	<description>Feed of posts on WordPress.com tagged "array"</description>
	<pubDate>Fri, 27 Nov 2009 20:23:35 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[PLSQL Oracle Tabelle mit Bulk Collect in Array einlesen ]]></title>
<link>http://rhde.wordpress.com/2009/11/26/plsql-oracle-tabelle-mit-bulk-collect-in-array-einlesen/</link>
<pubDate>Thu, 26 Nov 2009 11:02:59 +0000</pubDate>
<dc:creator>rhde</dc:creator>
<guid>http://rhde.wordpress.com/2009/11/26/plsql-oracle-tabelle-mit-bulk-collect-in-array-einlesen/</guid>
<description><![CDATA[Mit PLSQL eine komplette Oracle Tabelle in ein Array einlesen: declare type t_emp is table of emp%ro]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Mit PLSQL eine komplette Oracle Tabelle in ein Array einlesen:</p>
<pre>
declare
  type t_emp is table of emp%rowtype;
  a_emp t_emp;
begin
  select * bulk collect into a_emp from emp;
  dbms_output.put_line('emp.count ' &#124;&#124; a_emp.count);
  for i in a_emp.first .. a_emp.last loop
    dbms_output.put_line('empno ' &#124;&#124; a_emp(i).empno);
  end loop;
end;
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[writeArrayNicely()]]></title>
<link>http://chimpy.wordpress.com/2009/11/25/witearraynicely/</link>
<pubDate>Wed, 25 Nov 2009 10:29:32 +0000</pubDate>
<dc:creator>Mr Chimp</dc:creator>
<guid>http://chimpy.wordpress.com/2009/11/25/witearraynicely/</guid>
<description><![CDATA[Well I just wrote this function and then realised it&#8217;s basically redundant. When you write out]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Well I just wrote this function and then realised it&#8217;s basically redundant. When you write out the contents of an array in PHP using var_dump() it writes it all out on one line. Wouldn&#8217;t it be great if it wrote it all out neatly, properly nested and everything? So I wrote a function that does that. Then I realised that if you view the source then var_dump() already does that. Damnit! I even made it handle arrays recursively!</p>
<pre class="brush: php;">
	function writeArrayNicely($array, $depth=1){
		echo 'array(' . sizeof($array) . ') {&#60;br&#62;';
		foreach($array as $key=&#62;$value){
			for ($x=0;$x&#60;$depth;$x++)
				echo '&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;';
			if (gettype($key) == 'string')
				echo '[&#34;' . $key . '&#34;] =&#62; ';
			else
				echo '[' . $key . '] =&#62; ';
			if (gettype($value) == 'array')
				writeArrayNicely($value, ($depth+1));
			else
				echo gettype($value) . ' (' .  sizeof($value) . ') &#34;' . $value . '&#34;';
			echo '&#60;br&#62;';
		}
		for ($x=1;$x&#60;$depth;$x++)
			echo '&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;';
		echo '}';
	}

	$test = array(
		&#34;string&#34;=&#62;&#34;this is a string&#34;,
		&#34;integer&#34;=&#62;7,
		&#34;float&#34;=&#62;4.9,
		6 =&#62; 42,
		&#34;array&#34;=&#62;array(
			&#34;string1&#34; =&#62; &#34;blah1&#34;,
			&#34;string2&#34; =&#62; &#34;blah2&#34;
		)
	);

writeArrayNicely($test);
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struktur Data. Array]]></title>
<link>http://ibumei.wordpress.com/2009/11/25/struktur-data-array/</link>
<pubDate>Wed, 25 Nov 2009 04:16:56 +0000</pubDate>
<dc:creator>ibumei</dc:creator>
<guid>http://ibumei.wordpress.com/2009/11/25/struktur-data-array/</guid>
<description><![CDATA[Array merupakan kumpulan data dimana setiap elemen memakai nama yang sama dan bertipe sama.  Pada ar]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Array merupakan kumpulan data dimana setiap elemen memakai nama yang sama dan bertipe sama.  Pada array, setiap elemen diakses dengan membedakan indeksnya.  Contoh Array :</p>
<p>Misal nya ada Variabel array A yang terbagi menjadi  5 bagian   yaitu  :      </p>
<p>     23      15         45        12        14                                      </p>
<p>  A[0]   A[1]    A[2]    A[3]    A[4]</p>
<p><!--more-->masing-masing nilai di setiap lokasi mempunyai identitas yang sama yaitu A dan nomor indeks yang ditulis di dalam tanda kurung siku &#8216;[..]&#8216;.  sehingga terlihat bahwa : A[0] terisi nilai 23 atau biasa ditulis A[0]=23, A[1]=15, A[2]=45, A[3]=12, A[4]=14.</p>
<p>Jenis Array</p>
<p>1. Array Dimensi satu</p>
<p>Array dimensi satu adalah suatu variabel yang terbagi atas beberapa baris atau beberapa kolom.  Banyaknya indeks yang menandakan alamat pada variabel array ini hanya satu saja, yaitu yang menandakan baris ke-  atau kolom ke-. </p>
<p>Deklarasi array :  &#60;type data&#62;   nama_variabel [ukuran]</p>
<p> dengan Type  menyatakan jenis elemen array (int, char, unsigned dan lain-lain)</p>
<p>                 Ukuran  menyatakan jumlah maksimal elemen array</p>
<p>Contoh :   int   A[10];      &#8211;&#62; berarti Varibel A terbagi menjadi 10 baris/kolom dengan type integer</p>
<p>Untuk menginputkan nilai, mengoperasikan dan menampilkan nilai pada variabel array, dapat dideklarasikan satu per satu atau menggunakan fungsi perulangan agar lebih simple dalam penulisan programnya.</p>
<p>Contoh Program :</p>
<p>#include&#60;conio.h&#62;</p>
<p>#include&#60;iostream.h&#62;</p>
<p>main()</p>
<p>{  int  A[10], i;</p>
<p>for(i=0;i&#60;=9;i++)</p>
<p>      A[i]=i+1;</p>
<p>for(i=0;i&#60;=9;i++)</p>
<p>     cout&#60;&#60;A[i]&#60;&#60;&#8221;     &#8220;;</p>
<p>getch();</p>
<p>}</p>
<p>2. Array Dimensi Dua</p>
<p>Array dimensi dua adalah variabel array yang terbagi berdasarkan baris dan kolom. Banyaknya indeks yang menandakan alamat pada array ini ada dua yaitu menunjuk  (baris, kolom) ke-</p>
<p>Deklarasi Array dimensi dua :   &#60;type&#62;   nama_variabel[ukuran_baris][ukuran_kolom]</p>
<p>dengan                  type    adalah type data pada array</p>
<p>                                 ukuran baris adalah banyaknya pembagian baris pada array</p>
<p>                                ukuran kolom adalah banyaknya pembagian kolom pada array</p>
<p>Contoh array dimensi dua adalah matrik (merupakan susunan angka yang ditulis berdasarkan baris dan kolom)</p>
<p>Program :</p>
<p>#include&#60;conio.h&#62;</p>
<p>#include&#60;iostream.h&#62;</p>
<p>main()</p>
<p>{  int  A[10][10], i,j ;</p>
<p>for(i=0;i&#60;=9;i++)</p>
<p>   { for(j=1;j&#60;=9;j++)</p>
<p>            cin&#62;&#62;A[i][j]; }</p>
<p>for(i=0;i&#60;=9;i++)</p>
<p>   {  {for(j=0;j&#60;=9;j++)</p>
<p>          cout&#60;&#60;A[i][j]&#60;&#60;&#8221;      &#8220;;</p>
<p>     } cout&#60;&#60;endl;  }</p>
<p>getch();</p>
<p>}</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Array]]></title>
<link>http://drupalcms.wordpress.com/2009/11/24/array/</link>
<pubDate>Tue, 24 Nov 2009 22:31:14 +0000</pubDate>
<dc:creator>drupalcms</dc:creator>
<guid>http://drupalcms.wordpress.com/2009/11/24/array/</guid>
<description><![CDATA[Array]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Array</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Get Directory path than added to imageList]]></title>
<link>http://myxjulius.wordpress.com/2009/11/24/get-directory-path-than-added-to-imagelist/</link>
<pubDate>Tue, 24 Nov 2009 04:14:19 +0000</pubDate>
<dc:creator>Xjulius</dc:creator>
<guid>http://myxjulius.wordpress.com/2009/11/24/get-directory-path-than-added-to-imagelist/</guid>
<description><![CDATA[Sourcecode for Getting Pictures to Images-ArrayList 'New Code mFolder = &quot;%systemroot%&quot; If ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Sourcecode </strong>for Getting Pictures to Images-ArrayList</p>
<pre class="brush: vb;">

'New Code
 mFolder = &#34;%systemroot%&#34;
 If (Not String.IsNullOrEmpty(mFolder)) Then
 txtImageDirectory.Text = mFolder
 Else
 Return
 End If

 mImageList = New ArrayList()

 Dim Dir As New DirectoryInfo(mFolder)
 Dim f As FileInfo

'loop
 For Each f In Dir.GetFiles(&#34;*.*&#34;)
   Select Case (f.Extension.ToUpper())
   Case &#34;.JPG&#34;
   mImageList.Add(f.FullName)
   Case &#34;.BMP&#34;
   mImageList.Add(f.FullName)
   Case &#34;.GIF&#34;
   mImageList.Add(f.FullName)
   Case Else
 End Select
 Next
'end loop

 mImagePosition = 0
 SetImages() 'Set Image form array to list []

' End of New code
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[concise associative arrays for iPhone - xilla at() hack]]></title>
<link>http://quantblog.wordpress.com/2009/11/23/concise-associative-arrays-for-iphone-xilla-at-hack/</link>
<pubDate>Mon, 23 Nov 2009 03:52:36 +0000</pubDate>
<dc:creator>quantblog</dc:creator>
<guid>http://quantblog.wordpress.com/2009/11/23/concise-associative-arrays-for-iphone-xilla-at-hack/</guid>
<description><![CDATA[Objective-C can be quite verbose, especially when handling nested data &#8211; there is no simple as]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Objective-C can be quite verbose, especially when handling nested data &#8211; there is no simple associative array indexing of the kind found in PHP, Ruby etc.</p>
<p style="padding-left:30px;">ObjC : verbose : <strong>id value = [map objectForKey:@"key"];</strong></p>
<p style="padding-left:30px;">Using atx functions : concise : <strong>id value = at(map, @&#8221;key&#8221;);</strong></p>
<p>This comes in very handy for deeply nested json data trees, where you might want to index a multidimensional array or nested tree &#8211; vis :</p>
<p style="padding-left:30px;"><strong>id pop = at(at(at(stats, @&#8221;USA&#8221;), @&#8221;NewYork&#8221;), @&#8221;popn&#8221;);</strong></p>
<p>Not quite as simple as<strong> pop = stats["USA"]["NewYork"]["popn"];</strong> but more readable than several objectForKey&#8217;s.  Note, I propagate the nulls up so if an item is not found at any level, it can be checked once at the top level without crashing the app.</p>
<p>The small suite of related functions can be found at google code here, under BSD licence &#8211; <a href="http://code.google.com/p/xathack/">http://code.google.com/p/xathack/</a></p>
<p>enjoy.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cigarettes harbor many pathogenic bacteria]]></title>
<link>http://beckyminx.wordpress.com/2009/11/21/cigarettes-harbor-many-pathogenic-bacteria/</link>
<pubDate>Sat, 21 Nov 2009 14:52:01 +0000</pubDate>
<dc:creator>beckyminx</dc:creator>
<guid>http://beckyminx.wordpress.com/2009/11/21/cigarettes-harbor-many-pathogenic-bacteria/</guid>
<description><![CDATA[The research team describes the study as the first to show that cigarettes themselves could be the d]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div style="margin-bottom:10px;border:1px solid #ccc;width:202px;height:142px;background-image:url('http://images.websnapr.com/?size=s&#38;url=http://www.sciencedaily.com/releases/2009/11/091119121300.htm');"></div>
<p>The research team describes the study as the first to show that cigarettes themselves could be the direct source of exposure to a wide array of potentially pathogenic microbes among smokers and other people exposed to secondhand smoke.</p>
<p>Source:<br /><a href='http://www.sciencedaily.com/releases/2009/11/091119121300.htm'>http://www.sciencedaily.com/releases/2009/11/091119121300.htm</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cigarettes harbor many pathogenic bacteria]]></title>
<link>http://diychica.wordpress.com/2009/11/21/cigarettes-harbor-many-pathogenic-bacteria/</link>
<pubDate>Sat, 21 Nov 2009 12:28:23 +0000</pubDate>
<dc:creator>diychica</dc:creator>
<guid>http://diychica.wordpress.com/2009/11/21/cigarettes-harbor-many-pathogenic-bacteria/</guid>
<description><![CDATA[The research team describes the study as the first to show that cigarettes themselves could be the d]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div style="margin-bottom:10px;border:1px solid #ccc;width:202px;height:142px;background-image:url('http://images.websnapr.com/?size=s&#38;url=http://www.sciencedaily.com/releases/2009/11/091119121300.htm');"></div>
<p>The research team describes the study as the first to show that cigarettes themselves could be the direct source of exposure to a wide array of potentially pathogenic microbes among smokers and other people exposed to secondhand smoke.</p>
<p>Source:<br /><a href='http://www.sciencedaily.com/releases/2009/11/091119121300.htm'>http://www.sciencedaily.com/releases/2009/11/091119121300.htm</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Array Based Stack to find a Palindrome!]]></title>
<link>http://skud15.wordpress.com/2009/11/20/java-array-based-stack-palindrome/</link>
<pubDate>Fri, 20 Nov 2009 00:12:44 +0000</pubDate>
<dc:creator>Oliver O&#39;Mahony</dc:creator>
<guid>http://skud15.wordpress.com/2009/11/20/java-array-based-stack-palindrome/</guid>
<description><![CDATA[How many buzz words can you fit in a title? Microsoft and other companies often request you to compl]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>How many buzz words can you fit in a title?</p>
<p>Microsoft and other companies often request you to complete some algorithms in their interviewing process. Today I completed an attempt at an ArrayBasedStack to be able to find a palindrome. Something I must admit I have not touched since early college! This is going to be the first of some interview questions I got. Plus it is about time I wrote another blog post.</p>
<p>Using the excellent: <a href="http://ww0.java4.datastructures.net/" target="_blank">Data Structures and Algorithms in Java</a> by G&#38;T to define my <a href="http://ww0.java4.datastructures.net/source/ch04/Java/Stack-Stack.html" target="_blank">stack</a> I created an <a href="http://ww0.java4.datastructures.net/source/ch04/Java/ArrayStack-ArrayStack.html" target="_blank">array based stack</a> similar to what they have posted. Each developer has their own style. I prefer using return size() == 0 rather than their (top &#60; 0), but that is my preference.</p>
<p>Just remember a few things</p>
<p><em>A <strong>palindrome</strong> is a word, phrase, <a title="Palindromic number" href="http://en.wikipedia.org/wiki/Palindromic_number">number</a> or other sequence of units that can be read the same way in either direction (the adjustment of punctuation and spaces between words is generally permitted) &#8211; from wiki</em></p>
<p>Trim whitespace and lowercase the characters.</p>
<p>Stacks work on last in, first out principle. What? Well this comes in handy for the algorithm. LIFO gives you a reverse effect.</p>
<p>So &#8211; here it is, the algorithm. Hope it will help you with your stack based palindromes.</p>
<pre><span style="color:#000000;">private boolean isPalindrome(String str) {</span></pre>
<pre style="text-align:justify;padding-left:30px;"><span style="color:#000000;"> Stack&#60;Character&#62; stack = new ArrayBasedStack</span>&#60;Character&#62;<span style="color:#000000;">(str.length());
 str = str.toLowerCase().trim();</span> <span style="color:#008000;">//format the data</span>
 while(stack.size()&#60;(str.length()/2)) {
 <span style="color:#008000;"> //When the stack is less than half the length
  //(even numbers great, odd numbers ignore the middle!</span>
<pre style="padding-left:30px;">stack.push(str.charAt(stack.size()));
<span style="color:#008000;">//push the character at the position indexed by the size of the stack</span></pre>
</pre>
<pre style="padding-left:30px;"> }</pre>
<pre style="padding-left:30px;"> while(stack.size()&#62;0) { <span style="color:#008000;">//lets go back</span>
</pre>
<pre style="padding-left:60px;">if(stack.top() == str.charAt(str.length() - stack.size())) {
<span style="color:#008000;">//again use the stack size
//to index the position, minus the length
//so this counts down every time something is popped from the stack.
//You are checking the top of the stack is equal to the character
//in 2nd half of the word. since characters go in first, the characters,
//abba would have b on top and a on the bottom when hitting this loop -
//the first two characters - they are the same as the last two. Get it now? </span>
<pre style="padding-left:30px;">stack.pop(); <span style="color:#008000;">//remove <strong>palindromic</strong> characters</span></pre>
</pre>
<pre style="padding-left:60px;">} else {</pre>
<pre style="padding-left:90px;">return false; <span style="color:#008000;">//it is not a palindrome -
//you don't want to keep going and be inefficient if it is wasting time!</span></pre>
<pre style="padding-left:60px;">}</pre>
<pre style="padding-left:30px;"> }</pre>
<pre style="padding-left:30px;"> return true; <span style="color:#008000;">// if it gets here there can only be on conclusion.</span></pre>
<p style="text-align:justify;">}</p>
<p>Hope this helps and you learn my thinking behind this. Good luck with the interviews.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Arrays, hurray!]]></title>
<link>http://ebalitski.wordpress.com/2009/11/17/arrays-hurray/</link>
<pubDate>Wed, 18 Nov 2009 03:24:57 +0000</pubDate>
<dc:creator>ebalitski</dc:creator>
<guid>http://ebalitski.wordpress.com/2009/11/17/arrays-hurray/</guid>
<description><![CDATA[Well it took about 6 hrs but I finally got my little javascript assignment to work.  What a gong sho]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Well it took about 6 hrs but I finally got my little javascript assignment to work.  What a gong show!  I ended up emailing the code to Courtney to look at because I couldn&#8217;t see the problem.  She located the issue and made a suggestion and &#8220;ta da!&#8221;, my script worked!  It&#8217;s great having clever friends!  It&#8217;s also good to know that some of this language is starting the sink in. </p>
<div class="mceTemp" style="text-align:center;"><a href="http://ebalitski.wordpress.com/files/2009/11/screen_cap1.png"><img class="aligncenter size-full wp-image-89" title="screen_cap" src="http://ebalitski.wordpress.com/files/2009/11/screen_cap1.png" alt="" width="500" height="116" /></a></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Mencari Jumlah Karakter Terbesar dalam Array]]></title>
<link>http://rendramm2.wordpress.com/2009/11/16/mencari-jumlah-karakter-terbesar-dalam-array/</link>
<pubDate>Mon, 16 Nov 2009 02:07:50 +0000</pubDate>
<dc:creator>Rendra Kurniawan</dc:creator>
<guid>http://rendramm2.wordpress.com/2009/11/16/mencari-jumlah-karakter-terbesar-dalam-array/</guid>
<description><![CDATA[Ehem,,, biar aku ndak lupa, aku mau catat di sini aja sekalian bagi &#8211; bagi pengetahuan, siapa ]]></description>
<content:encoded><![CDATA[Ehem,,, biar aku ndak lupa, aku mau catat di sini aja sekalian bagi &#8211; bagi pengetahuan, siapa ]]></content:encoded>
</item>
<item>
<title><![CDATA[PHP: foreach]]></title>
<link>http://spic.wordpress.com/2009/11/15/php-foreach/</link>
<pubDate>Sun, 15 Nov 2009 21:16:28 +0000</pubDate>
<dc:creator>sCp</dc:creator>
<guid>http://spic.wordpress.com/2009/11/15/php-foreach/</guid>
<description><![CDATA[Wenn man mit foreach() arbeitet, sollte man vorher prüfen ob das Array überhaupt einen Eintrag hat. ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Wenn man mit <a href="http://de.php.net/manual/de/control-structures.foreach.php">foreach()</a> arbeitet, sollte man vorher prüfen ob das Array überhaupt einen Eintrag hat. Das habe ich nun einfach mit der Funktion <a href="http://de.php.net/manual/de/function.count.php">count()</a> realisiert.</p>
<p><code>if(count($arr) &#62;= 1) {<br />
foreach ($arr as $value) {<br />
echo "Value: $value\n";<br />
}<br />
}</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Simple EllipseNetwork]]></title>
<link>http://clausneergaard.wordpress.com/2009/11/13/simple-ellipsenetwork/</link>
<pubDate>Fri, 13 Nov 2009 12:29:09 +0000</pubDate>
<dc:creator>Claus</dc:creator>
<guid>http://clausneergaard.wordpress.com/2009/11/13/simple-ellipsenetwork/</guid>
<description><![CDATA[Trying to work out the code of the diagram seen on the cover of Casey Reas&#8217; and Ben Fry&#8217;]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Trying to work out the code of the diagram seen on the cover of Casey Reas&#8217; and Ben Fry&#8217;s book &#8216;<a title="http://www.amazon.com/Processing-Programming-Handbook-Designers-Artists/dp/0262182629/ref=sr_1_1?ie=UTF8&#38;s=books&#38;qid=1258115561&#38;sr=8-1" href="http://www.amazon.com/Processing-Programming-Handbook-Designers-Artists/dp/0262182629/ref=sr_1_1?ie=UTF8&#38;s=books&#38;qid=1258115561&#38;sr=8-1" target="_blank">Processing &#8211; A Programming Handbook for Visual Designers and Artist</a>&#8216;. Being relatively new to the <a title="http://www.processing.org/" href="http://www.processing.org/" target="_blank">processing.org</a> language, this is something of a mouthful for me.</p>
<p>This idea was to try and work with arrays and functions, returning values and using the data within the arrays to continue the development of the script. The optimistic strategy goes as follows;</p>
<p>1. build the &#8217;setup&#8217; (write the layout of the script, involving randomly placed ellipses, and passing all these values in to the array, for later usage),<br />
2. connect specific network elements to each other by evaluating distance between each component,<br />
3. apply noise() to all components, to make them move around, still updating connections between them,<br />
(4. apply rules of movement &#8211; thus transforming them in to boids / agents?).</p>
<p><strong><br />
Step 1.</strong></p>
<p><a href="http://clausneergaard.wordpress.com/files/2009/11/v1_01_large.jpg"><img class="aligncenter size-full wp-image-732" title="v1_01_thumbnail" src="http://clausneergaard.wordpress.com/files/2009/11/v1_01_thumbnail.jpg" alt="v1_01_thumbnail" width="400" height="142" /></a><br />
code for step1:</p>
<pre style="background:#F2F2F2;">// Network diagram v1
// written 09-11-13, Claus Rytter Bruun de Neergaard
// clausneergaard.wordpress.com

// (comments removed due to limited column width)

// GLOBAL VARIABLES -----------------------
int canvas = 900;
int amount = 400;
int minPtSize = 10;
int maxPtSize = 100;      

int[] ptsX = new int[amount];
int[] ptsY = new int[amount];    

// SETUP + DRAW RANDOM ELLIPSES -----------
void setup() {
  size(canvas, canvas);
  smooth();
  background(255);
  noStroke();
  strokeWeight(0.5);
  fill(0, 170, 250, 40);
  noLoop();

  for (int i = 0; i &#60; amount; i++) {
    int x = rdmValue(0, canvas);
    int y = rdmValue(0, canvas);
    ptsX[i] = x;
    ptsY[i] = y;
  }  

  for (int i = 0; i &#60; amount; i++) {
    float r = random(minPtSize, maxPtSize);
    ellipse(ptsX[i], ptsY[i], r, r);
    stroke(0, 100);
    fill(255, 100);
    ellipse(ptsX[i], ptsY[i], 3, 3);
    noStroke();
    fill(0, 170, 250, 40);
  }
}

// DRAW (MAIN FUNCTION) -------------------
void draw() {
  save("export.tif");
}

// FUNCTION RANDOM VALUE ------------------
int rdmValue(float bottom, float top) {
  int f = int(random(bottom, top));
  return f;
}</pre>
<p><strong><br />
Step 2.</strong></p>
<p><a href="http://clausneergaard.wordpress.com/files/2009/11/v02_14_large.jpg"><img class="aligncenter size-full wp-image-745" title="v02_14_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_14_thumb.jpg" alt="v02_14_thumb" width="400" height="135" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_15_large.jpg"><img class="aligncenter size-full wp-image-747" title="v02_15_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_15_thumb.jpg" alt="v02_15_thumb" width="400" height="128" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_16_large.jpg"><img class="aligncenter size-full wp-image-749" title="v02_16_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_16_thumb.jpg" alt="v02_16_thumb" width="400" height="159" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_18_large.jpg"><img class="aligncenter size-full wp-image-751" title="v02_18_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_18_thumb.jpg" alt="v02_18_thumb" width="400" height="143" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_19_large.jpg"><img class="aligncenter size-full wp-image-753" title="v02_19_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_19_thumb.jpg" alt="v02_19_thumb" width="400" height="150" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_20_large.jpg"><img class="aligncenter size-full wp-image-755" title="v02_20_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_20_thumb.jpg" alt="v02_20_thumb" width="400" height="138" /></a><br />
<a href="http://clausneergaard.wordpress.com/files/2009/11/v02_21_large.jpg"><img class="aligncenter size-full wp-image-757" title="v02_21_thumb" src="http://clausneergaard.wordpress.com/files/2009/11/v02_21_thumb.jpg" alt="v02_21_thumb" width="400" height="145" /></a><br />
code for step 2:</p>
<pre style="background:#F2F2F2;">// Network diagram v2
// written 09-11-13, Claus Rytter Bruun de Neergaard
// clausneergaard.wordpress.com

// (comments removed due to limited column width)

// GLOBAL VARIABLES --------------------------------------------
int canvasX = 1680;             // canvas size X
int canvasY = 1050;             // canvas size Y
int amount = 4000;              // amount of points on the screen
int minPtSize = 10;             // min size of points/ellipse's
int maxPtSize = 80;             // max size of points/ellipse's

int[] ptsX = new int[amount];   // declare + create new array
int[] ptsY = new int[amount];   // declare + create new array

// SETUP + DRAW RANDOM ELLIPSES --------------------------------
void setup() {
  size(canvasX, canvasY);
  smooth();
  background(0);
  noStroke();
  strokeWeight(0.8);
  fill(0, 170, 250, 40);
  noLoop();

  for (int i = 0; i &#60; amount; i++) {
    int x = rdmValue(10, canvasX-20);
    int y = rdmValue(10, canvasY-20);
    ptsX[i] = x;
    ptsY[i] = y;
  }  

  for (int i = 0; i &#60; amount; i++) {
    float r = random(minPtSize, maxPtSize);
    ellipse(ptsX[i], ptsY[i], r, r);
    stroke(255, 100);
    fill(0);
    ellipse(ptsX[i], ptsY[i], 2, 2);
    noStroke();
    fill(0, 170, 250, 40);
  }
}

// DRAW --------------------------------------------------------
void draw() {
  stroke(255, 40);
  strokeWeight(0.5);  

  for (int i = 0; i &#60; amount - 1; i++) {
    for (int j = i; j &#60; amount; j++) {
      if (dist(ptsX[j], ptsY[j], ptsX[i], ptsY[i]) &#60; 100) {
        line(ptsX[j], ptsY[j], ptsX[i], ptsY[i]);
      }
    }
  }
}

// FUNCTION RANDOM VALUE ---------------------------------------
int rdmValue(float bottom, float top) {
  int f = int(random(bottom, top));
  return f;
}</pre>
<p><strong><br />
Step 3.</strong></p>
<p><span style='text-align:center; display: block;'><br />
<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.vimeo.com/moogaloop.swf?clip_id=7609428&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA"><param name="quality" value="best" /><param name="allowfullscreen" value="true" /><param name="scale" value="showAll" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=7609428&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA" /></object><br />
</span></p>
<p>Okay, so the code for the basic noise()-movement has been created, and acts as shown in the video. Now, the idea is to combine previous network system with the actual movement, while the rules of connection still apply, even though the system is dynamic. The code might need to be restructured to work properly. Still, so far so good.</p>
<pre style="background:#F2F2F2;">// 'fly'-boids (noise with array test)
// written 09-11-14, Claus Rytter Bruun de Neergaard

int boids = 200;                       // number of boids
int canvasX = 800;                     // canvas size x-direction
int canvasY = 600;                     // canvas size y-direction
float inc = 0.003;                     // move increasement every loop
float nX, nY;

float[] ptsX = new float[boids];       // declare + create array X
float[] ptsY = new float[boids];       // decalre + create array Y

void setup() {
  size(canvasX, canvasY);
  smooth();
  stroke(0, 170, 250);
  strokeWeight(3);
  background(255);
  for (int i = 0; i &#60; boids; i++) {
    ptsX[i] = random(0, canvasX);      // write pts to array X
    ptsY[i] = random(0, canvasY);      // write pts to array Y
  }
}

void draw() {
  background(0);
  for (int i = 0; i &#60; boids; i++) {
    nX = noise(ptsX[i]) * canvasX;     // add noise value to nX
    nY = noise(ptsY[i]) * canvasY;     // add noise value to nY
    point(nX, nY);                     // insert pt
    ptsX[i] = ptsX[i] + inc;           // increase X with inc
    ptsY[i] = ptsY[i] + inc;           // increase Y with inc
  }
}</pre>
<p>Connection written (if dist &#60; 50 then draw connecting line, meaning that each loop this if-statement is evaluated, so that once the boid reaches a distance less than 50, the line will occur, as well as the other way around, of course).</p>
<p><span style='text-align:center; display: block;'><br />
<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.vimeo.com/moogaloop.swf?clip_id=7639225&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA"><param name="quality" value="best" /><param name="allowfullscreen" value="true" /><param name="scale" value="showAll" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=7639225&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=01AAEA" /></object><br />
</span></p>
<p>Updated code:</p>
<pre style="background:#F2F2F2;">// network studies (perlin noise + array) v2
// written 09-11-15, Claus Rytter Bruun de Neergaard

// comments removed due to limited column width

int boids = 100;       // amount of boids
int canvasX = 700;     // canvas size x-direction
int canvasY = 700;     // canvas size y-direction
float inc = 0.002;     // move increasement every loop

float[] ptsX = new float[boids];
float[] ptsY = new float[boids];
float[] posX = new float[boids];
float[] posY = new float[boids]; 

void setup() {
  size(canvasX, canvasY);
  smooth();
  stroke(0, 170, 250);
  strokeWeight(1);
  background(255);
  ellipseMode(CENTER);

  for (int i = 0; i &#60; boids; i++) {
    ptsX[i] = random(0, canvasX);
    ptsY[i] = random(0, canvasY);
    posX[i] = ptsX[i];
    posY[i] = ptsY[i];
  }
}

void draw() {
  background(0);
  fill(255);
  stroke(255, 100);
  strokeWeight(1);  

  // Update the boids' positions
  for (int i = 0; i &#60; boids; i++) {
    posX[i] = noise(ptsX[i]) * canvasX;
    posY[i] = noise(ptsY[i]) * canvasY;
    ptsX[i] = ptsX[i] + inc;
    ptsY[i] = ptsY[i] + inc;
  }

  // draw the connecting lines
  for (int i = 0; i &#60; boids-1; i++) {
    for (int j = i; j &#60; boids; j++) {
      if (dist(posX[j], posY[j], posX[i], posY[i]) &#60; 50) {
        line(posX[j], posY[j], posX[i], posY[i]);
      }
    }
  }

  // draw the boids (draw them last, so they are not masked by lines)
  for (int i = 0; i &#60; boids; i++) {
    ellipse(posX[i], posY[i], 4, 4);
  }
}</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Multidimensional Array in Flash AS3]]></title>
<link>http://jamesgibbens.wordpress.com/2009/11/12/multidimensional-array/</link>
<pubDate>Thu, 12 Nov 2009 02:34:01 +0000</pubDate>
<dc:creator>jamesgibbens</dc:creator>
<guid>http://jamesgibbens.wordpress.com/2009/11/12/multidimensional-array/</guid>
<description><![CDATA[This is a quick multidimensional array. In this example I am just adding some buttons to the stage a]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is a quick multidimensional array. In this example I am just adding some buttons to the stage and then placing a number.</p>
<p style="padding-left:30px;">package {</p>
<p style="padding-left:60px;">import fl.controls.Button;<br />
import flash.display.*</p>
<p style="padding-left:60px;">public class multiArr extends MovieClip {</p>
<p style="padding-left:90px;">private var currNum:Number = 1;<br />
private var pieceArray:Array = new Array();<br />
private var i:Number =0;<br />
private var j:Number=0;</p>
<p style="padding-left:60px;">public function buildArr() {<br />
for (i = 0; i &#60; 5; i++) {<br />
for (j = 0; j &#60; 5; j++) {<br />
var ta:Button = new Button();<br />
pieceArray.push(ta);<br />
ta.width = 100;<br />
ta.height =100;<br />
addChild(ta);<br />
ta.x = 100*j;<br />
ta.y= 100*i;<br />
ta.label = currNum.toString();<br />
currNum++;<br />
}<br />
}<br />
}<br />
}<br />
}</p>
<p>All you need is a button in the library.</p>
<p>There is probably a better way to accomplish this but this is how I do it. If you have a method you would like to share let me know &#8211; post it in a comment.</p>
<p>If anyone is interested I am going to post a revised version of this using XML.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Null returned from a method returning a collection or an array]]></title>
<link>http://javaantipatterns.wordpress.com/2009/11/11/null-returned-from-a-method-returning-a-collection-or-an-array/</link>
<pubDate>Wed, 11 Nov 2009 17:10:10 +0000</pubDate>
<dc:creator>Alex</dc:creator>
<guid>http://javaantipatterns.wordpress.com/2009/11/11/null-returned-from-a-method-returning-a-collection-or-an-array/</guid>
<description><![CDATA[Null should never be returned from a method returning a collection or an array. Instead return a emp]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Null should never be returned from a method returning a collection or an array.  Instead return a empty array (a static final empty array) or one of the empty collections (e.g. <code>Collections.EMPTY_LIST</code> assuming the client should not be modifying the collection).</p>
<p>(submitted by Rand McNeely)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cool Things You Didn't Know PHP Could Do: convert an array to an object]]></title>
<link>http://clarityamidstchaos.wordpress.com/2009/11/10/cool-things-you-didnt-know-php-could-do-convert-an-array-to-an-object/</link>
<pubDate>Tue, 10 Nov 2009 22:38:34 +0000</pubDate>
<dc:creator>mslade</dc:creator>
<guid>http://clarityamidstchaos.wordpress.com/2009/11/10/cool-things-you-didnt-know-php-could-do-convert-an-array-to-an-object/</guid>
<description><![CDATA[Ok, obviously you and I both knew that you can turn an array into an object.  You just do a nice and]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Ok, obviously you and I both knew that you can turn an array into an object.  You just do a nice and easy for loop around it:</p>
<pre>$obj = new stdClass;
foreach ($a as $key =&#62; $value) {
	$obj-&#62;key = $value;
}
</pre>
<p>Or maybe you&#8217;re sharper than me and already knew there was a much quicker way of doing this.  Congrats.  In my years of PHP development I never came across this, but evidently PHP allows you to cast an array to an object to accomplish the same thing:</p>
<pre>$a = array(
	'name' =&#62; 'Jimmy',
	'species' =&#62; 'Brown-headed Parrot',
	'temperament' =&#62; 'vicious but lovable',
	'angry' =&#62; 'usually'
);
print_r((object)$a);

// stdClass Object
// (
//     [name] =&#62; Jimmy
//     [species] =&#62; Brown-headed Parrot
//     [temperament] =&#62; vicious but lovable
//     [angry] =&#62; usually
// )
</pre>
<p>Not too shabby, right?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Random Walkers]]></title>
<link>http://draconiansolo.wordpress.com/2009/11/10/random-walkers/</link>
<pubDate>Tue, 10 Nov 2009 15:36:18 +0000</pubDate>
<dc:creator>fdevant</dc:creator>
<guid>http://draconiansolo.wordpress.com/2009/11/10/random-walkers/</guid>
<description><![CDATA[So, what&#8217;s Next? When you&#8217;re learning computer programming there is a big wall the day t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So, what&#8217;s Next?</p>
<p>When you&#8217;re learning computer programming there is a big wall the day that you get to Classes and objects, specifically when you start to need to work with basic data structures and with dynamic arrays of objects. In my case, i started with particle systems; but again&#8230; what sort of particles systems would be useful for me for motion graphics?</p>
<p>For starters i begun with a<a href="http://en.wikipedia.org/wiki/Random_walk"> random walker </a>exercise in the Processing <em>&#8220;Processing a programming handbook for visual designers and artists&#8221;</em> Book&#8230; and started thinking: hey, it&#8217;d be nice to have a particle system entirely made of this little thingies, wouldn&#8217;t it? so,<a href="http://www.openprocessing.org/visuals/?visualID=5916"> here it is</a>.</p>
<div class="wp-caption aligncenter" style="width: 410px"><img title="random walkers" src="http://farm4.static.flickr.com/3200/3016926929_060829d91b_o.jpg" alt="" width="400" height="538" /><p class="wp-caption-text">These were some of the first tries.</p></div>
<p>At that time, my way to manage dynamic arrays was a bit straight-forward&#8230; instead of using processing&#8217;s <em>ArrayLists</em>, I was using just a normal array of elements and the <em>append()</em> function&#8230; which with time proved not to be really fast.</p>
<p>Also i started noticing how you could work on anything that moves either in a cumulative or dynamic way, meaning doing a painting of sorts by never calling <em>background()</em> or doing an animation by completely redrawing every frame. This is also called Aggregate and instantaneous visualizations&#8230;</p>
<p>A bit more on that <a href="http://www.complexification.net/gallery/machines/interMomentary/index.php">here</a>, at Jared Tarbell&#8217;s <a href="http://www.complexification.net/">Complexification.net</a> site. Where you may start noticing that even using such a deterministic media as code, creative expression takes over, and the same tasks assigned to different artists end up with very different results.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Chasing tails]]></title>
<link>http://cherrytreelivesey.wordpress.com/2009/11/10/chasing-tails/</link>
<pubDate>Tue, 10 Nov 2009 09:39:31 +0000</pubDate>
<dc:creator>cherrytreelivesey</dc:creator>
<guid>http://cherrytreelivesey.wordpress.com/2009/11/10/chasing-tails/</guid>
<description><![CDATA[Yesterday morning awoke to being cold and the sun rising at 4.30am. Looked out the car window to see]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Yesterday morning awoke to being cold and the sun rising at 4.30am. Looked out the car window to see amazing cloud formations over the mountainside.</p>
<p>We decided to set up the solar panels.. which was about the time we realised we were one regulator short for our two solar arrays!</p>
<p>So being a gorgeous sunny day we decided to set up with only one and it worked a treat. We had to manually turn the panels to recieve maximum output but luckily we had time to do so.</p>
<p>We then moved some furniture in &#8211; just basics, wardrobes, tables, chairs.. It was starting to feel homelier <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Then we started chasing suppliers for quotes. So much to be done and so little time&#8230; So many recommendations.. and short drives &#8216;five or six k&#8217;s down the road&#8217; that never seemed to materialise!</p>
<p>We headed home after getting our new street number&#8230; woohoo.. now we know exactly how many kms to the end of our street from our driveway. Honestly there should be some owners guide to owning rural property!</p>
<p>A quick meal later and we were off to bed (in the car again).</p>
<p>&#160;</p>
<p>&#160;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Clearing the input buffer in C]]></title>
<link>http://codeaddicts.wordpress.com/2009/11/08/clearing-the-input-buffer-in-c/</link>
<pubDate>Sun, 08 Nov 2009 18:01:06 +0000</pubDate>
<dc:creator>guidj0s</dc:creator>
<guid>http://codeaddicts.wordpress.com/2009/11/08/clearing-the-input-buffer-in-c/</guid>
<description><![CDATA[Reading from the keyboard (stdin) in C might be tricky, for various reasons. One very common issue y]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Reading from the keyboard (stdin) in C might be tricky, for various reasons. One very common issue you might go through is that the input buffer might be dirty from stuff that remained there from a previous reading. To make things easier for me, I&#8217;ll call the input buffer &#8220;IB&#8221; from now on. Let&#8217;s start with some code:</p>
<pre>#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

int main()
{
char readinput1,readinput2;

	printf("\n\n\t Type a character to be stored into \"readinput1\": ");
	readinput1 = getchar();
	printf("\n\n\t Type a character to be stored into \"readinput2\": ");
	readinput2 = getchar();

	printf("\n\n\n\t You've typed: %c (readinput1) and %c (readinput2)", readinput1, readinput2);

	return 0;
}</pre>
<p>Ok, so what this code apparently does is ask the user to type in one character twice, storing each of them into a different variable of the appropriate type. In fact, though, when you run this code and test it, you&#8217;ll see that readinput2 ends up with the newline character (&#8216;\n&#8217;). That&#8217;s there because when the user presses the &#8220;enter&#8221; key (carriage return) to finalize the typing, two character codes are sent to the OS: &#8216;\r&#8217; (carriage return) and &#8216;\n&#8217; (&#8220;enter&#8221; is the same key used whenever you wanna add a new line on text input).</p>
<p>What happens then is the \n stays in the IB, and then when we call getchar() again, it will do just what it&#8217;s supposed to, which is to take one character from the IB and return it. That&#8217;s how readinput2 gets messed up.</p>
<p>On a more interesting example:</p>
<pre>#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

int main()
{
char readinput1[10],readinput2[10];

	printf("\n\n\t Type 9 characters to be stored into \"readinput1\": ");
	fgets(readinput1, sizeof(readinput1), stdin);
	printf("\n\n\t Type 9 characters to be stored into \"readinput2\": ");
	fgets(readinput2, sizeof(readinput2), stdin);

	printf("\n\n\n\t You've typed: %s (readinput1) and %s (readinput2)", readinput1, readinput2);

	return 0;
}</pre>
<p>Notice this code isn&#8217;t vulnerable to buffer overflows on readinput1 and readinput2, because we&#8217;ve specified we want to read up to and no more than sizeof(readinput1) and sizeof(readinput2) into each one, but here&#8217;s how we&#8217;re gonna do this: run the code, then type in &#8220;12345678901234567&#8243; when it asks for the first input. Press ENTER and watch what happens. Here it is:</p>
<p>&#160;</p>
<p>&#160;</p>
<p><img src="http://img69.imageshack.us/img69/166/img2.jpg"></p>
<p>&#160;</p>
<p>So what happened there? Well, we threw 18 bytes into the IB, and it looks like this: 12345678901234567\n. The first call to fgets() takes 9 bytes from it, throws into readinput1 (indeces 0..8), then finalizes readinput1 with the null byte character (&#8221;). Then there&#8217;s a second call to fgets(), but at this point the IB looks like this: 01234567\n, and look, there&#8217;s a \n at the end of it. fgets() will stop reading whenever it reaches a newline character, and that&#8217;s why the user doesn&#8217;t even get a chance to type anything. readinput2 then ends up with 01234567\n, as shown in the screen shot.</p>
<p><strong>All right, so how do we solve this?</strong></p>
<p>Well, if you think about it, we have functions in C that will pop characters off the IB, and that&#8217;s really all we need. In the first example, as you could have guessed, you could add a getchar(); after the first reading so as to get rid of the \n that&#8217;s left in stdin, but that&#8217;s hardly an efficient solution, because, as we&#8217;ve just demonstrated, we may have any amount of bytes left there, depending on what the user types. But coming up with a solution is simple enough, all we need to do is keep popping characters off stdin until we reach a \n or a nullbyte <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So here&#8217;s my code for that:
<p></p>
<pre>void clearib()
{
    int c;
    for(; c != EOF &#38;&#38; c != '\n'; c = getc(stdin));
}</pre>
<p>
So all you need to do is, whenever you think there might be trash left out there, call this function before reading anything in. So our example could be fixed like this:
<p></p>
<pre>#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

void clearib()
{
    int c;
    for(; c != EOF &#38;&#38; c != '\n'; c = getc(stdin));
}

int main()
{
char readinput1[10],readinput2[10];

	printf("\n\n\t Type 10 characters to be stored into \"readinput1\": ");
	fgets(readinput1, sizeof(readinput1), stdin);
	clearib();

	printf("\n\n\t Type 10 characters to be stored into \"readinput2\": ");
	fgets(readinput2, sizeof(readinput2), stdin);
	clearib();

	printf("\n\n\n\t You've typed: %s (readinput1) and %s (readinput2)", readinput1, readinput2);

	return 0;
}</pre>
<p>
Sure enough, if you give the same input you did for readinput1 the first time, you&#8217;ll see it&#8217;s fixed. Here I typed in &#8220;12345678901234567&#8243; again, pressed enter, and got asked to type in the input for readinput2. I gave it &#8220;aaaaaaaaaa&#8221; (10 times &#8216;a&#8217;), and both strings contained what they were supposed to at the end. Notice how I called clearib() after the second fgets(), so <strong>even though there is one &#8216;a&#8217; left</strong> in stdin after this (because fgets() reads 9 bytes + terminates the string with the null byte), the buffer is cleared with the given function and all is well. Here&#8217;s the output:</p>
<p><img src="http://img200.imageshack.us/img200/9729/img3bc.jpg" alt="" /></p>
<p>And that&#8217;s that. If anyone has any ideas/thoughts/comments/better solutions, please speak up. Otherwhise, enjoy <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Program Java Untuk Konversi Angka ke Huruf (versi array)]]></title>
<link>http://reycca.wordpress.com/2009/11/08/program-untuk-konversi-angka-ke-huruf-dengan-java/</link>
<pubDate>Sun, 08 Nov 2009 12:15:43 +0000</pubDate>
<dc:creator>reycca</dc:creator>
<guid>http://reycca.wordpress.com/2009/11/08/program-untuk-konversi-angka-ke-huruf-dengan-java/</guid>
<description><![CDATA[Program ini akan merubah / mengkonversi angka yang dimasukkan  oleh user  ke dalam suatu huruf / kat]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Program ini akan merubah / mengkonversi angka yang dimasukkan  oleh user  ke dalam suatu huruf / kata  yang mewakili angka yang dimasukkan tersebut.</p>
<p><strong>Algoritma</strong></p>
<p>Masukkan nilai dan diinisialkan sebagai n.</p>
<p>Buat deklarasi array huruf dengan value dari { “ ” …. “ sebelas ” }.</p>
<p>Cek nilai n :</p>
<ol>
<li>Jika kurang dari 12, maka kembalikan value dengan memanggil variabel huruf dengan indeks array n dan langsung ke langkah 3.9. Jika tidak lanjut ke langkah 3.2. Hasilnya simpan di dalam satu variabel misalnya v.</li>
<li>Jika kurang dari 20, kembalikan value dengan n – 10 diimbuhi kata belas dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak &#60; 20, lanjut ke langkah 3.3.</li>
<li>Jika kurang dari 100, untuk mendapatkan kata pertama maka ulang ke mulai langkah 3 dengan n sejumlah n / 10. Lalu langsung ke c dengan kata selanjutnya ulang langkah 3 dengan n senilai n modulus 10 dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak kurang dari 100, lanjut ke langkah 3.4.</li>
<li>Jika kurang dari 200, kata pertama diberi “seratus” kata selanjutnya ulang langkah 3 dengan n senilai n – 100 dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak kurang dari 200, lanjut ke langkah 3.5.</li>
<li>Jika &#60; 1000 kembali ke langkah 3 dengan n senilai n / 100, dan valuenya diimbuhi kata “ratus” kemudian untuk kata selanjutnya masukkan nilai n dengan n modulus 100 dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak &#60; 1000 lanjut ke langkah 3.6.</li>
<li>Jika &#60; 2000 masukkan kata “seribu” dan kembali ke langkah 3 dengan n senilai n – 1000 dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak &#60; 2000 lanjut ke langkah 3.7.</li>
<li>Jika &#60; 1000000, kembali ke langkah 3 dengan n senilai n / 1000. Dan imbuhi hasilnya dengan kata “ribu”. Lalu untuk kata selanjutnya kembali ke langkah 3 dengan n senilai n modulus 1000 dan hasil ditambahkan ke value v dan langsung ke langkah 3.9. Jika tidak &#60; 1000000 lanjut ke langkah 3.8.</li>
<li>Kumpulkan value v.</li>
</ol>
<p>Cetak nilai v.</p>
<p>Selesai.</p>
<p><strong>Flowchart</strong></p>
<p><img class="alignnone size-full wp-image-39" title="flowchart_angka_huruf" src="http://reycca.wordpress.com/files/2009/11/flowchart_angka_huruf1.jpg" alt="flowchart_angka_huruf" width="353" height="552" /></p>
<p><strong>Code</strong></p>
<p>import javax.swing.JOptionPane;<br />
public class Number_Word{<br />
public String konversi (int angka){<br />
String [] bilangan ={&#8220;&#8221;,&#8221;satu&#8221;,&#8221;dua&#8221;,&#8221;tiga&#8221;,&#8221;empat&#8221;,&#8221;lima&#8221;,&#8221;enam&#8221;,&#8221;tujuh&#8221;,&#8221;delapan&#8221;,&#8221;sembilan&#8221;,&#8221;sepuluh&#8221;,&#8221;sebelas&#8221;};<br />
String temp=&#8221; &#8220;;<br />
if (angka&#60;12){<br />
temp = &#8221; &#8221; + bilangan[angka];<br />
}<br />
else if(angka&#60;20){<br />
temp = konversi(angka-10) + &#8221; belas&#8221;;<br />
}<br />
else if(angka&#60;100){<br />
temp = konversi(angka/10) + &#8221; puluh&#8221; + konversi(angka%10);<br />
}<br />
else if(angka&#60;200){<br />
temp = &#8220;seratus&#8221; + konversi(angka-100);<br />
}<br />
else if(angka&#60;1000){<br />
temp = konversi(angka/100) + &#8221; ratus&#8221; + konversi(angka%100);<br />
}<br />
else if(angka&#60;2000){<br />
temp = &#8220;seribu&#8221;+ konversi(angka-1000);<br />
}<br />
else if(angka&#60;1000000){<br />
temp = konversi(angka/1000) + &#8221; ribu&#8221; + konversi (angka%1000);<br />
}<br />
return temp;<br />
}<br />
public static void main (String args[]){<br />
do{<br />
try {<br />
Number_Word num = new Number_Word();<br />
int konvert = Integer.parseInt(JOptionPane.showInputDialog(&#8220;Masukkan Nilai&#8221;));</p>
<p>if (konvert &#60; 0 &#124;&#124; konvert &#62;999999) {<br />
JOptionPane.showMessageDialog(null,&#8221;Angka di luar range!!!&#8221;,&#8221;WARNING&#8221;,JOptionPane.ERROR_MESSAGE);<br />
}<br />
else {<br />
JOptionPane.showMessageDialog(null,&#8221;Hasil = \n &#8221; + konvert + &#8221; = &#8221; + num.konversi(konvert),&#8221;RESULT&#8221;,JOptionPane.INFORMATION_MESSAGE);<br />
}<br />
}<br />
catch(Exception e){<br />
JOptionPane.showMessageDialog(null,&#8221;ERROR&#8221;,&#8221;WARNING&#8221;,JOptionPane.ERROR_MESSAGE);<br />
}<br />
}<br />
while(JOptionPane.showConfirmDialog(null,&#8221;Ingin Mengulang??&#8221;,&#8221;OPTION&#8221;,JOptionPane.ERROR_MESSAGE)==JOptionPane.YES_NO_OPTION);<br />
}<br />
}</p>
<p>Keterangan :</p>
<p><img class="alignnone size-full wp-image-40" title="code_konversi_angka" src="http://reycca.wordpress.com/files/2009/11/code_konversi_angka.jpg" alt="code_konversi_angka" width="452" height="603" /></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Array manipulation in shell scripting]]></title>
<link>http://mohammednv.wordpress.com/2009/11/08/array-manipulation-in-shell-scripting/</link>
<pubDate>Sun, 08 Nov 2009 05:29:17 +0000</pubDate>
<dc:creator>Mohammed</dc:creator>
<guid>http://mohammednv.wordpress.com/2009/11/08/array-manipulation-in-shell-scripting/</guid>
<description><![CDATA[Best way to understand shell scripting is from examples. Find the example below to understand differ]]></description>
<content:encoded><![CDATA[Best way to understand shell scripting is from examples. Find the example below to understand differ]]></content:encoded>
</item>
<item>
<title><![CDATA[PHP: วีธีสร้างรูปจาก Array Pixel]]></title>
<link>http://adaydesign.wordpress.com/2009/11/02/php-%e0%b8%a7%e0%b8%b5%e0%b8%98%e0%b8%b5%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%a3%e0%b8%b9%e0%b8%9b%e0%b8%88%e0%b8%b2%e0%b8%81-array-pixel/</link>
<pubDate>Mon, 02 Nov 2009 17:14:05 +0000</pubDate>
<dc:creator>adaydesign</dc:creator>
<guid>http://adaydesign.wordpress.com/2009/11/02/php-%e0%b8%a7%e0%b8%b5%e0%b8%98%e0%b8%b5%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%a3%e0%b8%b9%e0%b8%9b%e0%b8%88%e0%b8%b2%e0%b8%81-array-pixel/</guid>
<description><![CDATA[ขอบ่นก่อนเลย วันนี้มันไฟดับที่ห้องทำงานเราห้องเดี๋ยว อ่ะทั้งตึก งานก้อไม่ได้ทำ แล้ว zomdo ของเราจะมี]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>ขอบ่นก่อนเลย <span style="color:#ff0000;"><span style="text-decoration:underline;">วันนี้มันไฟดับที่ห้องทำงานเราห้องเดี๋ยว</span> </span>อ่ะทั้งตึก งานก้อไม่ได้ทำ แล้ว zomdo ของเราจะมีความคืบหน้าได้ยังไง (ก้อไม่มีไง) งั้นผมจะมาพูดถึง<span style="color:#008000;"><span style="text-decoration:underline;">วิธ๊การการเซฟรูปลงเซิฟเวอร์</span></span>กันดีกว่านะครับ</p>
<p><span style="text-decoration:underline;"><strong><span style="color:#ff6600;">code php</span></strong></span></p>
<blockquote><p>&#60;?php<br />
$data = explode(&#8220;,&#8221;, $_POST['img']);<br />
$width = $_POST['width'];<br />
$height = $_POST['height'];<br />
$image=imagecreatetruecolor( $width ,$height );<br />
$background = imagecolorallocate( $image ,0 , 0 , 0 );<br />
//Copy pixels<br />
$i = 0;<br />
for($x=0; $x&#60;=$width; $x++){<br />
for($y=0; $y&#60;=$height; $y++){<br />
$int = hexdec($data[$i++]);<br />
$color = imagecolorallocate ($image, 0xFF &#38; ($int &#62;&#62; 0&#215;10), 0xFF &#38; ($int &#62;&#62; 0&#215;8), 0xFF &#38; $int);<br />
imagesetpixel ( $image , $x , $y , $color );<br />
}<br />
}<br />
//Output image and clean<br />
header( &#8220;Content-type: image/jpeg&#8221; );<br />
imagegif ($image, &#8220;temp.jpeg&#8221; );<br />
imagedestroy( $image );<br />
?&#62;</p></blockquote>
<p><span style="text-decoration:underline;"><span style="color:#ff6600;"><strong>คำอธิบายคับ</strong></span></span></p>
<p>จากค่าที่ไฟล์ Flash ส่งมาให้จะส่งมา 3 ค่า มีชื่อว่า</p>
<ul>
<li><span style="color:#0000ff;">img</span> เก็บค่าอาเรย์ เป็นแบบนี้ 220d04,28130a,271109,210c03,200801,210a02,210400,230200,&#8230; <span style="color:#0000ff;">เป็นเลขฐาน 16 นะ</span>จำนวนก้อเท่ากับขนาดของ width*height ครับ (เลขแต่ละค่าจะเป็นค่าสีในแต่ละพิกเซลของภาพนั้น นั่นเอง)</li>
<li><span style="color:#0000ff;">width</span> และ <span style="color:#0000ff;">height</span> ค่าความกว้าง และสูงของรูป คับ (ก้อรู้ๆ กันอยู่เนอะ)</li>
</ul>
<p>เนี่ยหละ พอ Flash ส่งมายัง PHP &#8230; PHP ก้อจะรับค่าตัวแปรนั้นด้วยคำสั่ง <span style="color:#ff0000;">$_POST['img']</span> (ก้อคำสั่งรับค่า argument แบบ post เดิมๆคับ) แต่จะใช่ตัวแปรเก็บแบบ อาเรย์เอาไว้ (ไม่รู้นะว่า PHP ประกาศอาเรย์ไม่มี [ ] ..ผมอยู่ในระดับกำลังศึกษาคับ PHP อ่ะ) ใช้คำสั่ง explode แยกค่าตัวหนังสือออกจากตัวที่เรา <span style="color:#993366;">explode (เราใช้ , แบ่งตัวหนังสือคับ)</span> <span style="text-decoration:underline;">มันจะเหมือน string.split ใน จาวาอ่ะ</span> ส่วนค่า width และ height ก้อเอาเก็บไว้ในตัวแปรเหมือนกัน</p>
<p>1. เราเริ่มตัวตัว สร้าง image เป็นภาพที่มีขนาดตามที่เราส่งค่ามานะครับ ด้วยคำสั่ง<br />
<span style="color:#0000ff;">$image=imagecreatetruecolor( $width ,$height );</span></p>
<p>2. การสร้างค่าสีในภาพ ด้วยคำสั่ง <span style="color:#0000ff;">imagecolorallocate( $image ,0 , 0 , 0 );</span></p>
<p>3. ต่อไปเป็นการ ก้อปปี้ ค่าพิกเซล ทุกพิเซลนะครับ (ระวังด้วย หากภาพนั้นใหญ่เกินไปจะทำให้โปรแกรมวนลูป &#8230;ช้ามากๆ) ทำด้วยการวนลูปครับ <span style="color:#0000ff;">for 2 อันซ้อนกัน</span> วน width height</p>
<p>4. implement ข้างในลูปที่ 2 จากข้อ 3<br />
<span style="color:#0000ff;">$int = hexdec($data[$i++]);</span> //อ่านค่าตัวหนังสือ string เนี่ยให้เป็นค่าเลขฐาน 16 เพราะตัวหนังสือนั้นที่ส่งมาเป็นเลขฐาน 16 อยู่แล้วนะ<br />
<span style="color:#0000ff;">$color = imagecolorallocate ($image, 0xFF &#38; ($int &#62;&#62; 0&#215;10), 0xFF &#38; ($int &#62;&#62; 0&#215;8), 0xFF &#38; $int);</span>//<span style="color:#993300;">imagecolorallocate การกำหนดสีให้กับภาพครับ</span> พารามิตเตอร์ได้แก่ <span style="color:#808080;">objectภาพ สีแดง สีเขียว สีน้ำเงิน</span> <span style="color:#ff0000;"><span style="text-decoration:underline;">ทำไมมันชิปบิต??? ก้อเพราะค่าที่ส่งมาเป็นเลขฐาน 16 ไง</span></span>&#8230; เช่น 0&#215;5d88f2 เนี่ยนะครับมันประกอบด้วยค่าสีแดงเขียวน้ำเงิน ดังนั้นเราต้องชิปบิตด้วยนะเพื่อเอาค่าสีนั้นมาใส่ในพารามิตเตอร์ให้ถูกต้อง &#8230; *0*<br />
<span style="color:#0000ff;">imagesetpixel ( $image , $x , $y , $color );</span> //ตามชื่อฟังก์ชั่นนั้นหละ เปลี่ยนสีรูปภาพตามตำแหน่ง x y ของรูปภาพ ที่กำหนด</p>
<p>5. เมื่อได้ภาพที่เราส่งมาจาก Flash ถึง PHP แล้วเราก้อจะเซฟลงเซิฟเวอร์นะบัดนี้<br />
<span style="color:#0000ff;">header( &#8220;Content-type: image/jpeg&#8221; );</span>//กำหนดเฮดเดอร์ครับ ให้เป็นชนิดรูปภาพ ตามนามสกุล <strong><span style="color:#808000;">jpg, jpeg, gif, png</span></strong> เป็นต้น<br />
<span style="color:#0000ff;">imagejpeg ($image, &#8220;temp.jpeg&#8221; );</span>//ใช้ฟังก์ชั่นให้ตรงกับ นามสกุลของรูปที่เราตั้งด้วยนะ <span style="color:#339966;">ฟังก์ชั่นนี้จะสร้างรูปเซฟลงไปที่เซิฟเวอร์</span>ครับ ใครอยากให้มันเซฟลงที่ โฟลเดอร์ไหนก้อปรับแต่งได้ในพารามิตเตอร์ตัวที่ 2 นะ<br />
<span style="color:#0000ff;">imagedestroy( $image );</span>//เคลียเมมโมรี่ครับ เพราะเราจะไม่ได้ใช้มันแล้ว เป็นประหยัดทรัพยากรเครื่องด้วยนะ</p>
<p><span style="color:#ff0000;">OK</span> หมดหละเป็นวิธีที่จะทำให้ท่านส่งรูปจากโปรแกรม Flash ไปยังเซิฟเวอร์ได้อย่างถูกต้องและรวดเร็ว (มั่ง) &#8230; ผมน่าจะอธิบายละเอียดนะ บางฟังก์ชั่นเป็นฟังก์ชั่นพื้นฐานครับ แต่สำหรับผมใหม่หมดทุกฟังก์ชั่นเลย เพราะพึ่งเรื่มศึกษาก้อเจองานหินซะแล้ว แต่ยังดียังมีโค้ดบนเน็ตอยู่ทำให้ศึกษาได้เร็วขี้น&#8230;</p>
<p>วันนี้ <span style="color:#008000;"><span style="text-decoration:underline;">zomdo player ไม่มีอะไรคืบหน้าเพราะไฟดับ ไม่ได้ทำงานเลยมาเขียนบล็อคนี้แทนคับ </span></span>เป็นอันว่าจบดีกว่า &#8230;<span style="color:#ff9900;">บะบายนะ</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Complex data boundaries]]></title>
<link>http://automationbeyond.wordpress.com/2009/11/02/complex-data-boundaries/</link>
<pubDate>Mon, 02 Nov 2009 13:00:57 +0000</pubDate>
<dc:creator>Albert Gareev</dc:creator>
<guid>http://automationbeyond.wordpress.com/2009/11/02/complex-data-boundaries/</guid>
<description><![CDATA[Root page: Heuristics exposed Parent Page: Number Boundary Testing Number Boundary Testing -  Comple]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Root page:<strong> </strong><a title="Permanent Link to Heuristics exposed" rel="bookmark" href="http://automationbeyond.wordpress.com/2009/10/05/heuristics-exposed/" target="_blank"><strong>Heuristics exposed</strong></a></p>
<p>Parent Page: Number Boundary Testing</p>
<p><strong>Number Boundary Testing - </strong> <strong>Complex data boundaries</strong><strong> </strong></p>
<p>Complex data types are created by composition of basic data types. Compositions of data of the same type are formed as arrays. Compositions of data of different type are formed as records.</p>
<p>There are internal (technical) rules defining how complex data type is managed. The rules are platform and programming language specific. </p>
<p><strong>Arrays</strong> </p>
<p>For the each dimension it has an array has minimal and maximal index boundaries defined as numbers. In some programming languages array index begins with 0, in some other – with 1. That leads to lots of confuses based on:</p>
<ul>
<li>First element should be accessed as Array(0),</li>
<li>Last element should be accessed as Array(Number_of_elements minus one) </li>
</ul>
<p>When reported to the screen indexes should be converted to 1-based notations. When an input is received it should be converted to 0-based index before addressing an array element. </p>
<p>To overcome that issue programmers use various approaches. For example, I have seen the code below on a few projects and in different companies:</p>
<p>Months = Array (“Zerourary”, “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)</p>
<p>“Zerourary” month is defined to occupy the first slot which has index 0. </p>
<p>String is an array consisting of characters. Some programming languages reserve 256 elements for a string type and store the actual number of characters at index 0 element. So the string may have up to 255 characters total. Depending on the programming language and compiler directives, when the actual number of characters is exceeded the string is silently truncated or an automatic exception is thrown. </p>
<p>Enumerations and lists define possible values that could be taken. In addition to index boundaries there are could be additional rules as in the following examples:</p>
<ul>
<li>an array must contain same or less number of items as in the enumeration (e.g. reporting week days in timesheet)</li>
<li>an array may not contain duplicated items from the enumeration (e.g. week days should not be duplicated in the example above)</li>
<li>some items may not be duplicated and some could be (e.g. one can have multiple brothers, sisters, sons, daughters but only one mother and father. To make it more complicated: some countries allow having multiple spouses) </li>
</ul>
<p><strong>Records</strong> </p>
<p>Records may represent closely related values, like year, month, and day for the date; or somewhat related only business-wise, for example last name and SIN. Often values stored in a record require transformation before output to the screen. These transformation rules are subject to change depending on regional settings and customization settings in the program. </p>
<p>A code operating records is oriented to the specific format. Code modules that pass in and back data records should either follow the same convention with a format or have bridging functions that perform the conversion. That applies both to back-end and front-end functions. </p>
<p><strong>Testing the boundaries</strong> </p>
<p><em>The approach</em> </p>
<p>While defects with these types of boundaries usually impose a high severity issues they can be relatively easy caught at very early stages of development. Implementation of automated Unit Tests is better investment here rather than implementation of automated functional tests.</p>
<p>However there are a few good functional test sets that allow quickly check the most common scenarios. Since complex data type boundaries are internal the main trick here is to make a code make a mistake. </p>
<p><strong><span style="text-decoration:underline;">Examples.</span></strong> </p>
<ul>
<li>Strings. Although GUI may not allow user to input strings exceeding the boundaries tester may try to make an application to produce a string of an inappropriate length. For example, if full name is constructed by an application as a combination like “last name comma first name” based on the manual input of first and last name.</li>
<li>Arrays and enumerations. Tries to make a code assigning a wrong value work very well with combo boxes (leave black, try multi-select, try typing value not presented in the list), list boxes (select none, select all), radio groups (select none) and combinations of those, for example, try input two mothers. </li>
</ul>
<p><em>The challenges</em> </p>
<p>The challenges in identifying and proving a defect are similar to the ones described in <a href="http://automationbeyond.wordpress.com/2009/10/07/data-container-boundaries/" target="_blank">data container boundary testing</a>.</p>
<p>1. No immediate visible reaction</p>
<p>An application might accept an (invalid) input and still be alright. Causing it to output the value or use the value in some operations might help revealing a problem.</p>
<p>Boundary testing for a single value might require a whole scenario: post transaction – run processing – verify account balance.</p>
<p> 2. Internal messing</p>
<p>A single value might “travel” a pretty complicated path while being passed from one function to another inside the program. If somewhere within that chain the value won’t fit the memory cell the end-result will be wrong despite of the application accepted input. Or value could be properly stored in memory but will be messed up during saving into file or database record.</p>
<p>Test scenarios might be required to reveal those defects.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Perl: Storing arrays in hashes]]></title>
<link>http://teusje.wordpress.com/2009/11/02/perl-storing-arrays-in-hashes/</link>
<pubDate>Mon, 02 Nov 2009 12:31:58 +0000</pubDate>
<dc:creator>teusje</dc:creator>
<guid>http://teusje.wordpress.com/2009/11/02/perl-storing-arrays-in-hashes/</guid>
<description><![CDATA[Let&#8217;s start with a quote from &#8216;Learning Perl&#8216;: What Is a Hash? A hash is a data st]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Let&#8217;s start with a quote from &#8216;<a href="http://docstore.mik.ua/orelly/perl3/lperl/ch05_01.htm">Learning Perl</a>&#8216;:</p>
<blockquote>
<h2>What Is a Hash?</h2>
<p>A hash is a data structure, not unlike an array in that it can hold any number of values and retrieve them at will. But instead of indexing the values by <em>number</em>, as we did with arrays, we&#8217;ll look up the values by <em>name</em>. That is, the <em>indices</em> (here, we&#8217;ll call them <em>keys</em><a name="INDEX-373"></a> <a name="INDEX-374"></a>) aren&#8217;t numbers, but instead they are arbitrary unique strings</p></blockquote>
<p style="text-align:center;"><a href="http://teusje.wordpress.com/files/2009/11/hash.gif"><img class="size-full wp-image-503 aligncenter" title="hash" src="http://teusje.wordpress.com/files/2009/11/hash.gif" alt="hash" width="238" height="220" /></a></p>
<p>&#160;</p>
<p><strong>Our goal: </strong>We want to store an array as a value in the hash instead of saving a single value<strong>.</strong></p>
<p>Let&#8217;s write some code:</p>
<pre class="brush: perl;">
#!/usr/bin/perl
use strict;
use warnings;

my %hash = ();
my @array = (1, 2, 3, 4, 5);
my $aref = \@array;
$hash{&#34;Testing&#34;} = $aref;
push(@{$hash{&#34;Testing&#34;}},6);
print join &#34; &#34;,@{$hash{&#34;Testing&#34;}};
</pre>
<p>This piece of Perl code stores an array as a value in a hash and adds a new element to the array.</p>
<p>Now let&#8217;s analyze the code.</p>
<p>First we create an empty hash and we create an array and initialize it.</p>
<pre class="brush: perl;">
my %hash = ();
my @array = (1, 2, 3, 4, 5);
</pre>
<p><a href="http://teusje.wordpress.com/files/2009/11/empty-hash-and-array.png"><img class="alignnone size-full wp-image-504" title="empty-hash-and-array" src="http://teusje.wordpress.com/files/2009/11/empty-hash-and-array.png" alt="empty-hash-and-array" width="316" height="157" /></a></pre>
<p>Now we need a reference of our array (so that we can store it as a value in the hash):</p>
<pre class="brush: perl;">
my $aref = \@array;
</pre>
<p><a href="http://teusje.wordpress.com/files/2009/11/ref-to-array.png"><img class="alignnone size-full wp-image-505" title="reference to array" src="http://teusje.wordpress.com/files/2009/11/ref-to-array.png" alt="reference to array" width="319" height="185" /></a></pre>
<p>In the next step below we actually do what we wanted. Storing an array into a hash value. We create a key in our hash called "Testing" and <strong>store the reference of our array</strong> in the value field.</p>
<pre class="brush: perl;">
$hash{&#34;Testing&#34;} = $aref;
</pre>
<p><a href="http://teusje.wordpress.com/files/2009/11/hash-array-ref2.png"><img class="alignnone size-full wp-image-506" title="hash-array-ref2" src="http://teusje.wordpress.com/files/2009/11/hash-array-ref2.png" alt="hash-array-ref2" width="389" height="165" /></a></pre>
<p>We can see that the reference of our array ($aref) is pointing to our array so we can access the array in our hash. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>This code adds a new element with value '6' to our array:
<pre class="brush: perl;">
push(@{$hash{&#34;Testing&#34;}},6);
</pre>
<p><a href="http://teusje.wordpress.com/files/2009/11/hash-aray-push-item.png"><img class="alignnone size-full wp-image-507" title="hash-aray-push-item" src="http://teusje.wordpress.com/files/2009/11/hash-aray-push-item.png" alt="hash-aray-push-item" width="412" height="163" /></a></p>
<p>Explanation: </p>
<pre class="brush: perl;">
# Gives the value of key Testing, it's the reference to the array
$hash{&#34;Testing&#34;}

# Dereference it with {} to access the array (that's why we have an @ at the begin)
@{$hash{&#34;Testing&#34;}}
</pre>
<p>I hope that helped <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </pre>
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java - ¿Qué uso, Array o List?]]></title>
<link>http://cirovladimir.wordpress.com/2009/10/29/java-%c2%bfque-uso-array-o-list/</link>
<pubDate>Thu, 29 Oct 2009 18:38:43 +0000</pubDate>
<dc:creator>cirovladimir</dc:creator>
<guid>http://cirovladimir.wordpress.com/2009/10/29/java-%c2%bfque-uso-array-o-list/</guid>
<description><![CDATA[Dentro de nuestros programas siempre habrá algun pedazo de código donde utilicemos arreglos. Mientra]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img src="http://cirovladimir.wordpress.com/files/2009/10/screenshot5.png" alt="ArrayVSList" title="ArrayVSList" width="150" height="154" class="alignnone size-full wp-image-308" /><br />
Dentro de nuestros programas siempre habrá algun pedazo de código donde utilicemos arreglos.<br />
Mientras implementaba unos métodos para insertar y eliminar registros de una clase, noté que en algunos había utilizado <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html" target="_blank">Arrays</a> y en otros <a href="http://www.j2ee.me/javase/6/docs/api/java/util/List.html" target="_blank">Lists</a>. Por ello decidí buscar que es lo que recomendaban otros programadores al respecto, fue así como encontré <a href="http://stackoverflow.com/questions/716597/array-or-list-in-java-which-is-faster" target="_blank">este artículo</a>.</p>
<p>Finalmente quede convencido de utilizar Lists debido a la <strong>flexibilidad</strong> que ofrecen.</p>
<p>Ejemplo:</p>
<pre class="brush: java;">
public static void insert(List&#60;Dato&#62; datos) {
  //... configuracion de conexion
  for(Dato dato:datos){
	db.executeUpdate(&#34;insert into datos(desc,cantidad) values(:desc,:cantidad)&#34;,
	new Object[]{dato.getDescripcion(),dato.getCantidad()});
  }
}
</pre>
<p><strong>VS.</strong></p>
<pre class="brush: java;">
public static void insert(Dato[] datos) {
  //... configuracion de conexion
  for(Dato dato:datos){
	db.executeUpdate(&#34;insert into datos(desc,cantidad) values(:desc,:cantidad)&#34;,
	new Object[]{dato.getDescripcion(),dato.getCantidad()});
  }
}
</pre>
<p>Como puedes observar, es prácticamente lo mismo, la diferencia es que al invocar el primer método puedes pasar como párametro un <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html" target="_blank">ArrayList</a>, <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html" target="_blank">LinkedList</a>, <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html" target="_blank">Vector</a> o tu propia clase que implemente la interfaz <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html" target="_blank">List</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .<br />
<a href="http://es.wikipedia.org/wiki/Byte" target="_blank"><br />
byte!</a></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=8f838877-dace-8320-8c55-552e2426734b" alt="" /></div>
</div>]]></content:encoded>
</item>

</channel>
</rss>
