Friday, May 27, 2011

None of Us Knows What We’re Doing

http://www.feross.org/none-of-us-knows-what-were-doing/


The Myth of the Superhuman

They believe, it seems, that “successful people” like Steve Jobs, Mark Zuckerberg, Bill Gates, Paul Graham, Walt Disney, etc. have some sort of in-built superhuman awesomeness that makes them smarter, cleverer, more brilliant than the rest of us.
They believe that something about these people is unique, that their feats would beunachievable by anyone else.
To be fair, it sort of makes sense, right? I mean, these folks succeeded spectacularlywhere thousands of others failed forgettably. So, the successful people must be more brilliant than average folk like you and me, no?

Creating Custom Ajax Control Toolkit Controls

http://stephenwalther.com/blog/archive/2011/05/26/creating-custom-ajax-control-toolkit-controls.aspx

ASP.NET FaceBook Login UserControl

http://www.eggheadcafe.com/tutorials/aspnet/fca40a96-aa44-4956-8382-447bf53f6035/aspnet-facebook-login-usercontrol.aspx

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FacebookLogin
{
    public partial class FBLogin : System.Web.UI.UserControl
    {
         public static string FaceBookAppKey = ConfigurationManager.AppSettings["facebookAppKey"];

        protected void Page_Load(object sender, EventArgs e)
         {
             if(String.IsNullOrEmpty( FaceBookAppKey ))
                throw new InvalidOperationException("You must have a valid Facebook App Key in AppSettings element \"facebookAppKey\"");

             if (Request.Cookies["fbs_" + FaceBookAppKey] == null)
            {
                lblMessage.Text = "Not logged in.";
                 return// No cookie returned from Facebook!!
            }


            string cookie = Request.Cookies["fbs_" + FaceBookAppKey].Value;
                cookie = cookie.Replace("\""""); //fix Facebook bug...
                NameValueCollection facebookValues = HttpUtility.ParseQueryString(cookie);

                  // send an http-request to facebook using the token from the cookie
                 //and parse the JSON response
                string json = GetFacebookUserJSON(facebookValues["uid"], facebookValues["access_token"]);
                Hashtable jsonHash = (Hashtable) JSON.JsonDecode(json);

                 //ok, let's actually read some data from FB response
                string facebookName = jsonHash["name"as string;
                string firstName = jsonHash["first_name"as string;
                string lastName = jsonHash["last_name"as string;
                string facebookId = jsonHash["id"as string;
                string email = jsonHash["email"as string;
                     //We explicitly requested email (see fb-button)
            lblMessage.Text = "Welcome, " + firstName + " " + lastName + " [" + email + "]";

             // Can store name, email etc. in db here, get user profile, store info in Session, etc.
        }

         /// <summary>
        /// sends http-request to Facebook and returns the response string
        /// </summary>
        private static string GetFacebookUserJSON(string userid, string access_token)
        {
            string url = string.Format("https://graph.facebook.com/{0}?access_token={1}&fields=email,first_name,last_name", userid, access_token);
            WebClient wc = new WebClient();
            string s = wc.DownloadString(url);
             wc.Dispose();
             return s;
        }
    }
}

Thursday, May 26, 2011

How to solve "Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created."


Disable “Prevent saving changes that require the table re-creation” 
1.    Open SQL Server 2008 Management Studio (SSMS). Click Tools menu and then click on Options… as shown in the snippet below.

2.    In the navigation pane of the Options window, expand Designers node and select Table and Database Designers option as shown in the below snippet. Under Table Options you need to uncheck “Prevent saving changes that require the table re-creation” option and click OK to save changes.


Globalization in ASP.NET MVC, JavaScript and jQuery


There's a couple of basic things to understand though, before you create a multilingual ASP.NET application. Let's agree on some basic definitions as these terms are often used interchangeably.
  • Internationalization (i18n) - Making your application able to support a range of languages and locales
  • Localization (L10n) - Making your application support a specific language/locale.
  • Globalization - The combination of Internationalization and Localization
  • Language - For example, Spanish generally. ISO code "es"
  • Locale - Mexico. Note that Spanish in Spain is not the same as Spanish in Mexico, e.g. "es-ES" vs. "es-MX"