Scott Hanselman

This Developer's Life 2.0.6 - Play

November 17, 2011 Comment on this post [7] Posted in Podcast
Sponsored By

PlayWhat do you do when you're not staring at your computer screen? What obsession grips you as you drive home? In this episode we ask David Heinemeier Hansson and Pete Brown this very question.

I'd also like to encourage you to check out the last two episodes of This Developer's Life. We realize this isn't your typical podcast. It's not very technical, and it's not packed with information. We mean this show as an antidote to the usual technical talk shows as we try to dig more into issues and emotions that affect developers. We try to get to the center core of the developer and what makes them tick. Give us a listen and if you like the show, please review us on iTunes and Subscribe.

Download Episode 2.0.6 "Play" here or listen online.

Also, please check out our last two shows you might have missed. We're very proud of how they turned out.


Episode 2.0.4 - Taste

2.0.5 Typo

Who cares about typefaces and why should you? Well, these guys do and you should start caring. Rob and Scott explore the world of reading online with one of the godfathers in the world of typeface and fonts.

In this episode we talk to Bill Hill, the bearded Scotsman who created ClearType and Geoffrey Grosenbach, notable typeface enthusiast.


Episode 2.0.4 - Taste

2.0.4 Taste

What is taste? What is style? Do you have it? Scott and Rob have no idea what it is or how to get it - but they know it's important. In this show they talk to a designer who flexxes his good taste for a living - and a developer who is committed to spreading good taste where he can.

Michael Bach Designer at Microsoft
Geoffrey Grosenbach Owner/Founder of PeepCode


I hope you enjoy the show as much as Rob and I enjoy making it.

Again, big thanks to DevExpress. The bandwidth and other costs are picked up DevExpress and CodeRush! Visit them and thank them on Twitter.

This Developer's Life is brought to you by CodeRush for Visual Studio.

This Developer's Life is brought to you by CodeRush for Visual Studio.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

CSI: My Computer - What is netsession_win.exe from Akamai and how did it get on my system?

November 15, 2011 Comment on this post [70] Posted in Tools
Sponsored By

I know my system backwards and forwards and I do not like noticing stuff running in the background that I don't recognize. Recently I was checking out the Task Manager (right click on the clock, and select Task Manager or press Ctrl-Alt-Del and click Task Manager) and noticed TWO copies of "netsession_win.exe" running with a peak memory working set of about 25 megs. Ok, what's this? It's the Akamai Net Session Interface. Ick.

netsession_win.exe in my Windows Task Manager

You can always right click on suspicious processes and click Open File Location. This little tip is often enough to jog your memory and go, "Oh, THAT."

Open File Location in Task Manager's Context Menu

Hm, that dropped me into C:\Users\scottha\AppData\Local\Akamai. I know who Akamai is. They are a download accelerator used by lots of companies. Kind of the first large Content Distribution Network or CDN.

Am I sure it's them and not someone evil trying to fake me out? Right click on netsession_win.exe, then Properties.

Akamai's NetSession digital signature is legit

Well, they have a legitimate digital signature, interestingly they signed this on the 11th of November. Looks like this was recently installed automatically by something, perhaps Flash or Adobe Acrobat.

I wonder if someone needs to tell Akamai that their freshly installed service that just (kinda, a little) snuck on my system has a digital certificate that expires in 5 weeks. Are they or one of the companies that uses them going to update this client and cert soon?

Akamai's digital certiticate expires before Christmas

Running services.msc from Start | Run tells me that this runs as an Automatic Service. At least it's a Delayed Start so it doesn't slow down my boot.

Services (158)

The only thing I installed on my machine on the 11th was an automatic update to Adobe Flash. That's my #1 suspect right now as it's the only thing that I ran as Administrator that day.

For now, I'll keep it on my machine because it:

  • Is from a reputable (so far) company
  • Is known to be used by folks like Netflix, etc to speed up downloads
  • Has an uninstall available in Installed Programs
  • Feels legit
  • Has a control panel icon and a Read Me with lots of info about what it does (except who installed them)
  • Has a customer bill of rights online with details with test demo pages about their API.

I will say this, though. Whatever program installed it should have told me first before chaining it in. At least with Evil Toolbars I can see them. Not cool Akamai. Who installed you?

You're on notice.

UPDATE: Looks like this is using my own computers bandwidth to upload to other Akamai users. They're using our computers and network to make other people's uploads faster. That sounds like I'm running a Torrent and no one asked if it was OK. I'm continuing to dig into this, like disk space usage, etc.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

How To: Convert a PowerPoint Presentation from 4:3 ratio to 16:9 without distorted or stretched images

November 15, 2011 Comment on this post [21] Posted in Musings
Sponsored By

