<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HERGHELEGIU &#187; All</title>
	<atom:link href="http://herr.ro/blog/category/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://herr.ro</link>
	<description>Blog Herr.ro</description>
	<lastBuildDate>Tue, 20 Sep 2011 08:01:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Golden Rules</title>
		<link>http://herr.ro/blog/2011/09/golden-rules/</link>
		<comments>http://herr.ro/blog/2011/09/golden-rules/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 07:49:34 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[rules]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=200</guid>
		<description><![CDATA[Here are the golden rules for programming: KEEP IT SIMPLE Make it work Make it fast DONT change it if it works]]></description>
			<content:encoded><![CDATA[<p>Here are the golden rules for programming:</p>
<ol>
<li>KEEP IT SIMPLE</li>
<li>Make it work</li>
<li>Make it fast</li>
<li>DONT change it if it works</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/golden-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merge sort</title>
		<link>http://herr.ro/blog/2011/09/merge-sort/</link>
		<comments>http://herr.ro/blog/2011/09/merge-sort/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:10:23 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=154</guid>
		<description><![CDATA[Another sort method is merge sort

MERGE-SORT(A,p,r)
        
T(n) is THETA(n lg n)
Insertion sort run faster for low n because of the constant factors.
We can use insertion sort when subproblems is sufficient small.]]></description>
			<content:encoded><![CDATA[<p>Another sort method is merge sort</p>
<p>MERGE-SORT(A,p,r)</p>
<p>T(n) is THETA(n lg n)<br />
Insertion sort run faster for low n because of the constant factors.<br />
We can use insertion sort when subproblems is sufficient small.<br />
<code><br />
MERGE-SORT(A,p,r)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if  ( p &lt; r )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q = (p+r)/2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MERGE-SORT(A,p,q);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MERGE-SORT(A,q+1,r);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MERGE(A,p,q,r);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code><br />
&nbsp;<br />
<code><br />
MERGE(A,p,q,r)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;int i = p;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int j = q+1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int k = p;<br />
&nbsp;&nbsp;&nbsp;&nbsp;while( i &lt;=q || j&lt;=r )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min = 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( i&lt;=q &amp;&amp; ( !(j&lt;=r) || (j&lt;=r &amp;&amp; A[i] &lt; A[j]) )    )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min = A[i];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min = A[j];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B[k] = min;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k++;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for( i=p; i&lt;=r; i++ )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A[i] = B[i];<br />
}<br />
</code><br />
&nbsp;<br />
<code><br />
if ( i&lt;=q &amp;&amp; ( !(j&lt;=r) || (j&lt;=r &amp;&amp; A[i] &lt; A[j]) )    )<br />
</code><br />
can be rewrite as<br />
<code><br />
if ( i&lt;=q &amp;&amp; ( !(j&lt;=r) || (A[i] &lt; A[j]) )    )<br />
</code><br />
<br />
Read more on <a href="http://en.wikipedia.org/wiki/Merge_sort" target="_blank">Wikipedia Merge Sort</a></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/merge-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heap sort</title>
		<link>http://herr.ro/blog/2011/09/heap-sort/</link>
		<comments>http://herr.ro/blog/2011/09/heap-sort/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:09:59 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=152</guid>
		<description><![CDATA[Another sort method is the HEAP SORT which uses the heap property.
We can use to sort or for priority queues.

So, if we have the following:]]></description>
			<content:encoded><![CDATA[<p>Another sort method is the HEAP SORT which uses the heap property.<br />
We can use to sort or for priority queues.</p>
<p>So, if we have the following:</p>
<p><strong><br />
A is a heap<br />
</strong><br />
A[0..heapsize[A]-1]<br />
<strong><br />
Heap property: A[PARENT(i)] &gt;= A[i]<br />
</strong><br />
Height of the heap is the height of the root, THETA(lg n)</p>
<p>where:</p>
<p><code><br />
int PARENT(i)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return (i-1)/2;<br />
}<br />
&nbsp;<br />
int LEFT(i)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 2*i+1;<br />
}<br />
&nbsp;<br />
RIGHT(i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 2*i+2;<br />
</code><br />
<br />
First, we must build A as a heap</p>
<p><code><br />
BUILD-HEAP(A)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;for( int i = (length[A]-2)/2; i &gt;= 0; i--)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HEAPIFY( A, i, length[A] );<br />
}<br />
&nbsp;<br />
&nbsp;<br />
void HEAPIFY( A, i, heapSize ) // the left and right are heaps and we make a heap for i<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int l = LEFT(i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;int r = RIGHT(i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;int largest = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( l &lt;= heapsize &amp;&amp; A[l] &gt; A[i] )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;largest = l;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;largest = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( r &lt;= heapsize &amp;&amp; A[r] &gt; A[largest] )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;largest = r;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (largest != i )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exchange( A[i] - A[largest] );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HEAPIFY(A, largest, heapSize );<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code><br />
<br />
Now we can sort A:<br />
<code><br />
void HEAP-SORT(A) // - time O(n lg n)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;BUILD-HEAP(A);<br />
&nbsp;&nbsp;&nbsp;&nbsp;int heapsize = length[A];<br />
&nbsp;&nbsp;&nbsp;&nbsp;for( int i = length[A]-1; i&gt;0; i--)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exchange( A[0] , A[i] );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;heapsize = heapsize-1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HEAPIFY(A, 0, heapSize );<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p><code><br />
int HEAP-MAXIMUM(A) //- time THETA(1)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return A[0];<br />
}<br />
</code></p>
<p><code><br />
HEAP-EXTRACTMAX(A) //- time O(lg n)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( heapsize[A] &lt; 1 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error "heap underflow"<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;max  = A[0];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;A[0] = A[ heapsize[A]-1 ]<br />
&nbsp;&nbsp;&nbsp;&nbsp;heapsize[A] = heapsize[A]-1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;HEAPIFY(A,0, heapSize[A] );<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return max;<br />
}<br />
</code>    </p>
<p><code><br />
HEAP-INSERT(A, key) //- time O(lg n)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;heapsize[A] = heapsize[A] + 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;i = heapsize[A];<br />
&nbsp;&nbsp;&nbsp;&nbsp;while ( i &gt; 0 &amp;&amp; A[PARENT(i)] &lt; key )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A[i] = A[PARENT(i)];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i    = PARENT(i);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;A[i] = key;<br />
</code><br />
<br />
Read more about it on <a href="http://en.wikipedia.org/wiki/Heap_sort" target="_blank">Wikipedia</a></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/heap-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick sort</title>
		<link>http://herr.ro/blog/2011/09/quick-sort/</link>
		<comments>http://herr.ro/blog/2011/09/quick-sort/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:09:30 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[quick]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=150</guid>
		<description><![CDATA[QUICK-SORT(A,p,q) - uses the divide et impera alghoritm

it separates the elements from <strong>p</strong> to <strong>q</strong> into 2 partitions from <strong>p</strong> to <strong>r</strong> and from <strong>r+1</strong> to <strong>q</strong> 
where all the elements from the first partition are smaller than the elements from the second one.

The worst running time is O(n^2) but on average is very efficient THETA(n log n)
For balanced partitioning  9 good and 1 bad -&#62; O(n log n)]]></description>
			<content:encoded><![CDATA[<p>QUICK-SORT(A,p,q) &#8211; uses the divide et impera alghoritm</p>
<p>it separates the elements from <strong>p</strong> to <strong>q</strong> into 2 partitions from <strong>p</strong> to <strong>r</strong> and from <strong>r+1</strong> to <strong>q</strong><br />
where all the elements from the first partition are smaller than the elements from the second one.</p>
<p>The worst running time is O(n^2) but on average is very efficient THETA(n log n)<br />
For balanced partitioning  9 good and 1 bad -&gt; O(n log n)</p>
<p><code><br />
&nbsp;<br />
<strong>void QUICKSORT</strong>(A,p,r)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( p &lt; r )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q = PARTITION(A, p, r);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QUICKSORT(A, p, q);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QUICKSORT(A, q+1, r);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
&nbsp;<br />
&nbsp;<br />
<strong>int PARTITION</strong>(A, p, r) //- rearrange the A[p..r]<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;x = A[p];        // pivot element<br />
&nbsp;&nbsp;&nbsp;&nbsp;i = p-1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;j = r+1;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;while (true)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( j--; j&gt;=p &amp;&amp; A[j] &gt; x; j-- );<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( i++; i&lt;=r &amp;&amp; A[i] &lt; x; i++ );<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( i &lt; j )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exchange( A[i] , A[j] );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return j;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</code><br />
&nbsp;<br />
<br />
To avoid the worst time of the algorithm use the randomize partition<br />
<code><br />
&nbsp;<br />
<strong>int RANDOMIZED-PARTITION</strong>(A, p, r)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;i = RANDOM(p, r);<br />
&nbsp;&nbsp;&nbsp;&nbsp;exchange A[p]-A[i];<br />
&nbsp;&nbsp;&nbsp;&nbsp;return PARTITION(A, p, r);<br />
}<br />
</code></p>
<p>Read more on <a href="http://en.wikipedia.org/wiki/Quicksort" target="_blank">Wikipedia</a></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/quick-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear sort</title>
		<link>http://herr.ro/blog/2011/09/linear-sort/</link>
		<comments>http://herr.ro/blog/2011/09/linear-sort/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:09:00 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=148</guid>
		<description><![CDATA[The most simple sort a[i] = 1 if i exists and 0 otherwise]]></description>
			<content:encoded><![CDATA[<p>The most simple sort</p>
<p><code><br />
a[i] = 1 if <strong>i</strong> exists and 0 otherwise<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/linear-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable Intellisense for Visual Studio</title>
		<link>http://herr.ro/blog/2011/09/disable-intellisense-for-visual-studio/</link>
		<comments>http://herr.ro/blog/2011/09/disable-intellisense-for-visual-studio/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:07:43 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[intellisense]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=146</guid>
		<description><![CDATA[There is a undocumented way to disable C++ Intellisense:
Rename or delete the following file:

&#60;VS root path&#62;\VC\vcpackages\feacp.dll

After doing this the vba macros will not work.

And reconsider using <a href="http://www.wholetomato.com/" target="_blank">Visual Assist</a>]]></description>
			<content:encoded><![CDATA[<p>There is a undocumented way to disable C++ Intellisense:<br />
Rename or delete the following file:</p>
<p>&lt;VS root path&gt;\VC\vcpackages\feacp.dll</p>
<p>After doing this the vba macros will not work.</p>
<p>And reconsider using <a href="http://www.wholetomato.com/" target="_blank">Visual Assist</a></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/disable-intellisense-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLite wrapper</title>
		<link>http://herr.ro/blog/2011/09/sqlite-wrapper/</link>
		<comments>http://herr.ro/blog/2011/09/sqlite-wrapper/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:06:43 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[Spamfilter]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=144</guid>
		<description><![CDATA[If you need a database to support your anti spam filter consider <a href="http://www.sqlite.org" target="_blank">SQLite</a> for an embedded database.

Use the following class to execute a query:

<code>
<strong>class SQLiteQuery</strong>
</code>]]></description>
			<content:encoded><![CDATA[<p>If you need a database to support your anti spam filter consider <a href="http://www.sqlite.org" target="_blank">SQLite</a> for an embedded database.</p>
<p>Use the following class to execute a query:<br />
<span id="more-144"></span><br />
<code><br />
//<br />
// SQLiteQuery helper<br />
//<br />
// use like this<br />
// SQLiteQuery sqlQuery( lpszPath, szQuery );<br />
// for( ; SUCCEEDED( sqlQuery.GetStatus() ); sqlQuery.GetNext() )<br />
// {<br />
//    CString strValue    = sqlQuery.GetCurrentAsText( 0 );<br />
// }<br />
//<br />
<strong>class SQLiteQuery</strong><br />
{<br />
public:<br />
//<br />
// constructor<br />
//<br />
<strong>SQLiteQuery</strong>( const TCHAR * lpszPath, const TCHAR * szQuery )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_pDatabase         = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_pStatementQuery   = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_result            = SQLITE_OK;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;Start( lpszPath, szQuery );<br />
}<br />
&nbsp;<br />
&nbsp;<br />
//<br />
// destructor<br />
//<br />
<strong>~SQLiteQuery</strong>()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;Stop();<br />
}<br />
&nbsp;<br />
//<br />
// get status<br />
//<br />
HRESULT <strong>GetStatus</strong>()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase &amp;&amp; m_pStatementQuery &amp;&amp; m_result == SQLITE_ROW )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return S_OK;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return E_FAIL;<br />
}<br />
&nbsp;<br />
//<br />
// get status exec<br />
//<br />
HRESULT <strong>GetStatusExec</strong>()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase &amp;&amp; m_pStatementQuery &amp;&amp; m_result == SQLITE_DONE )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return S_OK;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return E_FAIL;<br />
}<br />
&nbsp;<br />
//<br />
// go next<br />
//<br />
void <strong>GetNext</strong>()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase &amp;&amp; m_pStatementQuery )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_result = sqlite3_step ( m_pStatementQuery );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( m_result != SQLITE_ROW )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
&nbsp;<br />
//<br />
// get column text or column int<br />
//<br />
CString <strong>GetCurrentAsText</strong>( int column = 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase == NULL || m_pStatementQuery == NULL )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return CString( _T("") );<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;TCHAR * szValue   = (TCHAR *) sqlite3_column_text16( m_pStatementQuery, column );<br />
&nbsp;&nbsp;&nbsp;&nbsp;return CString( szValue );<br />
}<br />
&nbsp;<br />
int <strong>GetCurrentAsInt</strong>( int column = 0 )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase == NULL || m_pStatementQuery == NULL )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return (int) sqlite3_column_int( m_pStatementQuery, column );<br />
}<br />
&nbsp;<br />
&nbsp;<br />
<strong>protected</strong>:<br />
//<br />
// start<br />
//<br />
void <strong>Start</strong>( const TCHAR * lpszPath, const TCHAR * szQuery )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;// open<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_result    = sqlite3_open16( lpszPath, &amp;m_pDatabase );<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_result != SQLITE_OK || m_pDatabase == NULL )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pDatabase         = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;// prepare<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_result    = sqlite3_prepare16_v2( m_pDatabase, szQuery, -1, &amp;m_pStatementQuery, NULL );<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_result != SQLITE_OK || m_pStatementQuery == NULL )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_pStatementQuery   = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;// SQLITE_DONE || SQLITE_ROW<br />
&nbsp;&nbsp;&nbsp;&nbsp;//<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_result    = sqlite3_step ( m_pStatementQuery );<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_result != SQLITE_ROW &amp;&amp; m_result != SQLITE_DONE )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
&nbsp;<br />
//<br />
// stop<br />
//<br />
void <strong>Stop</strong>()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pStatementQuery )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_result        = sqlite3_finalize( m_pStatementQuery );<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( m_pDatabase )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_result        = sqlite3_close( m_pDatabase );<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_pStatementQuery   = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_pDatabase         = NULL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;m_result            = SQLITE_ERROR;<br />
&nbsp;<br />
}<br />
&nbsp;<br />
protected:<br />
&nbsp;&nbsp;&nbsp;&nbsp;sqlite3 *           m_pDatabase;<br />
&nbsp;&nbsp;&nbsp;&nbsp;sqlite3_stmt *   m_pStatementQuery;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int                   m_result;<br />
&nbsp;<br />
};<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/sqlite-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular expressions</title>
		<link>http://herr.ro/blog/2011/09/regular-expressions/</link>
		<comments>http://herr.ro/blog/2011/09/regular-expressions/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:06:05 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Devel]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[regular]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=142</guid>
		<description><![CDATA[<img src="http://herr.ro/images/main/lupa.jpg" alt="regular expressions" />
Recently I wanted to test and validate an email address so the best way to do is to use the regular expressions.
The simple way is the use the one from Windows. (in the vbscript.dll)

<code>
// import the second table from vbscript
#<strong>import </strong>&#60;vbscript.dll&#62; tlbid(2) no_namespace named_guids raw_interfaces_only
</code>]]></description>
			<content:encoded><![CDATA[<p><img src="http://herr.ro/images/main/lupa.jpg" alt="regular expressions" /><br />
Recently I wanted to test and validate an email address so the best way to do is to use the regular expressions.<br />
The simple way is the use the one from Windows. (in the vbscript.dll)</p>
<p><code><br />
// import the second table from vbscript<br />
#<strong>import </strong>&lt;vbscript.dll&gt; tlbid(2) no_namespace named_guids raw_interfaces_only<br />
<br />CComBSTR bstrEmailValidation (  L"<strong>^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[A-Z]{2,6}$</strong>" );<br />
<br />CComPtr&lt;<strong>IRegExp</strong>&gt;    m_pRegExp;<br />
bool                bIsValid  = false;<br />
<br />
HRESULT m_hrCoInit = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );<br />
if ( SUCCEEDED( m_hrCoInit ) )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;HRESULT hr = <strong>m_pRegExp</strong>.CoCreateInstance( __uuidof(RegExp) );<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( SUCCEEDED( hr ) )<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr = m_pRegExp-&gt;put_IgnoreCase  ( VARIANT_TRUE );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr = m_pRegExp-&gt;put_Global      ( VARIANT_TRUE );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr = m_pRegExp-&gt;put_Pattern     ( bstrEmailValidation );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VARIANT_BOOL bMatch = VARIANT_FALSE;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr     = m_pRegExp-&gt;<strong>Test</strong>( CComBSTR(<strong>strText</strong>), &amp;bMatch );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( SUCCEEDED( hr ) )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bIsValid = (bMatch == VARIANT_FALSE) ? false : true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
<br />
// and later uninit<br />
m_pRegExp = NULL;<br />
if ( SUCCEEDED( m_hrCoInit ) )<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;CoUninitialize();<br />
}<br />
</code></p>
<p>If you need more info about regular expressions read this &#8220;<a href="http://www.regular-expressions.info/email.html" target="_blank">How to Find or Validate an Email Address</a>&#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spamfilter links</title>
		<link>http://herr.ro/blog/2011/09/spamfilter-links/</link>
		<comments>http://herr.ro/blog/2011/09/spamfilter-links/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:05:11 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Spamfilter]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=140</guid>
		<description><![CDATA[Here are the most important links for BullGuard Spamfilter: The description page at http://www.bullguard.com/why/bullguard-spamfilter.aspx and the help page at http://media.bullguard.com/is9_help/EN/SF/module_spamfilter_overview.html]]></description>
			<content:encoded><![CDATA[<p><img src="http://herr.ro/images/main/bullguard.png" alt="bullguard spamfilter" /><br />
Here are the most important links for BullGuard Spamfilter:</p>
<p>The description page at <a href="http://www.bullguard.com/why/bullguard-spamfilter.aspx" target="_blank">http://www.bullguard.com/why/bullguard-spamfilter.aspx</a></p>
<p>and the help page at <a href="http://media.bullguard.com/is9_help/EN/SF/module_spamfilter_overview.html" target="_blank">http://media.bullguard.com/is9_help/EN/SF/module_spamfilter_overview.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/spamfilter-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autologin in Win7</title>
		<link>http://herr.ro/blog/2011/09/autologin-in-win7/</link>
		<comments>http://herr.ro/blog/2011/09/autologin-in-win7/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:03:02 +0000</pubDate>
		<dc:creator>Cristian Herghelegiu</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[autologin]]></category>
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://herr.ro/?p=133</guid>
		<description><![CDATA[Follow this stepst to do the autologin in Windows 7 (but is not recommended) Press the Windows key + R on your keyboard to launch the &#8220;Run&#8221; dialog box. Type in &#8220;control userpasswords2&#8221; and press Enter. The User Accounts window will display. Uncheck the option &#8220;Users must enter a user name and password to use [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://herr.ro/images/main/win7.png" alt="autologin" width="120px"><br />
Follow this stepst to do the autologin in Windows 7 (but is not recommended)</p>
<ul>
<li>Press the <strong>Windows key + R</strong> on your keyboard to launch the &#8220;Run&#8221; dialog box.</li>
<li>Type in &#8220;<strong>control userpasswords2</strong>&#8221; and press Enter.</li>
<li>The User Accounts window will display.</li>
<li><strong>Uncheck </strong>the option &#8220;Users must enter a user name and password to use this computer&#8221;<br />
Click &#8220;OK&#8221;</li>
<li>You will then be prompted to enter the current password and confirm it.</li>
<li>After doing so, you will no longer be prompted to enter your password upon login.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://herr.ro/blog/2011/09/autologin-in-win7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

