<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jonathan C Dickinson &#187; Tricks</title>
	<atom:link href="http://jonathan.dickinsons.co.za/blog/category/tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathan.dickinsons.co.za/blog</link>
	<description>&#34;Jonathan Chayce Dickinson&#34;.ToString()</description>
	<lastBuildDate>Sun, 06 Jun 2010 11:07:31 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Block Toggler</title>
		<link>http://jonathan.dickinsons.co.za/blog/2009/12/code-block-toggler/</link>
		<comments>http://jonathan.dickinsons.co.za/blog/2009/12/code-block-toggler/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 22:42:34 +0000</pubDate>
		<dc:creator>Jonathan Dickinson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Top Hacks]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://jonathan.dickinsons.co.za/blog/?p=171</guid>
		<description><![CDATA[Handy snippet to switch between two code blocks.]]></description>
			<content:encoded><![CDATA[<p>I came across one of the most awesome meta-language features for C-style languages (specifically any language that has /* */ and // comment support). The nitty-gritties are up at <a href="http://theycallmemrjames.blogspot.com/2009/06/toggle-between-code-blocks.html">a rather good blog</a>. I whipped up a snippet to handle this automatically.</p>
<p>It has a few notable features &#8211; it gives a reason for the flip, it wraps it in a region, it has a auto-task FLIP: prefix and it explains how it&#8217;s used.</p>
<pre class="brush: csharp;">
            #region Flip - This new behaviour is experimental. -
            // FLIP: This new behaviour is experimental.
            //*/// Two proceding slashes will activate the first block, one will activate the second.
            Console.ReadLine();
            /*/
            Console.ReadLine();
            //*/
            #endregion Flip - This new behaviour is experimental. -
</pre>
<p>Drop it in your My Code Snippets folder. In VS select the code you want to flip-comment, Hold CTRL, Press K, Press S, Release CTRL, Press M, Press Enter, Press F, Press Enter (I wish you could assign hot keys to snippets!).</p>
<p><a href='http://jonathan.dickinsons.co.za/blog/wp-content/uploads/2009/12/flipper.txt'>Code Block Flipper</a> (WordPress won&#8217;t let me upload .snippet &#8211; so you will need to rename it)</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathan.dickinsons.co.za/blog/2009/12/code-block-toggler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Wrap BeginInvoke (dispatch)</title>
		<link>http://jonathan.dickinsons.co.za/blog/2009/12/automatically-wrap-begininvoke-dispatch/</link>
		<comments>http://jonathan.dickinsons.co.za/blog/2009/12/automatically-wrap-begininvoke-dispatch/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 07:24:46 +0000</pubDate>
		<dc:creator>Jonathan Dickinson</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://jonathan.dickinsons.co.za/blog/?p=165</guid>
		<description><![CDATA[Easily handle multi-threaded events in .Net WinForms.]]></description>
			<content:encoded><![CDATA[<p><em>C# supports implicit/explicit conversions to Delegates.</em></p>
<p>Yes, big news. I was very surprised when I gave this a shot. It&#8217;s really just one of those things you really don&#8217;t expect to work. So how does this help us? I am sure you are quite sick of writing the following code (the same stuff applies to WPF, you just need to access it via the Dispatch member):</p>
<pre class="brush: csharp;">
void _items_CollectionChanged(object sender, CollectionChangedEventArgs&lt;ConnectionListItem&gt; e)
{
    if (InvokeRequired)
    {
        Invoke(new EventHandler&lt;CollectionChangedEventArgs&lt;ConnectionListItem&gt;&gt;( _items_CollectionChanged ), sender, e);
        return;
    }

}
</pre>
<p>The &#8216;big news&#8217; allows us to do all the heavy lifting for the dispatch BeginInvoke in one simple class (this is a first try &#8211; I&#8217;ll get round to reviewing it later on).</p>
<pre class="brush: csharp;">
    /// &lt;summary&gt;
    /// Represent a wrapper for a delegate.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type of event args.&lt;/typeparam&gt;
    public class InvokeEventWrapper&lt;T&gt;
        where T : EventArgs
    {
        private EventHandler&lt;T&gt; _apparantHandler;
        private EventHandler&lt;T&gt; _rawHandler;
        private Control _parent;

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref="InvokeDelegateWrapper&lt;T&gt;"/&gt; class.
        /// &lt;/summary&gt;
        /// &lt;param name="parent"&gt;The parent.&lt;/param&gt;
        /// &lt;param name="handler"&gt;The handler.&lt;/param&gt;
        public InvokeEventWrapper(EventHandler&lt;T&gt; handler)
            : this(null, handler)
        {

        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref="InvokeDelegateWrapper&lt;T&gt;"/&gt; class.
        /// &lt;/summary&gt;
        /// &lt;param name="parent"&gt;The parent.&lt;/param&gt;
        /// &lt;param name="handler"&gt;The handler.&lt;/param&gt;
        public InvokeEventWrapper(Control parent, EventHandler&lt;T&gt; handler)
        {
            if (handler == null)
                throw new ArgumentNullException("handler");
            if (parent == null)
                parent = (Control)handler.Target;

            _parent = parent;
            _rawHandler = handler;
            _apparantHandler = new EventHandler&lt;T&gt;(Raise);
        }

        /// &lt;summary&gt;
        /// Performs an implicit conversion from &lt;see cref="SharedTerminals.InvokeDelegateWrapper&lt;T&gt;"/&gt; to &lt;see cref="System.EventHandler&lt;T&gt;"/&gt;.
        /// &lt;/summary&gt;
        /// &lt;param name="wrapper"&gt;The wrapper.&lt;/param&gt;
        /// &lt;returns&gt;The result of the conversion.&lt;/returns&gt;
        public static implicit operator EventHandler&lt;T&gt;(InvokeEventWrapper&lt;T&gt; wrapper)
        {
            return wrapper._apparantHandler;
        }

        /// &lt;summary&gt;
        /// Raises the event.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The sender.&lt;/param&gt;
        /// &lt;param name="e"&gt;The e.&lt;/param&gt;
        private void Raise(object sender, T e)
        {
            if (_parent.InvokeRequired)
                _parent.BeginInvoke(_rawHandler, sender, e);
            else
                _rawHandler(sender, e);
        }
    }
</pre>
<p>Using it is pretty simple:</p>
<ol>
<li>Navigate to the event in Intellisense.</li>
<li>Type <em>+=</em>.</li>
<li>Press Tab.</li>
<li>Replace EventHandler with InvokeEventWrapper.</li>
</ol>
<p>So in the end all of that ugly code becomes:</p>
<pre class="brush: csharp;">
_items.CollectionChanged += new InvokeEventWrapper&lt;CollectionChangedEventArgs&lt;ConnectionListItem&gt;&gt;( _items_CollectionChanged );
</pre>
<p>You will need to hold onto a reference for that wrapper if you wish to unsubscribe from the event (one of the things I need to look at).</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathan.dickinsons.co.za/blog/2009/12/automatically-wrap-begininvoke-dispatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Direct to MSDN Chrome Search Tag</title>
		<link>http://jonathan.dickinsons.co.za/blog/2009/08/direct-to-msdn-chrome-search-tag/</link>
		<comments>http://jonathan.dickinsons.co.za/blog/2009/08/direct-to-msdn-chrome-search-tag/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 09:27:21 +0000</pubDate>
		<dc:creator>Jonathan Dickinson</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Short]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://jonathan.dickinsons.co.za/blog/2009/08/direct-to-msdn-chrome-search-tag/</guid>
		<description><![CDATA[lo-band and high-band views easy in chrome.]]></description>
			<content:encoded><![CDATA[<p>If you ever need to get directly to the documentation for a specific type in MSDN (which Bing routinely fails to give me) here is a search provider for Chrome that will do the trick:</p>
<pre class="brush: plain;">http://msdn.microsoft.com/en-us/library/%s.aspx</pre>
<p>You can obviously also do something like:</p>
<pre class="brush: plain;">http://msdn.microsoft.com/en-us/library/%s(loband).aspx</pre>
<p>In case you need a refresher, here is how you add it:</p>
<ol>
<li>Click the wrench (top right).</li>
<li>Options</li>
<li>Basics (top)</li>
<li>Manage (alongside “Default Search”)</li>
<li>Add</li>
<li>Give it a name and keyword (the keyword is important).</li>
<li>Paste in my URL.</li>
</ol>
<p>To use it go to your address bar and type the keyword, tab and then the full type name. So for example (my keyword was msdnd):</p>
<pre class="brush: plain;">msdnd : [TAB] : system.xml.serialization.xmlelementattribute : [RETURN]</pre>
]]></content:encoded>
			<wfw:commentRss>http://jonathan.dickinsons.co.za/blog/2009/08/direct-to-msdn-chrome-search-tag/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Use Is.Gd/Tiny Url/Bookmarklet-X in Chrome</title>
		<link>http://jonathan.dickinsons.co.za/blog/2009/06/how-to-use-isgdtiny-urlbookmarklet-x-in-chrome/</link>
		<comments>http://jonathan.dickinsons.co.za/blog/2009/06/how-to-use-isgdtiny-urlbookmarklet-x-in-chrome/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 08:22:19 +0000</pubDate>
		<dc:creator>Jonathan Dickinson</dc:creator>
				<category><![CDATA[Migrated]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://jonathan.dickinsons.co.za/blog/?p=14</guid>
		<description><![CDATA[How to get the most out of bookmarklets in Google Chrome.]]></description>
			<content:encoded><![CDATA[<p>This morning I got sick of having to constantly open my bookmark toolbar to  use Is.Gd (it just messes with the zen of Chrome) so I tried to figure out how to have it as a shortcut.</p>
<p>One option is to name the bookmark something like !gd, while this works, you  have to type it in and press (down) twice, then enter. Not my cup of tea.</p>
<p>As it turns out Chrome doesn&#8217;t really need a query for a search engine, if  you make a engine with no location for the query string pressing Enter will  invoke it immediately.</p>
<p>So here are the steps:</p>
<ol>
<li>Right click on the link.</li>
<li>Select copy link address.</li>
<li>(Wrench) -&gt; Options</li>
<li>Basics tab.</li>
<li>To the right of &#8220;Default Search:&#8221; click Manage.</li>
<li>Click Add.</li>
<li>Give it a name (mine was Is.Gd)</li>
<li>Give it a keyword (like !isgd).</li>
<li>Paste in the URL.</li>
<li>Ok. Close. Close.</li>
<li>Right click the bookmark on your bookmark tab.</li>
<li>Delete.</li>
</ol>
<p>I tend to create bang-like keywords; just put an exclamation point in front of them.</p>
<p>The only shortcoming right now is that the bookmarks cant contain braces (&#8220;{&#8221; and &#8220;}&#8221;) and you may need to tweak them &#8211; a little. Jon Galloway has an ace bookmarklet that will <a href="http://weblogs.asp.net/jgalloway/archive/2008/08/30/msdn-low-bandwidth-bookmarklet.aspx">switch MSDN to the low bandwidth view</a>. The original format of the link is:</p>
<div class="code-header">Original bookmarklet</div>
<pre class="brush: js;">
javascript:
 if(document.cookie.indexOf('LoBandEnabled=yes')&lt;0)
 {
  document.cookie='LoBandEnabled=yes;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';
 }
 else
 {
  document.cookie='LoBandEnabled=no;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';
 }
 window.location.reload();
</pre>
<p>The first thing you can do is to strip off the <em>window.location.reload();</em>, Chrome does that in any case. The second thing you will have to do is to split it into two seperate bookmarklets.</p>
<div class="code-header">Seperate bookmarklets</div>
<pre class="brush: js; gutter: false; highlight: [1,3];">
document.cookie='LoBandEnabled=yes;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';

document.cookie='LoBandEnabled=no;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';
</pre>
<p>Finally turn them into methods and add the javascript prefix:</p>
<div class="code-header">Final bookmarklets</div>
<pre class="brush: js; gutter: false; highlight: [1,3];">
javascript:void(document.cookie='LoBandEnabled=yes;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';)

javascript:void(document.cookie='LoBandEnabled=no;path=/;domain=.microsoft.com;%20expires=Wed,%2001-Aug-2040%2008:00:00%20GMT';)
</pre>
<p>You can then create two bookmarklets. Mine were <em>!mlon</em> and <em>!mloff</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonathan.dickinsons.co.za/blog/2009/06/how-to-use-isgdtiny-urlbookmarklet-x-in-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
