Snow melting

Snow melting on the bonnet

CheckBoxList Helper extension method ASP.NET MVC 3

Here's a quick and dirty html helper for checkboxes in ASP.NET MVC 3. I'm sure Microsoft will eventually package one with the MVC framework just like they will a radiobuttonlist helper, but in the meantime, this one suits my purposes.

Of course, from a front-end point of view, a multi-select listbox is also an option, but checkboxes are a little more robust when it comes to user interaction. Nothing is more annoying as a user than forgetting to ctrl-click and having all your previous selections disappear.

You can probably find variations around, most that I've seen use a generic list of a custom class - mine uses a MultiSelectList instead, just for fun.

public static class NSCheckboxListExtensions
{
public static MvcHtmlString CheckboxListFor<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression,
MultiSelectList listOfValues)
{
var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
var sb = new StringBuilder();

if (listOfValues != null)
{
foreach (var item in listOfValues)
{
var id = string.Format("{0}_{1}", htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression)), item.Value);
var name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression));
var label = htmlHelper.Label(id, HttpUtility.HtmlEncode(item.Text));

var cb = new TagBuilder("input");
cb.MergeAttribute("type", "checkbox");
cb.MergeAttribute("name", name);
cb.MergeAttribute("value", @item.Value);
cb.MergeAttribute("id", id);
if (@item.Selected)
{
cb.MergeAttribute("checked", "checked");
}
sb.AppendFormat("{0}{1}</br>", cb, label);
}
}
return MvcHtmlString.Create(sb.ToString());
}
}

Installing Valgrind on Shared Hosting

So you want to tinker with the goodness that is Valgrind, but you want to do it on a shared host? No problem.

# grab the latest valgrind
curl -O http://valgrind.org/downloads/valgrind-3.7.0.tar.bz2

#run an md5sum and check it matches the one listed on the downloads page
md5sum valgrind-3.7.0.tar.bz2

#unpack the puppy
tar -xjvf valgrind-3.7.0.tar.bs2

cd valgrind-3.7.0

#configure and pass in a directory you have permission to
./configure --prefix=$HOME/opt

#make valgrind
make

#install it - will end up in directory specified above
make install

Now you should have a bunch of files under your $HOME/opt directory. If you try to run it now, you'll probably end up with an error something like

valgrind: failed to start tool 'memcheck' for platform 'blahblah-linux': No such file or directory

No problem - open up your .bash_profile (in your home directory) and add this in somewhere:

VALGRIND_LIB="$HOME/opt/lib/valgrind"
export VALGRIND_LIB

Finally, reload your .bash_profile - either log out and in again or simply

source .bash_profile
</code>

IIS 6 ASP.NET MVC3 Page Cannot Be Found 404 Errors

[caption id="attachment_346" align="alignnone" width="500" caption="404 Page not found"]404[/caption]

This is a sneaky little devil, this one. If you've done everything right and your site still isn't being served up correctly, try this little trick:

Step 1: Collect Underpants by opening up IIS Manager and right clicking on "Web Service Extensions": [caption id="attachment_347" align="alignnone" width="500" caption="Web Service Extensions"]Web Service Extensions[/caption]

Step 2: Select "Allow all Web service extensions for a specific application"

Step 3: Select "ASP.NET v4.0.30319" from the drop down and click "Ok": Allow ASP.NET v4.0.30319

RIP Steve Jobs

I'm a recent Apple convert. I decided about a year ago, after spending the better part of 10 years hacking my own computers together, that I no longer wanted to waste my time building the hardware. Everyone has different criteria for their hardware. For me what I really value is silence. My mac is the quietest computer I have ever owned. For that alone, I'm prepared to pay a premium. I know you can jump through hoops and make other computers near silent, but it just isn't worth it to me. My time is worth more. And, I just don't enjoy the endless faffing about with hardware - does this RAM fit in that motherboard. Is this hard drive compatible with this BIOS.....No thanks. Steve Jobs clearly cared a lot about the products Apple produced. And they are fantastic.

Cancer is a shitty way to go.

Rest In Peace.

Programming in one lesson

The art of programming consist in looking not merely at the immediate but at the longer effects of any expression; it consists in tracing the consequences of that expression not merely for one function but for the whole system.

With applogies to Henry Hazlitt

First ever smiley Sept 19 1982

According to wired.

Everything I know about the command line I learned from from Tron Legacy

Scene: In the Encom boardroom

Edward Dillenger, the evil wunderkind of Encom, on seeing the chaos of a barking dog video instead of the brand new Encom OS12:
ps -ef | grep -i os12

Thus he lists processes running that have a case insensitve match of the string os12.

Having found the rogue process above, Ed decides to terminate the puppy:

kill -9 17319

Scene: Sam, our hero, in his old man's underground laire

Finding a computer covered in dust, Sam wipes it (the dust) away and a lovely futuristic looking machine under a glass worktop comes to life:
whoami

He types, asking the machine for the effective username. It tells him: "flynn". Hmmm he thinks and then whips out a quick

uname -a

Oooh, gotta find out some operating system implementation info. The -a switch is a shortcut switch which basically means show all the info about the current OS. But this isn't enough for our hero. He has to try and log in, doesn't he:

login -n root

Now, he should have known better, I mean, his old man was the uber-geek genius of his generation. You can't just login as root without a password (yes I realise there is inconsistency in the story line here with the other terminal windows open etc but still). Next up, Sam tries the "backdoor"

backdoor

because every system in the world has a "backdoor" so named that will just let us in. On password change days, I kind of wish mine did.

Now, young Sam is curious. What was the old man up to?

bin/history

Hmm....nothing to see here, cows turn themselves inside out all the time, and dad clearly works on his last_will_and_testament.txt all the time too. Let's ignore all that and rather type in the ominous sounding LLLSDLaserControl command that was the last thing his dad typed in before disappearing off the face of the planet leaving his 'puter all powered up and such.

LLLSDLaserControl -ok 1

Well good thing he did too because he gets zapped into the grid and we get a movie out of the deal. Great Success!

Linked In - Social Advertising - WTF?

[caption id="attachment_253" align="alignnone" width="661" caption="Linked in Social Advertising"]Linked in Social Advertising[/caption]

So I'm opted in by default? WTF?

While I'm at it - how f-ing vague is the description:

When LinkedIn members recommend people and services, follow companies, or take other actions, their name/photo may show up in related ads shown to you. Conversely, when you take these actions on LinkedIn, your name/photo may show up in related ads shown to LinkedIn members.
I'm sorry, does that mean anything you do on linked in means they can then use your photo for "related" advertising? I'm not a lawyer, but it sounds like simply logging in to the service gives them the right to use my photo next to an advert that says "Hey there, Bevan thinks LinkedIn is great".

Um....no thanks.

Core Location and the iOS Simulator - Could not find location

If you happen to be playing with the iOS Simulator and the Core Location framework you cane sometimes find yourself getting the following error:

Could not find location Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

The solution is pretty simple - turn on your AirPort.

Previous Page | Next Page