<?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>Bit Matrix &#187; Technical</title>
	<atom:link href="http://blog.bit-matrix.com/category/technical/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bit-matrix.com</link>
	<description>Tech. Code. Linux. MySQL. Ones. Zeroes.</description>
	<lastBuildDate>Tue, 31 Aug 2010 01:10:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Facebook Cookie Bug? REST API data_getCookies()</title>
		<link>http://blog.bit-matrix.com/2010/07/22/facebook-cookie-bug-rest-api-data_getcookies/</link>
		<comments>http://blog.bit-matrix.com/2010/07/22/facebook-cookie-bug-rest-api-data_getcookies/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 00:26:22 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=148</guid>
		<description><![CDATA[I have noticed some of the metrics on my Facebook app going missing. In particular, the tracking of the user installation. This relies on Facebook&#8217;s cookies which are being set on the post-authorization page and then re-read on the main page of the site in order to record that the user installed the app. The [...]]]></description>
			<content:encoded><![CDATA[<p>I have noticed some of the metrics on my Facebook app going missing. In particular, the tracking of the user installation. This relies on Facebook&#8217;s cookies which are being set on the post-authorization page and then re-read on the main page of the site in order to record that the user installed the app. The reason why you must use the Facebook cookies and not your own is that it is Facebook hitting your server on the post-authorize and not the user themselves.</p>
<p>The calls I am using to record and retrieve these cookies are based on the old REST API:<br />
<code>$facebook->api_client->data_setCookie(user_id, cookie_name, value, expiry_time)</code><br />
<code>$facebook->api_client->data_getCookies(user_id, cookie_name)</code></p>
<p>The proper data format that Facebook is <i>supposed</i> to return looks like this:<br />
<code><br />
[<br />
  {<br />
    "uid": "542432762",<br />
    "name": "test",<br />
    "value": null,<br />
    "expires": null,<br />
    "path": null<br />
  }<br />
]<br />
</code></p>
<p>However, for the last few days, Facebook seems to be returning the data as a numerically-indexed array and not a array of hashes as above:<br />
<code><br />
[99990041857023, "cookie_name", "value", "expiry", "path"]<br />
</code></p>
<p>You can temporarily fix your app by translating this array into the equivalent hash, like this PHP snippet does:</p>
<p><code><br />
if( !isset($c['name']) )<br />
			{<br />
				$c = array(<br />
					'uid'     => $c[0],<br />
					'name'    => $c[1],<br />
					'value'   => $c[2],<br />
					'expires' => $c[3],<br />
					'path'    => $c[4]<br />
				);<br />
			}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/07/22/facebook-cookie-bug-rest-api-data_getcookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate your own Wordpress Permalink without GUIDs from database</title>
		<link>http://blog.bit-matrix.com/2010/03/01/generate-your-own-wordpress-permalink-without-guids-from-database/</link>
		<comments>http://blog.bit-matrix.com/2010/03/01/generate-your-own-wordpress-permalink-without-guids-from-database/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 19:25:31 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[guid]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=134</guid>
		<description><![CDATA[If you are generating links to your blog articles via some other mechanism than Wordpress itself you usually have to use the guid database field. This is the unique global indentifier of the post. In reality it is not globally unique but only unique to your blog.
Typically, the guid in the database will look something [...]]]></description>
			<content:encoded><![CDATA[<p>If you are generating links to your blog articles via some other mechanism than Wordpress itself you usually have to use the <b>guid</b> database field. This is the unique global indentifier of the post. In reality it is not globally unique but only unique to your blog.<span id="more-134"></span></p>
<p>Typically, the guid in the database will look something like this:</p>
<blockquote><p>http://blog.bit-matrix.com/?p=2411</p></blockquote>
<p>You can use this perfectly fine but it will hurt your SEO since search sites prefer descriptive links such as:</p>
<blockquote><p>http://blog.bit-matrix.com/2010/02/10/google-buzz-a-privacy-disaster</p></blockquote>
<p>As it turns out, you can easily construct this link from the database yourself. Wordpress will recognize the format of the link and display the appropriate post. The query to construct this is quite simple, all we need is a little date formatting:</p>
<blockquote><p>SELECT CONCAT(DATE_FORMAT(post_date,&#8217;%Y/%m/%d/&#8217;),post_name) AS permalink FROM wp_posts WHERE post_status=&#8217;publish&#8217;;</p></blockquote>
<p>This will return all the published post guid&#8217;s in the following format:</p>
<blockquote><p>2010/02/10/google-buzz-a-privacy-disaster</p></blockquote>
<p>That&#8217;s all!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/03/01/generate-your-own-wordpress-permalink-without-guids-from-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[haXe] Failed to load library : std.ndll</title>
		<link>http://blog.bit-matrix.com/2010/02/18/haxe-failed-to-load-library-std-ndll/</link>
		<comments>http://blog.bit-matrix.com/2010/02/18/haxe-failed-to-load-library-std-ndll/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:00:26 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=135</guid>
		<description><![CDATA[If, like me, you just started playing around with haXe and you might get the following error when including an external Flash resource:
Uncaught exception &#8211; load.c(232) : Failed to load library : std.ndll (std.ndll: cannot open shared object file: No such file or directory)
The solution is simple, you just need to install neko and neko-dev:
sudo [...]]]></description>
			<content:encoded><![CDATA[<p>If, like me, you just started playing around with haXe and you might get the following error when including an external Flash resource:</p>
<blockquote><p>Uncaught exception &#8211; load.c(232) : Failed to load library : std.ndll (std.ndll: cannot open shared object file: No such file or directory)</p></blockquote>
<p>The solution is simple, you just need to install neko and neko-dev:</p>
<blockquote><p>sudo apt-get install neko neko-dev</p></blockquote>
<p>Now simply run the setup:</p>
<blockquote><p>sudo haxelib setup</p></blockquote>
<p>Happy haXe-ing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/02/18/haxe-failed-to-load-library-std-ndll/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scary Privacy Quotes</title>
		<link>http://blog.bit-matrix.com/2010/02/10/scary-privacy-quotes/</link>
		<comments>http://blog.bit-matrix.com/2010/02/10/scary-privacy-quotes/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:35:55 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Rants]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[The Future]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[1984]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Orwell]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=122</guid>
		<description><![CDATA[&#8220;If you have something that you don&#8217;t want anyone to know, maybe you shouldn&#8217;t be doing it in the first place.&#8221;
- Google CEO Eric Schmidt

&#8220;&#8230;doing a privacy change for 350 million users is not the kind of thing that a lot of companies would do. But we viewed that as a really important thing, to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;If you have something that you don&#8217;t want anyone to know, maybe you shouldn&#8217;t be doing it in the first place.&#8221;</p>
<p>- <strong>Google</strong> CEO Eric Schmidt
</p></blockquote>
<blockquote><p>&#8220;&#8230;doing a privacy change for <b>350 million users</b> is not the kind of thing that a lot of companies would do. But we viewed that as a really important thing, to always keep a beginner&#8217;s mind and what would we do if we were starting the company now and <b>we decided that these would be the social norms now and we just went for it.</b>&#8221;</p>
<p>- <strong>Facebook</strong> CEO Mark Zuckerberg
</p></blockquote>
<blockquote><p>&#8220;There was of course no way of knowing whether you were being watched at any given moment&#8230; It was even conceivable that they watched everybody all the time.</p>
<p>But at any rate they could plug into your wire whenever they wanted to. You had to live &#8211; did live, from habit that became instinct &#8211; in the assumption that every sound you made was overheard, and except in darkness, every movement scrutinized.&#8221;</p>
<p>- George Orwell, <strong>1984</strong>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/02/10/scary-privacy-quotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Buzz: A Privacy Disaster</title>
		<link>http://blog.bit-matrix.com/2010/02/10/google-buzz-a-privacy-disaster/</link>
		<comments>http://blog.bit-matrix.com/2010/02/10/google-buzz-a-privacy-disaster/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:07:24 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[The Future]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[buzz]]></category>
		<category><![CDATA[do no evil]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google buzz]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=118</guid>
		<description><![CDATA[As someone who is no friend to Facebook, I was quite interested to hear that Google will be stepping into the social networking world with their newest product: Google Buzz. The introductory video looked good enough showing a slick, simple interface, easy message, photo and video posting and an good time to be had by [...]]]></description>
			<content:encoded><![CDATA[<p>As someone who is no friend to Facebook, I was quite interested to hear that Google will be stepping into the social networking world with their newest product: Google Buzz. The introductory video looked good enough showing a slick, simple interface, easy message, photo and video posting and an good time to be had by all. Perhaps, I thought, this means Facebook&#8217;s hegemony over the social networking sphere was coming to a close. Anything is better than Facebook&#8217;s blatant disregard for privacy right? Wrong.<span id="more-118"></span></p>
<h2>Et tu, Google?</h2>
<p>Why is it that the default modus operandi of every Internet company is to blatantly violate your privacy as a first rule of business?  Google, surely, is a company that should not need a cheap trick like this in order to promote their product. A company whose &#8220;<a href="http://www.google.com/corporate/tenthings.html">Do no evil.</a>&#8221; slogan seems to only apply as far as showing you the most targeted ads and not blatantly deceiving you. Google has embraced Facebook overnight revelation that <a href="http://www.readwriteweb.com/archives/facebooks_zuckerberg_says_the_age_of_privacy_is_ov.php">people don&#8217;t want or expect</a> and seems to have launched Buzz as an example of this brave new vision.</p>
<p>Buzz outdoes Facebook when it comes to airing all your dirty laundry to the searchable metaverse. The privacy controls in Buzz are all strictly opt-out. You might miss this fact, as I suspect most people will, unless you are naturally suspicious of any site that has access to too much information about you. And yes, we should all be suspicious of them.</p>
<p>Buzz will show your real name and make it searchable to everyone. It will also show the world who you are following and who is following you. Since it populated your follow list from your email contacts, it essentially reveals your contact list to the world. It also shows your Buzz messages on this publicly searchable profile so if you have something private to say to your friend or spouse, make sure you use Gmail and not Buzz. Of course, they both show up in the same Inbox so mistakes are likely.</p>
<p>What makes Google&#8217;s actions more inflammatory than Facebook&#8217;s is that your GMail data is used to generate this public content. As an email system, GMail implies privacy and strict control over who your messages go to and who can see them. Therefore, all  contacts and data in GMail were added by users with the expectation of full privacy. Buzz will, however, happily tell the world who you&#8217;ve been emailing the most. Beware.</p>
<p>There has already been a lot of complaints about this so-called privacy flaws. But can anyone really believe that this was a mistake in the design? That Google didn&#8217;t know the implications of making Buzz operate like this? They only need to look at Beacon and other privacy scandals Facebook has gone through to know where this leads.</p>
<p>One would think that launching a product like this that will expose the information of millions of users should take a bit of care and preparation. However, as of this time, Buzz doesn&#8217;t even have a Privacy Policy listed on Google&#8217;s <a href="http://www.google.com/support/accounts/bin/answer.py?hl=en&#038;answer=147806">Policy by Product</a> page!</p>
<p>There is no doubt that Google knew exactly what it was doing when they made Buzz work the way it does. I predict that they will run it for a few weeks as is, making it accumulate users, and then they will &#8220;fix the problem&#8221; due to user complaints. By this time the damage will be done and this privacy &#8220;flaw&#8221; will have served its purpose.</p>
<p>Should you decide to turn Buzz off, there is microscopic link at the very bottom of the page that will allow you to do this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/02/10/google-buzz-a-privacy-disaster/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lower-case all URLs with Apache mod_rewrite</title>
		<link>http://blog.bit-matrix.com/2010/02/05/lower-case-all-urls-with-apache-mod_rewrite/</link>
		<comments>http://blog.bit-matrix.com/2010/02/05/lower-case-all-urls-with-apache-mod_rewrite/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 20:46:36 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=109</guid>
		<description><![CDATA[Search engines, like Google, will index URLs on your site in a case-sensitive fashion, so www.yoursite.com/iamtest shows up as a different page than www.yoursite.com/iAmTest. This has negative consequences for your search rankings as these different URLs will be interpreted as duplicate content.
In this case we want to re-direct our users and any bots to the [...]]]></description>
			<content:encoded><![CDATA[<p>Search engines, like Google, will index URLs on your site in a case-sensitive fashion, so www.yoursite.com/iamtest shows up as a different page than www.yoursite.com/iAmTest. This has negative consequences for your search rankings as these different URLs will be interpreted as duplicate content.<span id="more-109"></span></p>
<p>In this case we want to re-direct our users and any bots to the same version of the URL (i.e. all lowercase). If you are running Apache, make sure <b>mod_rewrite</b> is installed and make the following changes to your configuration.</p>
<p>1. In your server config or virtual host file:<br />
<code>RewriteMap  lc int:tolower</code></p>
<p>2. In your .htaccess file at the root of your site:<br />
<code><br />
# Lower-case and 301 all requests<br />
RewriteEngine On<br />
RewriteCond %{REQUEST_URI} [A-Z]<br />
RewriteRule ^(.*)$ /${lc:$1} [L,R=301]<br />
</code></p>
<p><b>Note:</b> Beware that some standard files are mixed case and might be broken by doing this (such as AC_RunActiveContent.js).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2010/02/05/lower-case-all-urls-with-apache-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to install PHP 5.2 on CentOS 5</title>
		<link>http://blog.bit-matrix.com/2009/10/22/how-to-install-php-52-on-centos-5/</link>
		<comments>http://blog.bit-matrix.com/2009/10/22/how-to-install-php-52-on-centos-5/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 06:43:16 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[centos 5]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php 5.2]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=66</guid>
		<description><![CDATA[I recently needed to install PHP 5.2 on CentOS 5.3. This version of CentOS comes with PHP 5.1 but, in order to run phpMyAdmin, I needed 5.2. The CentOS software repositories are, unfortunately, still stuck with 5.1 and the only way to get a newer version of PHP installed via the package manager (yum) is [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to install PHP 5.2 on CentOS 5.3. This version of CentOS comes with PHP 5.1 but, in order to run phpMyAdmin, I needed 5.2. The CentOS software repositories are, unfortunately, still stuck with 5.1 and the only way to get a newer version of PHP installed via the package manager (yum) is to add another repository that has a newer version.<span id="more-66"></span></p>
<p>For this we will use the CentOS testing repository:<br />
<code><br />
cd /etc/yum.repos.d/<br />
sudo wget http://dev.centos.org/centos/5/CentOS-Testing.repo<br />
sudo rpm --import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing<br />
</code></p>
<p>Now we can fetch package information about PHP using the new repository:<br />
<code><br />
yum --enablerepo=c5-testing info php<br />
</code></p>
<p>Check the version number. If it is what you need you can go ahead and install it using yum:<br />
<code><br />
sudo  yum --enablerepo=c5-testing update php<br />
</code></p>
<p>Assuming that worked, you can now restart Apache and be on your way:<br />
<code><br />
sudo /etc/init.d/httpd restart<br />
</code></p>
<h4>Memcache</h4>
<p>If, like me, you were using memcache you might run into a problem where memcache never got updated to the proper version because it did not exist in the CentOS testing repository. The memcache module on the system ends up with a different PHP API version than is required by the new version of PHP you just installed.</p>
<p>Upon starting PHP you might see a warning similar to this:<br />
<code><br />
Module compiled with API 20040429<br />
PHP compiled with API 20060613<br />
</code></p>
<p>Again, we will add a new repository from <a href="http://blog.famillecollet.com/pages/Config-en">Remi Collet</a>. The steps should be as follows:<br />
<code><br />
cd /etc/yum.repos.d/<br />
wget http://rpms.famillecollet.com/remi-enterprise.repo<br />
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm<br />
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm<br />
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm<br />
</code></p>
<p>Now we can install the newest memcache library:<br />
<code><br />
sudo yum --enablerepo=remi install libmemcached\*<br />
</code></p>
<p>Build the PHP module using Pecl (you might have to install php-devel packages for this):<br />
<code><br />
pecl install memcache<br />
</code></p>
<p>Edit /etc/php.d/memcache.ini and add:<br />
<code><br />
extension=memcache.so<br />
</code></p>
<p>Restart Apache:<br />
<code><br />
sudo /etc/init.d/httpd restart<br />
</code></p>
<p>With a little bit of luck you will now have PHP 5.2.x and Memcache!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2009/10/22/how-to-install-php-52-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Replication &#8211; Silent Timeout Failure</title>
		<link>http://blog.bit-matrix.com/2009/07/19/mysql-replication-silent-failure/</link>
		<comments>http://blog.bit-matrix.com/2009/07/19/mysql-replication-silent-failure/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 04:19:23 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=62</guid>
		<description><![CDATA[I have been encountering a strange error that causes MySQL replication to stop working without any errors reported via SHOW SLAVE STATUS. The command reports everything running ok and that the slave is caught up with the master (seconds behind master=0).
However, looking into the running processes via SHOW FULL PROCESSLIST I noticed that the thread [...]]]></description>
			<content:encoded><![CDATA[<p>I have been encountering a strange error that causes MySQL <a title="What is replication?" href="/2008/11/26/what-is-mysql-replication/">replication</a> to stop working without any errors reported via SHOW SLAVE STATUS. The command reports everything running ok and that the slave is caught up with the master (seconds behind master=0).</p>
<p>However, looking into the running processes via SHOW FULL PROCESSLIST I noticed that the thread reading the binary log data from the master has disappeared mysteriously.<br />
<span id="more-62"></span></p>
<p>Normally you should see two threads related to replication running on a slave server under the <em>system user</em>. One for reading the binary log data from the master and the other one for executing fetched data from the relay log:</p>
<pre style="font-size:9px;">
mysql&gt;SHOW FULL PROCESSLIST;
+--------+-------------+---------------------+------+---------+---------+-----------------------------------------------------------------------+-----------------------+
| Id     | User        | Host                | db   | Command | Time    | State                                                                 | Info                  |
+--------+-------------+---------------------+------+---------+---------+-----------------------------------------------------------------------+-----------------------+
|  37550 | system user |                     | NULL | Connect | 5878076 | Waiting for master to send event                                      | NULL                  |
|  37551 | system user |                     | NULL | Connect |       0 | Has read all relay log; waiting for the slave I/O thread to update it | NULL                  |
| 119738 | you         | 127.0.0.1:37540 | NULL | Query   |       0 | NULL                                                                  | SHOW FULL PROCESSLIST |
+--------+-------------+---------------------+------+---------+---------+-----------------------------------------------------------------------+-----------------------+
3 rows in set (0.17 sec)

mysql&gt;
</pre>
<p>Restarting the slave would work for a short while until the same silent failure occurred.</p>
<p>In order to counter this, I looked into the variables related to networking and replication. modified the global variable &#8217;slave_net_timeout&#8217;. The default variable for this is 3600 seconds (ie. 1 hour). The slave timeout sets the number of seconds to wait for the master to send more data before aborting the read. I set it to a short, 10 second period:</p>
<pre>
SET GLOBAL slave_net_timeout=10;
</pre>
<p>This improved the situation and the incidence of replication mysteriously stopping dropped dramatically. Additionally now the slave IO thread would actually stop running which, at least, given an indication that something is wrong.</p>
<p>Overall, the number of these failures dropped to almost zero just as suddenly as they had appeared. This leads me to believe that there might have been something in the network connection between the master and slave servers (in different datacenters) that was causing this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2009/07/19/mysql-replication-silent-failure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress spam killing script</title>
		<link>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/</link>
		<comments>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 08:55:35 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=58</guid>
		<description><![CDATA[Blog comment spam is an unfortunate reality of having a blog. See the chart to get a sense of how much spam comes in on a daily basis to one of my blogs that receives a moderate amount of traffic. The red line shows the 30-day moving average for the number of spam comments daily.



Weeding [...]]]></description>
			<content:encoded><![CDATA[<p>Blog comment spam is an unfortunate reality of having a blog. See the chart to get a sense of how much spam comes in on a daily basis to one of my blogs that receives a moderate amount of traffic. The red line shows the 30-day moving average for the number of spam comments daily.</p>
<div class="mceTemp">
<a href="http://blog.bit-matrix.com/wp-content/uploads/2009/12/spam_comments.jpg"><img class="size-full wp-image-85" title="Number of daily spam comments on the typical blog" src="http://blog.bit-matrix.com/wp-content/uploads/2009/12/spam_comments.jpg" alt="Number of daily spam comments on the typical blog" /></a>
</div>
<p><span id="more-58"></span></p>
<p>Weeding out comments daily can be a real nuisance and, if you&#8217;ve missed a few days, the spam can pile up until it becomes a real time waster. Using the Akismet plugin for Wordpress goes a long way to rid you of spam and I would recommend that everyone use it. If, for some reason, you are looking for a standalone solution, I have hacked up a quick script to mark Wordpress Comments as spam based on the number of links in the comment. It is quite crude but if you have thousands of spam messages pilled up, you will appreciate it.</p>
<p>You will need Perl and the DBI module (if you don&#8217;t know what this is you should probably get the Akismet plugin <img src='http://blog.bit-matrix.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ).</p>
<pre>#!/usr/bin/perl
#
# wp_spam_kill.pl - brute force spam killing script
#
# Kill spam comments in WordPress based on the number of links in the comment
#
# date   : 2009.01.31
# http://bit-matrix.com
# license: GPL

use strict;
use DBI;

$| = 1;

# Configure your blog database
my $db = "DATABASE_NAME";
my $host = "DATABASE_HOST";
my $username = "DATABASE_USERNAME";
my $password = "DATABASE_PASSWORD";
my $comments_table = 'comments';
my $port = "3306";

# If a comment has more than this many links, mark it as spam
my $spam_level = 4;

sub query($$){
    my $dbh = shift;
    my $pre_bind = shift;

    my $sql = $dbh-&gt;prepare($pre_bind);
    return $sql-&gt;execute() ? $sql : undef;
};

# Connect to database
print "Connecting to $db...\n";
my $dsn = sprintf "DBI:mysql:database=%s;host=%s;port=%s;",$db,$host,$port;
my $dbh = DBI-&gt;connect($dsn,$username,$password);

# Fetch all unapproved comments
print "Getting comments...\n";
my $query = 'SELECT * FROM '.$comments_table.' WHERE comment_approved="0";';
my $c_sql = query($dbh,$query);
printf "%d Comments not approved yet\n",$c_sql-&gt;rows();

# Check each comment for number of links and mark it as spam if it has more links
my $spam_killed = 0;
while(my $c = $c_sql-&gt;fetchrow_hashref()){
    my @links = $c-&gt;{comment_content} =~ /(http:\/\/)/gs;
    if( $#links+1 &gt;= $spam_level ){
        printf "SPAM - %d links in comment\n",$#links+1;
        query($dbh,'UPDATE '.$comments_table.' SET comment_approved="spam" WHERE comment_ID="'.$c-&gt;{comment_ID}.'" LIMIT 1;');
        $spam_killed++;
    };
};

printf "Marked %d messages as spam\n",$spam_killed;

0;

__END__</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2009/01/30/wordpress-spam-killing-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How green is your code?</title>
		<link>http://blog.bit-matrix.com/2009/01/20/how-green-is-your-code/</link>
		<comments>http://blog.bit-matrix.com/2009/01/20/how-green-is-your-code/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 07:08:59 +0000</pubDate>
		<dc:creator>Bit Matrix</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[The Future]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.bit-matrix.com/?p=35</guid>
		<description><![CDATA[Is your code fast and efficient? Is your nasty for-loop killing penguins somewhere and You don&#8217;t even know about it? We all hacked and brute-forced through a problem at one time or another &#8211; it is inevitable. How much CO2 will your hack release into the atmosphere? Writing power-inefficient code is like driving a fuel-inefficient [...]]]></description>
			<content:encoded><![CDATA[<p>Is your code fast and efficient? Is your nasty for-loop killing penguins somewhere and You don&#8217;t even know about it? We all hacked and brute-forced through a problem at one time or another &#8211; it is inevitable. How much CO2 will your hack release into the atmosphere? Writing power-inefficient code is like driving a fuel-inefficient car &#8211; we&#8217;ve all done it but it&#8217;s just not cool anymore. With <strong><span style="color: #008000;">green</span></strong> finally becoming the buzz-word everywhere, it is time to take a look at a few numbers surrounding the environmental cost of bad code.</p>
<p><span id="more-35"></span></p>
<p>The issue at hand is the amount of power (as in electricity) that your code will consume when running on a large number of users&#8217; computers (since you write awesomely popular software) or over a long period of time (if your software will be in use for years).</p>
<h4>Hacks. Free(-as-in-beer)?</h4>
<p>Suppose you hacked together a quick Flash widget to go on the front page of your up-and-coming website. Your code is nasty and the widget takes up almost all CPU power on a single core but you have no time to fix it and release it as-is.</p>
<p>Lets run some very basic numbers. A normal user might spend 10 seconds viewing your front page before navigating to another page without the widget. Lets also say that a typical Intel Core 2 CPU will consume about <a href="http://en.wikipedia.org/wiki/CPU_power_dissipation">33W</a> when operating one of its cores at 100% load because of your crappy code. For those 10 seconds on the site, your widget has consumed 33W x 10s / 3600 s/h = 0.092 kW·h.</p>
<p>Let us now assume that you site got mildly popular and received a million visitors over the course of a year, each of which spent only 10 seconds on pages containing the widget. Now your widget has consumed about 92,000 kW·h, or 92 MW·h.</p>
<h4>Garbage In &#8211; Carbon Out</h4>
<p>The average household in the United States uses about <a href="http://tonto.eia.doe.gov/ask/electricity_faqs.asp#electricity_use_home">11,000 kW·h</a> (11 MW·h) of electricity, each year. <strong>Congratulations! Your inefficient code has used up enough electricity to power almost 8 homes for a full year</strong>!</p>
<p>If you live in the United States, <a href="http://en.wikipedia.org/wiki/File:Sources_of_electricity_in_the_USA_2006.png">half of this electricity is likely to come from coal</a>. Coal has en energy density of about <a href="http://en.wikipedia.org/wiki/Coal#Energy_density">2.0 kg / kW·h</a> meaning that the amount of coal burned to power your inefficient code is 0.5 * 92,000 kW·h / (2.0 kg / kW·h) = 92,000 kg = 92t. Yes, that is <strong>92 tons of coal!</strong></p>
<p>Given that producing energy from coal also releases CO2 at a rate of about <a href="http://en.wikipedia.org/wiki/Coal#Relative_carbon_cost">0.950 kg / (kW·h)</a>, your code will have resulted in <strong>87.4 tons of CO2</strong>.</p>
<p>These numbers seem quite depressing. What if your widget ends up on the front page of a big site with tens or hundreds of millions of visitors a year? How much environmental destruction can one nested for loop cause? How many dead penguins will you be responsible for? Gasp!</p>
<h4>Save The Planet?</h4>
<p>But let&#8217;s be realistic, code will always consume power and you can only do so much to reduce that. Some applications will have a net benefit of reducing energy consumption by making people more productive and efficient with their time and energy (your punch-the-monkey widget might or might not be one of those).</p>
<p>The point of the matter is that, even when programming, one can consider the environment. If that consideration provides you with the impetus to sit down and properly re-write a power-hungry piece of code then you have made a real physical change in the world. And now, you can put a number on it.</p>
<p>Safe the CPU cycles &#8211; save the world. <img src='http://blog.bit-matrix.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bit-matrix.com/2009/01/20/how-green-is-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
