<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Dmytro Shteflyuk's Home</title>
	
	<link>http://kpumuk.info</link>
	<description>In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming.</description>
	<pubDate>Wed, 31 Dec 2008 00:16:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://kpumuk.info/feed/" type="application/rss+xml" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item>
		<title>Memo #2: Useful Git tricks with remote branches</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/493413295/</link>
		<comments>http://kpumuk.info/development/memo-2-useful-git-tricks-with-remote-branches/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 22:59:15 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[memo]]></category>

		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://kpumuk.info/?p=245</guid>
		<description><![CDATA[Here in Scribd we are using Git as primary version control system. We have tons of branches created, merged and destroyed every day. Someday I hope to describe our workflow with Git, but today I want to write about some useful techniques of working with this incredible tool.
It&#8217;s implied that you know what is Git [...]]]></description>
			<content:encoded><![CDATA[<p>Here in <a href="http://www.scribd.com/">Scribd</a> we are using Git as primary version control system. We have tons of branches created, merged and destroyed every day. Someday I hope to describe our workflow with Git, but today I want to write about some useful techniques of working with this incredible tool.</p>
<p>It&#8217;s implied that you know what is Git itself and how to work with it. Below you can find some advanced tricks, that should be helpful for you (at least they were helpful for me).</p>
<p class="more"><span id="more-245"></span></p>
<p>As you may know, to remove local branch <tt>git branch -d branch_name</tt> command is used. But if this branch was pushed to the origin repo, it will never be deleted there. To remove a remote branch use the following command:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">git push origin :branch_name</div></td></table></div>
<p>where <tt>branch_name</tt> &#8212; the name of your branch.</p>
<p>When you are working in a team, everybody can create and push their own branches, which will be retrieved from the Git server during <tt>git pull</tt> or <tt>git fetch</tt>. If a branch being removed from the server, it will remain in your local repo forever. To clean these stale branches up, use this:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">git remote prune origin</div></td></table></div>
<p>Also don&#8217;t forget to take a look at the <a href="http://github.com/webmat/git_remote_branch/tree/master">git_remote_branch</a> command-line tool, which makes work with remote branches as easy as it is possible.</p>
<p>Have any questions? Ask me and I will answer you in following <a href="http://kpumuk.info/tag/memo/">Memo</a>- posts.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=yLKTo"><img src="http://feeds.feedburner.com/~f/kpumuk?i=yLKTo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=N5Kho"><img src="http://feeds.feedburner.com/~f/kpumuk?i=N5Kho" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=gIieo"><img src="http://feeds.feedburner.com/~f/kpumuk?i=gIieo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=tcCCO"><img src="http://feeds.feedburner.com/~f/kpumuk?i=tcCCO" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/493413295" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/development/memo-2-useful-git-tricks-with-remote-branches/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/development/memo-2-useful-git-tricks-with-remote-branches/</feedburner:origLink></item>
		<item>
		<title>Memo #1: Installing mysql and memcached gems on Mac OS X with MacPorts</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/492486618/</link>
		<comments>http://kpumuk.info/development/memo-1-installing-mysql-and-memcached-gems-on-mac-os-x-with-macports/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 19:20:39 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[gems]]></category>

		<category><![CDATA[macos]]></category>

		<category><![CDATA[macports]]></category>

		<category><![CDATA[memcached]]></category>

		<category><![CDATA[memo]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://kpumuk.info/?p=215</guid>
		<description><![CDATA[I have not posted anything here for a long time. It&#8217;s hard to start blogging again, so I will write a short tips and tricks series called &#8220;Memo&#8220;. Today I&#8217;m going to talk about two Ruby gems I&#8217;m using in all my Ruby on Rails project: mysql and memcached. Every time I try to install [...]]]></description>
			<content:encoded><![CDATA[<p>I have not posted anything here for a long time. It&#8217;s hard to start blogging again, so I will write a short tips and tricks series called &#8220;<a href="http://kpumuk.info/tag/memo/">Memo</a>&#8220;. Today I&#8217;m going to talk about two Ruby gems I&#8217;m using in all my Ruby on Rails project: <tt>mysql</tt> and <tt>memcached</tt>. Every time I try to install or update those gems on Mac OS X following error occurs:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">Building native extensions. &nbsp;This could take a while...<br />
ERROR: &nbsp;Error installing mysql:<br />
&nbsp; &nbsp; ERROR: Failed to build gem native extension.</div></td></table></div>
<p>And then I&#8217;m googling on how to install these gems. It&#8217;s time simplify my life and post commands here.</p>
<p class="more"><span id="more-215"></span></p>
<h3>Installing the ruby mysql gem on Mac OS X and MacPorts</h3>
<p>Installing <tt>mysql5</tt> from MacPorts:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">sudo port install mysql5</div></td></table></div>
<p>Now we can install <tt>mysql</tt> gem:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">kpumuk@kpumuk-mbp~: sudo gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5 <br />
Building native extensions. &nbsp;This could take a while...<br />
Successfully installed mysql-2.7<br />
1 gem installed</div></td></table></div>
<h3>Installing the ruby memcached gem on Mac OS X and MacPorts</h3>
<p>First you need to install <tt>memcached</tt> and <tt>libmemcached</tt>:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">sudo port install memcached libmemcached</div></td></table></div>
<p>And then <tt>memcached</tt> gem:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">kpumuk@kpumuk-mbp~: sudo env ARCHFLAGS=&quot;-arch i386&quot; gem install memcached --no-ri --no-rdoc -- --with-libmemcached-dir=/opt/local<br />
Building native extensions. &nbsp;This could take a while...<br />
Successfully installed memcached-0.12<br />
1 gem installed</div></td></table></div>
<p>If you have any questions that could be covered in this series &#8212; ask me in comments.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=UQmUo"><img src="http://feeds.feedburner.com/~f/kpumuk?i=UQmUo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=APdVo"><img src="http://feeds.feedburner.com/~f/kpumuk?i=APdVo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=wbVDo"><img src="http://feeds.feedburner.com/~f/kpumuk?i=wbVDo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=6moVO"><img src="http://feeds.feedburner.com/~f/kpumuk?i=6moVO" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/492486618" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/development/memo-1-installing-mysql-and-memcached-gems-on-mac-os-x-with-macports/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/development/memo-1-installing-mysql-and-memcached-gems-on-mac-os-x-with-macports/</feedburner:origLink></item>
		<item>
		<title>fb:editor FBML tag in Facebook applications</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/217793934/</link>
		<comments>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 18:59:56 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/</guid>
		<description><![CDATA[Some time ago I have started posting about Facebook Application Platform (see my posts about setFBML and Facebook libraries for .NET). Today&#8217;s topic is fb:editor. As you may see, Facebook has nice look and feel, and all applications usually adapted in some way to its interface. fb:editor FBML tag allows you to create forms which [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I have started posting about Facebook Application Platform (see my posts about <a href="http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/">setFBML</a> and <a href="http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/">Facebook libraries for .NET</a>). Today&#8217;s topic is <tt>fb:editor</tt>. As you may see, Facebook has nice look and feel, and all applications usually adapted in some way to its interface. <tt>fb:editor</tt> FBML tag allows you to create forms which looks just like native ones, but it has great limitation: it generates it&#8217;s own <tt>form</tt> tag, so can&#8217;t be used within ASP.NET server form. In this short post I&#8217;ll show HTML generated by <tt>fb:editor</tt> and a way how to use it in your ASP.NET application.</p>
<p class="more"><span id="more-183"></span></p>
<p>Here is example from <a href="http://wiki.developers.facebook.com/index.php/Fb:editor">fb:editor</a> documentation:</p>
<p><img src='http://kpumuk.info/wp-content/uploads/2007/09/fb-editor.png' alt='fb:editor' /></p>
<p>First we need to include <tt>fb:editor</tt> tag to the page to force loading of CSS files:</p>
<div class="codecolorer-container html4strict vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;display:none&quot;</span>&gt;&lt;fb:editor <span class="sy0">/</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span></div></td></table></div>
<p>Now we should define basic structure of the form:</p>
<div class="codecolorer-container html4strict vibrant" style="overflow:auto;white-space:nowrap;width:455px;height:300px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<span class="kw2">table</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;editorkit&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">cellspacing</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width:400px&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">tr</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;width_setter&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">th</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;width:50px&quot;</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">td</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">tr</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">th</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;detached_label&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">label</span> <span class="kw3">for</span><span class="sy0">=</span><span class="st0">&quot;login&quot;</span>&gt;</span>Login:<span class="sc2">&lt;<span class="kw2">br</span>&gt;&lt;<span class="kw2">small</span>&gt;</span>(required)<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">small</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">label</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">td</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;editorkit_row&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;login&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;login&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">td</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;right_padding&quot;</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">tr</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">th</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">td</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;editorkit_buttonset&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;submit&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;editorkit_button action&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Submit&quot;</span> <span class="sy0">/</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;<span class="kw2">td</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;right_padding&quot;</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;</span><br />
&nbsp; &nbsp; <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span><br />
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">table</span>&gt;</span></div></td></table></div>
<p>BTW, we have several enhancements in the original layout: we have specified <tt>for</tt> attribute for the <tt>label</tt> tag (now if you would click to the label, corresponding input would be selected), and added ability to mark required fields with <em>required</em> text (it&#8217;s impossible with <tt>fb:editor</tt>).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=PwyLl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=PwyLl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=hxVdl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=hxVdl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=FH56l"><img src="http://feeds.feedburner.com/~f/kpumuk?i=FH56l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=85WNL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=85WNL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/217793934" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/fbeditor-editor-tag-in-facebook-applications/</feedburner:origLink></item>
		<item>
		<title>Coalesce ?? operator in C# 2.0</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/216601394/</link>
		<comments>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 19:18:27 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[.net]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[syntax]]></category>

		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/</guid>
		<description><![CDATA[Operator ??, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I&#8217;ve participated. Therefore these snippets could be found in production code very often:
12345public string Caption
&#123;
&#160; &#160; get &#123; return ViewState&#91;&#34;Caption&#34;&#93; != null ? &#40;string&#41; ViewState&#91;&#34;Caption&#34;&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>Operator <tt>??</tt>, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I&#8217;ve participated. Therefore these snippets could be found in production code very often:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">string</span> Caption<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="kw1">null</span> <span class="sy0">?</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> <span class="sy0">:</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p class="more"><span id="more-191"></span></p>
<p>Or even:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px;height:300px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">string</span> VisibleStatistic<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">string</span> retval <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> retval <span class="sy0">==</span> <span class="kw1">null</span> <span class="sy0">?</span> <span class="st0">&quot;&quot;</span> <span class="sy0">:</span> retval<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">string</span> SelectedCategoryName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">object</span> retval <span class="sy0">=</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>retval <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> retval<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw4">String</span>.<span class="me1">Empty</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>Almost 50% of this could be easily removed, and you will get beautiful and clear code, just right after you will understand what the hell is operator <tt>??</tt>. Here is information from MSDN:</p>
<blockquote><div>The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.</div>
</blockquote>
<p>Easy and clean explanation. Let&#8217;s try to rewrite all these examples using this operator:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">string</span> Caption<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> <span class="sy0">??</span> <span class="kw4">String</span>.<span class="me1">Empty</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;Caption&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">string</span> VisibleStatistic<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> <span class="sy0">??</span> <span class="kw4">String</span>.<span class="me1">Empty</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;VisibleStatistic&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<br />
<span class="kw1">public</span> <span class="kw4">string</span> SelectedCategoryName<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> <span class="sy0">??</span> <span class="kw4">String</span>.<span class="me1">Empty</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;SelectedCategoryName&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>In case of value-types this approach will not work: you will get <tt>NullReferenceException</tt>. But do not worry &#8212; in this case we can use <tt>Nullable</tt>-types. Before:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">int</span> FirstWidth<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="kw1">null</span> <span class="sy0">?</span> <span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>After:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">int</span> FirstWidth<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <span class="br0">&#123;</span> <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw4">int</span><span class="sy0">?</span><span class="br0">&#41;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> <span class="sy0">??</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; set <span class="br0">&#123;</span> ViewState<span class="br0">&#91;</span><span class="st0">&quot;FirstWidth&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>When you are using <tt>??</tt> operator, expression will be evaluated in the left to right order, so you can use something like this:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">string</span> name <span class="sy0">=</span> FirstName <span class="sy0">??</span> LastName <span class="sy0">??</span> <span class="st0">&quot;Anonymous&quot;</span><span class="sy0">;</span></div></td></table></div>
<p>Of course, it looks more readably than the:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">string</span> name<span class="sy0">;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>FirstName <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; name <span class="sy0">=</span> FirstName<span class="sy0">;</span><br />
<span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>LastName <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; name <span class="sy0">=</span> LastName<span class="sy0">;</span><br />
<span class="kw1">else</span><br />
&nbsp; &nbsp; name <span class="sy0">=</span> <span class="st0">&quot;Anonymous&quot;</span><span class="sy0">;</span></div></td></table></div>
<p>And a fortiori than:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">string</span> name <span class="sy0">=</span> FirstName <span class="sy0">!=</span> <span class="kw1">null</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">?</span> FirstName<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">:</span> <span class="br0">&#40;</span>LastName <span class="sy0">!=</span> <span class="kw1">null</span> <span class="sy0">?</span> LastName <span class="sy0">:</span> <span class="st0">&quot;Anonymous&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></table></div>
<p>Add it to your armoury!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=G7W3l"><img src="http://feeds.feedburner.com/~f/kpumuk?i=G7W3l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=jv8tl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=jv8tl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=sXUql"><img src="http://feeds.feedburner.com/~f/kpumuk?i=sXUql" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=p07XL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=p07XL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/216601394" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/coalesce-operator-in-c-sharp-2-0/</feedburner:origLink></item>
		<item>
		<title>Correct using Cache in ASP.NET</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/215627214/</link>
		<comments>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 19:22:00 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[caching]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/</guid>
		<description><![CDATA[Often in ASP.NET application we see a code which looks like this one:
12345if &#40;Cache&#91;&#34;SomeData&#34;&#93; != null&#41;
&#123;
&#160; &#160; string name = &#40;&#40;SomeClass&#41; Cache&#91;&#34;SomeData&#34;&#93;&#41;.Name;
&#160; &#160; //.....
&#125;
Experienced developer, even if he is not a paranoiac, will find possible problem immediately &#8212; NullReferenceException. That&#8217;s because of caching implementation in ASP.NET. In ideal case an object, that has been cached, [...]]]></description>
			<content:encoded><![CDATA[<p>Often in ASP.NET application we see a code which looks like this one:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">if</span> <span class="br0">&#40;</span>Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span> name <span class="sy0">=</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>SomeClass<span class="br0">&#41;</span> Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">Name</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="co1">//.....</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>Experienced developer, even if he is not a paranoiac, will find possible problem immediately &#8212; <tt>NullReferenceException</tt>. That&#8217;s because of caching implementation in ASP.NET. In ideal case an object, that has been cached, will stay there up to application restart, but in real world it could be deleted between two calls: by the garbage collector when memory is over (because cache uses weak references <tt>WeakReference</tt>); by another thread to refresh cached data.</p>
<p>So the code I have mentioned before works in 99% of all cases, but sometimes you will get errors in your log, which can not be reproduced easily. Here is right cache usage approach:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">SomeClass someClass <span class="sy0">=</span> Cache<span class="br0">&#91;</span><span class="st0">&quot;SomeData&quot;</span><span class="br0">&#93;</span> <span class="kw1">as</span> SomeClass<span class="sy0">;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>someClass <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span> name <span class="sy0">=</span> someClass.<span class="me1">Name</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="co1">//.....</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>Do not relax your vigilance, it&#8217;s exactly what <strong>they</strong> are waiting for! (about bugs)</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=XlI7l"><img src="http://feeds.feedburner.com/~f/kpumuk?i=XlI7l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=c5dFl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=c5dFl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=Zp7Sl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=Zp7Sl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=gcYEL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=gcYEL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/215627214" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/correct-using-cache-in-aspnet/</feedburner:origLink></item>
		<item>
		<title>Crazy piece of code: Checking query parameter</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/201834488/</link>
		<comments>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 20:47:35 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/</guid>
		<description><![CDATA[How often you are laughing out loud when looking on the someone&#8217;s code? Today I found great code in my current project and I can&#8217;t hold posting this to my blog. So,
1234567891011if &#40;Request.QueryString.HasKeys&#40;&#41;&#41;
&#123;
&#160; &#160; string&#91;&#93; keys = Request.QueryString.AllKeys;
&#160; &#160; foreach &#40;string k in keys&#41;
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; if &#40;k == &#34;memberpagemode&#34; &#38;&#38; &#40;string&#41;Request.QueryString.GetValues&#40;k&#41;.GetValue&#40;0&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>How often you are laughing out loud when looking on the someone&#8217;s code? Today I found great code in my current project and I can&#8217;t hold posting this to my blog. So,</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">if</span> <span class="br0">&#40;</span>Request.<span class="me1">QueryString</span>.<span class="me1">HasKeys</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> keys <span class="sy0">=</span> Request.<span class="me1">QueryString</span>.<span class="me1">AllKeys</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="kw4">string</span> k <span class="kw1">in</span> keys<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>k <span class="sy0">==</span> <span class="st0">&quot;memberpagemode&quot;</span> <span class="sy0">&amp;&amp;</span> <span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span>Request.<span class="me1">QueryString</span>.<span class="me1">GetValues</span><span class="br0">&#40;</span>k<span class="br0">&#41;</span>.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="st0">&quot;edit&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pSett.<span class="me1">ChangeFormViewMode</span><span class="br0">&#40;</span>FormViewMode.<span class="me1">Edit</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></table></div>
<p>And how do you search through the hash for a key with specified value?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=zmZkl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=zmZkl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=Cy5wl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=Cy5wl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=NUthl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=NUthl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=EFsfL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=EFsfL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/201834488" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/asp-net/crazy-piece-of-code-checking-query-parameter/</feedburner:origLink></item>
		<item>
		<title>Sphinx Client API 0.3.1 and 0.4.0 r909 for Sphinx 0.9.8 r909 released</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/197652198/</link>
		<comments>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 18:33:10 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[RoR Plugins]]></category>

		<category><![CDATA[fulltext]]></category>

		<category><![CDATA[library]]></category>

		<category><![CDATA[plugin]]></category>

		<category><![CDATA[postgresql]]></category>

		<category><![CDATA[proximity]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[search]]></category>

		<category><![CDATA[sphinx]]></category>

		<category><![CDATA[stemming]]></category>

		<guid isPermaLink="false">http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/</guid>
		<description><![CDATA[ I have a good news: Sphinx Client API has been updated and now it supports all brand new features of the unstable Sphinx 0.9.8 development snapshot. What does it mean for you as a developer? What features you will get if you would decide to switch to the new version? I will describe most [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://kpumuk.info/wp-content/uploads/2007/12/sphinx.jpg' alt='Sphinx Search Engine' align="right" class="post-image" /> I have a good news: Sphinx Client API has been updated and now it supports all brand new features of the unstable Sphinx 0.9.8 development snapshot. What does it mean for you as a developer? What features you will get if you would decide to switch to the new version? I will describe most valuable improvements of the Sphinx in this article, and will show how to use them with new <a href="http://kpumuk.info/projects/ror-plugins/sphinx/">Sphinx Client API 0.4.0 r909</a>.</p>
<p class="more"><span id="more-188"></span></p>
<h2>Table of contents</h2>
<ul>
<li><a href="#multi-query">Multi-query support</a></li>
<li><a href="#engine-v2">Extended engine V2</a></li>
<li><a href="#64-bit">64-bit document and word IDs support</a></li>
<li><a href="#multiple-valued">Multiple-valued attributes</a></li>
<li><a href="#geodistance">Geodistance feature</a></li>
<li><a href="#download">Download</a></li>
</ul>
<p><a name="multi-query"></a></p>
<h2>Multi-query support</h2>
<p>What does it mean? Multi-query support means sending multiple search queries to Sphinx at once. It&#8217;s saving network connection overheads and other round-trip costs. But what&#8217;s much more important, it unlocks possibilities to optimize &#8220;related&#8221; queries internally. Here is quote from the Sphinx home page:</p>
<blockquote><div>
<p>One typical Sphinx usage pattern is to return several different &#8220;views&#8221; on the search results. For instance, one might need to display per-category match counts along with product search results, or maybe a graph of matches over time. Yes, that could be easily done earlier using the grouping features. However, one had to run the same query multiple times, but with different settings.</p>
<p>From now on, if you submit such queries through newly added multi-query interface (as a side note, ye good olde Query() interface is not going anywhere, and compatibility with older clients should also be in place), Sphinx notices that the full-text search query is the same and it is just sorting/grouping settings which are different. In this case it only performs expensive full-text search once, but builds several different (differently sorted and/or grouped) result sets from retrieved matches. I&#8217;ve seen speedups of 1.5-2 times on my simple synthetic queries; depending on different factors, the speedup could be even greater in practice.</p>
</div>
</blockquote>
<p>To perform multi-query you should add several queries using <tt>AddQuery</tt> method (parameters are exactly the same as in <tt>Query</tt> call), and then call <tt>RunQueries</tt>. Please note, that all parameters, filters, query settings are stored between <tt>AddQuery</tt> calls. It means that if you have specified sort mode using <tt>SetSortMode</tt> before first <tt>AddQuery</tt> call, then sort mode will be the same for the second <tt>AddQuery</tt> call. Currently you can reset only filters (using <tt>ResetFilters</tt>) and group by (<tt>ResetGroupBy</tt>) settings. BTW, you can use <tt>Query</tt> as usually to perform single query, but don&#8217;t try to make this call after you have added query into the batch using <tt>AddQuery</tt>.</p>
<p>Stop speaking, let&#8217;s look the example:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'group_id'</span>, <span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">AddQuery</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
<br />
sphinx.<span class="me1">ResetFilters</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'group_id'</span>, <span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">AddQuery</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
<br />
results = sphinx.<span class="me1">RunQueries</span><br />
pp results</div></td></table></div>
<p>As the result we will get array of 2 hashes:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px;height:300px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp; <span class="st0">&quot;status&quot;</span><span class="sy0">=&gt;</span><span class="nu0">0</span>,<br />
&nbsp; <span class="st0">&quot;matches&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; &nbsp;<span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1175658647</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>, <span class="st0">&quot;id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">3</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1175658490</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>, <span class="st0">&quot;id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;error&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span>,<br />
&nbsp; <span class="st0">&quot;words&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span><span class="sy0">=&gt;</span><span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span><span class="sy0">=&gt;</span><span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;time&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp; <span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;fields&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;total&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp; <span class="st0">&quot;warning&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>,<br />
&nbsp; <span class="st0">&quot;status&quot;</span><span class="sy0">=&gt;</span><span class="nu0">0</span>,<br />
&nbsp; <span class="st0">&quot;matches&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; &nbsp;<span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>, <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1175658555</span><span class="br0">&#125;</span>, <span class="st0">&quot;weight&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>, <span class="st0">&quot;id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;error&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span>,<br />
&nbsp; <span class="st0">&quot;words&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span><span class="sy0">=&gt;</span><span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span><span class="sy0">=&gt;</span><span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;time&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp; <span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>, <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; <span class="st0">&quot;fields&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp; <span class="st0">&quot;total&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>,<br />
&nbsp; <span class="st0">&quot;warning&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span><span class="br0">&#125;</span><span class="br0">&#93;</span></div></td></table></div>
<p>Each hash contains the same data as result of <tt>Query</tt> method call. Also they have additional fields <tt>error</tt> and <tt>warning</tt> which contains error and warning message respectively when not empty.</p>
<p>Note: I have added <tt>ResetFilters</tt> call before creating second query. Without this call our query will have two filters with conflicting conditions, so there will be no results at all.</p>
<p><a name="engine-v2"></a></p>
<h2>Extended engine V2</h2>
<p>New querying engine (codenamed &#8220;extended engine V2&#8243;) is going to gradually replace all the currently existing matching modes. At the moment, it is fully identical to extended mode in functionality, but is much less CPU intensive for some queries. Here are notes from Sphinx author:</p>
<blockquote><div>
<p>I have already seen improvements of up to 3-5 times in extreme cases. The only currently known case when it&#8217;s slower is processing complex extended queries with tens to thousands keywords; but forthcoming optimizations will fix that.</p>
<p>V2 engine is currently in alpha state and does not affect any other matching mode yet. Temporary SPH_MATCH_EXTENDED2 mode was added to provide a way to test it easily. We are in the middle of extensive internal testing process (under simulated production load, and then actual production load) right now. Your independent testing results would be appreciated, too!</p>
</div>
</blockquote>
<p>So, to use new matching mode we should use <tt>SPH_MATCH_EXTENDED2</tt> mode. Let&#8217;s do it!</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetMatchMode</span><span class="br0">&#40;</span><span class="re2">Sphinx::Client::SPH_MATCH_EXTENDED2</span><span class="br0">&#41;</span><br />
sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></td></table></div>
<p>Easy enough, right? You should try it by yourself to feel power of new engine. Please note, that this mode is temporary and it will be removed after release.</p>
<p><a name="64-bit"></a></p>
<h2>64-bit document and word IDs support</h2>
<p>Before version 0.9.8 the Sphinx was limited to index up to 4 billion documents because of using 32-bit keys. From here on it has ability to use 64-bit IDs, and new feature does not impact on 32-bit keys performance. Let&#8217;s look at the example. First we will make query to DB with 32-bit keys:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
result = sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span><br />
pp result<span class="br0">&#91;</span><span class="st0">'matches'</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">'id'</span><span class="br0">&#93;</span>.<span class="kw1">class</span></div></td></table></div>
<p>As you can see, class of the <tt>id</tt> field is <tt>Fixnum</tt>. Let&#8217;s try to make call to index with 64-bit keys. You will get <tt>Bignum</tt> as the result, and it means that you can have more than 4 billion documents!</p>
<p><a name="multiple-valued"></a></p>
<h2>Multiple-valued attributes</h2>
<p>Plain attributes only allow to attach 1 value per each document. However, there are cases (such as tags or categories) when it is necessary to attach multiple values of the same attribute and be able to apply filtering to value lists. In these cases we can use multiple-valued attributes now.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetFilter</span><span class="br0">&#40;</span><span class="st0">'tag'</span>, <span class="br0">&#91;</span><span class="nu0">1</span>,<span class="nu0">5</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
pp sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></td></table></div>
<p>In case of using miltiple-valued attribute <tt>tag</tt> you will get result like:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px;height:300px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="br0">&#123;</span><span class="st0">&quot;total_found&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp;<span class="st0">&quot;status&quot;</span><span class="sy0">=&gt;</span><span class="nu0">0</span>,<br />
&nbsp;<span class="st0">&quot;matches&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; <span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;tag&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#91;</span><span class="nu0">4</span>, <span class="nu0">5</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1175658555</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;weight&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><span class="st0">&quot;tag&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#91;</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>,<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1175658490</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;weight&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>,<br />
&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp;<span class="st0">&quot;error&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span>,<br />
&nbsp;<span class="st0">&quot;words&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;wifi&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#123;</span><span class="st0">&quot;hits&quot;</span><span class="sy0">=&gt;</span><span class="nu0">6</span>, <span class="st0">&quot;docs&quot;</span><span class="sy0">=&gt;</span><span class="nu0">3</span><span class="br0">&#125;</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="st0">&quot;time&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;0.000&quot;</span>,<br />
&nbsp;<span class="st0">&quot;attrs&quot;</span><span class="sy0">=&gt;</span><br />
&nbsp; <span class="br0">&#123;</span><span class="st0">&quot;price&quot;</span><span class="sy0">=&gt;</span><span class="nu0">5</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;tag&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1073741825</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;is_active&quot;</span><span class="sy0">=&gt;</span><span class="nu0">4</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;group_id&quot;</span><span class="sy0">=&gt;</span><span class="nu0">1</span>,<br />
&nbsp; &nbsp;<span class="st0">&quot;created_at&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span><span class="br0">&#125;</span>,<br />
&nbsp;<span class="st0">&quot;fields&quot;</span><span class="sy0">=&gt;</span><span class="br0">&#91;</span><span class="st0">&quot;name&quot;</span>, <span class="st0">&quot;description&quot;</span><span class="br0">&#93;</span>,<br />
&nbsp;<span class="st0">&quot;total&quot;</span><span class="sy0">=&gt;</span><span class="nu0">2</span>,<br />
&nbsp;<span class="st0">&quot;warning&quot;</span><span class="sy0">=&gt;</span><span class="st0">&quot;&quot;</span><span class="br0">&#125;</span></div></td></table></div>
<p>As you can see, multiple-valued attributes returned as array of integers.</p>
<p><a name="geodistance"></a></p>
<h2>Geodistance feature</h2>
<p>Sphinx now is able to compute geographical distance between two points specified by latitude and longitude pairs (in radians). So you now can specify per-query &#8220;anchor point&#8221; (and attribute names to fetch per-entry latitude and longitude from), and then use &#8220;@geodist&#8221; virtual attribute both in the filters and in the sorting clause. In this case distance (in meters) from anchor point to each match will be computed, used for filtering and/or sorting, and returned as a virtual attribute too.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">sphinx = <span class="re2">Sphinx::Client</span>.<span class="me1">new</span><br />
sphinx.<span class="me1">SetGeoAnchor</span><span class="br0">&#40;</span><span class="st0">'lat'</span>, <span class="st0">'long'</span>, <span class="nu0">0.87248</span>, <span class="nu0">0.63195</span><span class="br0">&#41;</span><br />
result = sphinx.<span class="me1">Query</span><span class="br0">&#40;</span><span class="st0">'wifi'</span><span class="br0">&#41;</span></div></td></table></div>
<p><a name="download"></a></p>
<h2>Download</h2>
<p>As always, you can download Sphinx Client API from <a href="http://kpumuk.info/projects/ror-plugins/sphinx/">project home page</a>. Take into account that version 0.3.1 of the client API intended to use with Sphinx 0.9.7, and Sphinx Client API 0.4.0 r909 requires Sphinx 0.9.8 r909 development snapshot. You could download Sphinx from the Download section of the <a href="http://www.sphinxsearch.com/">Sphinx home page</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=8HlTl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=8HlTl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=H81Vl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=H81Vl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=xt9tl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=xt9tl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=F9oYL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=F9oYL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/197652198" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/ror-plugins/sphinx-client-api-0-3-1-and-0-4-0-r909-for-sphinx-0-9-8-r909-released/</feedburner:origLink></item>
		<item>
		<title>What the fuck? Are Developers of Facebook client libraries for ASP.NET stupid?</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/158096462/</link>
		<comments>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 15:49:19 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/</guid>
		<description><![CDATA[Last week I faced strange bug in Facebook Developer Toolkit. When I tried to call setFBML method (I mentioned it in my previous post) I&#8217;ve got an exception about invalid signature. &#8220;Haha&#8221; I said and downloaded toolkit sources. After some debugging, I&#8217;ve found a few lines which just killed me:
123// Compute the MD5 hash of [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I faced strange bug in <a href="http://www.codeplex.com/FacebookToolkit/">Facebook Developer Toolkit</a>. When I tried to call <tt>setFBML</tt> method (I mentioned it in my <a href="http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/">previous post</a>) I&#8217;ve got an exception about invalid signature. &#8220;Haha&#8221; I said and downloaded toolkit sources. After some debugging, I&#8217;ve found a few lines which just killed me:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// Compute the MD5 hash of the signature builder</span><br />
hash <span class="sy0">=</span> md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="kw1">Default</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;signatureBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Trim</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></table></div>
<p class="more"><span id="more-182"></span></p>
<p>Just take a look into the MSDN&#8217;s topic about <tt>Encoding.Default</tt>: Gets an encoding for the system&#8217;s current ANSI code page. And below we can find <strong>Caution</strong>:</p>
<blockquote><div>
Different systems might use different encodings as the default; therefore, data streamed from one system to another might be translated incorrectly. To ensure that the encoded bytes are decoded properly, use a Unicode encoding (that is, <tt>UTF8Encoding</tt>, <tt>UnicodeEncoding</tt>, or <tt>UTF32Encoding</tt>) with a preamble. Another option is to use a higher level protocol to ensure that the same format is used for encoding and decoding.
</div>
</blockquote>
<p>Holly shit! Guys, did you read MSDN before writing libraries for others to use? I think you didn&#8217;t.</p>
<p>Anyways, I have fixed my local copy:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">// Compute the MD5 hash of the signature builder</span><br />
hash <span class="sy0">=</span> md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="me1">UTF8</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;signatureBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">Trim</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></table></div>
<p>Of course, it started working perfectly. I have posted a <a href="http://www.codeplex.com/FacebookToolkit/WorkItem/View.aspx?WorkItemId=6645">bug</a> to the tracker and decided to look at the <a href="http://www.codeplex.com/FacebookNET">Facebook.NET</a>, a better and much cleaner implementation according to <a href="http://www.ajaxninja.com/?p=131">AjaxNinja</a>.</p>
<p>And what do you think? Just open <tt>CreateSignature</tt> method in <em>Framework/Service/Core/FacebookRequestParameterList.cs</em> file:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">byte</span><span class="br0">&#91;</span><span class="br0">&#93;</span> hash <span class="sy0">=</span> md5.<span class="me1">ComputeHash</span><span class="br0">&#40;</span>Encoding.<span class="kw1">Default</span>.<span class="me1">GetBytes</span><span class="br0">&#40;</span>sigBuilder.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></table></div>
<p>Aaaaaaaaaa. They ate my brain! I don&#8217;t know what to do. I don&#8217;t know, how to explain to all developers about non-ASCII code pages. We are living in world that is not ideal. We have tons of languages, encodings, code pages. And we have UTF8, which should simplify our life. Hey, guys, WTF?</p>
<p><em>Updated 23 Sep 2007</em>: Facebook.NET developers has closed <a href="http://www.codeplex.com/FacebookNET/WorkItem/View.aspx?WorkItemId=1483">this bug</a>. Hope I will never see something like this again. Facebook Development Toolkit still does not working for me. I see 27 open bugs in its tracker, so I decided to use <a href="http://www.codeplex.com/FacebookNET">Facebook.NET</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=oenOl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=oenOl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=DhiGl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=DhiGl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=uhYMl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=uhYMl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=B7p7L"><img src="http://feeds.feedburner.com/~f/kpumuk?i=B7p7L" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/158096462" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/what-the-fuck-are-developers-of-facebook-client-libraries-for-asp-net-stupid/</feedburner:origLink></item>
		<item>
		<title>Crazy PHP world</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/156141271/</link>
		<comments>http://kpumuk.info/php/crazy-php-world/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 21:56:03 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://kpumuk.info/php/crazy-php-world/</guid>
		<description><![CDATA[We are living in XXI century, but PHPists can&#8217;t decide yet how to write: &#34;text $b&#34; or &#39;text &#39; . $b. I&#8217;m going slightly mad.
via Artjom Kurapov&#8217;s blog.
]]></description>
			<content:encoded><![CDATA[<p>We are living in XXI century, but PHPists can&#8217;t decide yet how to write: <tt>&quot;text $b&quot;</tt> or <tt>&#39;text &#39; . $b</tt>. I&#8217;m going slightly mad.</p>
<p>via <a href="http://kurapov.name/article/1741">Artjom Kurapov</a>&#8217;s blog.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=E4Fal"><img src="http://feeds.feedburner.com/~f/kpumuk?i=E4Fal" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=yr5Jl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=yr5Jl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=f9OYl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=f9OYl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=yrvkL"><img src="http://feeds.feedburner.com/~f/kpumuk?i=yrvkL" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/156141271" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/php/crazy-php-world/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/php/crazy-php-world/</feedburner:origLink></item>
		<item>
		<title>Generating content for the Facebook’s setFBML method in ASP.NET</title>
		<link>http://feeds.feedburner.com/~r/kpumuk/~3/156141272/</link>
		<comments>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 22:43:30 +0000</pubDate>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Facebook]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[controls]]></category>

		<category><![CDATA[fbml]]></category>

		<category><![CDATA[profile]]></category>

		<category><![CDATA[setFBML]]></category>

		<guid isPermaLink="false">http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/</guid>
		<description><![CDATA[In my current project we decided to build a Facebook application. This is really great platform with many interesting ideas inside, which usually means that you will spend a much time to make your application working as expected. Today I wanna talk about user profiles. Any Facebook application could add some action links, which will [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project we decided to build a <a href="http://www.facebook.com/">Facebook</a> application. This is really great platform with many interesting ideas inside, which usually means that you will spend a much time to make your application working as expected. Today I wanna talk about user profiles. Any Facebook application could add some action links, which will be displayed under the user&#8217;s picture, and some content for wide or narrow column. Of course, you can use FBML syntax, especially <tt>fb:if-&#8230;</tt> tags set to choose which content to show on specific profiles to concrete users.</p>
<p class="more"><span id="more-180"></span></p>
<p>For the beginning, I&#8217;ll post a few key points about user profiles. If you want to add some content to the profile of specific user, you should call <tt>profile.setFBML</tt> routine. For users that you have not called <tt>profile.setFBML</tt> for, the actions are read from the content in &#8220;Default FBML&#8221; section of your application settings. For the most part, this will apply to any user who has not added your application. What is &#8220;Default FBML&#8221; itself? If you have added application, you will see &#8220;Default FBML&#8221; on <strong>all profiles</strong> of users that you have not called <tt>profile.setFBML</tt> for, and it does not matter, if they have added your application or not (good place to put &#8220;Invite&#8221; link). The same behavior you would see, if you would call <tt>profile.setFBML</tt> for all users (and if you are crazy enough.)</p>
<p>Please note, &#8220;Default FBML&#8221; is cached indefinitely, so wait some time to get your content on profiles. Another thing &#8212; you can add only action links to user profiles, that have not added your application, and only your application user will see them. This is most important part of the documentation, and you should completely understand it. More detailed description could be found in the documentation for <a href="http://wiki.developers.facebook.com/index.php/Fb:profile-action">fb:profile-action</a> tag and <a href="http://wiki.developers.facebook.com/index.php/Profile.setFBML">profile.setFBML</a> routine.</p>
<h2>FBML-content for user profiles</h2>
<p>There are 4 profile-specific FBML tags exist:</p>
<ul>
<li><tt>fb:profile-action</tt> is used to add action links under the user picture.</li>
<li><tt>fb:subtitle</tt> will be shown right under the title of the your application box.</li>
<li><tt>fb:wide</tt> specifies content to be shown when your application box placed in wide column.</li>
<li><tt>fb:narrow</tt> specifies content to be shown when your application box placed in narrow column.</li>
</ul>
<p>Easy, right? So let&#8217;s examine these tags more precisely.</p>
<p>As I said early, <tt>fb:profile-action</tt> is used to place action links on the user&#8217;s profile. Usually you will add one link:</p>
<div class="codecolorer-container xml vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://www.mysite.com/action/&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; Perform Action<br />
<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span></div></td></table></div>
<p>What about following scenario: I want to see the link &#8220;View my products&#8221; when I&#8217;m looking my own profile, &#8220;View Taisia&#8217;s products&#8221;, if I&#8217;m looking profile of my wife Taisia (and she has added application too), and &#8220;Invite Roman to MyApp&#8221; when I&#8217;m looking profile of my friend Roman, and he has not added application. Here is the code:</p>
<div class="codecolorer-container xml vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span>View my products<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:if-is-app-user</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">possessive</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> products<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Invite.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invite <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> to MyApp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:if-is-app-user<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:if-is-own-profile<span class="re2">&gt;</span></span></span></div></td></table></div>
<p>Please note: this example is similar to example on the <a href="http://wiki.developers.facebook.com/index.php/Fb:profile-action">fb:profile-action</a> documentation page, but has one big difference &#8212; it&#8217;s working: <tt>fb:if-is-app-user uid=&quot;profileowner&quot;</tt> (in documentation example <tt>uid</tt> takes default value &#8220;loggedinuser&#8221;, but we need <tt>uid</tt> of the profile owner.)</p>
<p>This code will work completely only if you will put it into the &#8220;Default FBML&#8221; section of your application settings, or if you will call <tt>profile.setFBML</tt> for user, that has not added your application (but this is madness, what I have talked about early): I have specified action &#8220;Invite someone to MyApp&#8221; in section, which will be shown only on profile of user that has not added application.</p>
<p>BTW, do not forget to remove all line breaks before updating &#8220;Default FBML&#8221;, because Facebook replaces them with <tt>&lt;br/&gt;</tt>.</p>
<p>Another interesting thing you could see from working example: Facebook adds parameter <tt>id</tt> for all links in <tt>profile-action</tt>, and it equals to owner&#8217;s of the profile ID. In my previous example, if I will navigate to Roman&#8217;s profile, I will see hyperlink with URL <tt>http://apps.facebook.com/myapp/Invite.aspx?id=603839739</tt>. Great!</p>
<p>This example is simple, so let&#8217;s move ahead. We have two columns on the profile: left (narrow) and right (wide). You can specify in application settings which one will be default. To put content in wide column, use <tt>fb:wide</tt>, in narrow column &#8212; <tt>fb:narrow</tt>. Quite clear, right?</p>
<p>One more interesting issue. You can specify as many <tt>fb:wide</tt> and <tt>fb:narrow</tt> tags as you wish. All content, specified in <tt>fb:wide</tt> tags will be shown if you application box placed in wide column, all content from <tt>fb:narrow</tt> tags &#8212; when application box placed in narrow column. You can add content outside one of these tags, and it will be shown in both cases &#8212; when application in wide or narrow column. If no content specified for one of column, Facebook will show &#8220;No content to display.&#8221; text.</p>
<h2>When to generate profile FBML?</h2>
<p>Your application box on the user&#8217;s profile should reflect latest changes related to him. Facebook does not know when to update profile information, so you need to do it by yourself (anyway, only you as application developer know when something changes). So, usually you would call <tt>profile.setFBML</tt> after some changes in your application (for example, user or his friends added some data), depending on which information you are rendering on the profile. Sometimes it&#8217;s a good idea to set default data after user has added your application.</p>
<h2>Creating profile FBML content with ASP.NET</h2>
<p>For profile content generating I propose to use <tt>UserControl</tt>s:</p>
<div class="codecolorer-container xml vibrant" style="overflow:auto;white-space:nowrap;width:455px;height:300px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3">&lt;%@ Control <span class="re0">Language</span>=<span class="st0">&quot;C#&quot;</span> <span class="re0">AutoEventWireup</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">CodeBehind</span>=<span class="st0">&quot;ProfileFBML.ascx.cs&quot;</span> <span class="re0">Inherits</span>=<span class="st0">&quot;ProfileFBML&quot;</span> %<span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span>View my products<span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:if-is-app-user</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Products.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re0">possessive</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> products<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;fb:profile-action</span> <span class="re0">url</span>=<span class="st0">&quot;http://apps.facebook.com/myapp/Invite.aspx&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invite <span class="sc3"><span class="re1">&lt;fb:name</span> <span class="re0">uid</span>=<span class="st0">&quot;profileowner&quot;</span> <span class="re0">firstnameonly</span>=<span class="st0">&quot;true&quot;</span> <span class="re2">/&gt;</span></span> to MyApp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:profile-action<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:if-is-app-user<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/fb:else<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:if-is-own-profile<span class="re2">&gt;</span></span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;asp:XmlDataSource</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;xdsCountries&quot;</span></span><br />
<span class="sc3"> &nbsp; &nbsp;<span class="re0">DataFile</span>=<span class="st0">&quot;~/App_Data/CountryCodeList.xml&quot;</span> <span class="re2">/&gt;</span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;fb:wide<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;asp:Repeater</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">DataSourceID</span>=<span class="st0">&quot;xdsCountries&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;rptCountriesWide&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3">&lt;%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryCoded&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span> - <span class="sc3">&lt;%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryName&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/asp:Repeater<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:wide<span class="re2">&gt;</span></span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;fb:narrow<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;asp:Repeater</span> <span class="re0">runat</span>=<span class="st0">&quot;server&quot;</span> <span class="re0">DataSourceID</span>=<span class="st0">&quot;xdsCountries&quot;</span> <span class="re0">ID</span>=<span class="st0">&quot;rptCountriesNarrow&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3">&lt;%# XPath<span class="br0">&#40;</span><span class="st0">&quot;CountryCoded&quot;</span><span class="br0">&#41;</span> %<span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/div<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/ItemTemplate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/asp:Repeater<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/fb:narrow<span class="re2">&gt;</span></span></span></div></td></table></div>
<p>How to get string to put it into the <tt>profile.setFBML</tt>? Here is the code:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:455px"><table cellspacing="0" cellpadding="0"><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">StringBuilder sb <span class="sy0">=</span> <span class="kw3">new</span> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
StringWriter tw <span class="sy0">=</span> <span class="kw3">new</span> StringWriter<span class="br0">&#40;</span>sb<span class="br0">&#41;</span><span class="sy0">;</span><br />
HtmlTextWriter hw <span class="sy0">=</span> <span class="kw3">new</span> HtmlTextWriter<span class="br0">&#40;</span>tw<span class="br0">&#41;</span><span class="sy0">;</span><br />
Control c <span class="sy0">=</span> LoadControl<span class="br0">&#40;</span><span class="st0">&quot;~/ProfileFBML.ascx&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
Controls.<span class="me1">Add</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span><span class="sy0">;</span><br />
c.<span class="me1">RenderControl</span><span class="br0">&#40;</span>hw<span class="br0">&#41;</span><span class="sy0">;</span><br />
Controls.<span class="me1">Remove</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw4">string</span> fbml <span class="sy0">=</span> sb.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></table></div>
<p>I&#8217;ve added control to the <tt>Controls</tt> collection to get events fired. If you would call this snippet from <tt>OnLoad</tt>, only <tt>OnInit</tt> would be fired in <tt>ProfileFBML</tt>, so do not forget to call <tt>DataBind</tt> method to force data binding from <tt>OnInit</tt> in this case.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/kpumuk?a=gzIBl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=gzIBl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=xrwTl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=xrwTl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=TrqYl"><img src="http://feeds.feedburner.com/~f/kpumuk?i=TrqYl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/kpumuk?a=K536L"><img src="http://feeds.feedburner.com/~f/kpumuk?i=K536L" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/kpumuk/~4/156141272" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/feed/</wfw:commentRss>
		<feedburner:origLink>http://kpumuk.info/facebook/generating-content-for-the-facebooks-setfbml-method-in-aspnet/</feedburner:origLink></item>
	</channel>
</rss>
