Posts
60
Comments
36
Trackbacks
18
April 2009 Entries
Google App Engine Supports Java
I was perusing around earlier and noticed that Google's App Engine now supports the Java Language.  It said New! next to it,  so I figured, why not blog it.

Here is a link to the Google App Engine.

Read more at their app engine blog.

I certainly look forward at trying to leverage their hosting services at some point in the future.  I will also be considering Amazon's EC2, as well as Microsoft's Azure.  Most of my sites are in ASP.NET but wouldn't be entirely impossible to refactor at this point.  What would you do?
posted @ Tuesday, April 28, 2009 1:27 PM | Feedback (0)
Integrating Gravatar Into Your ASP.Net MVC Application

Naturally, whenever I try to overcomplicate things; I turn around and blog about them.  This will be short and sweet as adding a Gravatar to your site that is dynamically generated is actually fairly simple.  I always try to oversimplify too, but there were a few small snags I ran into while doing this.

  • You need to have your users email address (or hash) available to your .aspx
  • I use a string extension, so that I can call VarName.ToMd5()

Ok, so Gravatar is cool.  I ran across it for the first time about 20 minutes ago, and wow is it surprisingly easy, though there are a few minor complications I ran into.  Here is my story.

First, you will need a static class for your static extension.  Note, this MD5 was taken straight from an MSDN Library.  You must first lowercase the email address you are hashing.  Additionally, you will also need to .ToLowerCase() the MD5 string in the return line (This is for URL Case Sensitive request to Gravatar.com).  These were my most interesting issues while trying to match the hash for the Gravatar.  Code:

        /// <summary>
        /// Displays the Gravatar MD5 hash of the given string.
        /// </summary>
        /// <returns>MD5 Representation of this string</returns>
        public static string ToMd5(this string helper)
        {
            helper = helper.ToLower();
 
            // step 1, calculate MD5 hash from input
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(helper);
            byte[] hash = md5.ComputeHash(inputBytes);
 
            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString().ToLower();
        }

