<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kobi&#039;s Blog</title>
	<atom:link href="http://kobikobi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kobikobi.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 23 Jan 2012 14:16:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kobikobi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/e825295b3f53b016d78e9b1566d0ea2c?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Kobi&#039;s Blog</title>
		<link>http://kobikobi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kobikobi.wordpress.com/osd.xml" title="Kobi&#039;s Blog" />
	<atom:link rel='hub' href='http://kobikobi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>.Net Regular Expressions &#8211; Finding Decimal Numbers that are Divisible by Three</title>
		<link>http://kobikobi.wordpress.com/2011/05/19/net-regular-expressions-finding-decimal-numbers-that-are-divisible-by-three/</link>
		<comments>http://kobikobi.wordpress.com/2011/05/19/net-regular-expressions-finding-decimal-numbers-that-are-divisible-by-three/#comments</comments>
		<pubDate>Thu, 19 May 2011 17:27:53 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Balancing Group]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Decimal Numbers]]></category>
		<category><![CDATA[Non Practical]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=292</guid>
		<description><![CDATA[It&#8217;s very easy to check a decimal number is divisible by three using a simple DFA with 3 states. A regex, therefor, is possible, but not too pretty (source): Example: http://www.rubular.com/r/ZcRDblHg8M Here&#8217;s another approach, using .Net&#8217;s stacks as a simple counter: Why? Well, I was bored while I shaved. Luckily, this regex is simple enough [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=292&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very easy to check a decimal number is divisible by three using a simple <a href="http://en.wikipedia.org/wiki/Deterministic_finite-state_machine">DFA</a> with 3 states. </p>
<p>A regex, therefor, is possible, but not too pretty (<a href="http://stackoverflow.com/questions/2430556/regular-expression-for-any-number-divisible-by-60-using-c-net/3694683#3694683">source</a>):<br />
<pre class="brush: plain;">
(?:[0369]|
[147](?:[0369]*[147][0369]*[258])*(?:[0369]*[258]|[0369]*[147][0369]*[147])|
[258](?:[0369]*[258][0369]*[147])*(?:[0369]*[147]|[0369]*[258][0369]*[258])
)*
</pre></p>
<p>Example: <a href="http://www.rubular.com/r/ZcRDblHg8M">http://www.rubular.com/r/ZcRDblHg8M</a></p>
<p>Here&#8217;s another approach, using .Net&#8217;s stacks as a simple counter:</p>
<p><pre class="brush: plain;">
\b
(?&gt;             # No regrets - don't backtrack on if/else decisions.
    [0369]      # = 0 (mod 3)
    |
    [147]       # = 1 (mod 3)
    (?:         # if possible pop 2, else push 1
        (?&lt;-Sum&gt;){2}|(?&lt;Sum&gt;)
    )
    |
    [258]       # = 2 (mod 3)
    (?:         # if possible pop 1, else push 2
        (?&lt;-Sum&gt;)|(?&lt;Sum&gt;){2}
    )
)+
\b
(?(Sum)(?!)) # Assert nothing's left in the stack
</pre></p>
<p>Why? Well, I was bored while I shaved. Luckily, this regex is simple enough for Mono. Working example: <a href="http://ideone.com/Yp6Ti">http://ideone.com/Yp6Ti</a> (ok, maybe not, mono is missing 111222)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=292&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2011/05/19/net-regular-expressions-finding-decimal-numbers-that-are-divisible-by-three/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net Regular Expressions &#8211; Using the Stack State to Understand Numeric Values</title>
		<link>http://kobikobi.wordpress.com/2011/04/25/net-regular-expressions-using-the-stack-state-to-understand-numeric-values/</link>
		<comments>http://kobikobi.wordpress.com/2011/04/25/net-regular-expressions-using-the-stack-state-to-understand-numeric-values/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 14:28:58 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Balancing Group]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Non Practical]]></category>
		<category><![CDATA[Numeric]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=277</guid>
		<description><![CDATA[It is common knowledge that regular expressions should handle text and not values. A recent stack overflow question got me thinking though &#8211; it is possible to use .Net regular expressions to understand numbers or other values while matching the pattern? Regular expressions can be used to perform numerical tasks, but that is usually when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=277&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is common knowledge that regular expressions should handle <a href="http://stackoverflow.com/q/4098086/7586#4098123">text and not values</a>. A recent <a href="http://stackoverflow.com/q/5678422/7586">stack overflow question </a>got me thinking though &#8211; it is possible to use .Net regular expressions to understand numbers or other values while matching the pattern?<br />
Regular expressions can be used to perform numerical tasks, but that is usually when working in <a href="http://en.wikipedia.org/wiki/Unary_numeral_system">unary base</a>.<br />
It turns out this is possible &#8211; .Net keeps a stack for every capture of every matched group while matching the pattern, and that state is available for use while matching. The idea is simple: we can represent numbers as depth of the stack, so the number 0 is an empty stack, 6 is a stack with 6 captures, and so forth.</p>
<p><pre class="brush: plain;">
(?&gt;
    (?=[0-9])   # optimization - don't multiply when we don't have a digit.
    # multiply the content of the stack by 10
    # for each item on Stack, push 10 items to a Temp stack.
    (?(Decimal)
        (?&lt;-Decimal&gt;
            (?&lt;Temp&gt;){10}
        )
    ){100000}
    (?(Decimal)(?!))
    # Push all items from Temp back to Stack
    (?(Temp)
        (?&lt;-Temp&gt;
            (?&lt;Decimal&gt;)
        )
    ){100000}
    (?(Temp)(?!))
    # match a digit, and push its value to the stack
    (?:
        0                 |
        1 (?&lt;Decimal&gt;)    |
        2 (?&lt;Decimal&gt;){2} |
        3 (?&lt;Decimal&gt;){3} |
        4 (?&lt;Decimal&gt;){4} |
        5 (?&lt;Decimal&gt;){5} |
        6 (?&lt;Decimal&gt;){6} |
        7 (?&lt;Decimal&gt;){7} |
        8 (?&lt;Decimal&gt;){8} |
        9 (?&lt;Decimal&gt;){9}
    )
)+
</pre></p>
<p>The idea is very simple: when we see a new digit, we <strong>multiply</strong> the depth of the stack by 10, and <strong>add</strong> the number represented by the new digit. The value of the number can be verified using:</p>
<p><pre class="brush: csharp;">
match.Groups[&quot;Decimal&quot;].Captures.Count
</pre></p>
<p>A curious bit here is the use of the loop to copy stacks:</p>
<p><pre class="brush: plain;">
(?(Temp)
    (?&lt;-Temp&gt;
        (?&lt;Decimal&gt;)
    )
){100000}
</pre></p>
<p>I&#8217;d expect this to be enough:</p>
<p><pre class="brush: plain;">
(?&lt;-Temp&gt; (?&lt;Decimal&gt;) )*
(?(Temp)(?!))
</pre></p>
<p>It turns out the above loop is only executed once, and the condition always fails. It is probably a documented optimization, I&#8217;ll look more into that later. As a proof of concept, the workaround should do.</p>
<p>It is even possible to perform basic arithmetic operations on these stacks such as adding, subtracting, multiplying and such from within the regex engine, but that may be a few extra steps too many.<br />
It should go without saying, of course, that regex isn&#8217;t a good option here &#8211; this is for recreational use. The run time and complexity are far from ideal.</p>
<p><strong>See also: </strong></p>
<ul>
<li><a href="https://gist.github.com/940593">https://gist.github.com/940593</a> &#8211; Sample program that captures a decimal number followed by the same number in binary base.</li>
<li><a href="http://stackoverflow.com/q/2795065/7586">How to determine if a number is a prime with regex?</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=277&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2011/04/25/net-regular-expressions-using-the-stack-state-to-understand-numeric-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint 2010 &#8211; Adding Created, CreatedBy, Modified and ModifiedBy to SPMetal&#8217;s Generated Classes</title>
		<link>http://kobikobi.wordpress.com/2011/03/10/sharepoint-2010-adding-created-createdby-modified-and-modifiedby-to-spmetals-generated-classes/</link>
		<comments>http://kobikobi.wordpress.com/2011/03/10/sharepoint-2010-adding-created-createdby-modified-and-modifiedby-to-spmetals-generated-classes/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 09:44:25 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Copy-Paste Code]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[SPMetal]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=269</guid>
		<description><![CDATA[By default, SPMetal doesn&#8217;t map the Created, Created By, Modified and Modified By fields to it&#8217;s generated objects. To remind SPMetal they exist you can easily add them to your parameters XML file (using /parameters:myfile.xml at command line). Of course. You can selectively add where you need it, or add it to Item: Also, here&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=269&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>By default, SPMetal doesn&#8217;t map the Created, Created By, Modified and Modified By fields to it&#8217;s generated objects. To remind SPMetal they exist you can easily add them to your parameters XML file (using <strong>/parameters:myfile.xml</strong> at command line). Of course. You can selectively add where you need it, or add it to Item:</p>
<p><pre class="brush: xml;">
&lt;Column Name=&quot;Editor&quot; Member=&quot;CreatedBy&quot; /&gt;
&lt;Column Name=&quot;Author&quot; Member=&quot;ModifiedBy&quot; /&gt;
&lt;Column Name=&quot;Created&quot; /&gt;
&lt;Column Name=&quot;Modified&quot; /&gt;
</pre></p>
<p>Also, here&#8217;s a template of the SPMetal command:</p>
<p><pre class="brush: plain;">
&quot;%programfiles%\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\spmetal.exe&quot; &quot;/web:http://myserver/someweb/foo&quot; /language:csharp /code:SPFoo.cs /serialization:unidirectional /parameters:FooSPMetalParameters.xml
</pre></p>
<p>See also:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ee535056.aspx">Overriding SPMetal Defaults by Using a Parameters XML File</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ee535058.aspx">SPMetal Parameters XML Schema</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=269&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2011/03/10/sharepoint-2010-adding-created-createdby-modified-and-modifiedby-to-spmetals-generated-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net Regular Expressions &#8211; Finding Acronyms, and Reversing the Stack</title>
		<link>http://kobikobi.wordpress.com/2011/01/04/net-regular-expressions-finding-acronyms-and-reversing-the-stack/</link>
		<comments>http://kobikobi.wordpress.com/2011/01/04/net-regular-expressions-finding-acronyms-and-reversing-the-stack/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 20:46:47 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Balancing Group]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Non Practical]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[Stack Overflow]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=261</guid>
		<description><![CDATA[A recent Stack Overflow question asked if you could (not should) use regular expressions to find acronyms, specifically of the form &#8220;Original Poster (OP)&#8221; &#8211; words followed by the acronym in parentheses. Well, my first try was this: Seems simple &#8211; the first line captures the words and pushes each first letter to the stack. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=261&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A recent Stack Overflow question asked if you could (not should) <a href="http://stackoverflow.com/q/4593376/7586">use regular expressions to find acronyms</a>, specifically of the form <strong>&#8220;Original Poster (OP)&#8221;</strong> &#8211; words followed by the acronym in parentheses. </p>
<p>Well, my first try was this:<br />
<pre class="brush: plain;">
\b((?&lt;Acronym&gt;\w)\w*\W+)+
\((?&lt;-Acronym&gt;\k&lt;Acronym&gt;)+\)
(?(Acronym)(?!))
</pre><br />
Seems simple &#8211; the first line captures the words and pushes each first letter to the stack. The second line pops and matches it, and the last line makes sure there aren&#8217;t any extra letters. Seems nice, but wrong. The first letter on the stack in this case comes from the <em>last </em>word, so it matches a reversed acronym &#8211; <strong>&#8220;Oops, Wrong (WO)&#8221;</strong>.</p>
<p>What I had to do is to reverse the stack. I came up with this regex:<br />
<pre class="brush: plain;">
\b((?&lt;Acronym&gt;\w)\w*\W+)+
(?&lt;=(?&lt;-Acronym&gt;.(?=.*?(?&lt;Reverse&gt;\k&lt;Acronym&gt;)))+)(?(Acronym)(?!))
\((?&lt;-Reverse&gt;\k&lt;Reverse&gt;)+\)
(?(Reverse)(?!))
</pre><br />
Now, I&#8217;m not sure that&#8217;s the best way, but it works nicely. The second line is the only thing interesting &#8211; I won&#8217;t explain it too much, because nobody is reading it. Basically, I match every letter on the stack, and push it to a second stack. I match a dot for each letter because the engine has trouble matching a zero-width expression multiple times (though it works with {5}, for example, but not + or {1,5} &#8211; it only tries one). I can match backwards because I know I had at least that many letters, and can look forward because I&#8217;m optimistic &#8211; I expect to match these letters later, so if they aren&#8217;t there, I might as well fail now.</p>
<p>Here&#8217;s a sample program: <a href="https://gist.github.com/765417">https://gist.github.com/765417</a><br />
I tried creating an <a href="http://ideone.com/goy7R">ideone version</a>, but it fails (probably a mono bug)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=261&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2011/01/04/net-regular-expressions-finding-acronyms-and-reversing-the-stack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net Regex &#8211; Matching Mixed Balanced Parentheses</title>
		<link>http://kobikobi.wordpress.com/2010/12/14/net-regex-matching-mixed-balanced-parentheses/</link>
		<comments>http://kobikobi.wordpress.com/2010/12/14/net-regex-matching-mixed-balanced-parentheses/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 15:52:22 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Balancing Group]]></category>
		<category><![CDATA[Nested Parentheses]]></category>
		<category><![CDATA[Non Practical]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=245</guid>
		<description><![CDATA[Yesterday I got thinking about matching different types balanced parentheses using .net regular expression. I assumed it was similar to matching quotes or a single kind of parentheses, but soon realized it isn&#8217;t quite that simple. The main problem is looking into the stack &#8211; when I see a closed curly brace, for example, how [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=245&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday I got thinking about matching different types balanced parentheses using .net regular expression. I assumed it was similar to matching quotes or a single kind of parentheses, but soon realized it isn&#8217;t quite that simple. The main problem is looking into the stack &#8211; when I see a closed curly brace, for example, how can I tell the top of the stack has an open one?</p>
<p>A quick search brought up <a href="http://retkomma.wordpress.com/2009/09/26/regex-balancing-group-in-depth/">Linguistic Forms&#8217; Regex Balancing Group in Depth</a>, which has a clever approach to the problem in the best use I&#8217;ve seen yet to balancing groups, and taught me a few new tricks. I&#8217;d recommend reading it. The tl;dr version is this: when I see a closed bracket I look-behind my current position using whatever was matched since the last open bracket, revisit it, and check it again. So, if I see I had a <strong>{</strong> (by matching it again), I know I should now match a <strong>}</strong>.</p>
<p>While reading the post I had an interesting idea &#8211; how says I must push to the stack what I matched? What if wanted to push an arbitrary string to the stack? When I see an open bracket I really want to push a closing bracket &#8211; but how can I?<br />
The trick is to use a look-ahead: find the next occurrence of the character I want to push, and push it:</p>
<p><pre class="brush: plain;">
{(?=.*?(&lt;Stack&gt;}))
</pre></p>
<p>Next, when I want to match a closing brace, I already have the right one in stack.<br />
Using this approach, here&#8217;s a regex that matches tokens with matching balanced parentheses of 3 different typed:</p>
<p><pre class="brush: plain;">
(
    [^(){}\[\]]+
    | \( (?=[^)]*  (?&lt;Stack&gt; \) ) )
    | \[ (?=[^\]]* (?&lt;Stack&gt; \] ) )
    | \{ (?=[^}]*  (?&lt;Stack&gt; \} ) )
    | \k&lt;Stack&gt; (?&lt;-Stack&gt;)
)+?
(?(Stack) (?!))
</pre> </p>
<p>Of course, this approach does have limitations &#8211; you may not find the character you&#8217;d like to push (which <em>might </em>be a good thing &#8211; it allows you to fail early). It also gets much trickier if you want to balance something more complicated constant strings, but that&#8217;s another subject.</p>
<p>Here&#8217;s a sample program one ideone: <a href="http://ideone.com/WaXfZ">http://ideone.com/WaXfZ</a></p>
<p>Happy matching.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=245&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2010/12/14/net-regex-matching-mixed-balanced-parentheses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint 2010 &#8211; Using Document Id to Link to a Specific Version</title>
		<link>http://kobikobi.wordpress.com/2010/09/29/sharepoint-2010-using-document-id-to-link-to-a-specific-version/</link>
		<comments>http://kobikobi.wordpress.com/2010/09/29/sharepoint-2010-using-document-id-to-link-to-a-specific-version/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 21:40:31 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Document Id]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=231</guid>
		<description><![CDATA[SharePoint 2010 introduces Document Id, which is an easy way to create document permalinks across a SharePoint Site (SPSite), without worrying about changing names and folders. This is all nice and well, but what if you&#8217;ve enabled versioning, and want to link to a specific version? It is a shame DocIdRedir.aspx does not accept a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=231&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SharePoint 2010 introduces <a href="http://thecommunicator.co.cc/2010/05/27/document-id-feature-in-sharepoint-2010/">Document Id</a>, which is an easy way to create document permalinks across a SharePoint Site (SPSite), without worrying about changing names and folders.<br />
This is all nice and well, but what if you&#8217;ve enabled versioning, and want to link to a specific version?<br />
It is a shame <strong>DocIdRedir.aspx</strong> does not accept a version as an optional parameter, but a small shame, as it is easy enough to implement your own handler, using the API method <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.documentmanagement.documentid.findurlbyid.aspx">DocumentId.FindUrlById</a>. Alternately, you could have done that yourself and used <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.documentmanagement.documentid.findurlsbyid.aspx">DocumentId.FindUrl<strong>s</strong>ById</a>, find the appropriate SPListItem and find the version url, if you don&#8217;t approve of the way FindUrlById does that for you.<br />
My solution is to create another page, much like DocIdRedir.aspx, and have it accept a version and act accordingly (in this case I&#8217;ve created an ASHX handler, but it should be just the same):</p>
<p><pre class="brush: csharp;">
public void ProcessRequest(HttpContext context)
{
	string docId = context.Request.QueryString[&quot;id&quot;];
	string versionLabel = context.Request.QueryString[&quot;v&quot;];
	SPSite currentSite = SPContext.Current.Site;
	string url = null;
	try
	{
		url = GetUrlFromID(currentSite, docId, versionLabel);
	}
	catch (Exception ex)
	{
		string message = String.Format(&quot;Error finding document by id {0} and version [{1}], {2}&quot;
			, docId, versionLabel, ex.Message);
		SPUtility.TransferToErrorPage(message);
	}

	if (url == null)
	{
		string message = String.Format(&quot;Could not find document with id {0} and version [{1}]&quot;
			, docId, versionLabel);
		SPUtility.TransferToErrorPage(message);
	}
	else
	{
		context.Response.Write(url);
	}
}

private string GetUrlFromID(SPSite site, string docId, string version)
{
	//FindUrlById throws an exception if version is empty or null,
	// so I check it here to make sure it works.
	if (String.IsNullOrEmpty(version))
	{
		string[] urls = DocumentId.FindUrlsById(site, docId);
		return urls.Single(); // think about what you do here
	}
	else
	{
		return DocumentId.FindUrlById(site, docId, version);
	}
}
</pre></p>
<p>After creating and deploying your package, which is effortless in Visual Studio 2010, instead of using the default permalinks:</p>
<pre>/_layouts/DocIdRedir.aspx?ID=GROOVY-10-2</pre>
<p>you can use your own handler (you may want a shorter solution name and handler):</p>
<pre>/_layouts/mySolution/VersionedDocumentId.ashx?id=GROOVY-10-2&amp;v=2.5</pre>
<p><strong>See also:</strong></p>
<ul>
<li><a href="http://gist.github.com/601848">Source code of FindUrlById</a></li>
<li><a href="http://gist.github.com/601861">Source code of the default handler, DocIdRedir.aspx</a> &#8211; found in<br />
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\BIN\Microsoft.Office.DocumentManagement.Pages.dll</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=231&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2010/09/29/sharepoint-2010-using-document-id-to-link-to-a-specific-version/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>Using .Net Regex Balancing Groups to Match Words in Fibonacci Lengths</title>
		<link>http://kobikobi.wordpress.com/2010/09/06/using-net-regex-balancing-groups-to-match-words-in-fibonacci-lengths/</link>
		<comments>http://kobikobi.wordpress.com/2010/09/06/using-net-regex-balancing-groups-to-match-words-in-fibonacci-lengths/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 17:22:37 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Balancing Group]]></category>
		<category><![CDATA[Fibonacci]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=203</guid>
		<description><![CDATA[\b (?&#60;A&#62;\w)+\s+ (?&#60;A&#62;\w)+\s+ (?&#60;-A&#62;\w)+ (?(A)(?!)) \b The first example captures three words. Besides spaces and word boundaries, the interesting bits read: (?&#60;A&#62;\w)+ &#8211; Capture the first and second word. Push each letter to the A stack. A note here is the it might have been more correct to write (?:\w(?&#60;A&#62;))+, so I don&#8217;t push a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=203&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre>\b
(?&lt;A&gt;\w)+\s+
(?&lt;A&gt;\w)+\s+
(?&lt;-A&gt;\w)+
(?(A)(?!))
\b
</pre>
<p>The first example captures three words. Besides spaces and word boundaries, the interesting bits read:</p>
<ul>
<li><code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(?&lt;A&gt;\w)+</code> &#8211; Capture the first and second word. Push each letter to the A stack. A note here is the it might have been more correct to write <code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(?:\w(?&lt;A&gt;))+</code>, so I don&#8217;t push a value I don&#8217;t use to the stack, but I think the <code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(?&lt;A&gt;\w)</code> is clearer. I could have also compressed it to <code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">((?&lt;A&gt;\w)+\s+){2}</code>, but then it would have been even less readable.</li>
<li><code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(?&lt;-A&gt;\w)+</code> &#8211; On the third word, this will only match as many letters as matched before. An alternative syntax here would be <code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(\w(?&lt;-A&gt;))+</code>.</li>
<li><code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">(?(A)(?!))</code> &#8211; Fail the match if there are still letters in the A stack. This one is a must, in case the third word is shorter than the first two.</li>
<li><code style="display:inline;background-image:none;background-color:#eee;color:#45d;border-style:none;padding:0;">\b</code> &#8211; Last but the least, I need to make sure I match at word boundaries.</li>
</ul>
<p>Note that In the above regex I don&#8217;t care if the second word is longer or of equal length to the first. If this is a problem for you, it can be checked using the following pattern. I won&#8217;t explain it too much, but the idea here is to push two letters to the B stack for each letter you remove from the A stack:</p>
<pre>\b
(?&lt;A&gt;\w)+   # First word
\s+
(?&lt;B-A&gt;(?&lt;B&gt;)\w)+  # Second word - consume all A's, push an extra B
(?(A)(?!))   # Make sure A is finished
(?&lt;B&gt;\w)*    # Add more B's (or none)
\s+
(?&lt;-B&gt;\w)+ # Third word
(?(B)(?!))
\b
</pre>
<p>Finally, here&#8217;s a regex to capture a sequence of words, where the length of each word is equal to the sum of the lengths of the two previous words:</p>
<pre>\b
(?:
    (?&lt;A&gt;\w)+   # First word - push each letter
    \s+
    (?=
        (?&lt;A&gt;\w)+  # Second word - push each letter
        \s+
        (?&lt;-A&gt;\w)+ # Third word - pop letters
        (?(A)(?!))
        \b
    )    #Look Ahead
)+
\w+\s+\w+\b #Capture last two words (already looked at them)
</pre>
<p>This might look a bit strange: I match a single word at a time, and use the look-ahead to check the following two words. The result is a sequence of words whose lengths make a Fibonacci series.</p>
<p><strong>See Also:</strong><br />
<a href="http://retkomma.wordpress.com/2009/09/26/regex-balancing-group-in-depth/">Regex Balancing Group in Depth</a> &#8211; An excellent introduction to balancing groups and the basic concepts and tools used in .Net regular expressions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=203&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2010/09/06/using-net-regex-balancing-groups-to-match-words-in-fibonacci-lengths/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery UI Datepicker Slow On IE6</title>
		<link>http://kobikobi.wordpress.com/2010/01/01/jquery-ui-datepicker-slow-on-ie6/</link>
		<comments>http://kobikobi.wordpress.com/2010/01/01/jquery-ui-datepicker-slow-on-ie6/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 19:41:42 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jQuery UI]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=167</guid>
		<description><![CDATA[Internet Explorer 6 is, unfortunately, still is widely used in corporate environments. I&#8217;ve found the jQuery UI (1.7.2) Datepicker too slow on IE6, taking several seconds to display, and another few seconds to hide. Looking for a solution, I&#8217;ve found this thread, suggesting it&#8217;s an IE6 bug that caused it to load the same background [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=167&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Internet Explorer 6 is, unfortunately, still is widely used in corporate environments. I&#8217;ve found the <a href="http://docs.jquery.com/UI/Datepicker">jQuery UI (1.7.2) Datepicker</a> too slow on IE6, taking several seconds to display, and another few seconds to hide.</p>
<p>Looking for a solution, I&#8217;ve found <a href="http://old.nabble.com/ui.datepicker-ie6-running-very-slow-td20431806s27240.html">this thread</a>, suggesting it&#8217;s an IE6 bug that caused it to load the same background images dozens of times. The suggested solution, however, didn&#8217;t work for me. I came up with a slightly better solution. Simply add this CSS rule to prevent the background images from loading in IE6:<br />
<pre class="brush: css;">
* html .ui-datepicker tbody a {background-image:none !important;}
</pre></p>
<p>The next step is to disable animation. The date picker has many elements &#8211; animating them is too much work for IE6, resulting in the animation not showing at all &#8211; but still delaying the calendar. Wonderful. The solution is to disable the animation for IE6 by setting its duration to 0. You may also want to set the animation to null, because some animations ignore the zero duration. This is done <a href="http://docs.jquery.com/Utilities/jQuery.support">for IE6 only</a>, as there is no need to penalize modern browsers.</p>
<p><pre class="brush: jscript;">
$('input.Calendar').datepicker({
           showAnim: jQuery.support.boxModel ? 'drop' : null, // optional
           duration: jQuery.support.boxModel ? 'normal' : ''
        });
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=167&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2010/01/01/jquery-ui-datepicker-slow-on-ie6/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Items to a SharePoint List</title>
		<link>http://kobikobi.wordpress.com/2009/05/04/adding-items-to-a-sharepoint-list/</link>
		<comments>http://kobikobi.wordpress.com/2009/05/04/adding-items-to-a-sharepoint-list/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:23:06 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Permissions]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[SPItem]]></category>
		<category><![CDATA[SPList]]></category>
		<category><![CDATA[web part]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=144</guid>
		<description><![CDATA[Ok, a low-tech post this time. I&#8217;ve wasted the better part of my last few days battling Share Point permissions. My goal was to write a web part that lets users add an entry to a Share Point list. So, in case you (or me) need users to add items to a list, this could [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=144&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ok, a low-tech post this time. I&#8217;ve wasted the better part of my last few days battling Share Point permissions. My goal was to write a web part that lets users add an entry to a Share Point list. So, in case you (or me) need users to add items to a list, this could save us a lot of time&#8230;<br />
<span id="more-144"></span><br />
At first everything worked well, since I used a system account for testing. As expected, when switching to a regular user I started getting errors:</p>
<ol>
<li><strong>Access Denied</strong> &#8211; At first I received SharePoint&#8217;s Access Denied page. I soon remembered I had to elevate the permissions (lambda style).</li>
<li><strong>Another Access Denied</strong> &#8211; Even after using RunWithElevatedPrivileges, <a href="http://www.mikhaildikov.com/2007/07/runwithelevatedprivileges-watch-out-for.html">we have to reopen our SPSite and SPWeb</a>, we can&#8217;t use SPContext (it has the old permissions). Which is a shame, because we also have to close them later (here this is done with using, but in the real code I manage it on another class).</li>
<li><strong>Security Validation Exception</strong> &#8211; This one took me a few hours. When searching for the answer I saw someone <a href="http://blogs.msdn.com/mpoulson/archive/2005/12/02/499504.aspx">suggesting to use AllowUnsafeUpdates</a> (which a colleague said I should use on a different project). That means setting &#8220;web.AllowUnsafeUpdates = true;&#8221; before I make any updates, and setting it back to false later.<br />
<code>Microsoft.SharePoint.SPException:<br />
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. ---&gt;<br />
System.Runtime.InteropServices.COMException (0x8102006D): The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.<br />
</code>
</li>
<li><strong>ValidateFormDigest</strong> &#8211; While commenting the code I realized I don&#8217;t fully understand what AllowUnsafeUpdates does and why I use it. I came across a very detailed article, that explained I could <a href="http://hristopavlov.wordpress.com/2008/05/16/what-you-need-to-know-about-allowunsafeupdates/">use ValidateFormDigest</a> instead of this little hack.</li>
</ol>
<p>Sample code for users adding or updating an item:<br />
<pre class="brush: csharp;">
//A user cannot add items, needs elevated permissions.
SPSecurity.RunWithElevatedPrivileges(() =&gt;
{
  //when using RunWithElevatedPrivileges we cannot use
  // SPContext.Current - These SP objects have the old
  // privileges. We need to open a new SPSite and SPWeb.
  using (SPSite site = new SPSite(SPContext.Current.Site.ID))
  {
    using (SPWeb web = site.OpenWeb(&quot;/training&quot;))
    {
      //Validate form POST data.
      SPUtility.ValidateFormDigest();

      //demo code for adding or editing an item
      SPList registrations = web.Lists[&quot;Registrations&quot;];
      SPItem newItem = registrations.Items.Add();
      newItem[&quot;Title&quot;] = &quot;Added new Item&quot;;
      newItem.Update();
      //end of demo code.
    }
  }
});
</pre><br />
Second option &#8211; stronger but more hacky:<br />
<pre class="brush: csharp;">
//A user cannot add items, needs elevated permissions.
SPSecurity.RunWithElevatedPrivileges(() =&gt;
{
  //when using RunWithElevatedPrivileges we cannot use
  // SPContext.Current - These SP objects have the old
  // privileges. We need to open a new SPSite and SPWeb.
  using (SPSite site = new SPSite(SPContext.Current.Site.ID))
  {
    using (SPWeb web = site.OpenWeb(&quot;/training&quot;))
    {
      web.AllowUnsafeUpdates = true;

      //code for adding or editing an item...

      web.AllowUnsafeUpdates = false;
    }
  }
});
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=144&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2009/05/04/adding-items-to-a-sharepoint-list/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>
	</item>
		<item>
		<title>Sending Meeting Requests to Outlook via ASP.NET Mail Message</title>
		<link>http://kobikobi.wordpress.com/2009/01/03/sending-meeting-requests-to-outlook-via-aspnet-mail-message/</link>
		<comments>http://kobikobi.wordpress.com/2009/01/03/sending-meeting-requests-to-outlook-via-aspnet-mail-message/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 16:17:27 +0000</pubDate>
		<dc:creator>Kobi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Appointment]]></category>
		<category><![CDATA[Attachment]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[ical]]></category>
		<category><![CDATA[ics]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MailMessage]]></category>
		<category><![CDATA[Meeting]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://kobikobi.wordpress.com/?p=84</guid>
		<description><![CDATA[Numerous programs on my company deal with event registration. Naturally, that involves sending our employees meeting requests. Here&#8217;s the best way I&#8217;ve found so far for doing that. The long function at the end is from a web-service already in use for a few months. To make these ICS files dynamically, I use the .Net [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=84&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Numerous programs on my company deal with event registration. Naturally, that involves sending our employees meeting requests. Here&#8217;s the best way I&#8217;ve found so far for doing that. The long function at the end is from a web-service already in use for a few months.</p>
<div id="attachment_100" class="wp-caption alignright" style="width: 360px"><img class="size-full wp-image-100" title="meeting_request" src="http://kobikobi.files.wordpress.com/2008/12/meeting_request.png?w=510" alt="Meeting Request"   /><p class="wp-caption-text">Meeting Request</p></div>
<p>To make these ICS files dynamically, I use the .Net library <a href="http://sourceforge.net/projects/dday-ical/">DDay.iCal</a>. It&#8217;s aewsome.<br />
It took some trial and error, but at the end I was able to create events that work well for all versions of Outlook.<br />
Unlike the solutions I&#8217;ve found on the web, this one doesn&#8217;t use the office interop thing, so I don&#8217;t need outlook installed on the server. I&#8217;m using a regular SMTP mail message and add the ICS as attachment. </p>
<p>Anyway, assuming you know how to send mails and how to generate the right ICS for your event (we&#8217;ll get to that later), this is the way to send it to Outlook:<br />
First the variables:<br />
<pre class="brush: csharp;">
//init the message with your defaults (from, to, subject, etc)
MailMessage message = initMailMessage();
string iCal = initICal(parameters ...);
</pre><br />
And the code that adds the attachment:<br />
<pre class="brush: csharp;">
//Add the attachment, specify it is a calendar file.
System.Net.Mail.Attachment attachment =
System.Net.Mail.Attachment.CreateAttachmentFromString(
iCal, new ContentType(&quot;text/calendar&quot;));
attachment.TransferEncoding = TransferEncoding.Base64;
attachment.Name = &quot;EventDetails.ics&quot;; //not visible in outlook

message.Attachments.Add(attachment);

sendMailMessage(message);
</pre></p>
<p>Ok. That&#8217;s probably disappointing, since you can&#8217;t just copy-paste this code and make it work. I&#8217;m including more code you may want to use, but first some rules for the ICS files you&#8217;re about to create:</p>
<h4>Rules of Thumb</h4>
<ul>
<li>Make sure to specify the Method property &#8211; should be Publish or Request. Outlook won&#8217;t accept the file without it.</li>
<li>Add an Organizer &#8211; or Outlook 2007 won&#8217;t let people save the event.</li>
<li>Add the meeting&#8217;s subject and description to the ICS file, but also as the mail&#8217;s subject and body. Outlook may display either one.
</ul>
<p>Now for that extra code.<br />
This one is pretty simple &#8211; sends an SMTP message:<br />
<pre class="brush: csharp;">
private static void sendMailMessage(MailMessage mailMessage)
{
string mailHost = &quot;Ask.Someone.com&quot;;
SmtpClient smtpClient = new SmtpClient(mailHost, 25);
smtpClient.DeliveryMethod =
   SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Send(mailMessage);
}
</pre></p>
<p>This fine function creates the ICS:<br />
<pre class="brush: csharp;">
[WebMethod(Description =
   &quot;Send an appointment with much details.&quot;)]
public void SendAppointment(string from, string to,
   string title, string body, DateTime startDate,
   double duration, string location, string organizer,
   bool updatePreviousEvent, string eventId,
   bool allDayEvent,
   int recurrenceDaysInterval, int recurrenceCount)
{
  iCalendar iCal = new iCalendar();

  // outlook 2003 needs this property,
  //  or we'll get an error (a Lunar error!)
  iCal.Method = &quot;PUBLISH&quot;;

  // Create the event
  Event evt = iCal.Create();

  evt.Summary = title;

  evt.Start = new iCalDateTime(startDate.Year,
    startDate.Month, startDate.Day, startDate.Hour,
    startDate.Minute, startDate.Second);
  evt.Duration = TimeSpan.FromHours(duration);
  evt.Description = body;
  evt.Location = location;

  if (recurrenceDaysInterval &amp;gt; 0)
  {
    RecurrencePattern rp = new RecurrencePattern();
    rp.Frequency = FrequencyType.Daily;
    rp.Interval = recurrenceDaysInterval; // interval of days

    rp.Count = recurrenceCount;
    evt.AddRecurrencePattern(rp);
  }
  evt.IsAllDay = allDayEvent;

  //organizer is mandatory for outlook 2007 - think about
  // trowing an exception here.
  if (!String.IsNullOrEmpty(organizer))
    evt.Organizer = organizer;


  if (!String.IsNullOrEmpty(eventId))
    evt.UID = eventId;

  //&quot;REQUEST&quot; will update an existing event with the same
  // UID (Unique ID) and a newer time stamp.
  if (updatePreviousEvent)
    iCal.Method = &quot;REQUEST&quot;;

  // Save into calendar file.
  iCalendarSerializer serializer =
    new iCalendarSerializer(iCal);
  //serializer.Serialize(@&quot;iCalendar.ics&quot;);

  string icalData = serializer.SerializeToString();

  //send the iCal data. Also sends the subject and body
  //on the mail.
  SendAppointmentFromICalWithMailTitle(from, to,
    icalData, title, body);
}
</pre></p>
<h4>See Also:</h4>
<ul>
<li><a href='http://sourceforge.net/projects/dday-ical'>DDay.iCal</a> &#8211; The iCal C# library.</li>
<li><a href='http://www.mavetju.org/programming/outlook-ics.php'>http://www.mavetju.org/programming/outlook-ics.php</a> &#8211; This helped at the beginning, but written in Perl. Which is weird.</li>
<li><a href='http://chuckdotnet.blogspot.com/2007/10/send-outlook-meeting-requests-with.html'>http://chuckdotnet.blogspot.com/2007/10/send-outlook-meeting-requests-with.html</a> &#8211; A VB.Net version, creating his own iCal and using Alternate Views.</li>
<li><a href='http://www.ietf.org/rfc/rfc2446.txt'>The iTip RFC &#8211; RFC 2446</a> &#8211; Had to read parts of it.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kobikobi.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kobikobi.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kobikobi.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kobikobi.wordpress.com&amp;blog=4238694&amp;post=84&amp;subd=kobikobi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kobikobi.wordpress.com/2009/01/03/sending-meeting-requests-to-outlook-via-aspnet-mail-message/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fd75cd399cd893182d6e3d06d738d6d4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kobi</media:title>
		</media:content>

		<media:content url="http://kobikobi.files.wordpress.com/2008/12/meeting_request.png" medium="image">
			<media:title type="html">meeting_request</media:title>
		</media:content>
	</item>
	</channel>
</rss>
