<?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>Alex Stetsenko</title>
	<atom:link href="http://www.stetsenko.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stetsenko.net</link>
	<description>Life and software engineering :: thoughts and steps</description>
	<lastBuildDate>Tue, 01 May 2012 02:18:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>PHP: array_filter() with arguments</title>
		<link>http://www.stetsenko.net/2012/02/php-array_filter-with-arguments/</link>
		<comments>http://www.stetsenko.net/2012/02/php-array_filter-with-arguments/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 03:42:26 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1287</guid>
		<description><![CDATA[Recently I have been using a lot of array related functions. Especially array_count_values() function came in handy. It really saved me a lot of sweat while cracking some puzzles. Anyway the other day I got a chance to play with array_filter() function. At the first look this function works just fine and required callback function [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been using a lot of array related functions. Especially <strong>array_count_values()</strong> function came in handy. It really saved me a lot of sweat while cracking some puzzles.</p>
<p>Anyway the other day I got a chance to play with <strong>array_filter()</strong> function. At the first look this function works just fine and required callback function is extremely easy to write. Until one realizes it would be great to have an extra parameter the same way <strong>array_walk()</strong> does.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// some array</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// custom multiplier</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> walk<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$m</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// multiply each element of the array by $p</span>
<span style="color: #990000;">array_walk</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'walk'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So with <strong>array_walk()</strong> it is possible simply to add optional third parameter ($p in the example above) and it will just work. However <strong>array_filter()</strong> does not allow that third parameter &#8211; there are just two of them&#8230;</p>
<p>What I did not take into account that <a href="http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback">callback</a> function <strong><em>&#8220;can not only be simple functions, but also object methods, including static class methods&#8221;</em></strong>. As result this solves the issue in the way shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// some array</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// threshold to filter array elements</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// method of this class can be uses as a callback function</span>
<span style="color: #000000; font-weight: bold;">class</span> Filter <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$threshold</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$threshold</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">threshold</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$threshold</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> isLower<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">threshold</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Filter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'isLower'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Although the code above gets the job done, it feels like it is too much effort for an &#8220;extra parameter&#8221;. And this is when <strong>anonymous function</strong> and <strong>closure</strong> come helpful to provide one-line solution which <a href="http://www.stetsenko.net/2011/01/php-mac-address-validating-and-formatting/">I always appreciate</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">use</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$p</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Voilà &#8211; such an elegant way to solve the problem! <img src='http://www.stetsenko.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2012/02/php-array_filter-with-arguments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Job Queue article for PHPMaster.com</title>
		<link>http://www.stetsenko.net/2012/01/zend-job-queue-article-for-phpmaster-com/</link>
		<comments>http://www.stetsenko.net/2012/01/zend-job-queue-article-for-phpmaster-com/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 16:24:19 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1275</guid>
		<description><![CDATA[Last month I learned about great opportunity to write for PHPMaster.com and contacted their managing editor. It worked out very well and a blog post I had in mind for while turned into a great article. Any feedback is welcomed: Scheduling with Zend Job Queue.]]></description>
			<content:encoded><![CDATA[<p>Last month I learned about great <a href="http://phpmaster.com/writing/">opportunity to write for PHPMaster.com</a> and contacted their managing editor.<br />
It worked out very well and a blog post I had in mind for while turned into a great article. <img src='http://www.stetsenko.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Any feedback is welcomed: <a href="http://phpmaster.com/zend-queue/">Scheduling with Zend Job Queue</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2012/01/zend-job-queue-article-for-phpmaster-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB Atlanta</title>
		<link>http://www.stetsenko.net/2012/01/mongodb-atlanta/</link>
		<comments>http://www.stetsenko.net/2012/01/mongodb-atlanta/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 15:59:22 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1270</guid>
		<description><![CDATA[MongoDB conference is going to happen in Atlanta again this year. I&#8217;ve enjoyed MongoATL 2011 and already have made plans to attend this year too. Although the conference is still at &#8220;call for proposals&#8221; stage, I am sure there will be covered interesting topics since MongoDB popularity has grown significantly. It is probably a good [...]]]></description>
			<content:encoded><![CDATA[<p><strong>MongoDB conference</strong> is going to happen in Atlanta again this year. I&#8217;ve enjoyed <a href="http://www.stetsenko.net/2011/05/mongoatl-conference/">MongoATL 2011</a> and already have made plans to attend this year too. Although the conference is still at &#8220;call for proposals&#8221; stage, I am sure there will be covered interesting topics since MongoDB popularity has grown significantly.</p>
<p>It is probably a good idea to follow event details on the <a href="http://www.10gen.com/events/mongo-atlanta">MongoDB Atlanta 2012</a> official page. However location stays the same (<a href="http://www.gtri.gatech.edu/conference-center">GTRI Conference Center</a>) and date is already known &#8211; <strong>April, 20th</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2012/01/mongodb-atlanta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internet Made in Atlanta</title>
		<link>http://www.stetsenko.net/2011/11/internet-made-in-atlanta/</link>
		<comments>http://www.stetsenko.net/2011/11/internet-made-in-atlanta/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 01:18:11 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1214</guid>
		<description><![CDATA[Few days ago I started a new project of mine: Internet Made in Atlanta. It is merely content driven web-site to list internet companies of Atlanta which are recognized and appreciated by thousands of users and\or visitors monthly. The idea to create this project was hanging in the air for a while until I discovered [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I started a new project of mine: <a href="http://www.stetsenko.net/madeinatl/">Internet Made in Atlanta</a>.</p>
<p>It is merely content driven web-site to list internet companies of Atlanta which are recognized and appreciated by <strong>thousands</strong> of users and\or visitors monthly.</p>
<p>The idea to create this project was hanging in the air for a while until I discovered a similar project by <strong>NY Tech meetup</strong> team. So <a href="http://nytm.org/made/">Internet Made in NYC</a> finally triggered the start of my own project.</p>
<p>As of November, 1 there are only ten companies listed. However I am looking forward to many more submissions!</p>
<p>Let&#8217;s proudly show what&#8217;s <strong>made in Atlanta</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/11/internet-made-in-atlanta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The parable of the elephant</title>
		<link>http://www.stetsenko.net/2011/10/the-parable-of-the-elephant/</link>
		<comments>http://www.stetsenko.net/2011/10/the-parable-of-the-elephant/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 23:20:25 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Management]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1207</guid>
		<description><![CDATA[Few days ago I ran into another interesting parable: I once went to a circus and saw a huge elephant tied to a small pole with a rope, just standing there. So I wondered why is the elephant so obedient and doesn’t break away from the stick with all of its enormous strength and mass. [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I ran into another interesting <a href="http://www.stetsenko.net/2010/07/how-does-motivation-work/">parable</a>:</p>
<blockquote><p>I once went to a circus and saw a huge elephant tied to a small pole with a rope, just standing there. So I wondered why is the elephant so obedient and doesn’t break away from the stick with all of its enormous strength and mass. So they told me this story: once when the elephant was very young, it was tied to the pole the same way. Naturally, it didn’t like that and tried to escape, but try as it might, the rope and the pole were too strong for it. So the elephant eventually gave up.</p>
<p>Later on, when it was older, the elephant still believed it could not escape from the rope, and remained standing in the same place, despite the fact it could then easily escape.</p>
</blockquote>
<p>Interesting, ha? It is said something like past performance does not guarantee future results. Which usually means being successful in the past does not imply success within another company or just in future. However this parable is a wonderful example of the opposite. So it is important to realize what one may now be capable of doing regardless past experience.</p>
<p>It&#8217;s almost like being <a href="http://www.stetsenko.net/2010/03/scrum-basics/">Agile</a>: fail early and then start a new sprint. <img src='http://www.stetsenko.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/10/the-parable-of-the-elephant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile App Hackathon</title>
		<link>http://www.stetsenko.net/2011/10/mobile-app-hackathon/</link>
		<comments>http://www.stetsenko.net/2011/10/mobile-app-hackathon/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 18:01:22 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1193</guid>
		<description><![CDATA[Last month I attended AT&#038;T Mobile App Hackathon. Although our team did not make it to present an app it was absolutely fun experience. First of all it was interesting to learn what&#8217;s going on in the world of mobile development. For instance turns out not many prefer native development especially for Android. Also the [...]]]></description>
			<content:encoded><![CDATA[<p>Last month I attended <a href="http://mobileappatl.eventbrite.com/"><strong>AT&#038;T Mobile App Hackathon</strong></a>. Although our team did not make it to present an app it was absolutely fun experience.</p>
<p>First of all it was interesting to learn what&#8217;s going on in the world of mobile development. For instance turns out not many prefer native development especially for Android. Also the choice for non-native app development is not just limited to <em>PhoneGap</em> or <em>Titanium</em>. There are many more less known (for now) tools and APIs like <a href="http://www.appmobi.com/">appMobi</a> or <a href="http://apigee.com/">apigee</a>.</p>
<p>Second, I had a chance to work on text to speech and voice recognition features for Android which I may incorporate into next generation of <a href="http://www.stetsenko.net/2009/07/android-sat-vocabulary/">SAT Vocabulary</a>.</p>
<p>Third, there was no free Wi-Fi. However on the bright side everyone had a chance to try out <em>AT&#038;T 4G Mobile Hotspot device</em>. And it was absolutely awesome and fast which makes you want one. Kudos to AT&#038;T actually since T-Mobile devices were showing no signal at the <a href="http://atdc.org/">ATDC</a> location.</p>
<p>The top three apps were:</p>
<ul>
<li><strong>Four Corners</strong> &#8211; allows multiple players to scan a QR code to join a team in a game. Players tap on their own mobile device, which the impact is seen on the game board on a larger shared screen.</li>
<li><strong>YouJuke</strong> &#8211; social music selection.</li>
<li><strong>Food Porn</strong> &#8211; shows beautiful pictures of a food near you and gives you directions to it. It does nothing else and has absolutely no social networking whatsoever by design.</li>
</ul>
<p>Looking forward to attending more events like that. Also AT&#038;T is planning other hackathons in DC, SF, Boston and Orlando during October-December of 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/10/mobile-app-hackathon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: How to add where clause to processlist</title>
		<link>http://www.stetsenko.net/2011/08/mysql-how-to-add-where-clause-to-processlist/</link>
		<comments>http://www.stetsenko.net/2011/08/mysql-how-to-add-where-clause-to-processlist/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 00:58:30 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1140</guid>
		<description><![CDATA[MySQL&#8217;s show full processlist is a great way to monitor and diagnose what is going on with the database server at certain moment. However often it is needed to have an aggregated view or evaluate only specific type of users and\or queries. The solution turned out to be pretty simple since show full processlist is [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL&#8217;s <strong>show full processlist</strong> is a great way to monitor and diagnose what is going on with the database server at certain moment.</p>
<p>However often it is needed to have an aggregated view or evaluate only specific type of users and\or queries.</p>
<p>The solution turned out to be pretty simple since <strong>show full processlist</strong> is just an alias for a regular query to <strong>processlist table</strong> within <strong>information_schema database</strong>.</p>
<p>So the following queries are equivalent:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">FULL</span> PROCESSLIST;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist;</pre></div></div>

<p>As result it is possible to present the data from process list any convenient way. There are some basic examples below.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- display number of connections for each user</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`USER`</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">`USER`</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- display number of connections for each host</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`HOST`</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">COUNT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">`HOST`</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- display root user activity</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`USER`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'root'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- display processes associated with SELECT queries</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`INFO`</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'SELECT %'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- display average query time for each database</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`DB`</span><span style="color: #66cc66;">,</span> AVG<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`TIME`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>processlist
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">`DB`</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/08/mysql-how-to-add-where-clause-to-processlist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can you restore your backup?</title>
		<link>http://www.stetsenko.net/2011/08/can-you-restore-your-backup/</link>
		<comments>http://www.stetsenko.net/2011/08/can-you-restore-your-backup/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 00:57:05 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1149</guid>
		<description><![CDATA[In this short note I simply want to second Joel Spolsky&#8217;s post on backups: Let’s stop talking about &#8220;backups&#8221;. For instance many IT related people are comfortable enough knowing that necessary backups are done. However not many are concerned about restoring from the backup or actually tried the whole backup restore process. Nonetheless there is [...]]]></description>
			<content:encoded><![CDATA[<p>In this short note I simply want to second Joel Spolsky&#8217;s post on backups: <a href="http://www.joelonsoftware.com/items/2009/12/14.html">Let’s stop talking about &#8220;backups&#8221;.</a></p>
<p>For instance many IT related people are comfortable enough knowing that necessary backups are done. However not many are concerned about restoring from the backup or actually tried the whole backup restore process. Nonetheless there is always something unexpected happens during restore&#8230;</p>
<p>Thus the right question to ask is not &#8220;are you doing backups?&#8221; but <strong>&#8220;can you restore your backup?&#8221;</strong> or <strong>&#8220;are you doing restores?&#8221;</strong> is even better.</p>
<blockquote><p>The minimum bar for a reliable service is not that you have done a backup, but that you have done a restore. If you’re running a web service, you need to be able to show me that you can build a reasonably recent copy of the entire site, in a reasonable amount of time, on a new server or servers without ever accessing anything that was in the original data center. The bar is that you’ve done a restore.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/08/can-you-restore-your-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Blackberry Is Not Working!</title>
		<link>http://www.stetsenko.net/2011/08/my-blackberry-is-not-working/</link>
		<comments>http://www.stetsenko.net/2011/08/my-blackberry-is-not-working/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 03:01:22 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Funny stuff]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1138</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object width="480" height="303"><param name="movie" value="http://www.youtube.com/v/kAG39jKi0lI?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/kAG39jKi0lI?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="480" height="303" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/08/my-blackberry-is-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Current timestamp for new or updated rows</title>
		<link>http://www.stetsenko.net/2011/08/mysql-current-timestamp-for-new-or-updated-rows/</link>
		<comments>http://www.stetsenko.net/2011/08/mysql-current-timestamp-for-new-or-updated-rows/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 02:31:15 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.stetsenko.net/?p=1112</guid>
		<description><![CDATA[Often it is quite reasonable to have the database to take care of some audit related columns like date added or updated. Unfortunately MySQL does NOT allow functions within table definitions like let&#8217;s say MS SQL does, e.g.: CREATE TABLE t &#40;f datetime NOT NULL DEFAULT now&#40;&#41;&#41;; The only work around is to use timestamp [...]]]></description>
			<content:encoded><![CDATA[<p>Often it is quite reasonable to have the database to take care of some audit related columns like date added or updated.<br />
Unfortunately MySQL does NOT allow functions within table definitions like let&#8217;s say MS SQL does, e.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t <span style="color: #66cc66;">&#40;</span>f datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> now<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>The only work around is to use <strong>timestamp</strong> column instead of date or datetime ones. There can be <strong>only one auto set timestamp column</strong> though.<br />
So I normally use it to store date updated and save the date created manually.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t
<span style="color: #66cc66;">&#40;</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  date_updated <span style="color: #993333; font-weight: bold;">TIMESTAMP</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
               <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">CURRENT_TIMESTAMP</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">CURRENT_TIMESTAMP</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Also there are <strong>two things to keep in mind</strong>:</p>
<ul>
<li>date_updated will be set based on MySQL server time. This is especially important if other data is stored using GMT or non-server time zone.</li>
<li>date_updated must NOT be a part of update or insert query.
        </li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- set date_updated to current time</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> t <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">UPDATE</span> t <span style="color: #993333; font-weight: bold;">SET</span> name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'test'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- override date_updated to certain value</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> t <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> date_updated<span style="color: #66cc66;">&#41;</span>
       <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'2011-08-02 20:00:00'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">UPDATE</span> t <span style="color: #993333; font-weight: bold;">SET</span> name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span>
             date_updated <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'2011-08-02 20:00:00'</span>;</pre></div></div>

<p>Alternatively it is possible to use <strong>triggers</strong> to have as many auto updated datetime columns as needed. However personally I prefer to avoid triggers as much as possible. Mostly because often triggers are misused and as result application complexity is increased for no reason.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stetsenko.net/2011/08/mysql-current-timestamp-for-new-or-updated-rows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

