jQuery ScrollUp plugin

I wanted to add a scroll to top button to my website. I didn’t want it to rely on being random buttons in the middle of the html. A button like this makes way more sense to be affixed to the UI. It also shouldn’t be visible when you can’t actually scroll up.  Mark Goodyear wrote a great (and simple) jQuery plugin to do this: ScrollUp it is MIT licensed and you can check out the source on github.

View the live demo

$(function () {

Is literally all the source it takes after you include jquery and jquery.scrollup.js files to your page.

It is also highly configurable. Definitely worth a look.

jQuery on click is raised by text selection

So today I was building some basic toggle capabilities into a web page. Everything is working well, then I test selecting the text. Of course this causes the element to collapse on mouse up.

After some googling Stackoverflow of course had the answer…

$('h4').on('click', function() {
    if (getSelection() == "") {
        //do stuff

All it took was wrapping my code in a single if statement using getSelection().

dynamitey and dynamic MVC models

So today I’m building out my new MVC application and get to writing this small block of code

  return View(new { Items = model });


Server Error in ‘/’ Application.

‘object’ does not contain a definition for ‘Items’

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ‘object’ does not contain a definition for ‘Items’

Apparently what I want to do is literally impossible. Ironically I had already commented on one of these answers.

Eventually the rabbit hole leads me to dynamitey (github)   and now I can do:

  return View(Build<ExpandoObject>.NewObject(Items: model });


Recent learns for Javascript / Web Development

File this in the unusual category, XHTML which likely all of us have used, never officially supported target=_blank for hyperlinks. XHTML Strict 1.0 – target=“_blank” not valid? is a more detailed discussion of this on StackOverflow. Ultimately it was only ever incorporated into the transitional specification. I just find it really ironic how something all of us take for granted wasn’t even in the official language specification.

Douglas Crockford knows how to troll. Straight from Code Conventions for the JavaScript Programming Language

Avoid conventions that demonstrate a lack of competence

Straight up says don’t do stuff just because it’s easier. Do stuff right. Or you suck.

Well said Crockford, well said.

At the bottom of his conventions I actually found out that JavaScript has a comma operator. I did a serious WTF when I read that. Of course it says to not use it. I did a little bit of digging to find out what is a comma operator Comma operator(,) Where it can “really” be useful.

Taking the best real world example from StackOverflow:

A Fibonacci generator:

for (
    var i=2, r=[0,1];
    r.push(r[i-1] + r[i-2]), i++
// 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377

That’s some crazy stuff there. It certainly looks cool at how you just 1 lined the Fibonacci sequence, but it certainly doesn’t add readability to code. I’m sure this is why Crockford advises against it.

Code that your first thought looking at it is #WTF does not belong in your codebase. The only exceptions to this are extreme performance optimized codeblocks that were deemed necessary by actual profiling. Optimizing without a profiler is the ultimate exercise in futility. You will most likely just make your application slower, harder to understand, and never touched the original problem.

Polly Transient Fault handling

So I started reading about Paramore Brighter CommandProcessor, didn’t get far and started reading about the packages it uses. This called out Polly (github)  this project takes the voodoo out of writing retry handling. In the past I’ve raised comments on .NET discussions expressing my desire for this to be built directly into the BCL. That never really seemed to go anywhere.

really seemed to face the same dilemma and decided to roll his own. I haven’t used it yet, but from reading the markdown readme it has a beautiful fluent interface. I will definitely be using this in the future. Some usage examples:

// Retry multiple times, calling an action on each retry 
// with the current exception, retry count and context 
// provided to Execute()
    .Retry(3, (exception, retryCount, context) =>
        // do something 

Just awesome.


So it’s been a somewhat rather long time since I’ve posted. Numerous times I’ve said to myself I need to dedicate time and post some real blogs. Clearly that didn’t work out. Since that hasn’t absolutely occurred. I’m going to do some pseudo-micro-blogging and talk about some stuff I’ve learned recently. Each post will likely be short, but I’ll have new stuff! Finally!

Also I’ll have an elaborate bookmark for myself. I’m self serving, what can I say.