<?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"
	>

<channel>
	<title>coding.sergey &#187; Uncategorized</title>
	<atom:link href="http://coding.sergey.me/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://coding.sergey.me</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Tue, 02 Mar 2010 21:52:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Cybersecurity</title>
		<link>http://coding.sergey.me/2010/03/02/cybersecurity/</link>
		<comments>http://coding.sergey.me/2010/03/02/cybersecurity/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 21:50:03 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=32</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><object width="480" height="300"><param name="movie" value="http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/player.swf"></param><param name="allowFullScreen" value="true"></param><param name="bgcolor" value="282828"></param><param name="allowscriptaccess" value="always"></param><param name="flashvars" value="file=http://www.whitehouse.gov/videos/2009/May/20090529_POTUS_Cyber_Security.m4v&#038;path_to_plugins=http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins&#038;path_to_player=http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player&#038;skin=http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/skins/EOP_skin.swf&#038;captions_url=http://www.whitehouse.gov/sites/default/files/av_closedcaption/05292009_POTUS_on_Cybersecurity.srt&#038;image=http://www.whitehouse.gov/sites/default/files/audio-video/video_thumbnail/040_0.jpg&#038;controlbar=bottom&#038;frontcolor=AAAAAA&#038;plugins=http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/privacy/privacy,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/hat/hat,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/share/share,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/captions/captions&#038;captions.file=http://www.whitehouse.gov/sites/default/files/av_closedcaption/05292009_POTUS_on_Cybersecurity.srt"></param><embed src="http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/player.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="300" flashvars="file=http://www.whitehouse.gov/videos/2009/May/20090529_POTUS_Cyber_Security.m4v&#038;path_to_plugins=http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins&#038;path_to_player=http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player&#038;skin=http://www.whitehouse.gov/sites/all/modules/swftools/shared/flash_media_player/skins/EOP_skin.swf&#038;captions_url=http://www.whitehouse.gov/sites/default/files/av_closedcaption/05292009_POTUS_on_Cybersecurity.srt&#038;image=http://www.whitehouse.gov/sites/default/files/audio-video/video_thumbnail/040_0.jpg&#038;controlbar=bottom&#038;frontcolor=AAAAAA&#038;plugins=http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/privacy/privacy,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/hat/hat,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/share/share,http://www.whitehouse.gov/sites/default/modules/wh_multimedia/wh_jwplayer/plugins/captions/captions&#038;captions.file=http://www.whitehouse.gov/sites/default/files/av_closedcaption/05292009_POTUS_on_Cybersecurity.srt&#038;stretching=fill&#038;menu=false"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2010/03/02/cybersecurity/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Get list of all foreign key constraints.</title>
		<link>http://coding.sergey.me/2010/02/05/get-list-of-all-foreign-key-constraints/</link>
		<comments>http://coding.sergey.me/2010/02/05/get-list-of-all-foreign-key-constraints/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 14:34:47 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=27</guid>
		<description><![CDATA[Here is the way i do this -

SELECT conname,
       t.relname AS TABLE,
       tf.relname AS ftable,
       a.attname AS field,
       af.attname AS ffield
FROM pg_constraint c,
     pg_attribute a,
   [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the way i do this -</p>
<pre>
SELECT conname,
       t.relname AS TABLE,
       tf.relname AS ftable,
       a.attname AS field,
       af.attname AS ffield
FROM pg_constraint c,
     pg_attribute a,
                   pg_attribute af,
                   pg_stat_user_tables t,
                   pg_stat_user_tables tf
WHERE c.contype='f'
  AND c.conkey[1]=a.attnum
  AND c.conrelid=a.attrelid
  AND c.confkey[1]=af.attnum
  AND c.confrelid=af.attrelid
  AND t.relid=c.conrelid
  AND tf.relid=c.confrelid
</pre>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2010/02/05/get-list-of-all-foreign-key-constraints/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Multithread url fetch using PHP.</title>
		<link>http://coding.sergey.me/2010/01/04/multithread-url-fetch-using-php/</link>
		<comments>http://coding.sergey.me/2010/01/04/multithread-url-fetch-using-php/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 21:08:49 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[curl]]></category>

		<category><![CDATA[multithreading]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=25</guid>
		<description><![CDATA[To be honest, that&#8217;s not a good idea to use fork in php since it eats memory very aggressively. However, in some situations this can be really useful or can be a temporary solution.
Here is an example of using php function pcntl_fork:



Another useful function that can be used for downloading from several urls at the [...]]]></description>
			<content:encoded><![CDATA[<p>To be honest, that&#8217;s not a good idea to use fork in php since it eats memory very aggressively. However, in some situations this can be really useful or can be a temporary solution.</p>
<p>Here is an example of using php function pcntl_fork:</p>
<p><code><br />
<?php</p>
<p>$urls = file('urls.txt');<br />
foreach ($urls as &#038;$url) {</p>
<p>  $pid=pcntl_fork();<br />
  if ($pid == -1) {<br />
	 die('could not fork');<br />
  }<br />
  elseif ($pid)<br />
	{<br />
	}<br />
  else<br />
  {<br />
	// child<br />
	file_put_contents(mt_rand(1, 999999), file_get_contents($url));<br />
        exit;<br />
  }<br />
}</p>
<p>//parent<br />
while (pcntl_wait($status)>0) {};</p>
<p>?><br />
</code></p>
<p>Another useful function that can be used for downloading from several urls at the same time:</p>
<p><code><br />
<?php<br />
function multi_request($urls)<br />
{<br />
  $curly = array();<br />
  $result = array();<br />
  $mh = curl_multi_init();</p>
<p>  foreach ($urls as $id => $url) {<br />
    $curly[$id] = curl_init();<br />
    curl_setopt($curly[$id], CURLOPT_URL, $url);<br />
    curl_setopt($curly[$id], CURLOPT_HEADER, 0);<br />
    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);<br />
    curl_setopt($curly[$id], CURLOPT_TIMEOUT, 30);<br />
    curl_setopt($curly[$id], CURLOPT_FOLLOWLOCATION, true);<br />
    curl_setopt($curly[$id], CURLOPT_SSL_VERIFYPEER, 0);<br />
    curl_setopt($curly[$id], CURLOPT_SSL_VERIFYHOST, 0);<br />
    curl_multi_add_handle($mh, $curly[$id]);<br />
  }</p>
<p>  $running = null;<br />
  do {<br />
    curl_multi_exec($mh, $running);<br />
  } while($running > 0);</p>
<p>  foreach($curly as $id => $c) {<br />
    $result[$id] = curl_multi_getcontent($c);<br />
    curl_multi_remove_handle($mh, $c);<br />
  }<br />
  curl_multi_close($mh);<br />
  return $result;<br />
}<br />
?><br />
</code></p>
<p>A <em>kind of</em> multithreading can be also achieved with popen function and curl or wget:<br />
<code><br />
foreach($urls as $url)<br />
{<br />
   $pps[] = popen(&#8221;wget -O - &#8220;.escapeshellarg($url) , &#8216;r&#8217;);<br />
}<br />
foreach($pps as $pp)<br />
{<br />
   $out = fread($pp,1024*1024);<br />
   // do something with the output<br />
}<br />
</code></p>
<p>Of course the last example is not a real multithreading since have to process the output in a linear manner, but the downloading occurs in parallel.<br />
In addition, this allows using external commands like wget and all their features.</p>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2010/01/04/multithread-url-fetch-using-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>row_number() for Postgres before 8.4</title>
		<link>http://coding.sergey.me/2009/07/10/row_number-for-postgres-before-84/</link>
		<comments>http://coding.sergey.me/2009/07/10/row_number-for-postgres-before-84/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 16:03:31 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[postgresql]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=20</guid>
		<description><![CDATA[Unfortunately i found a solution for this problem only this week, after the new postgres version 8.4 was already released. In the new version this function is already implemented along with many other functions called &#8220;window functions&#8220;.
In any way, for everyone that still uses Postgress version less then 8.4, here is my solution for this [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately i found a solution for this problem only this week, after the new <a href="http://www.postgresql.org/about/news.1108">postgres version 8.4</a> was already released. In the new version this function is already implemented along with many other functions called &#8220;<a href="http://www.postgresql.org/docs/8.4/static/functions-window.html">window functions</a>&#8220;.<br />
In any way, for everyone that still uses Postgress version less then 8.4, here is my solution for this - </p>
<p><code><br />
CREATE OR REPLACE FUNCTION counter(int) RETURNS INT AS $$<br />
return $_[0] + $_SHARED{counter}++; $$<br />
LANGUAGE plperl;</p>
<p>CREATE OR REPLACE FUNCTION get_counter() RETURNS INT AS $$<br />
return $_SHARED{counter}++;<br />
$$<br />
immutable<br />
LANGUAGE plperl; </p>
<p>create or replace function get_row_number() returns integer as<br />
&#8217;select counter(get_counter()*-1);&#8217;<br />
language sql<br />
</code></p>
<p>After declaring this set of functions you will be able to run queries like this - </p>
<p><code>select get_row_number(),* from table...</code></p>
<p>I think this solution is better then creating temporary sequences and using nextval(&#8217;rownum&#8217;).</p>
<p>Your comments are appreciated</p>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2009/07/10/row_number-for-postgres-before-84/feed/</wfw:commentRss>
		</item>
		<item>
		<title></title>
		<link>http://coding.sergey.me/2009/05/31/15/</link>
		<comments>http://coding.sergey.me/2009/05/31/15/#comments</comments>
		<pubDate>Sun, 31 May 2009 19:52:23 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=15</guid>
		<description><![CDATA[
&#8220;Where mysql is good, grep is good too&#8221;
from russian forums&#8230;



]]></description>
			<content:encoded><![CDATA[<blockquote>
<p style="text-align: right;"><span style="color: #808080;">&#8220;Where mysql is good, grep is good too&#8221;<em></em></span></p>
<p style="text-align: right;"><span style="color: #808080;"><em>from russian forums&#8230;</em></span></p>
</blockquote>
<p style="text-align: left;">
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2009/05/31/15/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Eclipse for editing remote files with ssh/sftp.</title>
		<link>http://coding.sergey.me/2008/08/22/using-eclipse-for-editing-remote-files-with-sshsftp/</link>
		<comments>http://coding.sergey.me/2008/08/22/using-eclipse-for-editing-remote-files-with-sshsftp/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 20:47:36 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=5</guid>
		<description><![CDATA[It took me a while to figure out how to work with remote files on server using Eclipse. It seems most of Eclipse users are developing locally and upload already tested code to the server (maybe i&#8217;am wrong). But for me it is important to work directly with remote files.
While on linux you can open [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a while to figure out how to work with remote files on server using <a href="http://www.eclipse.org/">Eclipse</a>. It seems most of Eclipse users are developing locally and upload already tested code to the server (maybe i&#8217;am wrong). But for me it is important to work directly with remote files.<br />
While on linux you can open and edit any file on the server using fish:// (or something like this), on windows there is no such option&#8230; On windows there is an option to install some software like <a href="http://www.magnetk.com/sftpdrive/">sftpDrive</a>, but it costs some 40$&#8230; </p>
<p>So I first tried to use <a href="http://winscp.net/">winscp</a> and configure Eclipse as an editor, but it didn&#8217;t worked because every time i clicked a file it was opening another copy of Eclipse despite any configurations i tried.</p>
<p>Then i played with several Eclipse plugins like <a href="http://eclipsetail.sourceforge.net/eclipsesshconsole.html">Eclipse SSH Console</a>, <a href="http://www.jcraft.com/eclipse-sftp/">SFTP Plug-in for Eclipse</a>, and <a href="http://www.aptana.com">aptana&#8217;s</a> &#8220;Syncronize feature&#8221;, but no of them gave me the result i expected. None of the plugins give the ability to browse/edit/save  remote file.</p>
<p>And FINALLY i found <a href="http://www.eclipse.org/dsdp/tm/tutorial/index.php">Remote System Explorer</a> that solves everything. You <a href="http://download.eclipse.org/dsdp/tm/updates/2.0/">download</a> the plugin an intall it, and then you get a small button &#8220;Remote Systems&#8221; at the bottom of your eclipse that allow you to connect to you servers directly from eclipse. Great success!!</p>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2008/08/22/using-eclipse-for-editing-remote-files-with-sshsftp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Get list of databases/tables/views in Postgresql</title>
		<link>http://coding.sergey.me/2008/08/21/get-list-of-databasestablesviews-in-postgresql/</link>
		<comments>http://coding.sergey.me/2008/08/21/get-list-of-databasestablesviews-in-postgresql/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 21:12:59 +0000</pubDate>
		<dc:creator>sergey</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[postgresql]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://coding.sergey.me/?p=3</guid>
		<description><![CDATA[Get list of databases -
select datname FROM pg_catalog.pg_database;
This displays tables, views, indexes and sequences except postgres internal tables/views
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN
'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid [...]]]></description>
			<content:encoded><![CDATA[<p>Get list of databases -<br />
<code>select datname FROM pg_catalog.pg_database;</code></p>
<p>This displays tables, views, indexes and sequences except postgres internal tables/views<br />
<code>SELECT n.nspname as "Schema",<br />
c.relname as "Name",<br />
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN<br />
'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",<br />
u.usename as "Owner"<br />
FROM pg_catalog.pg_class c<br />
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner<br />
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace<br />
WHERE c.relkind IN ('r','')<br />
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')<br />
AND pg_catalog.pg_table_is_visible(c.oid)<br />
ORDER BY 1,2;</code></p>
<p>Same, but only for tables<br />
<code>select c.relname FROM pg_catalog.pg_class c<br />
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace<br />
WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')<br />
AND pg_catalog.pg_table_is_visible(c.oid);</code></p>
<p>This shows table columns of a given table and their types -<br />
<code>SELECT<br />
attname as Field,<br />
(select typname from pg_type where oid=pga.atttypid) as  Type<br />
FROM pg_attribute pga<br />
WHERE<br />
attrelid=(select oid from pg_class where relname=$table) and<br />
attisdropped=false and<br />
attnum>0</code></p>
]]></content:encoded>
			<wfw:commentRss>http://coding.sergey.me/2008/08/21/get-list-of-databasestablesviews-in-postgresql/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
