<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>I want to be free</title>
	
	<link>http://i1t2b3.com</link>
	<description>Any fool can make things bigger and more complex</description>
	<lastBuildDate>Wed, 28 Jul 2010 14:34:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3462</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/i1t2b3com" /><feedburner:info uri="i1t2b3com" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Convert latin1 to utf8</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/B-izXChfiN8/</link>
		<comments>http://i1t2b3.com/2010/04/14/convert-latin1-to-utf8/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 12:51:35 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=598</guid>
		<description><![CDATA[If you import unicode text into latin1 database column, the symbols would be screwed up — russian symbols become a shit like &#8220;Ð·Ð°Ð»Ð¾Ð³Ð¾Ð²Ñ‹Ð¹ Ð´ÐµÐ¿Ð¾Ð·Ð¸Ñ‚&#8221;. To convert such quickly (as a test) you can use Lebedev&#8217;s convertor. To convert the whole table do the following (thanks to dull.ru): The most important step: dump such data in [...]]]></description>
			<content:encoded><![CDATA[<p>If you import unicode text into latin1 database column, the symbols would be screwed up — russian symbols become a shit like &#8220;Ð·Ð°Ð»Ð¾Ð³Ð¾Ð²Ñ‹Ð¹ Ð´ÐµÐ¿Ð¾Ð·Ð¸Ñ‚&#8221;.</p>
<p><img class="aligncenter size-full wp-image-599" title="extras" src="/wp-content/uploads/2010/04/extras.png" alt="" width="484" height="218" /></p>
<p>To convert such quickly (as a test) you can use <a rel="nofollow" href="http://www.artlebedev.ru/tools/decoder/">Lebedev&#8217;s convertor</a>.</p>
<p>To convert the whole table do the following (thanks to <a rel="nofollow" href="http://dull.ru/2008/11/06/konvertirovat_bazu_v_utf8/">dull.ru</a>):</p>
<ol>
<li>The most important step: dump such data in a file with <code>mysqldump</code>
<pre><code>mysqldump -u user -p <strong>--default-character-set=latin1 </strong>--skip-set-charset --no-create-info --extended-insert --complete-insert dbname table &gt; dbname.sql</code></pre>
<p>If not the whole table data is bad, create another table (<code>CREATE TABLE t2 LIKE t1</code>) and copy wrong rows to the new table.</li>
<li>Replace <code>latin1</code> by <code>utf8</code> in the file<br />
This can be done manually in your editor or by this command:</p>
<pre><code>sed -r 's/latin1/utf8/g' dbname.sql &gt; dbname_utf.sql</code></pre>
</li>
<li>Convert your latin1-table to utf8 (and maybe truncate it):
<pre><code>ALTER TABLE `table` CONVERT TO CHARACTER SET 'utf8';</code></pre>
</li>
<li>Import the utf8 data back to the table:
<pre><code>mysql -u user -p --default-character-set=utf8 dbname &lt; dbname_utf.sql</code></pre>
</li>
</ol>
<p>That&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/04/14/convert-latin1-to-utf8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2010/04/14/convert-latin1-to-utf8/</feedburner:origLink></item>
		<item>
		<title>Zend View Helpers inheritance</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/0KfoWFQ5TOc/</link>
		<comments>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 16:01:38 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=591</guid>
		<description><![CDATA[It&#8217;s handy to use View Helpers in Zend FW driven project. For example, you want to make an in-place tracker (e.g. Google Analytics) &#8212; you create a helper class My_View_Helper_Tracker inherited from Zend_View_Helper, Zend finds its automatically and then you are free to use your helper method: echo $this->tracker( $trackerID ); The question is what [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s handy to use <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.view.helpers.html">View Helpers</a></noindex> in Zend FW driven project. For example, you want to make an in-place tracker (e.g. Google Analytics) &mdash; you create a helper class My_View_Helper_Tracker inherited from Zend_View_Helper, Zend finds its automatically and then you are free to use your helper method:</p>
<pre><code>echo $this->tracker( $trackerID );</code></pre>
<p>The question is what you gonna do if you want a base class for a family of trackers?</p>
<p>It&#8217;s not so obvoius due to naming conventions.</p>
<p>Let&#8217;s say you want 2 kinds of trackers: Google Analytics and Euroads.</p>
<p>1. You create such files structure:</p>
<pre><code>
library
 - My
   - View
    - Helper
      - Tracker
        Abstract.php
        - Google
          Page.php
        - Euroads
          Owner.php
          Guest.php
</code></pre>
<p>2. You name your classes as:</p>
<ul>
<li>My_View_Helper_Tracker_Euroads_Guest (extends My_View_Helper_Tracker_Abstract)</li>
<li>&#8230; so on &#8230;</li>
</ul>
<p>3. Class methods are:</p>
<pre><code class="php">public function tracker_euroads_guest(...) ...</code></pre>
<p>4. And the trickiest part: the helper call:</p>
<pre><code class="php">echo $this->tracker_<strong>E</strong>uroads_<strong>G</strong>uest</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/</feedburner:origLink></item>
		<item>
		<title>Cannot upload a big file?</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/WlemJFsZ08c/</link>
		<comments>http://i1t2b3.com/2010/03/25/cannot-upload-a-big-file/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:43:02 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=588</guid>
		<description><![CDATA[If you want to work with big files uploads (photos, videos, CSV data dumps) you might need to prepare your PHP server for this &#8212; increase the values of these variables in your php.ini: upload_max_filesize = 512M post_max_size = 512M memory_limit = 512M The same should be done if you try to upload SQL dumps [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to work with big files uploads (photos, videos, CSV data dumps) you might need to prepare your PHP server for this &mdash; increase the values of these variables in your <code>php.ini</code>:</p>
<pre><code>upload_max_filesize = 512M
post_max_size = 512M
memory_limit = 512M
</code></pre>
<p>The same should be done if you try to upload SQL dumps by phpMyAdmin and get a correspondent error message.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/03/25/cannot-upload-a-big-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2010/03/25/cannot-upload-a-big-file/</feedburner:origLink></item>
		<item>
		<title>How to rate Points Of Interest automatically</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/0Yum6RPpOrM/</link>
		<comments>http://i1t2b3.com/2010/03/13/how-to-rate-points-of-interest-automatically/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 13:13:31 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[api]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ideas]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=579</guid>
		<description><![CDATA[During my work on SunnyRentals I&#8217;ve got a task to add 2 closest airports to every property an owner creates. I implemented it quite fast since we have a database of airports with coordinates. While playing with this feature, we found out that it is not good enough — the real task must be to [...]]]></description>
			<content:encoded><![CDATA[<p>During my work on <a href="http://www.sunnyrentals.com">SunnyRentals</a> I&#8217;ve got a task to add 2 closest airports to every property an owner creates.</p>
<p>I implemented it quite fast since we have a database of airports with coordinates.</p>
<p>While playing with this feature, we found out that it is not good enough — the real task must be to add 2 <strong>closest and biggest</strong> airports. The problem is that we don&#8217;t have any data in airports DB to guess how big or famous a particular airport is.</p>
<p>So we need to rate every airport somehow&#8230;</p>
<p>The solution we found was simple — we need to google for the airport name and get the search results count. The count can be considered as rating value — London Heathrow airport has 2.33 million results while Kiev Zhulyany airport has only 0.77 mln which looks fair.</p>
<p>Several things to pay attention to:</p>
<ul>
<li>the query we formed was [city name] + [airport name] + &#8216; airport&#8217;</li>
<li>if this query gives zero result, I omit the city name — at times it hepls</li>
<li>we put the query into quotes to google for the exact phrase, otherwise the London City airport gets the highest rating due to the fact that &#8220;<em>city</em>&#8221; is a general term</li>
<li>if the airport name includes the city name (<em>Melbourne Intl</em>), we omit the city name — &#8221;<em>Melbourne Intl airport</em>&#8221; is better then &#8220;<em>Melbourne Melbourne Intl airport</em>&#8220;</li>
<li>in addition to previous idea — if the airport name sounds like the city name, we omit the city name as well. Example: Narsarsuaq airport in Narssarssuaq city. I used <code>soundex</code> function for this comparison — it&#8217;s present in PHP and MySQL.</li>
</ul>
<p>To get the google results you can use the <noindex><a rel="nofollow" href="http://code.google.com/intl/en-US/apis/ajaxsearch/documentation/#fonje">Google Search API</a></noindex>:</p>
<pre><code>$queryTemplate = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q=%s';
$airportQuery = '"London Heathrow airport"';
$query = sprintf( $queryTemplate, urlencode( $airportQuery ) );
$json = json_decode( file_get_contents( $query ), 1 );
$rating = (int)$json['responseData']['cursor']['estimatedResultCount'];</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/03/13/how-to-rate-points-of-interest-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2010/03/13/how-to-rate-points-of-interest-automatically/</feedburner:origLink></item>
		<item>
		<title>Federated engine – MySQL table as symlink</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/6sttoUzsKGc/</link>
		<comments>http://i1t2b3.com/2010/01/29/federated-table-as-symlink/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 13:54:38 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=570</guid>
		<description><![CDATA[Are you aware of Federated engine in MySQL (apart from MyISAM and InnoDB)? This engine allows you to define a table that sucks data from another table, even from a remore server. The tables definition must be the same. I use it for the following: Every time I rebuild the project, I have wait for [...]]]></description>
			<content:encoded><![CDATA[<p>Are you aware of <a href="http://dev.mysql.com/doc/refman/5.1/en/federated-storage-engine.html">Federated engine</a> in MySQL (apart from MyISAM and InnoDB)?</p>
<p>This engine allows you to define a table that sucks data from another table, even from a remore server. The tables definition must be the same.</p>
<p>I use it for the following:</p>
<ol>
<li>Every time I rebuild the project, I have wait for 15 minutes while two big tables are created and filled with data — these are geo data tables (world cities, regions, etc), 4 mln records, and <acronym title="Points Of Interest">POI</acronym> table, 2 mln records. I use Federated tables to create two separate databases and just link these tables in my project.</li>
<li>These tables are shared between several environments (dev, test and live) on the same server.</li>
</ol>
<p>To check if your MySQL server has the Federated engine supported, you can use just a phpMyAdmin — go to home page of you phpMyAdmin installation (click Home picture), then choose Engines tab and check there.</p>
<p>If it&#8217;s not enabled (gray), open your <em>my.ini</em> file, find the &#8220;<em>[mysqld]</em>&#8221; part and make it to look like this:</p>
<pre><code>[mysqld]
federated</code></pre>
<p>P.S. If you have an error in the table definition, phpMyAdmin shows your database as empty. To fix this, log in via mysql console and try to make a SELECT from this poorly defined table and you get the error message to work with.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2010/01/29/federated-table-as-symlink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2010/01/29/federated-table-as-symlink/</feedburner:origLink></item>
		<item>
		<title>Currency exchange in your application</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/Y2K6DLvRvwk/</link>
		<comments>http://i1t2b3.com/2009/09/28/currency-exchange/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 10:53:17 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=555</guid>
		<description><![CDATA[That&#8217;s easy, you need 2 things: Fresh currencies exchange rates Some way to excange amount from one currency to another. This how I did it: get values from European Central Bank (ECB) for step #1 and wrote MySQL user defined function for step #2. Here is how to export currencies rates from ECB (EUR is [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s easy, you need 2 things:</p>
<ol>
<li>Fresh currencies exchange rates</li>
<li>Some way to excange amount from one currency to another.</li>
</ol>
<p>This how I did it: get values from European Central Bank (ECB) for step #1 and wrote MySQL user defined function for step #2.</p>
<p>Here is how to export currencies rates from ECB (EUR is a base currency, and I add self rate as 1:1). First I create such  database table:</p>
<pre><code class="sql">CREATE TABLE IF NOT EXISTS `currency` (
  `code` char(3) NOT NULL DEFAULT '',
  `rate` decimal(10,5) NOT NULL COMMENT 'Rate to EUR got from www.ecb.int',
  PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Currency rates (regularly updated)';
</code></pre>
<p>Now let&#8217;s fill it with rates:</p>
<pre><code class="php">&lt;?php

class CurrencyController extends Controller_Ajax_Action {

  public function importAction() {

    $db = Zend_Registry::get('db');
    $db-&gt;beginTransaction();

    $url = 'http://www.ecb.int/stats/eurofxref/eurofxref.zip?1c7a343768baab4322620e3498553b5a';
    try {
      $contents = file_get_contents($url);
      $contents = archive::unzip($contents);
      $contents = explode(&quot;\n&quot;, $contents);

      $names = explode(',', $contents[0]);
      $rates = explode(',', $contents[1]);

      $names[] = 'EUR';
      $rates[] = 1;

      for ($i = 1; $i &lt; sizeof($names); $i++) {
        if (!(float) $rates[$i]) continue;
        $db-&gt;query( sprintf('INSERT INTO `currency`(`code`, `rate`)
              VALUES (&quot;%s&quot;, %10.5f)
              ON DUPLICATE KEY UPDATE `rate`=VALUES(`rate`)',
             trim( $names[$i] ),
             trim( $rates[$i] )
        ) );
      }

      $db-&gt;commit();
    } catch ( Exception $O_o ) {
      error_log( $O_o-&gt;getMessage() );
      $db-&gt;rollback();
    }

  }
}</code></pre>
<p>Now let&#8217;s create a SQL function for handy converts. Create a <code>udf.sql</code> file and add this in it:</p>
<pre><code class="sql">DELIMITER //

DROP  FUNCTION IF EXISTS EXCHANGE;
CREATE FUNCTION EXCHANGE( amount DOUBLE, cFrom CHAR(3), cTo CHAR(3) ) RETURNS DOUBLE READS SQL DATA DETERMINISTIC
    COMMENT 'converts money amount from one currency to another'
BEGIN
    DECLARE rateFrom DOUBLE DEFAULT 0;
    DECLARE rateTo DOUBLE DEFAULT 0;

    SELECT `rate` INTO rateFrom FROM `currency` WHERE `code` = cFrom;
    SELECT `rate` INTO rateTo   FROM `currency` WHERE `code` = cTo;

    IF ISNULL( rateFrom ) OR ISNULL( rateTo ) THEN
        RETURN NULL;
    END IF;

    RETURN amount * rateTo / rateFrom;
END; //

DELIMITER ;</code></pre>
<p>and run this command in your shell:</p>
<pre><code>mysql --user=USER --password=PASS DATABASE &lt; udf.sql</code></pre>
<p>This is how you can use this function &mdash; how to convert 10 US dollars to Canadian dollars:</p>
<pre><code class="sql">SELECT EXCHANGE( 10, 'USD', 'CAD')</code></pre>
<p>which results in $10 = 10.93 Canadian dollars.</p>
<p>P.S. Consider adding the currency export action call to your cron scripts.</p>
<p>P.P.S. A function to unzip the data file can be got at <noindex><a rel="nofollow" href="http://ua2.php.net/manual/en/ref.zip.php">php.net</a></noindex></p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/28/currency-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2009/09/28/currency-exchange/</feedburner:origLink></item>
		<item>
		<title>Ajax controller in Zend project</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/vrsRf88mv0I/</link>
		<comments>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 14:34:35 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=543</guid>
		<description><![CDATA[I want to share a couple of features I use to handle AJAX requests in projects based on Zend Framework. 1. AJAX request handling What: some parts of your application can be not loaded if currect request is AJAX. Why: you don&#8217;t need views, templates, some routes &#8212; so you can add an AJAX check [...]]]></description>
			<content:encoded><![CDATA[<p>I want to share a couple of features I use to handle AJAX requests in projects based on Zend Framework.</p>
<h3>1. AJAX request handling</h3>
<p><strong>What</strong>: some parts of your application can be not loaded if currect request is AJAX.</p>
<p><strong>Why</strong>: you don&#8217;t need views, templates,  some routes &mdash; so you can add an AJAX check in your Initializer or bootstrap file and avoid loading not necessary things.</p>
<p><strong>How</strong>: Zend Request object has a <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.controller.request.html#zend.controller.request.http.ajax"><code>isXmlHttpRequest</code> method</a></noindex> to find out whether it&#8217;s AJAX request or not. It&#8217;s based on &#8216;<code>X-Requested-With</code>&#8216; header, which is sent by jQuery, Prototype, Scriptaculous, YUI and MochiKit frameworks.</p>
<h3>2. AJAX Controller</h3>
<p>Most AJAX controller&#8217;s methods I saw had an <code>exit()</code> inside to not to output Zend&#8217;s template &mdash; it is a work-around. The proper way to do so is to tell to Zend not to load anything. One step forward is to create an abstract Controller class and inherit all you AJAX classes from it:</p>
<p><code>/library/Koodix/Controller/Ajax/Action.php</code>:</p>
<pre><code>&lt;?php

require_once 'Zend/Controller/Action.php';

abstract class Koodix_Controller_Ajax_Action
  extends Zend_Controller_Action
{
    public function init() {
        //disable the standard layout output
        $this-&gt;_helper-&gt;layout()-&gt;disableLayout();
        $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();
    }

    public function postDispatch() {
        //envelope and output json field
            if( !empty( $this-&gt;json ) ) {
                echo json_encode( $this-&gt;json );
            }
        }
}</code></pre>
<p><code>/application/modules/default/controllers/AjaxController.php</code>:</p>
<pre><code>&lt;?php

class AjaxController extends Koodix_Controller_Ajax_Action
{
 // bla-bla-bla
</code></pre>
<p>Take a look at <code>postDispatch</code> method &mdash; idea behind it is to convert to JSON and output anything that is set to <code>json</code> field of your controller. If you want to send JSON data in special header (and not in body, like it&#8217;s done in my example), you can do it in this method.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2009/09/22/ajax-controller-in-zend-project/</feedburner:origLink></item>
		<item>
		<title>Flash uploader and HTTP password protection</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/oqdd2s7dssU/</link>
		<comments>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 16:24:43 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=535</guid>
		<description><![CDATA[You are working on a project and you want to protect the beta version with password so that only allowed people (beta testers) could access it. You decide not to invent the wheel and to use the standard HTTP authentication. First idea is to use your Apache web server to do this, so you write [...]]]></description>
			<content:encoded><![CDATA[<p>You are working on a project and you want to protect the beta version with password so that only allowed people (beta testers) could access it.</p>
<p>You decide not to invent the wheel and to use the standard HTTP authentication.</p>
<p>First idea is to use your Apache web server to do this, so you write something like that in <code>.htaccess</code> file: </p>
<pre><code>AuthName "Private zone"
AuthType Basic
AuthUserFile /path/to/.htpasswd
require valid-use</code></pre>
<p>This solution is simple and that&#8217;s why good.</p>
<p>A problem comes on stage when a Flash file uploader is added to your project &#8211; usually it cannot &#8220;login&#8221; to your site, i.e. users are not able to use the Flash file uploader behind beta login.</p>
<p>That&#8217;s how I solved it.</p>
<p>It&#8217;s not the web server who must solve this (Apache), it&#8217;s the application server (PHP). So remove the lines above from <code>.htaccess</code> and use <noindex><a rel="nofollow" href="http://framework.zend.com/manual/en/zend.auth.adapter.http.html">Zend_Auth_Adapter_Http</a></noindex>  for this purpose &mdash; it&#8217;s Zend&#8217;s HTTP Authentication Adapter.</p>
<p>What concerns the Flash uploader: it sends &#8216;Shockwave Flash&#8217; as value of &#8216;User-Agent&#8217; request header. So in your Initializer or Bootstrap file (where you load Zend_Auth_Adapter_Http) check this header value, and if it&#8217;s not Flash&#8217;s, go for HTTP authentication.</p>
<p>P.S. Hackers can assume this and fake the header to access your site. To cope with that, use an additional secret request variable (Flash uploaders allow this) and check it at server side.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/</feedburner:origLink></item>
		<item>
		<title>Reverse Geocoding</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/QCYxUAEH5Y0/</link>
		<comments>http://i1t2b3.com/2009/09/06/reverse-geocoding/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 07:48:18 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[geo]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=512</guid>
		<description><![CDATA[Reverse Geocoding is process opposite to Geocoding (when you get map coordinates by city/country given). So the idea is to get city name by coordinates on the map. Why you may need it? For example, user is supposed to add a marker on the map, and you want to check that the marker is within [...]]]></description>
			<content:encoded><![CDATA[<p>Reverse Geocoding is process opposite to Geocoding (when you get map coordinates by city/country given). So the idea is to get city name by coordinates on the map.</p>
<p>Why you may need it? For example, user is supposed to add a marker on the map, and you want to check that the marker is within a particular country or region.</p>
<p>Solutions:</p>
<ol>
<li><noindex><a rel="nofollow" href="http://code.google.com/intl/en/apis/maps/documentation/services.html#ReverseGeocoding">Google GeoCoder </a></noindex>(JavaScript) can work with coordinates to retrieve location name. Advantage is that return information is translated to the preferred language of your browser. Here is <noindex><a rel="nofollow" href="http://code.google.com/intl/en/apis/maps/documentation/examples/geocoding-reverse.html">an example</a></noindex> you can play with.</li>
<li><noindex><a rel="nofollow" href="http://www.geonames.org/export/web-services.html">GeoNames.org</a></noindex> offers several services, among which you can find Reverse Geocoding web service (REST or JSON) which can work with coordinates and postal codes. Advantage &mdash; you can download city/region/country names and <abbr title="Points of Interest">POI</abbr> with coordinates.</li>
</ol>
<p><img src="http://i1t2b3.com/wp-content/uploads/2009/09/globe1.gif" alt="GeoNames" title="GeoNames" width="50" height="50" class="alignright size-full wp-image-520" />By the way, here are results of benchmarking <noindex><a rel="nofollow" href="http://www.peterbe.com/plog/google-reverse-geocoding-vs.-geonames">Google vs. GeoNames</a></noindex>.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/06/reverse-geocoding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2009/09/06/reverse-geocoding/</feedburner:origLink></item>
		<item>
		<title>XML to CSV conversion</title>
		<link>http://feedproxy.google.com/~r/i1t2b3com/~3/9ZxJvlMG8ys/</link>
		<comments>http://i1t2b3.com/2009/09/03/xml-to-csv/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:18:10 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[ideas]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=497</guid>
		<description><![CDATA[Data feeds often come in XML format, so your application must be able to deal with that format. As I already wrote, data in CSV format (comma separated values) can be loaded to database extremely fast. So my idea was to convert XML data files to CSV and then use bulk load to database. My [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-504" title="MySQL" src="http://i1t2b3.com/wp-content/uploads/2009/09/mysql-doplhins.png" alt="MySQL" width="180" height="176" />Data feeds often come in XML format, so your application must be able to deal with that format.</p>
<p>As I already <a href="/2009/01/14/quick-csv-import-with-mapping/">wrote</a>, data in CSV format (comma separated values) can be loaded to database extremely fast. So my idea was to convert XML data files to CSV and then use bulk load to database. My tests shown that this is faster in 10-100 times than one by one inserts.</p>
<p>Yesterday I decided to write a generalized solution for this, and it turned out that there is no need: it&#8217;s just coming — <a rel="nofollow" href="http://dev.mysql.com/doc/refman/6.0/en/load-xml.html">MySQL 6 will have such feature</a>!</p>
<p>How it works: you create a table, name its columns exactly as XML nodes/attributes names or  — and MySQL server will load it correspondently.</p>
<p>Example   — you downloaded a POI list file (Points of Interest) called <code>poi.xml</code> that looks like this:</p>
<pre><code class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;gpx&gt;
    &lt;wpt lat="58.691931900" lon="11.253125962"&gt;
        &lt;name&gt;Parking&lt;/name&gt;
    &lt;/wpt&gt;
    &lt;wpt lat="58.315525000" lon="12.305828000"&gt;
          &lt;name&gt;Fast Food Restaurant:Max i trollhattan&lt;/name&gt;
    &lt;/wpt&gt;
    &lt;wpt lat="57.717958100" lon="11.880860600"&gt;
          &lt;name&gt;Picnic spot&lt;/name&gt;
    &lt;/wpt&gt;
&lt;/gpx&gt;</code></pre>
<p>You create a MySQL table:</p>
<pre><code class="sql">CREATE TABLE IF NOT EXISTS `poi` (
  `lat` varchar(255) NOT NULL,
  `lon` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL
) DEFAULT CHARSET=utf8;
</code></pre>
<p>OK, now you load the XML data to your table:</p>
<pre><code class="sql">LOAD XML INFILE '\\path\\to\\poi.txt'
INTO TABLE `poi`
ROWS IDENTIFIED BY '&lt;wpt&gt;'</code></pre>
<p>Voila!</p>
<p>The good thing is that <a rel="nofollow" href="http://mysql.west.mirrors.airband.net/Downloads/MySQL-6.0/">MySQL 6 is already available</a> in alpha version — good enough for development purposes; I gave it a try — it takes 5 seconds to load 4.8 Mb of data in 19 files.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/09/03/xml-to-csv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://i1t2b3.com/2009/09/03/xml-to-csv/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 3.496 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-07-28 17:54:52 --><!-- Compression = gzip -->
