<?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>Th30z - Coding on the Fly &#187; Tips</title>
	<atom:link href="http://th30z.netsons.org/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://th30z.netsons.org</link>
	<description>Matteo Bertozzi, Objective-C, Cocoa, C, C++, Qt4, iPhone, Mac OS X, Open Moko, Matteo Bertozzi Development</description>
	<lastBuildDate>Sun, 22 Nov 2009 09:47:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[TIP] XCode Header Search Path</title>
		<link>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/</link>
		<comments>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 10:26:08 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1243</guid>
		<description><![CDATA[For many of you, this sounds like a stupid thing. But for those that just use gcc -I from command line, can be a pain find how to do it.
So, the problem is. How can I specify my Include path in XCode (gcc -I./mypath).

Tap on your project target, and click &#8220;Get Info&#8220;, tap on &#8220;Build&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>For many of you, this sounds like a stupid thing. But for those that just use gcc -I from command line, can be a pain find how to do it.</p>
<p>So, the problem is. How can I specify my Include path in XCode (gcc -I./mypath).</p>
<p style="text-align: center;"><a href="http://th30z.netsons.org/wp-content/uploads/XCode-SearchHeaderPath1.png"><img class="aligncenter size-full wp-image-1245" title="XCode Search Header Path" src="http://th30z.netsons.org/wp-content/uploads/XCode-SearchHeaderPath1.png" alt="XCode Search Header Path" width="566" height="279" /></a></p>
<p>Tap on your project target, and click &#8220;<strong>Get Info</strong>&#8220;, tap on &#8220;<strong>Build</strong>&#8221; tab and search &#8220;Path&#8221; as showed in the figure above. Then click on the &#8220;<strong>Header Search Paths</strong>&#8221; options and add your favorite include paths for selected target.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[TIP] Generic Key Comparer</title>
		<link>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/</link>
		<comments>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 17:49:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Distributed Computation]]></category>
		<category><![CDATA[Key Comparer]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1133</guid>
		<description><![CDATA[I&#8217;m back to code on my &#8220;Cloud&#8221; FileSystem, and distributed tools. And here is a little tip.
When you&#8217;re working on Data, probably you store it as a Key-Value Pair on a BTree or something similar, and maybe this key is an aggregation of information&#8230; Maybe you&#8217;ve one bit of flag, N bytes of ParentKey, and [...]]]></description>
			<content:encoded><![CDATA[<p><em>I&#8217;m back to code on my &#8220;Cloud&#8221; FileSystem, and distributed tools. And here is a little tip.</em></p>
<p>When you&#8217;re working on Data, probably you store it as a Key-Value Pair on a BTree or something similar, and maybe this key is an aggregation of information&#8230; Maybe you&#8217;ve one bit of flag, N bytes of ParentKey, and others&#8230;</p>
<p>Now, the problem is&#8230; How can a &#8220;foreign&#8221; server sort correctly my keys? The solution is to send to the server the information on how to sort.. or a method to do it&#8230; but today, I&#8217;m focusing on the first one.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.png"><img class="aligncenter size-full wp-image-1138" title="Generic Key" src="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.png" alt="Generic Key" width="428" height="133" /></a></p>
<p>The code below show an implementation in Python of the Generic Key Comparer. At the end of the source code you can find an usage example. The Full Source Code is available here. <a href="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.py">Generic Key Comparer Source Code</a>.<br />
<code></p>
<pre>
def __indexOfOne(data, tokens, offset):
   for i in xrange(offset, len(data)):
   if data[i] in tokens:
      return i
   return -1

def rawComparer(data1, data2, comparer):
   typeIds = [ 's', 'u', 'c', 'i', 'f', 'x' ]
   pyBinMap = {
      ('u', 1): 'B', ('u', 2): 'H', ('u', 4):'L', ('u', 8):'Q',
      ('i', 1): 'b', ('i', 2): 'h', ('i', 4):'l', ('i', 8):'q',
      ('f', 4): 'f', ('f', 8): 'd'
   }

   p = i = 0
   while i &lt; len(comparer):
      nextIdx = __indexOfOne(comparer, typeIds, i + 1)
      if (nextIdx &lt; 0): nextIdx = len(comparer)

      format = None
      length = 1 if (i + 1) == nextIdx else int(comparer[i+1:nextIdx])
      if comparer[i] == 's':
         format = str(length) + 's'
      elif comparer[i] == 'c':
         format = 'c'
      elif (comparer[i], length) in pyBinMap:
         format = pyBinMap[(comparer[i], length)]         

      if format != None:
         d1 = struct.unpack(format, data1[p:p+length])[0]
         d2 = struct.unpack(format, data2[p:p+length])[0]

         if d1 &lt; d2:
            return -1
         elif d1 &gt; d2:
            return 1         

      p += length
      i = nextIdx
   return 0

# Usage Example
if __name__ == '__main__':
  data1 = struct.pack('4sLch', 'test', 10, 'A', -3)
  data2 = struct.pack('4sLch', 'test', 10, 'A', -3)
  print 'Equal (test 10 A -3)', rawComparer(data1, data2, 's4u4ci2')

  data1 = struct.pack('4sLch', 'test', 10, 'A', 1)
  data2 = struct.pack('4sLch', 'test', 10, 'A', 0)
  print '(test 10 A 1) > (test 10 A 0)', rawComparer(data1, data2, 's4u4ci2')

  data1 = struct.pack('4sLch', 'test', 10, 'A', 0)
  data2 = struct.pack('4sLch', 'test', 10, 'A', 1)
  print '(test 10 A 0) < (test 10 A 1)', rawComparer(data1, data2, 's4u4ci2')
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TIP] Non Blocking C Read</title>
		<link>http://th30z.netsons.org/2009/05/tip-non-blocking-c-read/</link>
		<comments>http://th30z.netsons.org/2009/05/tip-non-blocking-c-read/#comments</comments>
		<pubDate>Mon, 11 May 2009 11:10:05 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=858</guid>
		<description><![CDATA[This is Just a simple code that maybe all the Linux C Developer knows, but if someone is still learning, This is a function that wrap the standard read function adding the non blocking feature. It&#8217;s Really useful in relation with Sockets.


int nonblock_read (int fd, char *buffer, size_t bufsize, int timeout) {
  if (timeout [...]]]></description>
			<content:encoded><![CDATA[<p>This is Just a simple code that maybe all the Linux C Developer knows, but if someone is still learning, This is a function that wrap the standard read function adding the non blocking feature. It&#8217;s Really useful in relation with Sockets.<br />
<code></p>
<pre>
int nonblock_read (int fd, char *buffer, size_t bufsize, int timeout) {
  if (timeout &gt; 0) {
    struct timeval tv;
    fd_set rfds;

    FD_ZERO(&amp;rfds);
    FD_SET(fd, &amp;rfds);

    tv.tv_sec = 0;
    tv.tv_usec = timeout * 1000;

    if (select(1, &amp;rfds, NULL, NULL, &amp;tv) &lt;= 0)
      return(-ETIME);
  }

  return(read(fd, buffer, bufsize));
}
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/05/tip-non-blocking-c-read/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TIP] Words Tokenization</title>
		<link>http://th30z.netsons.org/2009/04/tip-words-tokenization/</link>
		<comments>http://th30z.netsons.org/2009/04/tip-words-tokenization/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 12:03:18 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tokenization]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=761</guid>
		<description><![CDATA[Sometimes is useful to split the input text in a list of words to Indexing or Searching data.
Here is how to extract words from a sentence in C.


char str[] = &#34;Hi, I'm a test. (This is just a test). &#34;
             &#34;Join The #qt [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes is useful to split the input text in a list of words to Indexing or Searching data.<br />
Here is how to extract words from a sentence in C.<br />
<code></p>
<pre>
char str[] = &quot;Hi, I'm a test. (This is just a test). &quot;
             &quot;Join The #qt IRC Channel!&quot;
             &quot;GNU/Linux - theo@gmail.com&quot;;
char delims[] = &quot; !\&quot;#$%&amp;\'()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~&quot;;

char *result = NULL;
result = strtok(str, delims);
while(result != NULL) {
    printf(&quot;%s\n&quot;, result);
    result = strtok(NULL, delims);
}
</pre>
<p></code><br />
&#8230;and this is the Qt way.<br />
<code></p>
<pre>
QString str = &quot;Hi, I'm a test. (This is just a test). &quot;
        &quot;Join The #qt IRC Channel! GNU/Linux - theo@gmail.com&quot;;
QString delim = QRegExp::escape(&quot; !\&quot;#$%&amp;\'()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~&quot;);
QRegExp regexp(QString(&quot;[%1]&quot;).arg(delim),Qt::CaseSensitive,QRegExp::RegExp2);
qDebug() &lt;&lt; str.split(regexp, QString::SkipEmptyParts);
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/04/tip-words-tokenization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSSL: License Key with RSA</title>
		<link>http://th30z.netsons.org/2008/11/openssl-license-key-with-rsa/</link>
		<comments>http://th30z.netsons.org/2008/11/openssl-license-key-with-rsa/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 13:38:26 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[OpenSSL]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=308</guid>
		<description><![CDATA[In the last days I&#8217;ve played a bit with C libraries like OpenSSL and SQLite. The first post after Site downtime is dedicated to OpenSSL.
how do can you create your own license system for your application? With OpenSSL and less than 10 lines of code, you can do it. Take a look at the code [...]]]></description>
			<content:encoded><![CDATA[<p>In the last days I&#8217;ve played a bit with C libraries like OpenSSL and SQLite. The first post after Site downtime is dedicated to OpenSSL.<br />
how do can you create your own license system for your application? With OpenSSL and less than 10 lines of code, you can do it. Take a look at the code below.</p>
<pre>
...
unsigned char checkDigest[SHA_DIGEST_LENGTH];
unsigned char shaDigest[SHA_DIGEST_LENGTH];
const char *userKey = "Matteo License";
unsigned char *signature = NULL;
unsigned int signatureLength = 0;

/* Generate Your RSA Key Pair */
RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);

/* Generate SHA1 of User Key */
SHA1(userKey, strlen(userKey), shaDigest);

/* Create License Key for the User Key */
signature = OPENSSL_malloc(RSA_size(rsa));
signatureLength = RSA_private_encrypt(SHA_DIGEST_LENGTH, shaDigest,
                                 signature, rsa, RSA_PKCS1_PADDING);

/* Check if User Signature is a valid License Key */
if (RSA_public_decrypt(signatureLength, signature, checkDigest,
                                rsa, RSA_PKCS1_PADDING) != SHA_DIGEST_LENGTH)
{
      /* Valid License Key */
} else {
      /* Invalid License Key */
}

free(signature);
RSA_free(rsa);
...
</pre>
<p>You need to store the RSA Public Key in your app and then give to each user a generated signature, and it&#8217;s all.<br />
Ok, this is a really base example (less than 10 lines of code) if you don&#8217;t want reinvent a License Key system, take a look at AquaticPrime Framework (<a href="http://www.aquaticmac.com/">http://www.aquaticmac.com/</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/openssl-license-key-with-rsa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TIP] Test TCP Port with PHP</title>
		<link>http://th30z.netsons.org/2008/09/tip-test-tcp-port-with-php/</link>
		<comments>http://th30z.netsons.org/2008/09/tip-test-tcp-port-with-php/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 07:19:22 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=184</guid>
		<description><![CDATA[I need to test if specified TCP Port on specified Host is opened or Not, and i need to do it from a Web Service&#8230; This is my Solution a simple &#8220;ping&#8221; method written in PHP.

function qPing ($host, $port, $timeout = 5) {
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if [...]]]></description>
			<content:encoded><![CDATA[<p>I need to test if specified TCP Port on specified Host is opened or Not, and i need to do it from a Web Service&#8230; This is my Solution a simple &#8220;ping&#8221; method written in PHP.</p>
<pre>
function qPing ($host, $port, $timeout = 5) {
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) return(1);

    if (!socket_set_nonblock($socket))
        return(2);

    $time = time();
    while (!@socket_connect($socket, $host, $port)) {
        $err = socket_last_error($socket);
        if ($err == 115 || $err == 114) {
            if ((time() - $time) >= $timeout) {
                socket_close($socket);
                return(3);    # Connection timed out.
            }
            usleep(500);
            continue;
        }
        echo $err . ' ' . socket_strerror($err) . "\n";
        return(4);
    }

    socket_close($socket);
    return(0);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/09/tip-test-tcp-port-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
