<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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>Nucc</title>
	<link>http://nucc.bteam.hu</link>
	<description>bloggin on...</description>
	<pubDate>Sun, 15 Aug 2010 16:42:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Header files</title>
		<link>http://nucc.bteam.hu/?p=36</link>
		<comments>http://nucc.bteam.hu/?p=36#comments</comments>
		<pubDate>Sun, 15 Aug 2010 16:38:18 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[class]]></category>

		<category><![CDATA[header]]></category>

		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=36</guid>
		<description><![CDATA[On Friday we had a short debate in the room with the guys about the role of header and cpp files. I didn&#8217;t support to separate unit tests to header and implementation part, because I guess in this case it&#8217;s not necessary. Why?
Data types (i.e. classes) have abstract and concrete aspects. We store the abstract [...]]]></description>
			<content:encoded><![CDATA[<p>On Friday we had a short debate in the room with the guys about the role of header and cpp files. I didn&#8217;t support to separate unit tests to header and implementation part, because I guess in this case it&#8217;s not necessary. Why?</p>
<p>Data types (i.e. classes) have abstract and concrete aspects. We store the abstract aspects in header files (using c++ this is the .h file) and the concrete aspects in implementation files (cpp file). In the header we define the data type&#8217;s signature, export interface (public part of a class), parameters, methods, properties. Using C this kind of approach is shown better because header files can be separate from the implementation well, while in C++ sometimes you must store implementation specific properties in the header (usually in the private space).</p>
<p>The more information we define in the header file in connection with the implementation, the harder to change the implementation later without changing the header file. It can be a problem in a complex and huge software, where changing something in a deeper layer can result more hours compilation time.</p>
<p>In my example I show you an implementation of the stack data type. Stack is a very simple type, we can push elements to it, pop these elements out and get the number of the stored elements. The stack can be implemented in different ways, we can use vector or linked list to make it work.</p>
<p>In this example I&#8217;m going to store integer value in it.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#ifndef STACK__H</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define STACK__H</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Stack</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Stack<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> size<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ~Stack<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; Stack&amp;  push<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> value<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>     pop<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>     size<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw4">const</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span>:</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span>   *entries;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>   stack_size;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#endif</span></div>
</li>
</ol>
</div>
<p>There&#8217;s a problem with this header file. Using int *entries assumes we want to use array to store values. However it&#8217;s good for shorter stacks, since handling larger stack is not so efficient, because we have to allocate in the memory the whole size of the stack at the beginning. Later, when you want to change it to linked list to it can be more efficient in memory consumption, you must recompile every part of your software that includes this header file.</p>
<p>Using another structure we can change very easy to different implementation without to compile the software again. Considering the next change:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#ifndef STACK__H</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#define STACK__H</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> _stack_impl;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Stack</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Stack<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> size<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; ~Stack<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Stack&amp;  push<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> value<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>     pop<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>     size<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw4">const</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">private</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _stack_impl *impl;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>         stack_size;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#endif</span></div>
</li>
</ol>
</div>
<p>stack_impl structure gives opportunity to define properties in the cpp file. Stack_size is a property of the stack, so it can be in the header file.</p>
<p>In the cpp file that&#8217;s using linked list, the stack_impl looks like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> Entry <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry   *prev;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span>      value;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> _stack_impl</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry     *first;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry     *top;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span>       size;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
</ol>
</div>
<p>and with array:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> Entry <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp; &nbsp;value;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">struct</span> _stack_impl</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry *entries;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp;top;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
</ol>
</div>
<p>The implementation with linked list (stack.cpp) is:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#include &quot;stack.h&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> Entry <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry &nbsp; *prev;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp; &nbsp;value;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> _stack_impl</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; Entry &nbsp; &nbsp; *first;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry &nbsp; &nbsp; *top;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp; &nbsp; size;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">Stack::<span class="me2">Stack</span><span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> size<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; : stack_size<span class="br0">&#40;</span>size<span class="br0">&#41;</span>, impl<span class="br0">&#40;</span><span class="kw3">new</span> _stack_impl<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;first = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;top &nbsp; = <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; impl-&gt;size &nbsp;= <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Stack::~Stack<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw3">delete</span> impl;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Stack&amp;</div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">push</span><span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> value<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>stack_size == impl-&gt;size<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; throw <span class="st0">&quot;FULL&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry *entry = <span class="kw3">new</span> Entry;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; entry-&gt;value = value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; entry-&gt;prev &nbsp;= impl-&gt;top;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;top &nbsp; &nbsp;= entry;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;size++;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> *<span class="kw3">this</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span></div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>impl-&gt;size == <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; throw <span class="st0">&quot;EMPTY&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry *temp = impl-&gt;top;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;top = impl-&gt;top-&gt;prev;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span> value = temp-&gt;value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">delete</span> temp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> value;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span></div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw4">const</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> impl-&gt;size;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And the implemantation with array (stack2.cpp)</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co2">#include &quot;stack.h&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> Entry <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp; &nbsp;value;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> _stack_impl</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Entry *entries;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span> &nbsp; &nbsp;top;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">Stack</span><span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> size<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; : stack_size<span class="br0">&#40;</span>size<span class="br0">&#41;</span>, impl<span class="br0">&#40;</span><span class="kw3">new</span> _stack_impl<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;entries = <span class="kw3">new</span> Entry<span class="br0">&#91;</span>size<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;top = <span class="nu0">-1</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">Stack::~Stack<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">delete</span><span class="br0">&#91;</span><span class="br0">&#93;</span> impl-&gt;entries;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">Stack&amp;</div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">push</span><span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">int</span> value<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>impl-&gt;top<span class="nu0">+1</span> == stack_size<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; throw <span class="st0">&quot;FULL&quot;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; impl-&gt;top = impl-&gt;top<span class="nu0">+1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; impl-&gt;entries<span class="br0">&#91;</span>impl-&gt;top<span class="br0">&#93;</span>.<span class="me1">value</span> = value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> *<span class="kw3">this</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span></div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>impl-&gt;top == <span class="nu0">-1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; throw <span class="st0">&quot;EMPTY&quot;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">return</span> impl-&gt;entries<span class="br0">&#91;</span>impl-&gt;top&#8211;<span class="br0">&#93;</span>.<span class="me1">value</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span></div>
</li>
<li class="li1">
<div class="de1">Stack::<span class="me2">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw4">const</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> impl-&gt;top<span class="nu0">+1</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Using this somewhere (let this be the main.cpp), we can call the stack&#8217;s methods:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;stdio.h&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &quot;stack.h&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; Stack stack<span class="br0">&#40;</span><span class="nu0">5</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; stack.<span class="me1">push</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; stack.<span class="me1">push</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; stack.<span class="me1">push</span><span class="br0">&#40;</span><span class="nu0">4</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;pop: %d<span class="es0">\n</span>&quot;</span>, stack.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;pop: %d<span class="es0">\n</span>&quot;</span>, stack.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;size: %d<span class="es0">\n</span>&quot;</span>, stack.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&lt;/stdio.<span class="me1">h</span>&gt;</div>
</li>
</ol>
</div>
<p>Create the object files using g++:</p>
<pre>
  g++ -c main.cpp
  g++ -c stack.cpp
  g++ -c stack2.cpp</pre>
<p>Finally we create two different executable code:</p>
<pre>
  g++ stack.o main.o -o linked_list
  g++ stack2.o main.o -o array</pre>
<p>So for unit testing I would create only a cpp file and put the class declaration and definition there inline, because it doesn&#8217;t have any implementation code that we want to hide. I guess the unit test be simple, perspicuous and brief, so guys, don&#8217;t separate it&#8230;</p>
<p><map name='google_ad_map_36_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/36?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_36_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=36&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D36' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=36</wfw:commentRss>
		</item>
		<item>
		<title>Bundle error</title>
		<link>http://nucc.bteam.hu/?p=35</link>
		<comments>http://nucc.bteam.hu/?p=35#comments</comments>
		<pubDate>Sun, 18 Jul 2010 10:20:24 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[bundle]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=35</guid>
		<description><![CDATA[Using bundler it throws the following error after running bundle exec rake spec/Library/Ruby/Gems/1.8/gems/bundler-1.0.0.beta.5/lib/bundler/shared_helpers.rb:128:in `bin_path': can't find executable bundle (Gem::Exception)I&#8217;ve tried to find a nice solution for the problem, but finally I made a very dirty workaround to make it work. I created an executable bundle file in [bundle_dir]/bin and now it&#8217;s work properly.



]]></description>
			<content:encoded><![CDATA[<p>Using bundler it throws the following error after running bundle exec rake spec<code>/Library/Ruby/Gems/1.8/gems/bundler-1.0.0.beta.5/lib/bundler/shared_helpers.rb:128:in `bin_path': can't find executable bundle (Gem::Exception)</code>I&#8217;ve tried to find a nice solution for the problem, but finally I made a very dirty workaround to make it work. I created an executable bundle file in [bundle_dir]/bin and now it&#8217;s work properly.</p>
<p><map name='google_ad_map_35_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/35?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_35_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=35&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D35' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=35</wfw:commentRss>
		</item>
		<item>
		<title>Párhuzamos rendszerek modellezése OPM segítségével</title>
		<link>http://nucc.bteam.hu/?p=34</link>
		<comments>http://nucc.bteam.hu/?p=34#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:35:25 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[Hungarian]]></category>

		<category><![CDATA[opm]]></category>

		<category><![CDATA[parallel]]></category>

		<category><![CDATA[petri]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=34</guid>
		<description><![CDATA[ 





 		 	 



]]></description>
			<content:encoded><![CDATA[<p><center> <object id="doc_410267596085972" name="doc_410267596085972" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline-color: -moz-use-text-color; outline-style: none; outline-width: medium" height="600" width="450"></p>
<param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"></param>
<param name="wmode" value="opaque"></param>
<param name="bgcolor" value="#ffffff"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<param name="FlashVars" value="document_id=33734869&amp;access_key=key-2m8ge742we80g14zfzbc&amp;page=1&amp;viewMode=list"></param> 		<embed src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=33734869&amp;access_key=key-2m8ge742we80g14zfzbc&amp;page=1&amp;viewMode=list" id="doc_410267596085972" name="doc_410267596085972" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" bgcolor="#ffffff" height="600" width="450"></embed> 	</object> </center></p>
<p><map name='google_ad_map_34_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/34?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_34_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=34&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D34' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=34</wfw:commentRss>
		</item>
		<item>
		<title>Ruby on Rails - Balabit Meetup</title>
		<link>http://nucc.bteam.hu/?p=32</link>
		<comments>http://nucc.bteam.hu/?p=32#comments</comments>
		<pubDate>Thu, 22 Apr 2010 20:42:03 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[balabit]]></category>

		<category><![CDATA[meetup]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=32</guid>
		<description><![CDATA[Rails is the best framework to build web applications using agile techniques. On Balabit Meetup we had a journey in the world of Rails, created a sample application that stored products in sqlite database. You can find the result of demo here!








]]></description>
			<content:encoded><![CDATA[<p>Rails is the best framework to build web applications using agile techniques. On Balabit Meetup we had a journey in the world of Rails, created a sample application that stored products in sqlite database. You can find the result of demo <a href="http://nucc.bteam.hu/wp-content/uploads/2010/04/meetupbalabit.tgz" title="Rails Meetup Demo">here</a>!<br />
<center><br />
<object width="425" height="355">
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-100422162332-phpapp02&#038;rel=0&#038;stripped_title=rails-3822010" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=rails-100422162332-phpapp02&#038;rel=0&#038;stripped_title=rails-3822010" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></center></p>
<p><map name='google_ad_map_32_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/32?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_32_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=32&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D32' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=32</wfw:commentRss>
		</item>
		<item>
		<title>Ruby presentation - Balabit Meetup</title>
		<link>http://nucc.bteam.hu/?p=31</link>
		<comments>http://nucc.bteam.hu/?p=31#comments</comments>
		<pubDate>Fri, 19 Mar 2010 19:53:22 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[balabit]]></category>

		<category><![CDATA[meetup]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=31</guid>
		<description><![CDATA[On Wednesday I did a presentation on Balabit Meetup. I talked about a programming language that&#8217;s very close to me. It&#8217;s called, Ruby. You can check my presentation on the next few slides, moreover if you wanna try this brilliant language out, check the tryruby.org!












]]></description>
			<content:encoded><![CDATA[<p>On Wednesday I did a presentation on Balabit Meetup. I talked about a programming language that&#8217;s very close to me. It&#8217;s called, Ruby. You can check my presentation on the next few slides, moreover if you wanna try this brilliant language out, check the <a href="http://tryruby.org">tryruby.org</a>!</p>
<div style="width:425px; margin: auto" id="__ss_3480550">
<object width="425" height="355"></p>
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=ruby-meetup-balabit-100319141515-phpapp01&#038;rel=0&#038;stripped_title=ruby-meetup-balabit" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/>
<embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=ruby-meetup-balabit-100319141515-phpapp01&#038;rel=0&#038;stripped_title=ruby-meetup-balabit" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"><br />
</embed><br />
</object>
</div>
<p><map name='google_ad_map_31_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/31?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_31_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=31&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D31' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=31</wfw:commentRss>
		</item>
		<item>
		<title>Mr Geek</title>
		<link>http://nucc.bteam.hu/?p=30</link>
		<comments>http://nucc.bteam.hu/?p=30#comments</comments>
		<pubDate>Sat, 20 Feb 2010 15:50:47 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=30</guid>
		<description><![CDATA[Tonight I&#8217;m going to a masquerade party and dressing to Mr Geek. Here is the result&#8230;






Masquerade






]]></description>
			<content:encoded><![CDATA[<p>Tonight I&#8217;m going to a masquerade party and dressing to Mr Geek. Here is the result&#8230;<br />
<center></p>
<table style="width: 194px">
<tr>
<td style="background: transparent url('http://picasaweb.google.com/s/c/transparent_album_background.gif') no-repeat scroll left center; height: 194px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial" align="center"><a href="http://picasaweb.google.com/nucler.pl/Masquerade?feat=embedwebsite"><img src="http://lh3.ggpht.com/_GL9T82Bmzns/S4ABhiFVu0E/AAAAAAAAAQ0/Puf6Ulj8QAU/s160-c/Masquerade.jpg" style="margin: 1px 0pt 0pt 4px" height="160" width="160" /></a></td>
</tr>
<tr>
<td style="text-align: center; font-family: arial,sans-serif; font-size: 11px"><a href="http://picasaweb.google.com/nucler.pl/Masquerade?feat=embedwebsite" style="color: #4d4d4d; font-weight: bold; text-decoration: none">Masquerade</a></td>
</tr>
</table>
<p></center></p>
<p><map name='google_ad_map_30_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/30?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_30_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=30&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D30' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=30</wfw:commentRss>
		</item>
		<item>
		<title>Számítógépes hálózatról konyhanyelven</title>
		<link>http://nucc.bteam.hu/?p=29</link>
		<comments>http://nucc.bteam.hu/?p=29#comments</comments>
		<pubDate>Sun, 14 Feb 2010 16:16:32 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[Hungarian]]></category>

		<category><![CDATA[hálózat]]></category>

		<category><![CDATA[network]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=29</guid>
		<description><![CDATA[A következő kis szösszenetet még 2006-ban írtam egyetemi éveim alatt, eddig a blogter oldalán pihent. Gondoltam megkeresem, és felveszem a már hivatalos blog oldalamra. Tehát íme egy szösszenet 2006-ból&#8230;
Gondoltam megpróbálom szemléltetni a számítógépes hálózatok működését, mert úgy vettem észre egyetemen sokan csak dobálóznak a szavakkal, de hogy mi micsoda, az néha megválaszolatlanul marad.[OFF] Mikor elkezdtem [...]]]></description>
			<content:encoded><![CDATA[<p>A következő kis szösszenetet még 2006-ban írtam egyetemi éveim alatt, eddig a <a href="http://nucc.blogter.hu/48416/szamitogepes_halozatok_vs_posta">blogter</a> oldalán pihent. Gondoltam megkeresem, és felveszem a már hivatalos blog oldalamra. Tehát íme egy szösszenet 2006-ból&#8230;</p>
<p>Gondoltam megpróbálom szemléltetni a számítógépes hálózatok működését, mert úgy vettem észre egyetemen sokan csak dobálóznak a szavakkal, de hogy mi micsoda, az néha megválaszolatlanul marad.[OFF] Mikor elkezdtem ezt a blogot, nem gondoltam volna, hogy lesz valaki aki olvassa. Meglepetés erejével hatott az a 30 látogató is, még ha nem is olvasták végig, erőt adtak hogy folytassam. Nehéz gondolatokról írni, de megpróbálkozom vele&#8230; [/OFF]</p>
<p>Egyetemünkön mindig nagy para van hálózatok évfolyamzh előtt. Újra előkerülnek a kedves kis algoritmusok, Dijkstra, Bellmann-Ford, megint ellepik az 53-as portot a dig lekeresek, es sorolhatnam. A problémát ott látom, hogy senki sem tudja mit miért csinál, copy paste, ide ezt kell írni, oda meg azt. Talán mondhatjuk, hogy a tömegképzés hátránya? A következő pár sorban csak egy kis képet szeretnék mutatni az anyagról, nem oktató jelleg, csak hogy legyen egy kis képünk a dologról.</p>
<p>Próbálok szemléltetést adni az egész tárgyhoz, kicsit az ELTE-s oktatás oldaláról. Sajnos nálunk 1 félévig oktatják, ebben is teli lényegtelen dolgokkal, de mit tehet az ember. Ez van. Megjegyezném, ez nem doksi, ez csak csupán pár gondolat összefűzése.</p>
<p>Az, hogy hogy alakult ki a hálózat, nem mennék bele. De minthogy az informatika az élet digitalizálása, 0-1-re alakítása, így a minta, amire épül nem újkeletű.</p>
<p>Képzeljük el a következőt. Levelet szeretnénk küldeni egyik nagyon jó ismerősünknek. Fogunk egy papirt, ceruzát, megírjuk levelünket, borítékba helyezzük, elszaladunk a postára, majd a posta eljuttatja barátunknak. Ha válaszol rá, akkor pár nap múlva ott lesz a ládánkban a levele. A számítógépes hálózat olyan mint egy postai rendszer. Posta meg már mióta létezik. Na szedjük össze, mi mi is egész pontosan.</p>
<p>Először is, meg kell írnunk a levelet. Vegyünk egy txt filet. Miután megírtuk, fogunk egy borítékot. Ez a boríték felelős azért, hogy más ne tudja elolvasni, és hogy ellássuk olyan információkkal, hogy kinek is küldjük. Ezért lesznek felelősök a csomagolások (amikor fejlécezzük őket).<br />
Na igen. Hogy kinek is küldjük. Az életben mindenkinek van egy postai címe, név, utca, házszám, város, irányítószám. A címe mindenkinek egyedi (az irányítószámot most még ne keverjük bele), elég érdekes lenne, ha egy másik ember kapná meg levelünket, úgyhogy az adatok teljes mértékben rá illenek. Ezért felelős a MAC Address. A <span style="font-weight: bold">MAC Address</span> nem más, mint a hálózati eszköz beleégetett kódja (na jó, ha ügyes az ember megváltoztathaja). Ez alapján mindenki egyedi. A Mac address-el viszont van egy kis probléma. Honnan tudjuk, merre is van az a szerencsétlen célpont. Ez körülbelül olyan, mintha nevet írnék, meg utcát. Talán egyszer megérkezne levelünk, de nem garantálnám biztosra. Kell egy mód, ami alapján levelünk a leggyorsabban ér célba.</p>
<p>Mikor a borítékra felírjuk az irányítószámot, kihangsúlyoznám, irányító!!, azt mondjuk meg a postának, hogy merre fele küldje. Minden posta rendelkezik egy számmal, és a posták közötti forgalom ezekkel a számokkal történik.<br />
Most a példa megkönnyítéséért mindenkinek legyen egy postafiókja, ezzel egyszerűbb lesz követni.</p>
<p>Vegyünk hálózatokat. <span style="font-weight: bold">Hálózat</span>ok ugye gépek összekapcsolása. Tehát definiálunk egy közös tulajdonságot, melyre ha illeszkedik egy gép, akkor egy hálózatban vannak. A mi esetünkben egy hálózatban legyenek azok a postafiókok, melyek egy irányítószám alá esnek. Remélem idáig egyértelmű. Az IP cimünk nem más, mint az irányítószám és a postafiókunk egyfajta kotyvaléka. De mi is az az IP cím?</p>
<p>Az <span style="font-weight: bold">IP</span>-nek (Internet Protokol) jelenleg két verziója él. A 4-es és a 6-os. Amiről most szó lesz, az a 4-es verzió, a 6-os még csak az előszobában jár, a mobil-távközlés fogja a nappalinkba terelni. Az IP cím 4 darab 8-bites számból áll, ezeket ponttal választjuk el. 8 bit =&gt; 0..255. A 0-nak és a 255-nek kitüntetett szerepe van, ilyen címet nem kaphat gép. Ez alapján tudunk elérni egy gépet. Elrugaszkodva a postától, ez olyan mint egy telefonszám. Amikor azt mondom, hogy 192.168.1.1, akkor ez egy 4-es verziójú IP cím. Egy hálózati eszköz több ilyen címmel is rendelkezhet (több postafókunk is lehet), de egy IP egy géphez tartozik (1 postafiók csak egy 1 személyé lehet). Valahogy definiálnunk kéne azt a közös tulajdonságot, mely alapján 2 gép egy hálózatba kerül. Erre való a <span style="font-weight: bold">netmask</span>. Ez a netmask olyan mint egy maszk. Innen is ered a neve. Most képzeletben vegyünk két ugyanolyan hosszú bináris számsorozatot. Legyen mondjuk a 100110 és a 101001. Az első legyen a cím, a második a mask. Most helyezzük rá a maskot a címre, ahol egyes van, ott legyen az eredeti szám, ahol nulla, oda ne írjunk semmit. Mi a következőt kaptuk: 1_0__0. Ahol _ jel van, oda írhatunk 0-t vagy 1-et, ahol szám, az változatlan. Amely cimek ezek után erre illeszkedik, az a hálózat tagja lesz. Tehát <span style="font-weight: bold">1</span>1<span style="font-weight: bold">0</span>11<span style="font-weight: bold">0</span>, <span style="font-weight: bold">1</span>0<span style="font-weight: bold">0</span>10<span style="font-weight: bold">0</span> egy hálózatba kerülnek, mert a séma mindkettőre illeszkedik. Most még egy gyors példa. Szeretnénk egy olyan hálózatot, mely 2 gépet számol. 192.168.1.1, legyen az egyik cim, 192.168.1.3 legyen a másik cím. Ekkor a gépek az utolsó előtti bitben térnek el, tehát a netmask 255.255.255.253 (mert a 2^1-n változik, és az 255-2=253), az IP amire pedig illesztek, az a 192.168.1.1. Amúgy ha azt írnám, hogy 192.168.1.0/24, az azt jelenti, hogy az IP cím első 24 bitjének változatlannak kell maradnia, de az utolsó 8 bitre, a mi esetünkben a 0 helyére, bármit írhatunk, azok a gépek egy hálózatban lesznek. Létezik továbbá olyan, hogy <span style="font-weight: bold">broadcast</span>, ez egy kitüntetett IP cím, ez felelős azért, hogy egy csomagot minden gép megkapjon. Például azt szeretnénk elküldeni minden gépnek, hogy kapcsoljon ki. Ilyenkor a broadcast cimre küldünk egy kikapcs üzenetet és ilyenkor ezt az összes, a hálózatban lévő gép meg fogja kapni.</p>
<p>Tehát ez alapján már tudunk gépeket csoportosítani. Most nézzük hogy jut el egy boríték egyik helyről a másikra.</p>
<p>A postára érkezik egy levél, amin van egy irányítószám. Mi is történik ezután. Fogja a hölgy a levelet, megnézi hogy a szám ugyanaz-e, mint az ő ir.számuk. Ha igen, akkor berakja a kiküldésre váró levelek közé. Ha nem, megy a központba, majd ott eldöntik mi legyen vele. A központba megérkeznek a levelek, van rengeteg zsák, az egyik zsák az 1-essel keződőek, a másik a 2-essel, és így tovább. Majd amikor megtelik egy zsák, megnézik a számot, és ha 6-ossal kezdődik akkor megy az Alföldre, és így tovább. Majd az Alföldi központban nézik a második  számot, megint zsákba, és így tovább (csak Kecskemét száma ugrott most be&#8230;).<br />
Gondolom találkoztunk már azzal a szóval hogy <span style="font-weight: bold">Router. </span>Ha otthon több gépünk van, akkor biztos fent van egy a falon, de léteznek ezekből az eszközökből hatalmas példányok is. A router nem más, mint az a hölgy, vagy úr, aki a leveleket zsákokba rakja. A router olyan, mint egy polip. A lábain hálózatok vannak, és van egy kitüntetett lába, ez lesz a <span style="font-weight: bold">GateWay</span>. Jön egy levél, ami egy IP címmel rendelkezik, mégpedig a címzettel. A router megnézi a címet, majd megnézi létezik e olyan hálózat valamelyik lábán, amire ez a cím illeszkedik. Ha nem, akkor a kitüntetett lábra kerül, vagyis a GateWay-re, majd talán ott eldöntik mi legyen vele. Vagyis amikor a postán a kisasszony megnézte, hogy az irányítószám ugyanaz-e, mint az ő számuk, akkor ha igen, akkor ment az egyik lábon a fiókba, ha nem, akkor gateway-re rakta, majd a feljebblévők eldöntik mi is legyen vele. Megjegyezném, hogy minden gépnek van routing táblája, és minden gép ezáltal egy router. Ha ezt most olvasod, akkor egyben egy router előtt is ülsz, aminek a gateway ága ott lóg hátul&#8230;</p>
<p>Ha jobban megnézzük, a levelek egy gráfon (pontok, melyek vonalakkal vannak összekötve) vándorolnak, ahol a csúcsok a posták, élek pedig a postások útja, vagy a vonaté ami szállítja, stbstb. Mondjuk Debrecenbe nem úgy szeretnénk eljuttatni levelünket, hogy elküldjük Győrbe, majd Pécsre, majd Szegedre, és onnan végül Debrecenbe. Kicsit sokba kerülne a postának. Dijkstra (azt hisszem Holland matematikus volt, de most hirtelen ??? ) villamosvezetékek elrendezésére kitalált egy algoritmust, amivel legkevesebb vezetékből lehet elektromos hálózatot építeni. Ez lényegében egy gráfon megkeresi a legkisebb súlyú feszítőfát (egyik pontból a másikba a legrövidebb utat, mégpedig minden pontra működik). Vagyis ha összekötjük a postákat, és utána súlyozzuk az éleket a posták közti utazási idővel, akkor egy gráfot kapunk, melyre ha Dijkstra algoritmusát alkalmazzuk megkapjuk a legrövidebb utat két posta között. A routereket ezek alapján konfigurálják, ezzel érik el, hogy minél kevesebb csomagütközés legyen, és lehetőleg a leggyorsabban jusson el csomagunk a partnerhez. Gondolom nem örülnél neki, ha a 2mbites adsl kapcsolattal csak 3 kbyte/sec-el tudnál tölteni, mert körbeutazza a csomag a világot, pedig csak a szomszédnak küldesz egy mp3-at.</p>
<p>Ha már mp3, vagyis zene. Biztos volt már úgy, hogy walkmant hallgattatok és szerettetek volna megmutatni egy számot a haverotoknak. Viszont a szám sztereóban élvezhető, és &#8230; na yolvan, a lényeg hogy szükség volt egy jack osztóra. Hálózatoknál is előfordul, hogy hirtelen bekerül egy gép a lakásba, viszont a routeren már nincs több férőhely. Ilyenkor az ember vesz egy <span style="font-weight: bold">switch</span>et, amivel toldhat. Régebben voltak <span style="font-weight: bold">hub</span>ok, mostanában már nem kapni, a switch egy intelligens hub. A switch tudja, hogy milyen gép van a lábánál, a hub nem. A hub minden gépnek elküldi az üzenetet ami ő rá van kötve, a switch csak bizonyos lábán. Röviden ennyi a különbség. A probléma akkor áll fenn, ha nagyobb hálózatunk van, tele switchekkel, meg hálózatokkal, és mondjuk az egyik hálózatnak van csak internet kapcsolata. Előfordulhat ugyanis, hogy kör alakul ki, és ekkor egy csomag el kezd cirkulálni a hálózaton, majd bizonyos idő után persze inaktívvál válik és meghal, de addig is lassítja az adatforgalmat.<br />
Erre használjuk Bellmann-Ford algoritmust, ami szintén egy feszítőfát állít elő, ezzel a switchek kimenő ágait tudjuk korlátozni, ezzel küszöböljük ki a köröket.</p>
<p><map name='google_ad_map_29_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/29?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_29_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=29&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D29' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=29</wfw:commentRss>
		</item>
		<item>
		<title>Creating snowman</title>
		<link>http://nucc.bteam.hu/?p=27</link>
		<comments>http://nucc.bteam.hu/?p=27#comments</comments>
		<pubDate>Sat, 30 Jan 2010 16:21:31 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[fun]]></category>

		<category><![CDATA[snowman]]></category>

		<category><![CDATA[team]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=27</guid>
		<description><![CDATA[Binh, Zoli and me have created a snowman in the court of the club&#8230;

  






  










]]></description>
			<content:encoded><![CDATA[<p>Binh, Zoli and me have created a snowman in the court of the club&#8230;</p>
<p><center><embed src="http://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" flashvars="host=picasaweb.google.com&amp;hl=en_US&amp;feat=flashalbum&amp;RGB=0x000000&amp;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fnucler.pl%2Falbumid%2F5432566645243083057%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer" height="267" width="400"></embed></p>
<p></center> <center> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" id="qikPlayer" align="middle" height="319" width="425"></p>
<param name="allowScriptAccess" value="always"></param>
<param name="allowFullScreen" value="true"></param>
<param name="movie" value="http://qik.com/swfs/qikPlayer5.swf"></param>
<param name="quality" value="high"></param>
<param name="bgcolor" value="#333333"></param>
<param name="FlashVars" value="rssURL=http://qik.com/video/eb0b7093dc594ac6982d545d443fa247.rss&amp;autoPlay=false&amp;polling=false"></param><embed src="http://qik.com/swfs/qikPlayer5.swf" quality="high" bgcolor="#333333" name="qikPlayer" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="rssURL=http://qik.com/video/eb0b7093dc594ac6982d545d443fa247.rss&amp;autoPlay=false&amp;polling=false" align="middle" height="319" width="425"></embed></object></p>
<p></center> <center> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" id="qikPlayer" align="middle" height="319" width="425"></p>
<param name="allowScriptAccess" value="always"></param>
<param name="allowFullScreen" value="true"></param>
<param name="movie" value="http://qik.com/swfs/qikPlayer5.swf"></param>
<param name="quality" value="high"></param>
<param name="bgcolor" value="#333333"></param>
<param name="FlashVars" value="rssURL=http://qik.com/video/4c54c0f870334c86b458621207c34bbd.rss&amp;autoPlay=false&amp;polling=false"></param><embed src="http://qik.com/swfs/qikPlayer5.swf" quality="high" bgcolor="#333333" name="qikPlayer" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="rssURL=http://qik.com/video/4c54c0f870334c86b458621207c34bbd.rss&amp;autoPlay=false&amp;polling=false" align="middle" height="319" width="425"></embed></object></p>
<p></center></p>
<p><map name='google_ad_map_27_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/27?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_27_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=27&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D27' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=27</wfw:commentRss>
		</item>
		<item>
		<title>Announcement!</title>
		<link>http://nucc.bteam.hu/?p=26</link>
		<comments>http://nucc.bteam.hu/?p=26#comments</comments>
		<pubDate>Thu, 31 Dec 2009 13:08:49 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=26</guid>
		<description><![CDATA[Bonanza Team supports the Tinu open source C/C++ unit test framework. You can find more information about the project on the tracker site, and you can read a short interview with the owner of the project, Herczy.



]]></description>
			<content:encoded><![CDATA[<p>Bonanza Team supports the Tinu open source C/C++ unit test framework. You can find more information about the project on the <a href="https://tracker.bteam.hu/projects/tinu">tracker site</a>, and you can read a <a href="http://herczy.blogs.balabit.com/2009/12/tinu-went-public.html" title="shprt interview">short interview</a> with the owner of the project, <a href="http://herczy.blogs.balabit.com">Herczy</a>.<meta charset="utf-8" /></p>
<p><map name='google_ad_map_26_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/26?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_26_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=26&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D26' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=26</wfw:commentRss>
		</item>
		<item>
		<title>My new server - Part 2</title>
		<link>http://nucc.bteam.hu/?p=25</link>
		<comments>http://nucc.bteam.hu/?p=25#comments</comments>
		<pubDate>Fri, 06 Nov 2009 17:51:05 +0000</pubDate>
		<dc:creator>Nucc</dc:creator>
		
		<category><![CDATA[English]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[server]]></category>

		<category><![CDATA[aufs]]></category>

		<category><![CDATA[chroot]]></category>

		<category><![CDATA[iso]]></category>

		<category><![CDATA[mongrel]]></category>

		<category><![CDATA[passenger]]></category>

		<category><![CDATA[rack]]></category>

		<category><![CDATA[unionfs]]></category>

		<guid isPermaLink="false">http://nucc.bteam.hu/?p=25</guid>
		<description><![CDATA[As I&#8217;ve mentioned my server provides Ruby On Rails service for companies also, so I&#8217;d like to write in short about Rails hosting. Rails is a framework written in Ruby. There&#8217;s a ruby application repository called rubygems like apt-get. So when you want to upgrade your Rails, as in apt-get, you can do it by [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned my server provides <a href="http://rubyonrails.org/" target="_blank">Ruby On Rails</a> service for companies also, so I&#8217;d like to write in short about Rails hosting. Rails is a framework written in Ruby. There&#8217;s a ruby application repository called <a href="http://docs.rubygems.org/" target="_blank">rubygems</a> like apt-get. So when you want to upgrade your Rails, as in apt-get, you can do it by the gem management application. The current rails version is over the 2.0 release and rubygems is over the 1.3. When we were working on the sites (those are being hosted currently), we used Rails 1.2.3 and rubygems 0.7. Today these versions are unsupported, and the upgrade is not so trivial.</p>
<p>Rails application opens ports by its own server engine (you should only call script/server in the project to start a process on the 3000 port), or you can use other software, for example <a href="http://mongrel.rubyforge.org" target="_blank">Mongrel</a> (there is another solution with fastcgi, but the restart is complicated). You can specify the number of the listening ports and the number of the parallel threads to response to the requests. You need to bunch these ports to port 80, so you need a server that proxies the requests coming on the port 80 to the Rails processes. So briefly, you need a web server to proxy, and Mongrel processes which run the Rails applications.</p>
<p>Currently the <a href="http://www.modrails.com/">Passenger</a> module to <a href="http://nginx.net/" target="_blank">Nginx</a> and Apache skips the application server part of the previous process (the Mongrel processes), and creates Rails instances directly from the web server, so you should specify only your application&#8217;s public directory in the web server&#8217;s configuration file, and it works out of the box. So, I have an old active system with the 3-step-process, and there is a better solution that I would like to support and would be comfortable in the future.</p>
<p>I was sitting on a fence how I should solve this problem, how I could separate similar environments to different scopes. Building a virtual server park could be an alternative, but I don&#8217;t want to run a lot of apache web servers and ssh daemons concurrently. My other problem was ssh protocol doesn&#8217;t not support virtual hosts, and since I haven&#8217;t got different IP addresses to each virtual server, I should support ssh access on different ports, which I don&#8217;t want.</p>
<p>I tried to make a solution for this hosting problem, and finally the result was different chrooted environments for the old and the new version of Rails. I decided to use that kind of separation for all bigger components, like database services, name server, mail server, developer part, so I would call these bigger environments as racks. Backuping files is very important on servers, therefore I needed to found a solution  for that problem also, so I&#8217;d like to show some tricks which is very comfortable later.</p>
<p><strong>Receipt:</strong></p>
<p>You will need <a href="http://squashfs.sourceforge.net/" target="_blank">squashfs</a> and aufs first. <a href="http://aufs.sourceforge.net/">Aufs</a> is an union filesystem in kernel space (using postfix caused some aufs ooops in kernel, so I recommend to use <a href="http://podgorny.cz/moin/UnionFsFuse">fuse-unionfs</a> in this case, the problem it&#8217;s running in user space, so the context switches cause performance decrease)</p>
<p>First create a minimal chroot environment that will be extended to service oriented rack. Using mksquashfs, we pack it to an image file that will be the hibernated service. Using aufs, make a merge of the read only image file&#8217;s content with a writable directory on the file system. All changes in this rack appear in this writable directory, so when you want to make a backup, you have to save only the writable partition. So the goal is each read only image (created by mksquashfs) contains (only) the whole software environment for a service (like mail-server, database-server), and each more file like configurations, created and modified files will be on the writable partition.</p>
<p>My directory structure is the following:</p>
<p><code>/racks - all the data of the racks<br />
/racks/iso - iso files which contain the services<br />
/racks/readonly - readonly directories mounted by loopback<br />
/racks/readwrite - modified files<br />
/racks/active - merged readonly and a readwrite directories<br />
/var/share - shared files like unix sockets, common log files...<br />
/racks/share/dev - dev directory into chroot environments</code></p>
<p>Building steps:Let webserver-1.0.iso is the web server environment. Building racks will be in the next part of this thread, till then you can create chroot environment with <a href="http://www.debian-administration.org/articles/426" target="_blank">debootstrap</a> in Debian or Ubuntu (of course it won&#8217;t contain webserver components), or download a Gentoo stage 3 archive.</p>
<p><code>debootstrap --variant=minbase lenny /tmp/chroot_base<br />
mksquashfs /tmp/chroot_base /racks/iso/webserver-1.0.iso</code></p>
<p>webserver-1.0.iso is in the /racks/iso directory, and you can burn it to a disc for backup. According to the previous directory roles, you need to create the corresponding directories in the rack structure, so you need</p>
<p><code>/racks/readonly/webserver<br />
/racks/readwrite/webserver<br />
/racks/active/webserver</code></p>
<p>Mount the image to the readonly directory:</p>
<p><code>mount -o loop,ro /racks/iso/webserver-1.0.iso /racks/readonly/webserver</code></p>
<p>Merge it with the readwrite part to the active directory</p>
<p><code>mount -t aufs -o br=/racks/readwrite/webserver=rw:/racks/readonly/webserver=ro none /racks/active/webserver</code></p>
<p>After merge is ready, we have to mount the default directories:</p>
<p>Mount /proc</p>
<p><code>mount -t proc none /racks/active/webserver/proc</code></p>
<p>Mount /dev<code>mount -o bind /racks/share/dev /racks/active/webserver/dev</code></p>
<p>Mount /var/share</p>
<p><code>mount -o bind /var/share /racks/active/webserver/dev</code></p>
<p>Mount /home</p>
<p><code>mount -o bind /home /racks/active/webserver/home</code></p>
<p>And finally, jump to the rack with</p>
<p><code>chroot /racks/active/webserver</code></p>
<p>I have a script that runs these steps, starts daemon applications after the mount process, when you want to stop the rack it stops all daemons and processes and unmount the directories in the right order.When you have a new upgrade from a software (for example when a new Nginx or Apache is released), just extract the current image to somewhere, upgrade the software in the new one, test it by chroot into it, when everything seems to be good, make a new iso with squashfs and edit your script to use webserver-2.0.iso instead of 1.0. The writable layer is the same, and if something goes wrong, you just back up to 1.0.</p>
<p>In the next part I&#8217;m going to show how you can create environments from scratch, which contain only that software you need.</p>
<p></p>
<p><map name='google_ad_map_25_6fa944e7346ab1e9'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/25?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_25_6fa944e7346ab1e9' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=25&amp;url= http%3A%2F%2Fnucc.bteam.hu%2F%3Fp%3D25' /></p>]]></content:encoded>
			<wfw:commentRss>http://nucc.bteam.hu/?feed=rss2&amp;p=25</wfw:commentRss>
		</item>
	</channel>
</rss>