It always sucks to show up to a conference with a slide deck that looks lovely with lots of pictures and evocative hipster stock photography all nicely formatted for a 4:3 ratio (1024x768 pixels is common) and then find out their projectors are 16x9 and run something like 1280x720 pixels.

Nobody wants to be THIS stretchy guy:

My giant head with the wrong ratio

It is true that some people have a genetic inability to see that 4:3 content has been uncomfortably stretched to fit a 16:9 screen. We have a name for these people. They are called "Bad People.™"*

As an aside, there are few sadder technical things than 4:3 content stretched across an expensive 16:9 widescreen HDTV. From electronic stores to hotel lobbies, airport status displays to café menus. Make it stop.

What's the easiest way to convert your 4:3 slide deck to 16:9 in a pitch and still have your images look nice? There' s a number of ways on the internet but they all involve "math" and "ratios" and "thought." Nonsense. Too hard. Here's what I do.

Step 0 - Switch to 16:9 and see bad images.

Click Design | Page Setup and switch from 4:3 to 16:9. Other folks say to enter in custom numbers and do multiplication. Hang in there, this is easier.

First, switch to 16x9

At this point, all your images WILL be stretched out.

Step 1 - Fix image ratios without messing up their sizes

Here's the trick. Right click on an image and select Size and Position. From this dialog, click in the Height box. Now, just click up once and down once. As long as the Lock Aspect Ratio checkbox is checked, just changing the scale by 1 step and then switching back will fix your image. You can do it with your keyboard even faster.

Step two, change the scale up and down

Here's trick #2. You don't need to close the Size and Position dialog. It's modeless. You can leave it open and go from slide to slide quickly changing your images. Just click the image, click Height, then up/down, then do another image. Repeat until it's all done. It'll take just a few seconds per slide.

My enormous corectly ratio-ed head. Or IS IT?!

This trick will fix all your image ratios, but expect to do one more pass to make sure that you're using all the space afforded by this new widescreen layout. Regardless of how you images are sized you might want to make some tweaks to the layout and spacing of your text and images.

How to you switch your slides from 16:9 to 4:3? Exactly the same steps except adjust the ratio in Step 0.

Hope this helps someone.

* They aren't really bad people. They are good people with bad presentations. Relax. It's a blog post.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Solving the Shakespeare Million Monkeys Problem in Real-time with Parallelism and SignalR

November 12, 2011 Comment on this post [26] Posted in ASP.NET | Javascript | SignalR
Sponsored By

A monkey with a skull. Oh yes.A little over 18 months ago I was talking to Stephen Toub (he of the Parallel Computing fame) about parallelism and the kinds of problems it could solve.

I said, naively, "could we solve the million monkey's problem?"

He said, "the what?"

"You know, if you have an infinite number of monkeys and an infinite number of keyboards they will eventually write Shakespeare."

We brainstormed some ideas (since Stephen is a smarter than I, this consisted mostly of him gazing thoughtfully into the air while I sat on my hands) and eventually settled on an genetic algorithm. We would breed thousands of generations of (hypothetical) monkeys a second and then choose which ones would be allowed to perpetuate the species based solely on their ability to write Shakespeare.

We used the .NET 4 Task Parallel Library to make it easier for the algorithm to scale to available hardware. I mean, anyone can foreach over a million monkeys. But loops like that in parallel over 12 processors takes talent, right? Well, kinda. A lot of it is done for you by the Parallelism Features in .NET and that's the point. It's Parallel Processing for the Masses.

We created a WinForms version of this application and I've used it on and off to demonstrate parallel computing on .NET. Then Paul Batum and I went to the Keeping It Realtime conference to demonstrate SignalR this last week. I didn't want to do the same "here's a real-time chat app" or "here's a map that shows its results in real-time" demos that one always does at these kinds of things. I suggested that we port our WinForms Shakespeare Monkey demo to ASP.NET and SignalR and that's what Paul proceeded to do.

Looks like 80,000 generations of monkeys

When doing something that is crazy computationally intensive but also needs to return real-time results you might think to use node for the real-time notification part and perhaps spawn off another process and use C or something for the maths and then have them talk to each others. We like node and you can totally run node on IIS or even write node in WebMatrix. However, node is good at some things and .NET is good at some things.

For example, .NET is really good at CPU-bound computationally intensive stuff, like, I dunno, parallel matrix multiplication in F# or the like. ASP.NET is good at scaling web sites like Bing, or StackOverflow. You may not think IIS and ASP.NET when you think about real-time, but SignalR uses asynchronous handlers and smart techniques to get awesome scale when using long-polling and scales even more in our labs when using an efficient protocol like WebSockets with the new support for WebSockets in .NET 4.5.

