<?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>I want to be free &#187; development</title>
	<atom:link href="http://i1t2b3.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<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=895</generator>
		<item>
		<title>Convert latin1 to utf8</title>
		<link>http://i1t2b3.com/2010/04/14/convert-latin1-to-utf8/</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>
		</item>
		<item>
		<title>Zend View Helpers inheritance</title>
		<link>http://i1t2b3.com/2010/04/06/zend-view-helpers-inheritance/</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>
		</item>
		<item>
		<title>How to rate Points Of Interest automatically</title>
		<link>http://i1t2b3.com/2010/03/13/how-to-rate-points-of-interest-automatically/</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>
		</item>
		<item>
		<title>Federated engine &#8211; MySQL table as symlink</title>
		<link>http://i1t2b3.com/2010/01/29/federated-table-as-symlink/</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>
		</item>
		<item>
		<title>Currency exchange in your application</title>
		<link>http://i1t2b3.com/2009/09/28/currency-exchange/</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>
		</item>
		<item>
		<title>Flash uploader and HTTP password protection</title>
		<link>http://i1t2b3.com/2009/09/11/how-to-skip-http-password-by-flash-uploader/</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>
		</item>
		<item>
		<title>Reverse Geocoding</title>
		<link>http://i1t2b3.com/2009/09/06/reverse-geocoding/</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>
		</item>
		<item>
		<title>XML to CSV conversion</title>
		<link>http://i1t2b3.com/2009/09/03/xml-to-csv/</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>
		</item>
		<item>
		<title>Setting the file access permissions for files and folders</title>
		<link>http://i1t2b3.com/2009/07/09/file-access-permissions-files-n-folders/</link>
		<comments>http://i1t2b3.com/2009/07/09/file-access-permissions-files-n-folders/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 11:33:44 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=452</guid>
		<description><![CDATA[You have a web application hosted on a server and you want to set file access permissions by chmod command, different for files and folders. Why different? A folder must have &#8216;x&#8217; (access) flag: drwxr-xr-x At the same time a file shouldn&#8217;t have it (otherwise it would be executable): rw-r--r-- How can you set it [...]]]></description>
			<content:encoded><![CDATA[<p>You have a web application hosted on a server and you want to set file access permissions by <code>chmod</code> command, different for files and folders.</p>
<p>Why different? A folder must have &#8216;x&#8217; (access) flag:</p>
<pre><code>drwxr-xr-x</code></pre>
<p>At the same time a file shouldn&#8217;t have it (otherwise it would be executable):</p>
<pre><code>rw-r--r--</code></pre>
<p>How can you set it up for all nested files/folders in your application folder?</p>
<p>You can solve this task by setting common persmissions for all files and folders (step 1) and then make folders accessable (step 2), recursively:</p>
<pre><code>chmod -R 644 .
chmod -R a+X .</code></pre>
<p>But <code>chmod</code> allows you to set up only access flag for folders, you cannot set one persmission for folders and another for files. </p>
<p>Here is a script written by my collegue Anton [vojtoshik] Voitovych to solve this task.</p>
<p>Copy it and save to a file (I saved it in <code>/bin/rchmod</code> &mdash; thus it&#8217;s accessable for all users of my system):</p>
<pre><code>#!/bin/bash

files=&quot;0644&quot;;
directories=&quot;0755&quot;;

path=$1;
shift;

while getopts &quot;d:f:&quot; OPTION
do
case $OPTION in
f) files=&quot;$OPTARG&quot; ;;
d) directories=&quot;$OPTARG&quot; ;;
esac
done

if [ &quot;$path&quot; != '' ]; then
    find &quot;$path&quot; -type d ! -name &quot;.&quot; -exec chmod &quot;$directories&quot; {} \;
    find &quot;$path&quot; -type f -exec chmod &quot;$files&quot; {} \;
else
    echo &quot;Usage: rchmod &lt;path_to_directory&gt; [-d &lt;directories mode&gt;] [-f &lt;files mode&gt;]&quot;;
    echo -ne \\n;
fi</code></pre>
<p>OK, now make it executable:</p>
<pre><code>chmod 755 rchmod</code></pre>
<p>How to use it.</p>
<p>1. You are in your application folder and want to set 755 (<code>drwxr-xr-x</code>) mode for folders and 644 (<code>rw-r--r--</code>) mode for files which is the default:</p>
<pre><code>rchmod .</code></pre>
<p>2. You want to set <code>123</code> permissions only for folders in a particular folder::</p>
<pre><code>rchmod /some/path/to/folder -d 123</code></pre>
<p>3. You want to set <code>123</code> permissions for folders and <code>456</code> permission for files in a particular folder::</p>
<pre><code>rchmod /some/path/to/folder -d 123 -f 456</code></pre>
<p>Note: don&#8217;t forget that every time after that command run you should make some folders writable (<code>wp-content/uploads</code>, <code>cache</code>, <code>temp</code> &mdash; what else you have in your webapp).</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/07/09/file-access-permissions-files-n-folders/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Auth Session Expiration Time</title>
		<link>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/</link>
		<comments>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 11:02:52 +0000</pubDate>
		<dc:creator>Skakunov Alexander</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://i1t2b3.com/?p=439</guid>
		<description><![CDATA[After authentication in my project it takes about 10-20 minutes for the auth session to expire, which is not handy &#8212; you go to get a snack and see a login screen coming back. This is how to make the TTL of your auth session longer: $s = new Zend_Session_Namespace( $this-&#62;_auth-&#62;getStorage()-&#62;getNamespace() ); $s-&#62;setExpirationSeconds( strtotime('30 day', [...]]]></description>
			<content:encoded><![CDATA[<p>After authentication in my project it takes about 10-20 minutes for the auth session to expire, which is not handy &mdash; you go to get a snack and see a login screen coming back.</p>
<p>This is how to make the <acronym title="Time To Live">TTL</acronym> of your auth session longer:</p>
<pre><code class="php">$s = new Zend_Session_Namespace(
    $this-&gt;_auth-&gt;getStorage()-&gt;getNamespace() );

$s-&gt;setExpirationSeconds( strtotime('30 day', 0) );</code></pre>
<p>Now your users will log in for 30 days.</p>
<p>You can call this code in your login action after successful authentication and before the redirect to the landing page.</p>
]]></content:encoded>
			<wfw:commentRss>http://i1t2b3.com/2009/07/08/zend-auth-session-expiration-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
