<?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>{ Code: Impossible } &#187; Open Source</title>
	<atom:link href="http://codeimpossible.com/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:58:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>W.O.M.M. #6 &#8211; enumerateOver()</title>
		<link>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/</link>
		<comments>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 04:17:52 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jsoq]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=478</guid>
		<description><![CDATA[
I&#8217;ve been focusing more and more on  my port of Ling-to-Objects, Jsoq the past few weeks. It&#8217;s still in really early stages and I&#8217;m not quite sure about it&#8217;s actual usefulness but I&#8217;m learning a lot about JavaScript and having a ton of fun along the way!
Jsoq deals with arrays a lot. About 95% [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://codeimpossible.com/wp-content/uploads/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" /></p>
<p>I&#8217;ve been focusing more and more on <a href="http://bitbucket.org/codeimpossible/jsoq"> my port of Ling-to-Objects, Jsoq</a> the past few weeks. It&#8217;s still in really early stages and I&#8217;m not quite sure about it&#8217;s actual usefulness but I&#8217;m learning a lot about JavaScript and having a ton of fun along the way!</p>
<p>Jsoq deals with arrays a lot. About 95% of it&#8217;s use cases involve either looping through, altering, or creating arrays. Having a ton of <code>for</code> loops in my code just seems so&#8230; not right. For loops have always seemed dirty to me. They just aren&#8217;t elegant enough. </p>
<p>Here is your normal, average, everyday <code>for</code> loop in Javascript.</p>
<pre class="prettyprint"><code>
var array = "1,2,3,4,5,6,7,8,9,10".split(',');

for(var i = -1, l = array.length; ++i &lt; l;) {
    alert(array[i]);
}
</code></pre>
<p>This works. It&#8217;s reliable and gets the message across. But what if we needed to loop over an array and get all the items that matched a condition? Using a <code>for</code> loop the code could look something like:</p>
<pre class="prettyprint"><code>
var array = [ 1, 2, 3, 4, 5, 1, 2, 3, 4 ];
var results = [];
var condition = function(i) { return i%2 == 0; };

for(var itt = -1, len = array.length; ++itt &lt; len;) {
	if( condition(array[itt]) ) {
		results.push(array[itt]);
	}
}
</code></pre>
<p>This does work, I&#8217;ve written code like this many times before, and while <em>technically</em> there isn&#8217;t anything wrong with it I think there is still room for improvement.</p>
<p>Jsoq is going to be handling arrays all over the place so the solution to this problem <em>needs</em> to be simple.</p>
<p>Here&#8217;s what I need:</p>
<ul>
<li>to loop over an entire collection and perform an action on each item.</li>
<li>If that action produces a result, the item is to be pushed into an array and returned to after the loop is done</li>
<p>.</p>
<li>Also: it needs to be readable, someone else coming along should be able to determine what this thing is doing without too much difficulty. So I had my work cut out for me. </li>
</ul>
<p>A few hours later I had a decent function that I could use to replace a lot of the <code>for</code> loops I had. After some more refactoring I was able to wipe them all out and replace them with calls to <code>enumerateOver()</code>. Here is the latest version from source control:</p>
<pre class="prettyprint"><code>
function enumerateOver(collection, work) {
	var result = [], val = [];

	if (isArray(collection)) {
		try {
			for (var i = -1, l = collection.length; ++i < l;) {
				result = work(collection[i], i);
				if (typeof result !== "undefined" &#038;&#038; result != null) {
					val.push(result);
				}
			}
		}catch (e) {
			if (e != jsoq.$break) throw(e);
		}

		if (val.length > 0) {
			return val;
		}
	}else {
		try {
			val = work(collection, 0);
		}
		catch (e) {
			if (e != jsoq.$break) throw(e);
		}
		if (typeof val !== 'undefined') {
			return val;
		}
	}
	return result == null ? [] : result;
}
</code></pre>
<p>And here is the code to replace the <code>for</code> loops above, re-written to use <code>enumerateOver()</code></p>
<pre class="prettyprint"><code>
var results2 = enumerateOver(array, function(i, c) {
     return i%2 == 0;
});
</code></pre>
<p>So by implmenting this function I was able to come up with a more readable, testable and streamlined codebase. Is this suitable for everyone? Definitely not, but I did it for a few reasons:</p>
<ol>
<li>Like I mentioned before. I&#8217;ve never been at ease with <code>for</code> loops and being able to replace them all with calls to a single function was a huge win for me</li>
<li>The normal use-case didn&#8217;t fit right. I needed to not only iterate over arrays but also return the results of work performed on those items. Doing this the &#8220;regular&#8221; way just wouldn&#8217;t work (see previous reason)</li>
<li>I thought this was a fun problem to solve</li>
</ol>
<p>If you have any feedback, good, bad, or indifferent add a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft .Net Framework Public Classes Data Dump</title>
		<link>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/</link>
		<comments>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 06:24:27 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=748</guid>
		<description><![CDATA[I&#8217;ve wrapped up work on v0.4 of the Jsoq Console, and the insanely strenuous release cycle for v0.1 of WhatDidIJustEat.com so I&#8217;m starting another side project tonight.
Ever been working with a programming language you&#8217;re not 100% familiar with and find yourself wondering:
Is this function a built-in function or in some included library?
What assembly is this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve wrapped up work on <a href="http://codeimpossible.com/jsoq">v0.4 of the Jsoq Console</a>, and the insanely strenuous release cycle for v0.1 of <a href="http://whatdidijusteat.com">WhatDidIJustEat.com</a> so I&#8217;m starting another side project tonight.</p>
<p>Ever been working with a programming language you&#8217;re not 100% familiar with and find yourself wondering:</p>
<blockquote><p><em>Is this function a built-in function or in some included library?<br />
What assembly is this class in again?<br />
Can I name my class XXXX without conflicting with another class?<br /></em></p></blockquote>
<p>I&#8217;ve had these questions recently and found myself annoyed and frustrated to no end (PHP, I&#8217;m looking at you) so I&#8217;ve decided to build a system to keep track of this stuff for me :D. </p>
<p>The first thing on my list (because it was the easiest) was to do a data dump of all the public classes in the .Net Framework, including the ones in my GAC, and store some metadata for each one in a database table. I&#8217;ve just finished this step and thought that this data might be useful, so I&#8217;m posting it here. </p>
<p>Currently the fields included in the data dump are:</p>
<p><code><br />
[namespace] = The namespace that the class exists in (ex: System.Collections.Generic)<br />
[class_name] = The name of the class (ex: StringBuilder)<br />
[assembly_fullname] = The display name of the assembly (ex: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)<br />
[assembly_file] = The full file path to the assembly (ex: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll)<br />
[framework_name] = The framework that uses this class, for this dump they will all be 'Microsoft .Net'<br />
[framework_version] = The framework version that uses this class (ex: v.2.0.50727)<br />
</code></p>
<p>The .sql file takes about 18 seconds to run to completion on my AMD Athlon X2 2.53ghz machine with 4gb of RAM.</p>
<p>If you&#8217;re curious about how I generated the .sql file, below is the code I used to find all the classes. It&#8217;s not pretty but then again it was just meant to get the data into the database. Just paste the code into a new console app and run it in a command window like so:</p>
<p><code> [application_name].exe &gt; c:\classes.sql</code></p>
<p>Or, you can <a href="http://www.box.net/shared/u8vsuy9lz1">download the .sql file I&#8217;ve generated</a> (it will also create the table you need to store the data).</p>
<pre class="prettyprint"><code>
static void Main(string[] args)
{
	var dictionary = new Dictionary<string, string>(){
		{ "v2.0.50727", @"C:\Windows\Microsoft.NET\Framework\v2.0.50727" },
		{ "v3.0", @"C:\Windows\Microsoft.NET\Framework\v3.0" },
		{ "v3.5", @"C:\Windows\Microsoft.NET\Framework\v3.5" },
		{ "v???", @"c:\windows\assembly\gac" }
	};

	var types = new List<Type>();

	foreach (var pair in dictionary)
	{
		var path = pair.Value;

		var assemblies = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);

		foreach (string file in assemblies)
		{
			try
			{
				Assembly asm = Assembly.LoadFile(file);

				foreach (Type t in asm.GetTypes())
				{
					if (t.IsPublic)
					{
						Console.WriteLine(String.Format(
							"INSERT INTO Classes (" +
								"[namespace], " +
								"class_name, " +
								"assembly_fullname, " +
								"assembly_file, " +
								"framework_name, " +
								"framework_version" +
							") " +
							"VALUES (" +
								"'{0}', " +
								"'{1}', " +
								"'{2}', " +
								"'{3}', " +
								"'Microsoft .Net', " +
								"'{4}'" +
							")",
							String.IsNullOrEmpty(t.Namespace) ?
								"GLOBAL" :
								t.Namespace,
							t.Name
								.Replace("`1", "<T>")
								.Replace("`2", "<T1,T2>")
								.Replace("`3", "<T1,T2,T3>"),
							t.Assembly.FullName,
							t.Assembly.Location,
							pair.Key == "v???" ?
								t.Assembly.GetName().Version.ToString() :
								pair.Key
						));
					}
				}
			}
			catch { }
		}
	}
}
</code></pre>
<p>If you found this useful, let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/12/08/microsoft-net-framework-public-classes-data-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>W.O.M.M. #4 &#8211; Asp MVC Route Attributes</title>
		<link>http://codeimpossible.com/2009/06/22/w-o-m-m-4-asp-mvc-route-attributes/</link>
		<comments>http://codeimpossible.com/2009/06/22/w-o-m-m-4-asp-mvc-route-attributes/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:40:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=403</guid>
		<description><![CDATA[Download the source code mentioned in this blog post.

A few weeks ago on the StackOverflow podcast, something Jeff said got me thinking. Jeff was discussing how the stackoverflow team implemented their route mappings:

Those routes are&#8230; the way we implemented them are actually like decorators. Attributes on the methods. - Jeff Atwood (stackoverflow episode #54)

This instantly [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.box.net/shared/1q4bq5scuz" target="_blank">Download the source code mentioned in this blog post.</a></p>
<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://wpup.codeimpossible.com/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" /></p>
<p>A few weeks ago <a href="http://itc.conversationsnetwork.org/audio/download/ITC.SO-Episode54-2009.05.20.mp3">on the StackOverflow podcast</a>, something Jeff said got me thinking. Jeff was discussing how the stackoverflow team implemented their route mappings:</p>
<p><em><br />
Those routes are&#8230; the way we implemented them are actually like decorators. Attributes on the methods. <cite>- Jeff Atwood (stackoverflow episode #54)</cite><br />
</em></p>
<p>This instantly piqued my interest and I completely zoned out for the rest of the podcast: caught up in working out the details of how I could do this for my own Asp.net MVC projects. </p>
<p>Coming up with the actual attribute code was easy; writing the code to set up all the Routes using only data defined in by the attribute was tricky.</p>
<p>Being new to attributes, and reflection in general, it took me a few hours until I had a very basic demo working. However, I was really starting to like where it was going.</p>
<p class="right side-note callout-green">
As a side note: There are lot of &#8220;helper&#8221; classes and objects in the route attribute project (it feels cluttered to me) and the reason I did this was to make the code in AssemblyExtensions.GetRoutes() easier to read.
</p>
<p>After a few nights of <a href="http://twitter.com/digitalBush/status/2121662803" target="_blank">Mtn Dew and convenience-store cherry-pie</a> I finished the rough code, tests and demo project (included in this blog post) and I was starting to realize that:</p>
<ol>
<li>Using the attributes is more declaritive and it feels cleaner</li>
<li>Having your route information right above your actions is incredibly useful</li>
<li>I had no more need to switch back and forth between your controller and the Global.asax.cs</li>
</ol>
<h2>How does it work?</h2>
<p>All of the real work for the RouteAttribute is done in the AssemblyExtensions class. This class uses extension methods to augment the System.Reflection.Assembly class with two methods: GetControllers() and GetRoutes().</p>
<p>GetRoutes is the only method that is used by other classes, I made GetControllers public for unit testing.</p>
<h3>GetRoutes()</h3>
<p>GetRoutes&#8217; first order of business is to make a list of data that it will need to build out all the routes for the assembly it was passed. After thats done GetRoutes will loop through the collected route data, build up each route and add it to the dictionary that will eventually be returned.</p>
<pre class="prettyprint"><code>
namespace CodeImpossible.Mvc.Routing
{
    public static class AssemblyExtensions
    {

        public static BindingFlags ActionFlags =
            BindingFlags.Instance |
            BindingFlags.Public |
            BindingFlags.DeclaredOnly;

        public static IList&lt;ControllerMetaData&gt; GetControllers(this Assembly assembly)
        {
            var controllers = assembly.GetTypes().ToList().FindAll(type =>
            {
                var isValidController = type.IsClass &#038;&#038;
                    type.IsPublic &#038;&#038;
                    type.IsSubclassOf&lt;Controller&gt;();

                var hasValidActions = type.GetMethods(ActionFlags).ToList().Any(m =>
                {
                    var valid = false;
                    if (m.ReturnParameter != null &#038;&#038; m.ReturnParameter.ParameterType == typeof(ActionResult))
                    {
                        valid = m.GetAttributesOfType&lt;RouteAttribute&gt;().Count > 0;
                    }

                    return valid;
                });

                return isValidController &#038;&#038; hasValidActions;
            }).Select&lt;Type, ControllerMetaData&gt;((t) => new ControllerMetaData(t)).ToList();

            return controllers;
        }

        public static IDictionary&lt;string, Route&gt; GetRoutes(this Assembly assembly)
        {
            var Routes      = new Dictionary&lt;string, Route&gt;();

            var data = (from c in assembly.GetControllers()
                        from a in c.GetActions()
                        from r in a.Data
                        select new
                        {
                            ControllerName = c.Name,
                            ActionName = a.Name,
                            RouteData = r,
                            RouteParams = a.Params
                        }).ToList();

            foreach (var r in data)
            {
                var route               = new Route(r.RouteData.RoutePath, new MvcRouteHandler());
                route.Constraints       = new RouteValueDictionary();
                route.Defaults          = new RouteValueDictionary(new {
                    controller = r.ControllerName,
                    action = r.ActionName
                });

                if (r.RouteData.RequireRouteParams &#038;&#038; r.RouteParams.Count() == 0)
                {
                    throw new MissingRouteParameterException("Unknown", r.RouteData.RoutePath);
                }

                var missingParams = new List&lt;ParameterMetaData&gt;();

                if (r.RouteData.RequireRouteParams)
                {
                    missingParams = (from p in r.RouteParams
                                     where r.RouteData.RoutePath.IndexOf("{" + p.Name + "}") == -1
                                     select p).ToList();
                }

                if (missingParams.Count > 0)
                {
                    var param = missingParams.First();
                    throw new MissingRouteParameterException(param.Name, r.RouteData.RoutePath);
                }

                foreach (var param in r.RouteParams)
                {
                    if (param.Data != null)
                    {
                        if (param.Data.DefaultValue != null)
                        {
                            route.Defaults.Add(param.Name, param.Data.DefaultValue);
                        }

                        if (param.Data.Constraint != null)
                        {
                            route.Constraints.Add(param.Name, param.Data.Constraint);
                        }
                    }
                }

                Routes.Add(r.RouteData.Name ?? r.RouteData.RoutePath, route);
            }

            return Routes;
        }
    }
}
</code></pre>
<h2>Getting the Routes into the RouteTable</h2>
<p>Slapping route attributes onto your classes and methods is all well and good but it doesn&#8217;t mean anything unless we can get those routes into the RouteTable object easliy. Originally I had the code to add the routes looking something like</p>
<pre class="prettyprint"><code>
var routes = Assembly.GetCurrentExecutingAssembly().GetRoutes();

routes.ForEach(r => RouteTable.Add(r));
</code></pre>
<p>This, although pretty easy, wasn&#8217;t as readible as I wanted. So I added some extension methods to the RouteTable class:</p>
<pre class="prettyprint"><code>
RouteTable.Routes.IncludeRoutesFromAssembly();
</code></pre>
<p>I think both of these are much clearer than doing:</p>
<pre class="prettyprint"><code>
RouteTable.Routes.MapRoute("Root",
    "",
    new { controller = "Test", action = "GetItem", id = 1 });

RouteTable.Routes.MapRoute("Search",
    "Search/{id}",
    new { controller = "Test", action = "Search", id = 1 });
//.. SNIP ...
</code></pre>
<h2>Using the RouteAttribute and RouteParamAttribute</h2>
<p>In the controller &#8220;TestController&#8221; below there are three actions: Index, FindByText, and GetItem. Using the RouteAttribute and RouteParamAttribute makes it pretty clear that the routes for FindByText and GetItem are the same but use different RouteContraints. </p>
<p>So a request for /Test/Search/Hello will go to FindByText while /Test/Search/1 will go to GetItem. Also notice how GetItem has a default value of 2 for the id argument.</p>
<pre class="prettyprint"><code>
public class TestController : Controller
{

    [Route(RoutePath = "Test")]
    public ActionResult Index()
    {

        return View();
    }

    [Route(RoutePath = "Test/Search/{query}")]
    public ActionResult FindByText(
        [RouteParam(Constraint="[a-zA-Z]{1,}")]
        string query)
    {

        return View();
    }

    [Route(RoutePath = "Test/Search/{id}")]
    public virtual ActionResult GetItem(
        [RouteParam(Constraint=@"\d{1,}", DefaultValue=2)]
        int id)
    {

        return View();
    }
}</code></pre>
<p>There is support for binding multiple routes to the same action; just add another Route attribute:</p>
<pre class="prettyprint"><code>
[Route("Products/Search/{id}")]
[Route("Products/{id}")]
public ActionResult GetProductById(int id)
{
    return View();
}
</code></pre>
<h2>Downsides or things I haven&#8217;t gotten to yet</h2>
<p>Just some gotchas that I think people might raise issue with.</p>
<p><strong>All of your controllers must inherit from the System.Web.Mvc.Controller class</strong><br />
This isn&#8217;t really a big deal because if you are using Asp.net MVC then you really should inherit from the Controller class, but for those of you using FubuMVC or another MVC framework this should be easy to change.</p>
<p><strong>Attributes can be ugly</strong><br />
I know a few people out there are against attributes but I think that this is a more than acceptable use because it made the code much easier to understand.</p>
<p><strong>Reflection can be slow</strong><br />
Honestly, when I first started working on this demo I was sort of turned off by the use of Reflection myself. After weighing the possible performance loss against the gains in both readability and maintenance I decided this was definitely worth it. I haven&#8217;t performance tested this code so, as always YMMV.</p>
<p>As always, if I screwed up or there is a better way to do this, please let me know in the comments.</p>
<p><a href="http://www.box.net/shared/1q4bq5scuz" target="_blank">Download the source code mentioned in this blog post.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/06/22/w-o-m-m-4-asp-mvc-route-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://itc.conversationsnetwork.org/audio/download/ITC.SO-Episode54-2009.05.20.mp3" length="33894437" type="audio/mpeg" />
		</item>
		<item>
		<title>W.O.M.M. weekly post #3 &#8211; HtmlHelper.Gravatar</title>
		<link>http://codeimpossible.com/2009/04/18/womm-weekly-post-3-htmlhelpergravatar/</link>
		<comments>http://codeimpossible.com/2009/04/18/womm-weekly-post-3-htmlhelpergravatar/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 05:32:12 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=292</guid>
		<description><![CDATA[Long story short: I hate re-inventing the wheel. If there is a free service that does something I need I will try my hardest to get that service into whatever I am working on. I&#8217;m currently working on an Asp .Net MVC project that needs Avatars (you know, those funny little pictures next to peoples [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://wpup.codeimpossible.com/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" />Long story short: I <b>hate</b> re-inventing the wheel. If there is a free service that does something I need I will try my hardest to get that service into whatever I am working on. I&#8217;m currently working on an Asp .Net MVC project that needs Avatars (you know, those funny little pictures next to peoples names on Twitter). Enter <a href="http://www.gravatar.com">Gravatar</a>.<br />
<br />
Gravatar is an awesome service for anyone looking to add avatars to their apps. It&#8217;s free, incredibly simple to implement, and removes a lot of the hassle around getting avatar support into your web/windows app.</p>
<p>Adding Gravatar support to an application is pretty simple. Can you get a users email address? Can you MD5 said email address? Can you make an HTTP GET? BANG. You sir, or madam, can have Gravatars.</p>
<p>This week for the W.O.M.M. code sample I&#8217;d like to show how I integrated gravatar support into an Asp .Net MVC application.</p>
<h3>How Gravatar Works In A Nutshell</h3>
<p>Gravatar is a free service where you sign up and link images to one or more email addresses that you provide.</p>
<p>Once you link an image to an email address, any application that supports getting an image over the internet can show your Gravatar by making a request to a special URL. This URL is generated by combining an MD5 hash of your email address with some other parameters and the end result is a link to your Gravatar image.</p>
<p>IE: the link to my Gravatar on the right of this page is:</p>
<p><code></p>
<p>http://www.gravatar.com/avatar/15559d868ec27b8583f42116a6b96c14?s=140</p>
<p></code></p>
<p>So 15559d868ec27b8583f42116a6b96c14 is the hash of my email address &#8211; don&#8217;t worry it&#8217;s a one-way hash. The &#8220;s&#8221; parameter is the size of the image that I want, in this case 140 pixels.</p>
<p>That is pretty much it as far as how the system works, but if you want to read more, check out <a href="http://en.gravatar.com/site/implement">Gravatar&#8217;s implementation documentation</a>.</p>
<h3>The Goal</h3>
<p>What I wanted was an HtmlHelper extension method that I could use in my view pages to create an IMG tag with the correct Gravatar URL. After <a href="http://en.gravatar.com/site/implement/url">looking at the documentation on Gravatars &#8220;How the URL is constructed&#8221; page</a>, I decided my helper extension should support the following:</p>
<p><b>Avatar Size (the &#8220;s&#8221; parameter)</b><br />
When making a Gravatar URL you can specify a specific size for the Gravatar image. The size can be anything from 1 to 512 pixels, but the default is 80.</p>
<p><b>Default Avatars (the &#8220;d&#8221; parameter)</b><br />
If the email address you are using doesn&#8217;t have any Gravatars setup, Gravatar will generate one for you by default. You can choose from 3 predefined Gravatar types or you can include a URL to a custom avatar of your own. The predefined Gravatar types are Identicon, Wavatar, and Monsterid.</p>
<p><b>Rating (the &#8220;r&#8221; parameter)</b><br />
This wasn&#8217;t a requirement for what I was working on, but you can designate the maximum &#8220;rating&#8221; of the avatars that Gravatar will generate. The accepted values are &#8220;g&#8221;, &#8220;pg&#8221;, &#8220;r&#8221;, and &#8220;x&#8221; and they are inclusive, so specifying &#8220;r&#8221; will allow &#8220;g&#8221; and &#8220;pg&#8221; rated Gravatars to be generated. Gravatars that are rated &#8220;x&#8221; will be returned as one of the predefined avatars above. The default rating is &#8220;g&#8221;.</p>
<h3>The Code</h3>
<p>Okay, so now I know what I need to support. Now it&#8217;s just a matter of getting the code to do this. Let&#8217;s take a look at the class file I used to get this done.</p>
<pre class="prettyprint"><code>
namespace System.Web.Mvc
{
    using System;
    using System.Web.Routing;
    using System.Web.Security;

    public enum GravatarDefaultTypes
    {
        Identicon,
        Wavatar,
        Monsterid,
        Custom
    }

    public static class GravatarExtension
    {
		public static string Gravatar(
			this HtmlHelper hh,
			string emailAddress,
			int size,
			GravatarDefaultTypes defaultType,
			string customImageUrl,
			RouteValueDictionary htmlAttributes)
        {
            var tagBuilder = new TagBuilder("img");
            string url = "http://www.gravatar.com/avatar/{0}?d={1}&#038;s={2}";

	    // thanks to jon galloway for this one-liner!
            // http://www.eggheadcafe.com/aspnet/how-to/141740/adding-gravatars-to-your.aspx
            string hash = FormsAuthentication
				.HashPasswordForStoringInConfigFile(emailAddress, "MD5");
            string defImg = defaultType.ToString().ToLower();

            if (defaultType == GravatarDefaultTypes.Custom)
            {
                defImg = System.Web
					.HttpUtility
					.UrlEncode(customImageUrl);
            }

            url = String.Format(
                url,
                hash.ToLower(),
                defImg,
                size.ToString());

            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("src", url);

            return tagBuilder.ToString(TagRenderMode.Normal);
        }
    }
}
</code></pre>
<p>So you can see I&#8217;m not storing the hash of the email address, instead I am going to pass in the unaltered string. I didn&#8217;t want to have another piece of data to update when the user changed their email address so the Gravatar() method takes an email address and encodes it using a call to FormsAuthentication.HashPasswordForStoringInConfigFile(), which is awesome ( Thanks Jon, you rock!).</p>
<p>Also, I&#8217;m not sure if this is a no-no or what, but I did put the extension class under the System.Web.Mvc namespace. This was mainly a convenience (read: laziness) thing and can be easily changed.</p>
<p>Alright so we have some code now, let&#8217;s take a look at how it can be used in our views.</p>
<pre class="prettyprint"><code>
    &lt;%= Html.Gravatar(
        	Model.Email, // the email address
        	50, // size, in pixels of the avatar
        	GravatarDefaultTypes.Identicon,
        	null,
        	new RouteValueDictionary(new {
        		style = "vertical-align: middle;"
        	})
    )%> 
    <b> &lt;%= Model.UserName %> </b>
</code></pre>
<p>Let&#8217;s see how that looks.</p>
<p><img src="http://wpup.codeimpossible.com/2009/04/user-avatar.png" alt="user-avatar" title="user-avatar" width="84" height="81" class="size-full wp-image-378" /></p>
<p>Booyah, avatar support in 55 lines of code. As always, if I screwed up or there is a better way to do this, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/04/18/womm-weekly-post-3-htmlhelpergravatar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>W.O.M.M. weekly post #2</title>
		<link>http://codeimpossible.com/2009/04/10/womm-weekly-post-2/</link>
		<comments>http://codeimpossible.com/2009/04/10/womm-weekly-post-2/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 04:37:19 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=364</guid>
		<description><![CDATA[Due to me being insanely sick this week I&#8217;m going to be changing up the format for the Works On My Machine weekly project post for this week.
Instead of presenting a project that I&#8217;ve worked on I&#8217;d like to highlight some .Net OSS projects / source code that I&#8217;ve been working with / looking at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://wpup.codeimpossible.com/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" />Due to me being insanely sick this week I&#8217;m going to be changing up the format for the Works On My Machine weekly project post for this week.</p>
<p>Instead of presenting a project that I&#8217;ve worked on I&#8217;d like to highlight some .Net OSS projects / source code that I&#8217;ve been working with / looking at lately.</p>
<p> </p>
<ul>
<li><a href="http://code.google.com/p/morelinq/" target="_blank">The More Linq project</a> &#8211; An extension library for LinqToObjects run by Jon Skeet.</li>
<li><a href="http://www.musikcube.com/" target="_blank">MusikCube</a> &#8211; Awesome music player that uses SqlLite to allow &#8220;smart playlists&#8221; (eg. show me all songs that were added this week that have fewer than 4 stars and have been played less than 10 times).</li>
<li><a href="http://code.google.com/p/moq/" target="_blank">Moq</a> &#8211; IMHO the best mocking framework for .net development.</li>
<li>Scott Hanselman posted some code on his website a while back about <a href="http://www.hanselman.com/blog/TheWeeklySourceCode35ZipCompressingASPNETSessionAndCacheState.aspx" target="_blank">how to Zip Compress your Session and Cache data</a> in Asp.net.</li>
</ul>
<p>Feel free to send me any code that you come across and I&#8217;ll feature it in a future post.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/04/10/womm-weekly-post-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Works on my machine weekly project #1</title>
		<link>http://codeimpossible.com/2009/04/05/works-on-my-machine-weekly-project-1/</link>
		<comments>http://codeimpossible.com/2009/04/05/works-on-my-machine-weekly-project-1/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 04:34:49 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=347</guid>
		<description><![CDATA[Download the source code mentioned in this blog post.
 
I&#8217;m a hopeless code junkie. I love to write code. Most people do one thing for work and then another for their hobby. My girlfriend for instance works as an IT / Systems Engineer  and her other thing is photography.
My other thing is writing more code. I never [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.box.net/shared/hacsh3b3s4" target="_blank">Download the source code mentioned in this blog post.</a></p>
<p> </p>
<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://wpup.codeimpossible.com/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" />I&#8217;m a hopeless code junkie. I love to write code. Most people do one thing for work and then another for their hobby. My girlfriend for instance works as an IT / Systems Engineer  and her other thing is photography.</p>
<p><em>My</em> other thing is writing <strong>more</strong> code. I never did this with any of my previous jobs (save dish washer&#8230; I did wash dishes when I was at home but I wasn&#8217;t trying out new, cooler ways to wash them).</p>
<p>&#8230; So where was I? Oh, right code junkie. So, I really like to write code and what I&#8217;ve decided to do is start a new small project each week and try to use some new chunk of .Net or a new library and I&#8217;ll post the end results of my efforts here for you all.</p>
<p>All of these projects will be offered under the CodeImpossible &#8220;works on my machine&#8221; code quality guarantee. But I&#8217;ll never post something that flat-out doesn&#8217;t work.</p>
<p>Sound good? Cool, let&#8217;s kick it off &#8211; as the first entry into this space I&#8217;d like to present <strong>TweetCommander</strong>.</p>
<p>TweetCommander is a small .Net v3.5 console application that lies in wait, watching a twitter account for any new Direct Messages from another user (we&#8217;ll call this person the &#8220;owner&#8221;).</p>
<p>When a direct message from the owner is found, TweetCommander will check to see if it contains certain text, and depending on that text, will perform a series of actions on the machine it is running on.</p>
<p>TweetCommander will support three commands: &#8220;current_screenshot&#8221;, &#8220;exit&#8221;, and &#8220;set_interval&#8221;.</p>
<ul>
<li>Sending &#8220;current_screenshot&#8221; will tell TweetCommander to take a screen capture of the Windows desktop, upload it to TwitPic, and then send the url for that image to the owner user in a Direct Message.</li>
<li>Sending &#8220;exit&#8221; will cause TweetCommander to exit</li>
<li>The &#8220;set_interval&#8221; is followed by a number that represents the number of seconds TweetCommander should wait between requests for new direct messages from twitter. This is more to avoid the API limit than anything else.</li>
</ul>
<p><strong>Settings</strong><br />
TweetCommander will need to store the Twitter ID for the last successfully processed Direct Message somewhere so we aren&#8217;t constantly processing the same commands over and over again. The end user won&#8217;t need to be aware of this value but it&#8217;s worth mentioning anyway.</p>
<p>We&#8217;ll also need to store the wait interval so we don&#8217;t lose this information if we need to restart TweetCommander for whatever reason.</p>
<p>Okay, so here is the settings file I have so far:</p>
<p><img class="aligncenter size-full wp-image-348" title="tweet_mon_console_settings" src="http://wpup.codeimpossible.com/2009/04/tweet_mon_console_settings.jpg" alt="tweet_mon_console_settings" width="473" height="170" /></p>
<p><strong>Working with Twitter</strong><br />
All right so now we need to be able to interact with Twitter. Now, I don&#8217;t want to write my own API library so I&#8217;ll <a href="http://code.google.com/p/tweetsharp" target="_blank">go out and get the latest copy of TweetSharp</a> which will give me a nice, readable interface to twitter&#8217;s API. After getting this built I&#8217;ll be able to get the most recent direct messages using the following code:</p>
<pre class="prettyprint"><code>
var directMessages = FluentTwitter.CreateRequest()
	.AuthenticateAs(
		TWITTERACCOUNT_USERNAME,
		TWITTERACCOUNT_PASSWORD)
	.DirectMessages()
	.Received()
	.Since(Properties
		.Settings
		.Default
		.LastProcessedCommandID)
	.AsJson()
	.Request()
	.AsDirectMessages();
</code></pre>
<p>Thats pretty freakin&#8217; sweet I must say. Tweet# really takes the brain work out of working with twitter and there is no way to look at that code and <strong>not</strong> understand what it is doing immediately. Epic win.</p>
<p>To get this running on your machine, just<a href="http://www.box.net/shared/hacsh3b3s4" target="_blank"> grab the source from my box.net folder</a>, and change these values at the top of the Program.cs file:</p>
<pre class="prettyprint"><code>
// this is our "owner account" we will only act upon direct messages
// send from this user
private static string TWITTEROWNER  = "codeimpossible"; 

// this is our listener accounts username
private static string TWITTERACCOUNT_USERNAME = "someuser";

// this is our listener accounts password
private static string TWITTERACCOUNT_PASSWORD = "somepassword";
</code></pre>
<p><em>Note: The solution file for this contains a reference to a compiled version of  the Tweet# library that contains </em><a href="http://code.google.com/p/tweetsharp/issues/detail?id=36"><em>a quick patch I made for an issue that affects uploading an image to Twitpic</em></a><em>. However this issue has been fixed officially in the most recent source.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/04/05/works-on-my-machine-weekly-project-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing The JavaScript Object Query Library</title>
		<link>http://codeimpossible.com/2009/02/10/introducing-the-javascript-object-query-library/</link>
		<comments>http://codeimpossible.com/2009/02/10/introducing-the-javascript-object-query-library/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 06:51:16 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jsoq]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.wordpress.com/?p=272</guid>
		<description><![CDATA[So, yeah I originally started writing this article back in september when I was about mid-way through JSOQ. Some things have changed since then and I&#8217;ve tried to keep the post up-to-date. Enjoy!
Also, another similar library has come out recently: JSINQ which is a really feature-rich LINQ to Object implementation in Javascript. Really bad-ass stuff.
The Elevator [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>So, yeah I originally started writing this article back in september when I was about mid-way through JSOQ. Some things have changed since then and I&#8217;ve tried to keep the post up-to-date. Enjoy!</em></p>
<p><em>Also, another similar library has come out recently: <a href="http://www.codeplex.com/jsinq" target="_blank">JSINQ</a> which is a really feature-rich LINQ to Object implementation in Javascript. Really bad-ass stuff.</em></p></blockquote>
<p>The Elevator Pitch:</p>
<p>JSOQ is an open-source pet project of mine that lets you easily access the data that you need from large collections in JavaScript. It was developed over a two week period in September of 2008 and is currently at version 1.1.</p>
<p>Everyone probably just shrugged and said &#8220;so??&#8221; Well let me show you. </p>
<p>Lets assume that you have the following JSON string from another web application like, say <a title="Twitter search results in JSON" href="http://search.twitter.com/search.json?q=codeimpossible" target="_blank">twitter search results</a> for example:</p>
<pre class="brush:javascript">
{"results":[
{
"text":"Just another day at the office",
"to_user_id":null,
"from_user":"codeimpossible",
"id":1194587890,
"from_user_id":1316793,
"iso_language_code":"en",
"profile_image_url":"www.path.to.image.us",
"created_at":"Tue, 10 Feb 2009 05:47:33 +0000"
},
{
"text":"@spolsky thats easy! http:\/\/tinyurl.com\/2z42bs",
"to_user_id":1357501,
"to_user":"spolsky",
"from_user":"codeimpossible",
"id":1194582705,
"from_user_id":1316793,
"iso_language_code":"en",
"profile_image_url":"www.path.to.image.us",
"created_at":"Tue, 10 Feb 2009 05:44:51 +0000"
}
]} 
</pre>
<p>In the sample above we only have two results but JSOQ has been tested to work with collections of tens of thousands of items.</p>
<p>The JSON object we have here is perfectly fine if we watned to show a whole bunch of data to the end user, but what if I only wanted to show the search results after a certain date? Or what if I only wanted the text from each message that was typed to this &#8220;spolsky&#8221; character?</p>
<p>To accomplish this in &#8220;straight&#8221; javascript I&#8217;d be looking at writing a lot of loops and if/else code and then I would still have all these extra properties that I don&#8217;t even need.</p>
<p>JSOQ allows me to query a javascript object or collection of objects using a specified criteria and return only the properties/methods I want.</p>
<p>So lets go with the second option. Let&#8217;s get all the .text members from all the messages that were sent to the &#8220;spolsky&#8221; user.</p>
<pre class="brush:javascript">
var search_results = eval(our_json_result);
var result = null;
with(jsoq) {
    result = From(search_results.results)
                .query('text')
                .where(function(i) {
                    return i.to_user === "spolsky";
                });
}
</pre>
<p> </p>
<p>And now our result object is filled with a bunch of other objects that would look something like:</p>
<pre class="brush:javascript">
{
    text: "@spolsky thats easy! http:\/\/tinyurl.com\/2z42bs"
}
</pre>
<p> </p>
<p>Pretty simple eh? For more information on JSOQ please check back here in the near future or contribute to <a title="JSOQ Google Code Page" href="http://code.google.com/p/jsoq/" target="_blank">the google code repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2009/02/10/introducing-the-javascript-object-query-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wp.com hosted blogs now on 2.5</title>
		<link>http://codeimpossible.com/2008/04/04/wpcom-hosted-blogs-now-on-25/</link>
		<comments>http://codeimpossible.com/2008/04/04/wpcom-hosted-blogs-now-on-25/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 02:22:45 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://pistalwhipped.wordpress.com/?p=126</guid>
		<description><![CDATA[What a great way to end the week. I logged in to my dashboard tonight to prep a post for tomorrow and found that my hosted wp.com blog has now been upgraded to WordPress 2.5. Excellent! Right now I am really digging the new look of the admin section (full-screen editing ftw!) and I can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>What a great way to end the week. I logged in to my dashboard tonight to prep a post for tomorrow and found that my hosted wp.com blog has now been upgraded to WordPress 2.5. Excellent! Right now I am really digging the new look of the admin section (full-screen editing ftw!) and I can&#8217;t wait to see how the blog performs with the new performance enhancements.</p>
<p>Expect a lot more posts about WP 2.5 over the next couple of days.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/04/04/wpcom-hosted-blogs-now-on-25/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress 2.5 released!</title>
		<link>http://codeimpossible.com/2008/03/31/wordpress-25-released/</link>
		<comments>http://codeimpossible.com/2008/03/31/wordpress-25-released/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 02:57:53 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://pistalwhipped.wordpress.com/?p=120</guid>
		<description><![CDATA[
I am so excited about this release of wordpress. Whats new? load-time improvements, built-in Gravatar and gallery support (YES!!!), built-in plugin upgrade feature oh, yeah and the entirely new admin interface and customizable dashboard screen. What am I most excited about? Well aside from the already mentioned bitchin&#8217; admin interface I&#8217;m really excited about the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://pistalwhipped.wordpress.com/2008/03/31/wordpress-25-released/wordpressorg/" target="_blank" rel="attachment wp-att-121" title="WordPress.org"><img src="http://pistalwhipped.files.wordpress.com/2008/03/wordpressorg.png" alt="WordPress.org" border="0" height="270" width="428" /></a></p>
<p>I am so excited about this release of wordpress. Whats new? load-time improvements, built-in Gravatar and gallery support (YES!!!), built-in plugin upgrade feature oh, yeah and the entirely new admin interface and customizable dashboard screen. What am I most excited about? Well aside from the already mentioned bitchin&#8217; admin interface I&#8217;m really excited about the code improvements (more detailed comments and database optimizations FTW).</p>
<p>When can wp.com users (like yours truly) expect some 2.5 action? Within the next week or so you should see the new interface in your admin consoles.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/03/31/wordpress-25-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What a battle: &#8217;switchEditors is not defined&#8217; in WordPress</title>
		<link>http://codeimpossible.com/2008/02/04/what-a-battle-switcheditors-is-not-defined-in-wordpress/</link>
		<comments>http://codeimpossible.com/2008/02/04/what-a-battle-switcheditors-is-not-defined-in-wordpress/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 05:33:09 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pistalwhipped.net/bl/og/2008/02/04/what-a-battle-switcheditors-is-not-defined-in-wordpress/</guid>
		<description><![CDATA[Okay, so the blog looks like it is back up and running. The front-end has been up for about 2-3 hours now but the admin section has been a royal pain in the ass to get back to a livable state. What happened was that earlier today I noticed that several of my toolbar items [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so the blog looks like it is back up and running. The front-end has been up for about 2-3 hours now but the admin section has been a royal pain in the ass to get back to a livable state. What happened was that earlier today I noticed that several of my toolbar items had disappeared from my edit page (most notably the &#8220;More&#8221; page break button) and I could no longer toggle between Visual and Code view.</p>
<p>After <a href="http://wordpress.org/search/switchEditors+is+not+defined?forums=1&amp;bugs=1" target="_blank">researching</a> <a href="http://wordpress.org/search/switchEditors+is+not+defined?forums=1" target="_blank">the</a> <a href="http://wordpress.org/support/topic/145002" target="_blank">problem</a> <a href="http://wordpress.org/support/topic/117860?replies=2" target="_blank">it</a> <a href="http://mu.wordpress.org/forums/topic.php?id=5701&amp;page" target="_blank">looked</a> like I had my work cut out for me. To make a long story short I ended up doing all of the following steps:</p>
<ol>
<li>Upgraded my wordpress installation</li>
<li>down graded my wordpress installation</li>
<li>added / removed a new MCE</li>
<li>added / removed another MCE</li>
<li>edited about 5 -6 wordpress php files</li>
<li>reverted those 5 &#8211; 6 wordpress php files</li>
<li>upgraded word press again</li>
</ol>
<p>Until, finally, I gave up and implemented the ugliest hack ever (I am not sure why wordpress seemingly &#8216;forgot&#8217; my toolbar settings) <a href="http://wordpress.org/support/topic/145002" target="_blank">which I discovered over at this site</a> (last post to the thread). If anyone has figured out how to fix this (in such a way that it doesn&#8217;t feel so klooged together) then please speak up and let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/02/04/what-a-battle-switcheditors-is-not-defined-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
