Go to home page mail me! RSS Feed
FoxMetrics Web Analytics

A potentially dangerous Request.Form value was detected from the client…

image

 

To fix use the follow attributes on your Actions for ASP.NET MVC or <httpRuntime requestValidationMode="2.0" /> in your config.

 

        [HttpPost, ValidateInput(false)]
        public ActionResult NewJavaScript(FormCollection fc)
        {

            return RedirectToAction("JavaScripts");
        }

TypedJS: Annotate your functions with type signatures

Now this is a better way of testing, I’m loving it. I’ve always been looking for a flexible way to test y JS libraries but haven’t found any because they are way too complicated to setup, however, typedjs by Ethan Fast is looking very promising. I’m starting a new project next week, I’m going to try it out. The only concern at this moment is how flexible is it or will it be as some of my JS functions get pretty complex.

TYPEDJS uses a function's type signature to generate input parameters, and evaluates the function upon these inputs to form a test case. This test case fails if an exception occurs, or the output violates function constraints. While type signatures provide a limited form of program specification, TYPEDJS adds a quick and rigorous sanity check to your deployment pipeline. The code lives on github.

 

//+ my_prop :: {name:String, valid:Boolean} -> Boolean
function my_prop(obj){
  if(obj.valid === true){
    return "true"; // Error, we are 
  }                // returning a string here
  else{
    return obj.valid;
  }
};

The Twitter team has done it again–Hogan.js

As I have mentioned before, I’m a fan of the Twitter development team and they have done it again. They recently launched a JavaScript templating engine called Hogan.js and its awesome. Obviously, there are a lot of templating engines out there but there are a few that actually works efficiently and simply.

Hogan.js is a 2.5k JS templating engine developed at Twitter. Use it as a part of your asset packager to compile templates ahead of time or include it in your browser to handle dynamic templates.

 

<!-- include hogan -->
<script src="/js/hogan.js"></script>

<!-- include your server-side compiled templates -->
<script src="/js/my-templates.js"></script>

<!-- render your templates -->
<script>
  var context = { variable: 'myVariable' };
  var partial = { partial: myPartial };
  var template = myTemplate.render(context, partial);
  document.body.innerHTML = template;
</script>

 

image

Bootstrap, from Twitter

I’m loving the twitter development team as I’ve always been a fan of their designs, simple and elegant. I’ve been playing with their web framework recently (html, CSS & JavaScript) and its awesome, simple and powerful. love it! Thanks Twitter team.

 

Simple and flexible HTML, CSS, and Javascript for popular user interface components and interactions.

 

Design for everyone, everywhere.

 

Features

  • Built for and by nerds
  • 12-column grid
  • Growing library
  • HTML5
  • For all skills
  • Responsive design
  • Custom JQuery plugins
  • Cross-everything
  • Styleguide docs
  • Built on LESS
  • CSS3
  • Open-source

DateTime.Now vs DateTime.UtcNow

Try to use .UtcNow() as much as you can over .Now() as it is inherently faster than the later. The problem seems to stem from the fact that DateTime.Now performs a DateTime.UtcNow first and then performs a very expensive called to figure out daylight savings time and time zone information.

public static DateTime Now
{
    get
    {
        DateTime utcNow = DateTime.UtcNow;
        bool isAmbiguousDst = false;
        long ticks = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utcNow, 
out isAmbiguousDst).Ticks;
        long num = utcNow.Ticks + ticks;
        if (num > 3155378975999999999L)
        {
            return new DateTime(3155378975999999999L, DateTimeKind.Local);
        }
        if (num < 0L)
        {
            return new DateTime(0L, DateTimeKind.Local);
        }
        return new DateTime(num, DateTimeKind.Local, isAmbiguousDst);
    }
}
 