To implement in your page (assuming your STATIC extension class/method(above) are reachable from your ASP.NET MVC Page or class, call this method using something similar to:

<img src="http://www.gravatar.com/avatar/<%= VarName.Email.ToMd5() %>.jpg" />

I certainly hope your endeavor in adding this web service was as pleasurable as mine.  Enjoy.

Technorati Tags: ,,,,
posted @ Sunday, April 26, 2009 1:10 AM | Feedback (0)
A Dog Named Bo? Dear President Obama:

I am sure this won't reach the people that need to see it, but maybe, just maybe, I can explain why to NEVER name a dog Bo.  My dog is named Bo, and he is about hard headed.  We realized this issue first when potty training, as we try to train them by saying "No".  We learned after a year or two that "No" rhymes with "Bo".  We now have to say something like "Ot" or "Awk" to train him properly.

To all of those that want a dog named the same thing as a President's, please do not name your dog "Bo".  Name him something with more than 1 syllable and certainly not anything that rhymes with "No".  As for the President, I am sure that he has more than the necessary hype to have a trainer that can train him perfectly. 

For the President himself, I certainly hope that your dog turns out perfect.  If he ends up thinking that pooping on the carpet is a good thing, I am glad you have your own cleaning crew.  Myself on the other-hand, will make sure that my SMALL audience doesn't name their dog Bo.  I prefer my alternate name (after the fact) of BoDawg.

I certainly hope you find great companionship from your new puppy.  I definitely do. 

posted @ Monday, April 13, 2009 5:25 PM | Feedback (1)
Add a Short Url Service to Your Site

This is a short tutorial on JQuery Ajax.  We will show you how to have your own little short url service with just a few simple changes to a web page of your choice.  In our first note, we will talk about creating a page that shortens a url.  In our second note, we will talk about adding a button to a site that, when clicked, it allows you to fetch a short url for that page. 

Part 1:

This is a simple example of how you can provide your customers with their own short Urls in three easy steps.  This example is in plain xhtml and uses JQuery 1.3.2 to query the Hurl.me service to gain access to your short url.

  • Create a basic xhtml or html page (or use mine), make sure to include the location of your JQuery script.  I have mine in a folder called scripts:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello Hurl</title>
    <script type="text/javascript" src="script/jquery-1.3.2.min.js"></script>
  </head>

  <body>
  </body>
  • Put a blank div (with id="shorturl"), text box and a button on your page, make sure to name these elements, this is being done in between the body tags in the previous bullet:
  <body>
    <div id="shorturl"></div>
    <input type="text" name="url" />
    <input type="button" name="go" value="go" />
  </body>
  • Create the javascript to query the hurl service for url shortening, I use a shorthand jQuery function to add a click listener to the button (by name), use the textbox by name to grab the url and the blank div to hold the value once it comes back, using the following code:
<input type="button" name="go" value="go" />

<script type="text/javascript">
$(function(){
    $("input[name=go]").click(function(){
    // This is the url that we input in our textbox
    var urlToShorten = encodeURIComponent($('input[name=url]').val());
    // The location of hurl's service
    var urlService = "http://hurl.me/service/createshorturl";
    // The querystring to use (note the second questionmark is not a mistake)
    // this is a placeholder for jQuery to put the callback function id in.
    var queryString = "?callback=?&url="
    // Build the complete service address.
    var urlBuild = urlService + queryString + urlToShorten;
    // alert(urlBuild);//Uncomment out the first comment to debug
    // Below we are calling our built url AND sending the data to 
    // processShortUrl function below
    $.getJSON(urlBuild,processShortUrl);                                    
   });
});

//function to gather the collected data and present in our div.
processShortUrl = function(data){
    var baseServiceUrl = "http://hurl.me/";
    $("#shorturl").html(baseServiceUrl + data.ShortUrl);
}
</script>

</body>

And so here we have it.  We just created everything we need to have our own Url shortening service.  Below you will find the completed code, just extract to your desktop and open the index.html file in your favorite browser (IE may require you to accept using javascript on this page).  Enjoy and realize that this service will always be free.  If you have any comments, know a easier way?  Leave the comments here.

Want to see the complete example? Full Project Source

Technorati Tags: ,,,
posted @ Thursday, April 09, 2009 9:54 PM | Feedback (1)
Cross Domain Ajax Calls ASP.NET MVC

I was looking around the web recently searching for a quick fix to sending Ajax requests back and forth between different servers, and a specific fix for ASP.NET MVC using JQuery's getJSON() method.  This is for a service that I would like to make for http://hurl.me.  After some research it was apparent that I was going to have to get in their and dirty my hands.  Here is what I determined.

  1. Cross Domain (i.e. http://example.com requesting an object from http://hurl.me) is not a "trusted" technique
  2. Web services (*.ascx) aren't suiting my needs, I want to go custom
  3. Possible through JQuery using a ?callback=?&append other information here
  4. One or two responses on the web doing similar stuff in other languages (Python, PHP), Sending back the callback variable like this callback + "(" + JSON Object + ")"

So I determined first that it was possible and that there were no sites currently boasting about this in ASP.NET MVC (I don't write my own stuff if I can find a solution that already works).  This could be very helpful for RESTful services when you want to use several web servers to carry out extensive solutions that meet specific requirements.

Some other things that I was concerned about were testing.  It isn't that difficult, as I have the two environments, but I did not want to go back and forth thrashing through my web application, since I am plugging it in and not doing it in a separate solution. 

I started with DotNet Reflector, seeing how they are using the current Json() available to controllers.  This was an interesting dive, surprisingly simple.  Some things to note here are that I would like to eventually just extend Json(), though my time is extremely pressed.

After some Reflector Awakening, I set out to put this into play.  First thing I did was create a new class (right click the folder or project -> new class).  I named this file JsonExtension (remember my future plans of extending Json() instead of the current way I do it here).  I also followed along with the steps here.

Here is my code for the cross domain solution (Custom to My Solution: Hurl2.Controllers, you may want to put it in the same namespace as your controllers):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.Web.Script.Serialization;

namespace Hurl2.Controllers
{
    public class JsonServer : ActionResult
    {
        public Object Data { get; set; }
        public string CallBack { get; set; }

        public JsonServer() { }

        public JsonServer(Object obj, string CallBack) 
        {
            this.CallBack = CallBack;
            this.Data = obj;
        }

        public override void ExecuteResult(ControllerContext context)
        {

            if (context == null)
                throw new ArgumentNullException();

            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = "application/json";

            if (this.Data != null)
            {

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                response.Write(
                    String.Format(
                        "{1}({0})", 
                        serializer.Serialize(this.Data), 
                        this.CallBack)
                        );

            }


        }
    }
}

This is how I use it.  Notice that I am very close to the current use of Json(), except I have a new JsonServer(params) object instance for now.  This is a small example for proof of concept.  You will not get the same results if you try calling this function at Hurl.  Below is using regular ASP.NET MVC Conventions for routing in this case.  The route is /Url/IsAvailable?query string.  To make the call cross domain it would be {domain name}/Url/IsAvailable?callback=?&other query strings.

 

public ActionResult IsAvailable(string shortUrl)
{
    var callback = Request.QueryString["callback"];
    if (String.IsNullOrEmpty(callback))
        return Json(new { isAvailable = ShortUrl.isAvailable(shortUrl).ToString() });
    else
    {
        return new JsonServer(new { isAvailable = ShortUrl.isAvailable(shortUrl).ToString() }, callback);
    }
}

From the page where I call this, my JQuery looks like this.  The cross domain is trivial in this case, since it works both ways.  I could (above) take the first if statement out but I would like the option of providing the callback or not.

$.getJSON("/Url/IsAvailable?callback=?&shorturl=" + encodeURIComponent($('input[name=ShortUrl]').val()),processShortUrl);

In this article, we cover plugging in cross domain compatible AJAX for services that don't reside on the server.  This is a server side way to solve the cross domain issue if you want to provide services to others.  This is the "easiest fix" approach.  It is probably a good idea to do some refactoring where you see that being beneficial.  If you have improvements or have overridden Json(string callback, object data), then feel free to let me know so I can save time.  70 hours a week + programming 3 or 4 sites on the side really kills the spare time!

Enjoy.

posted @ Sunday, April 05, 2009 7:30 PM | Feedback (5)
Sleep Overs! Fun Birthdays!

How to have a successful sleep over.  I am sitting here as 10 girls throw their pillows around and wonder whose bright idea this was.  Oh, it was mine.  I am in for one heck of a night.  Here is what our agenda has been and it worked out rather well.  At 6pm we started accepting our daughters friends (she is a first grader) and just about everyone in her class with a few extras are here.

After initially accepting them here, we made sure to get all of the parents "tonight" contact information for emergencies and other things if necessary!  We then started out with Little Caesar's pizza.  After the pizza we let them run ra,pant and play for about 10 or 15 minutes.

Next thing up, arts and crafts.  What a blast they had with this, what kind of contraptions can they come up with now?  After this BLAST we decided to do a Cherades and this was a ton of fun.  The girls and boys alikke really enjoyed this as they all guessed what it was at the TOPS of their voices.

Now it is time for the local pillow fight, change into jammies and shortly there will be a movie.  Will they settle down?  I am not sure.  One thing I know is they are absolutely having a blast.  This one is hopefully one for the ages!

I recommend this activity for any 7 year old.  They are at the age where they will have an absolute blast and remember what fun it was for the REST of their lives.  Keep them busy and wear them out; then move in for the rest of the night with a calm movie and quiet alas.

posted @ Friday, April 03, 2009 9:01 PM | Feedback (0)
Excited to Release Assembly.Web
Are you tired of obfuscation from all these new fancy languages?  A small team of my developers here in the midwest finally got tired of it and after some serious debates we designed Assembly (dot) Web, spelled Assembly.Web.  This new framework has absolutely no overhead and it is cross platform (works on ...Windows 3.+, Unix, IBM, and all other technologies  here...

Stay tuned for the official projects home page later today.
posted @ Wednesday, April 01, 2009 7:32 AM | Feedback (0)
News
My Developer Notebook! This also happens to be my opinion place. Thanks for coming by.