mo.notono.us

Tuesday, January 26, 2010

Testing sms to blog functionality. Not sure why i'd do this instead of blogging by email, but (geeky) cool nonetheless...

Tuesday, January 19, 2010

Today’s Prediction: Republicans beat Democrats 41-59

“See, it’s not that the democrats are playing checkers and the republicans are playing chess.  It’s that the republicans are playing chess, and the democrats are in the nurse’s office because once again they’ve glued their balls to their thighs.”
- Jon Stewart @09:10/10:05

Labels: , ,

Tuesday, January 12, 2010

Mission Failure

Just read a notice from BlackBerry that there is a software update for my phone.  Not only did they completely gfail to sell me on the upgrade (what’s new?), they inject such a barrage of technical-ese that anyone’s eyes would glaze over.

Something tells me Apple would not have sent the same kind of email – see highlighted section below…

BlackBerry Software Update Notification
Update Today!
----------------------------------------------------
What else can your BlackBerry® smartphone do for you?

Find out when you update to the latest smartphone software! This free update is ready and waiting to help you do more with your BlackBerry smartphone. To update today visit http://www.blackberry.com/updates

New ways to work and play!

   * As an aid to comprehension, this section provides a brief overview of the life-cycle of a device upgrade.  * Each OTASL capable device will contain one or more OTASL Service Records(SR) each identifying a Device Manager (DM). The DM may be located at RIM, may be part of a BES or, in future, could be associated with a 3rd party application provider. Each SR will identify the applications which are of interest to the corresponding DM. SRs may be delivered by PRV, BES or in an upgrade application loaded OTA. … (it goes on, but there’s no point).

Labels: , , , ,

Monday, January 11, 2010

Well, I guess it’s settled then.

Me: "Who did you play with today, Erik?"

- "Divon... and Riley, when I grow up, you know daddy, when I grow up I'm gonna marry Riley!"

"Really?"

- "Yeah! Cause we're the same color!"

"Huh?"

- "Yeah, we're both light!  And you're light and mommy's light and I'm light and Lottie's light, so.."

"You know you don't have to marry someone who has the same skin color as you, Erik - you can marry anybody you like!"

- "You can?  ... I'm gonna marry Riley.  And when I grow up, I'm gonna be a dogtornarian!"

"Really - a dogtornarian?"

- "Yeah, a dogtornarian is a doctor for dogs.  And he gives the dogs shots, and the dogs are really good, and they get a flu shot so they don't get sick!  And when Riley grows up, she's gonna be a vegternarian, but she's only going to treat cats, and we're gonna treat both dogs AND cats!  And we're gonna have a little baby, and  the baby is going to to a school, and we're going to go to work!  Just like Lottie and me go to school, and you and mommy go to work!"

...

- "Daddy, we're having a great conbersation, do you like it?"

"Yes, Erik, I do.  A lot."

Labels: , ,

Wednesday, January 06, 2010

MVC Route Constraint to Exclude Values

For Album Credits I wanted to allow personalized urls of the format http://albumcredits.com/yournamehere.  This turned out to be quite an interesting routing exercise.

Since this is an MVC app, our standard url format is of the usual http://albumcredits.com/{controller}/{action}/{index} kind, and for some pages, I need to allow the url to simply specify the controller, defaulting the action to index – again, the usual ASP.NET MVC pattern.

I was familiar with the constraint parameter option for the AddRoute method, but had never studied it in much detail – we’d used it to limit certain indexes to be numeric, but that was all.  For the root-level personalized urls we needed a more robust constraint – specifically we needed to exclude any controller from the list of valid personalized Urls.

I first spent more time than I cared to trying to come up with a regular expression pattern that would NOT match the list of controller names – it looked something like this:
^(?:(?!\b(foo|bar)\b).)*$
(thanks to Justin Poliey/stackoverflow.com) where foo and bar, etc were the controller names to NOT match.

Not until after I got that to work did I think to google “mvc custom route constraint”.  Of course the MS MVC team was smarter than that – custom route constraints are really very straight forward…

For my purposes, I went with David Hayden’s approach – the code below is essentially the same as his, just with the logic reversed.

using System;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace AlbumCredits.Web
{
	/// <summary>
	/// Route constraint that returns true if the parameter value is not one of the excluded values.
	/// </summary>
	/// <example>A controller constraint like 
	/// <code>new { controller = new ExcludeValuesConstraint("foo", "bar") }</code>
	/// will match "blah" or "snort" but will not match "foo" or "bar".
	/// </example>
	public class ExcludeValuesConstraint : IRouteConstraint
	{
		private readonly string[] _excludeValues;
		/// <summary>
		/// Initializes a new instance of the <see cref="ExcludeValuesConstraint"/> class.
		/// Example: <code>new { controller = new ExcludeValuesConstraint("foo", "bar") }</code>
		/// will match "blah" or "snort" but will not match "foo" or "bar".
		/// </summary>
		/// <param name="excludeValues">The excluded values.</param>
		public ExcludeValuesConstraint(params string[] excludeValues)
		{
			_excludeValues = excludeValues;
		}

		/// <summary>
		/// Determines whether the URL parameter contains a valid value for this constraint.
		/// </summary>
		/// <param name="httpContext">An object that encapsulates information about the HTTP request.</param>
		/// <param name="route">The object that this constraint belongs to.</param>
		/// <param name="parameterName">The name of the parameter that is being checked.</param>
		/// <param name="values">An object that contains the parameters for the URL.</param>
		/// <param name="routeDirection">An object that indicates whether the constraint check is being performed when an incoming request is being handled or when a URL is being generated.</param>
		/// <returns>
		/// true if the URL parameter contains a valid value; otherwise, false.
		/// </returns>
		public bool Match(HttpContextBase httpContext, Route route, string parameterName, 
			RouteValueDictionary values, RouteDirection routeDirection)
		{
			return !(_excludeValues.Contains(values[parameterName].ToString(), StringComparer.InvariantCultureIgnoreCase));
		}
	}
}

I can now use this when setting up my Route Table like this:

	routes.MapRoute("PersonalizedUrl",
		/* for urls like  */ "{personalizedUrl}",
		/* route defaults */ new { controller = MVC.Profile.Name, action = MVC.Profile.Actions.IndexByPersonalizedUrl, personalizedUrl = string.Empty },
		/* where          */ new { personalizedUrl = new ExcludeValuesConstraint(ControllerNameArray) }
	);

Labels: , , ,