public static DateTime UtcNow
{
    [TargetedPatchingOptOut("Performance critical to 
inline across NGen image boundaries"), SecuritySafeCritical]
    get
    {
        long systemTimeAsFileTime = DateTime.GetSystemTimeAsFileTime();
        return new DateTime((ulong)(systemTimeAsFileTime + 
504911232000000000L | 4611686018427387904L));
    }
}

Thanks to Keyvan Nayyeri who did a detail analysis of DateTime.Now, DateTime.UtcNow and Stopwatch class at his blog post called The Darkness Behind DateTime.Now. Very good read for detail explanation.

Quantitative comparison between DateTime.Now, DateTime.UtcNow, and StopWatch in .NET

 

Note that Environment.TickCount is also faster than DateTime.UtcNow.Ticks.

Framework layers on layers

As an architect, I stress to my team, colleagues or anyone that wants to talk IT that a solid developer needs to understand the fundamentals of how things work – especially when dealing with such a large framework such as the .Net Framework.

I’m usually very slow when it comes to adopting new versions of the framework, as of now I still write code in 2.0/3.5 while 4.5 is about to start collecting dust. It has become clear to me in the past years that sometimes frameworks simply get bloated. I wrote comfortable powerful and sophisticated applications with .NET 2.0 but when 4.0 came out everyone claimed it and jumped, yeah - I started writing code in assembly, therefore, I believe in less layers which is what newer framework versions are usually made up of.

If a framework does not provide with critical patches and newer features, then there is no need for me to upgrade. simply converting 6 lines of code to 2 lines by wrapping it is just not enough.

HandleError – ASP.NET Mvc Attribute

I’m not a fan of hiding error messages, as it could bite you real hard. However, there are existing functionalities that just need to be discussed such as the HandleError attribute of the ASP.NET MVC application. If you are not a fan of displaying the very common Yellow Screen of Death, then HandleError should be your new friend.

By default, I take certain steps when I’m setting up a new MVC app to prevent my users from ever seeing a single error page by implementing NLog, creating custom error pages and so on and so forth.

HandleError is an action filter and MVC has several others such as Authorize, OutputCache, RequireHttps, etc.. It simply provides a way to map exceptions to a specific template, therefore, enabling you to display your custom error pages when an exception occurs or a simple generic error view.

Once an error is detected the filter first checks the controller specific folder for an error file, i.e. if you are in Home, it will check Views/Home/Error.aspx and if not found, it will default to the shared views folder at Views/Shared/Error.aspx to locate the file.

 

    [HandleError]
    public class ListController : Controller
    {
        //
        // GET: /List/
        public ActionResult Index()
        {
            return View();
        }
    }

I usually extend the System.Web.Mvc.Controller class and override its OnException method, which provides me with a single entry point to capture and log all errors as I see fit.

        protected override void OnException(ExceptionContext filterContext)
        {
            // TODO: NLog exception here. base.OnException(filterContext);
        }

Note that overriding OnException prevents HandleError from taking control, therefore, it becomes completely useless, its almost like you can’t use both, its either clean view or log error but I want and need both.

Here is my final OnException override that gives me both clean messages to my users and also logs using NLog to disk and database for my review.

        protected override void OnException(ExceptionContext filterContext)
        {
            // TODO: NLog exception here.

            // Handle exception
            if (filterContext.HttpContext.IsCustomErrorEnabled)
            {
                filterContext.ExceptionHandled = true;
                Response.StatusCode = 500;
                Response.TrySkipIisCustomErrors = true;
                this.View("Error").ExecuteResult(this.ControllerContext);

                //
                base.OnException(filterContext);
            }
        }

Page size offender – JavaScript

We all love JavaScript and yes its my favorite language thingy! However, because it is loosely coupled, you can easily write very bad bloated code and there aren’t any sweet tools out there to help with this. It is only logical to determine why the existing JavaScript IDE’s are not getting powerful – because its not a language that compiles, therefore, it is very difficult to analyze compared to other languages such as C# & F#.

Its imperative that you remove unused code, write efficient code – check out the work of John Resig, he founder of the JQuery framework.

Pingdom surveyed the top 1,000 sites and the results are astonishing, images have always been a problem, however, JavaScript is the new offender as of 2011. So no excuses clean up your code and compress them and better yet place them on a CDN for better delivery. Here are some nice charts.

Web page size change in one year

 

Web page content size change in percent

My top 10 favorite domain generators

We all know how painful it is when you conceive an idea and you want to start building the foundation for it and you get stuck hunting down a domain that makes sense for several hours. It has been said multiple times that the domain really doesn’t matter but I still think it does and the simpler and easier it is to remember the better it is. It is usually the most important or most complicated step to complete.

Here are the domain generators that I’ll recommend, they will simplify your task of choosing a domain name or names. If GoDaddy had one built in – wouldn’t that make all our lives easier?

There are a billion of these – I’m just listing a few to get you on your way.

  1. http://www.bustaname.com/ – my personal favorite, they suggest, validate and check availability. The domain maker tool is pretty powerful.
  2. http://domai.nr/ – pretty sweet and clean interface and insanely fast, lacks any options or configuration
  3. http://www.dotomator.com/ – Availability is not on screen, the send you to a domain provide which sucks as I have to keep bouncing back and forth. Word combination and suggestion tool is pretty handy and they have an iPhone app.
  4. https://domize.com/ – another nice and clean home page, you can’t possibly get lost. Suggestions are not available it only checks different length of the same word.
  5. http://www.domainsbot.com/ – Super fast and provides lots of juicy data for premium domains and etc..
  6. http://www.stuckdomains.com/ – Helps you hunt down expired domains, you never know you might get lucky
  7. http://ajaxwhois.com/ – Fast since its Ajax driving, however, its missing lost of features.
  8. http://namethingy.com/ – does all the guess work for you, pretty intuitive, just relax and click words that interest you as you see them appear
  9. http://impossibility.org/ –use this very frequently as you can simply type in a word and it will suggest several availability readable domains
  10. http://blungr.com/ – new at this time but it works great and also suggest none .com domains if you are looking for something like list.co

Webcast: The basics of SQL server high availability and disaster recovery – Clustering, Log Shipping, Replication and More

You got to love Brent Ozar, his posts are usually if not always valuable and informative. He is a SQL Server performance tuning guru and I read his blog religiously as it has some juicy stuff.

His most recent post talks about the pros and cons of several methods in which you can make SQL server more reliable which usually leads to happy days.

Here is a  30 minutes video that is great for production DBAs how haven’t implemented clustering, replication or log shipping before and want to get started quickly.

Next entries »