So, we wanted to see if you combined asynchronous background work, use as many processors as you have, get real-time status updates via SignalR over long-polling or Web Sockets, using C#, .NET 4.5, ASP.NET and IIS.

It takes about 80,000 generations of monkeys at thousands of monkey generations a second (there's 200 monkeys per generation) to get the opening line of Hamlet. So that's ~16,000,000 monkeys just to get this much text. As they say, that's a lot of monkeys.

Here's the general idea of the app. The client is pretty lightweight and quite easy. There's two boxes, two buttons and a checkbox along side some text. There's some usual event wireup with started, cancelled, complete, and updateProgress, but see how those are on a monkey variable? That's from $.connection.monkeys. It could be $.connection.foo, of course, as long as it's hanging off $.connection.

Those functions are client side but we raise them from the server over the persistent connection then update some text.

<script src="Scripts/jquery-1.6.4.min.js"></script>    
<script src="Scripts/json2.min.js"></script>
<script src="Scripts/jquery.signalR.min.js"></script>
<script src="signalr/hubs"></script>
<script>
$(function () {
$('#targettext').val('To be or not to be, that is the question;\nWhether \'tis nobler in the mind to suffer\n\The slings and arrows of outrageous fortune,\n\Or to take arms against a sea of troubles,\n\And by opposing, end them.');

var monkeys = $.connection.monkeys,
currenttext = $('#currenttext'),
generationSpan = $('#generation'),
gpsSpan = $('#gps');

monkeys.updateProgress = function (text, generation, gps) {
currenttext.val(text);
generationSpan.text(generation);
gpsSpan.text(gps);
};

monkeys.started = function (target) {
$('#status').text('Working...');
$('#targettext').val(target);
$('#cancelbutton').removeAttr('disabled');
};

monkeys.cancelled = function () {
$('#status').text('Cancelled');
$('#cancelbutton').attr('disabled', 'disabled');
};

monkeys.complete = function () {
$('#status').text('Done');
$('#cancelbutton').attr('disabled', 'disabled');
};

$.connection.hub.start({}, function () {
$('#startbutton').click(function (event) {
$('#status').text('Queued...');
monkeys.startTyping($('#targettext').val(), $('#isparallel').is(':checked'));
});

$('#cancelbutton').click(function (event) {
monkeys.stopTyping();
});
});

});
</script>

The magic start with $.connection.hub.start. The hub client-side code is actually inside ~/signalr/hubs. See how that's include a the top? That client-side proxy is generated based on what hub or hubs are on the server side.

The server side is structured like this:

[HubName("monkeys")]
public class MonkeyHub : Hub
{
public void StartTyping(string targetText, bool parallel)
{
}

public void StopTyping()
{
}

}

The StartTyping and StopTyping .NET methods are callable from the client-side via the monkeys JavaScript object. So you can call server-side C# from the client-side JavaScript and from the C# server you can call methods in JavaScript on the client. It'll make the most sense if you debug it and watch the traffic on the wire. The point is that C# and Json objects can flow back and forth which blurs the line nicely between client and server. It's all convention over configuration. That's how we talk between client and server. Now, what about those monkeys?

You can check out the code in full, but StartTyping is the kick off point. Note how it's reporting back to the Hub (calling back to the client) constantly. Paul is using Hub.GetClients to talk to all connected clients as broadcast. This current implementation allows just one monkey job at a time. Other clients that connect will see the job in progress.

public void StartTyping(string targetText, bool parallel)
{
var settings = new GeneticAlgorithmSettings { PopulationSize = 200 };
var token = cancellation.Token;


currentTask = currentTask.ContinueWith((previous) =>
{
// Create the new genetic algorithm
var ga = new TextMatchGeneticAlgorithm(parallel, targetText, settings);
TextMatchGenome? bestGenome = null;
DateTime startedAt = DateTime.Now;

Hub.GetClients<MonkeyHub>().started(targetText);

// Iterate until a solution is found or until cancellation is requested
for (int generation = 1; ; generation++)
{
if (token.IsCancellationRequested)
{
Hub.GetClients<MonkeyHub>().cancelled();
break;
}

// Move to the next generation
ga.MoveNext();

// If we've found the best solution thus far, update the UI
if (bestGenome == null ||
ga.CurrentBest.Fitness < bestGenome.Value.Fitness)
{
bestGenome = ga.CurrentBest;

int generationsPerSecond = generation / Math.Max(1, (int)((DateTime.Now - startedAt).TotalSeconds));
Hub.GetClients<MonkeyHub>().updateProgress(bestGenome.Value.Text, generation, generationsPerSecond);

if (bestGenome.Value.Fitness == 0)
{
Hub.GetClients<MonkeyHub>().complete();
break;
}
}
}
}, TaskContinuationOptions.OnlyOnRanToCompletion);
}

If he wanted, he could use this.Caller to communicate with the specific client that called StartTyping. Inside ga.MoveNext we make the decision to go parallel or not based on that checkbox. This is where we pick two random high quality parent monkeys from our population for a potential future monkey. Hopefully one whose typing looks more like Shakespeare and less like a Regular Expression.

By simply changing from Enumerable.Range to ParallelEnumerable.Range we can start taking easily parallelizable things and using all the processors on our machine. Note the code is the same otherwise.

private TextMatchGenome[] CreateNextGeneration()
{
var maxFitness = _currentPopulation.Max(g => g.Fitness) + 1;
var sumOfMaxMinusFitness = _currentPopulation.Sum(g => (long)(maxFitness - g.Fitness));

if (_runParallel)
{
return (from i in ParallelEnumerable.Range(0, _settings.PopulationSize / 2)
from child in CreateChildren(
FindRandomHighQualityParent(sumOfMaxMinusFitness, maxFitness),
FindRandomHighQualityParent(sumOfMaxMinusFitness, maxFitness))
select child).
ToArray();
}
else
{
return (from i in Enumerable.Range(0, _settings.PopulationSize / 2)
from child in CreateChildren(
FindRandomHighQualityParent(sumOfMaxMinusFitness, maxFitness),
FindRandomHighQualityParent(sumOfMaxMinusFitness, maxFitness))
select child).
ToArray();
}
}

My 12 proc desktop does about 3800 generations a second in parallel.

Hexacore Super Computer!

Big thanks to Paul for the lovely port of this to SignalR and to Stephen Toub for the algorithm. 

The code for the SignalR monkeys demo is on my BitBucket. Right now it needs .NET 4.5 and the Visual Studio Developer Preview, but you could remove a few lines and get it working on .NET 4, no problem.

Note that that SignalR works on .NET 4 and up and you can play with it today. You can even chat with the developers in the SignalR chat app in the 'aspnet' room at http://chatapp.apphb.com. Just /nick yourself then /join aspnet.

No monkeys were hurt in the writing of this blog post.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Your users don't care if you use Web Sockets

November 10, 2011 Comment on this post [28] Posted in HTML5 | Musings
Sponsored By

I had a lovely time at the Keeping It Realtime Conference this week in Portland. The conference was put on by the lovely folks over at &yet and I'm glad I met them. "KRTConf" was a whole conference dedicated to "real-time" web applications. This largely meant node but also other real-time frameworks including Damien and David's SignalR that Paul Batum (Paul owns Web Sockets for .NET) and I presented. I'll blog our demo soon.

Some folks in the audience wanted to make a real-time app today but really wanted to use Web Sockets today and had concerns about broad support. Coincidentally, I had just visited &yet's new site for product called "&!" or "AndBang," a collaboration tool for teams. However, when I visited the page I got this message: https://andbang.com/you-need-websockets-yo.

Your browser doesn't support Web Sockets, so be sad

Switching protocols from HTTP to WebSocketsIn the near future, all browsers and servers will support Web Sockets, a technique by which a persistent connection is negotiated over HTTP and then a protocol switch happens from http:// to ws://. However, not every browser or server is there yet (IE9, for example) and there's some arguing about versioning, etc. If you don't support Web Sockets, falling back to "Long Polling" is a way to get effectively the same behavior that works everywhere.

Long polling is a technique that lets it look like your browser has a "persistent connection" to the server when in fact you've just got a really "persistent client." By this I mean, rather than a connection that doesn't shut down (persistent) you have a client that will make a call and when it completes, it'll call back. The very definition of persistent, eh? See what I did there?

Persistent: Continuing firmly or obstinately in a course of action in spite of difficulty or opposition.

Long Polling is not as efficient but it works nicely and is a totally reasonable fallback when Web Sockets support is unavailable. The latest preview release of IE10 includes Web Sockets support. But my mom doesn't know about Web Sockets and shouldn't have to.

The 10,000 people on the planet that care about Web Sockets are not your customers, and while using Web Sockets might get you mentioned on TechCrunch, supporting only Web Sockets is a great way to cut your potential audience in half.

You can use the lovely CanIUse web site to find out if you browser supports something you'd like to use. Here's their Web Sockets table.

Table of Browsers and their support for Web Sockets

Your users don't care about Web Sockets. They care about delightful sites. We use JavaScript polyfills when our browsers don't support HTML5 features we want. We use jQuery when JavaScript support is dodgy between browsers. And our web frameworks should gracefully fallback to use Long Polling when Web Sockets isn't available.

Related Links

P.S. Yes, if your app is a real-time trading app or and needs down-to-the-millisecond timing, then sure, maybe you need Web Sockets. But your app isn't that app.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.