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!

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 - turn on your AirPort.

How to speed up Ubuntu 11.04 - Swappiness

Or pretty much any Ubuntu version really. This is aimed at desktop installations, not servers.

Ubuntu has a fancy little property called swappiness. Swappiness basically tells Ubuntu how often to move processes out of memory and onto the hard drive. Things that are in memory are faster. Just like remembering something is faster than wondering off to google and looking it up. So in general, on your average Ubuntu desktop, you want to tell the operating system to keep processes in memory for longer. Enter swappinesss.

To find out your swappiness open up a terminal and try this: cat /proc/sys/vm/swappiness


It will probably report back "60". Now, for desktops, the recomended value of swappiness is 10. So let's change the swappiness factor - open up /etc/sysctl.conf in your favourite text editor (you get extra imaginary points if you use vim instead of gedit). Again, at the terminal type:
<code class="bash">
sudo gedit /etc/sysctl.conf

Search for (or add if it isn't there) "vm.swappiness" and change it to: vm.swappiness=10 Save, reboot and hey presto off you go. For the curious, read more about swap than you could ever want to know.

I have no idea why Ubuntu doesn't set this by default on desktop installs really, it's one of the things that is standing in the way of it really taking off for the average computer user. Not swappiness per se, but just the fact that you have to get your hands a little dirty when you run Ubuntu, when the average person just wants to install and then play Internet, Facebook, Twitter, type a few documents and check their bank balance. Still, now you can do all that. Only faster.

Previous Page | Next Page