Scott Hanselman

The Internet is not a black box. Look inside.

November 11, 2012 Comment on this post [31] Posted in Back to Basics | Musings
Sponsored By

All too often I see programmers trying to solve their problems on the internet by blindly "flipping switches."

Change something, hit refresh in the browser. "Why is that cached? What's going on?" Change something else, hit refresh in the browser. "What's the deal?"

You may have heard the term "cargo cult programming" where islanders after World War II would wave sticks hoping that planes full of supplies would fly over. They drew a conclusion that the sticks waving caused the planes to come.

Think about abstractions. This is a good reminder for the beginner and the long-time expert. This applies not just to computers but to cars, light bulbs, refrigerators and more.

What are you not seeing? Look underneath.

When coding on the web, remember that effectively NOTHING is hidden from you.

A friend emailed with a question about some CSS files not caching. This is a smart guy with a long question about a confusing behavior in the browser. I asked - as I often ask - what's happening underneath? Did you look inside?

Are you using Fiddler? Did you press F12 in your browser of choice and explore their network tools? Are you using WireShark?

Literally this moment, as I am writing this post, I just noticed that the Twitter box on my blog here doesn't have my latest tweet embedded.

Where's my tweet?

I could hit refresh a bunch of times, google around for vague terms, email a friend, or I could look inside.

I hit F12 in my browser. I look at the Network tab, and sort by Status.

Remember to use the Network Tools in your browser

Hey, suddenly my Twitter API call is a 404. First, that's lame of them. They should have redirected me, but alas, no one respects the permalink anymore. #getoffmylawn

With this single  insight I am now armed with googleable terms. I do a single search for "twitter user timeline json api" and see at the Twitter Developer Center that they've changed the format to included "api." and a version number.

I change my template to call this changed URL https://api.twitter.com/1/statuses/user_timeline/shanselman.json?callback=twitterCallback2&count=10 instead, and hit Refresh in my browser, once.

There's my tweet?

There's my tweet. No joke, this just happened. Good timing, I think.

You decide how deep you want to go down the rabbit hole. I am not expecting everyone to be a neurosurgeon or a professional network engineer but I firmly believe that digging just one layer deeper in all things will enhance your life and your work.

Learn basic HTTP debugging and ALWAYS check your result codes. Even if you are a non-technical blogger, learn how to check for 404s and 301s and 500s and assert your assumptions.

The world - and the internet - is not a black box. Look inside.

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

Windows 8, Step 0 - Turn on continuous backups via File History

November 10, 2012 Comment on this post [52] Posted in Win8
Sponsored By

So you've installed Windows 8. I'm going to do a small series of posts called "Windows 8, Step 0" with tips on what to be sure to do after you've installed Windows.

Here's an important TODO for you. Do it NOW. Do it all your machines, especially Non Technical Family Member's machine. Take that giant external USB drive you've got lying around and plug it in.

From within the Windows 8 Start Screen, type "File History" then click "Settings"

File History in Settings

Click it. Turn on File History and point it to your giant external drive, or some large network share that you have available.

File History is ON

This is kind of like Time Machine on a Mac. It will keep a constant shadow of your files backed up to this other drive. It runs automatically and you don't think about it until you lose something. It will automatically backup anything and everything in your Libraries (including Documents, Photos, Videos, Music) and everything on your Desktop.

If you want to backup more specific stuff, add whatever files you want to your Windows Libraries. I've added photos from another drive, for example as well as Documents from my DropBox folder.

image

You can click Advanced Settings there on the left to control how long the files are kept, how much disk space is used and how often it happens.

My File History runs hourly and uses 5% of the drive

I've also checked the box under HomeGroup to automatically recommend this large drive to the rest of the house! This is awesome for a few reasons. Other machines in the HomeGroup will automatically see this drive and can use it just by clicking "Turn on."

In the screenshot below you can see the File History dialog from my laptop with the 3TB drive from my other machine called HEXPOWER7 being recommended as a good drive for File History. One click, now my files are backed up on this machine.

File History from another computer recommends the main HomeGroup machine

HomeGroups are groups of computers at home that you trust and want to share files and devices with. You can make a HomeGroup in less than a minute. From the Start Screen, type "HomeGroup" then Click "Settings." Follow the instructions.

If you want, you can click Select Drive and pick any drive on your machine or add a network location. I have a 5TB Synology NAS so I could use that also. Any Windows-compatible SMB/Samba NAS will do.

File History to a NAS

Now I'm backing up to the Network Attached Storage (NAS).

File History on my NAS

Restoring from File History

Once you've been running File History for a while, you can go back to the Start Screen and type "Restore Your Files" and click "Settings" to get this dialog:

Restore File History with my files in a scrolling calendar

There's folder I want from my Desktop but it's not there as I've deleted it before. I will click the back button (you can hold it down to go back in time fast) until I get to a day when that file existed. I can also search my entire File History for previous versions of files.

I've backed up to November 6th and there's the file on my Desktop.

An old file from the past

Just click the green back-in-time Restore button and it's put back where it was. I can also restore it to a specific new place if I want to.

I hope this helps you. It's helped me!

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

Many Raspberry Pi projects - How can you not love a tiny computer?

November 08, 2012 Comment on this post [23] Posted in Hardware | Open Source | Reviews
Sponsored By

Picade Raspberry Pi ArcadeHow can you not love a tiny computer? I posted about Top 10 Raspberry Pi Myths and Truths and since then I'm up to four Raspberry Pi devices. The most recent is the new Raspberry Pi "Model B" that includes 512 megs of RAM.

Sure, Raspberry Pis aren't fast, but what they lack in performance they make up for with chutzpah. They have a nice GPU as well which will decode 1080p MP4 video in hardware and play it just fine. Even better, for about $4 you can get a license to unlock MPEG-2 or VC-1 decoding in hardware.

I also have a Netduino and Netduino Plus as well as an Arduino that I use with the greatest FPS Controller in history, the SpaceTec SpaceOrb along with a custom OrbShield that provides a bridge between the RS-232 Serial Port and the Arduino.

All these devices are very reasonably priced and a great fun for kids or adults.  Next I'm looking at the PIX-6T4 "game console" that lets you write tiny games in C# on a Netduino Mini or perhaps a Netduino Go.

Don't listen to the folks who write negative headlines about the Raspberry Pi. Sure, it's the wild west but with a little patience you'll do fine. There's an amazing community around the Raspberry Pi.

The amount of excitement around these tiny machines is amazing. There's even a Kickstarter for a "Picade" tiny arcade cabinet.

To make things easier once you get your Pi, I do recommend the Adafruit Raspberry Pi Budget Pack if you don't want to go hunting for parts. This kit includes a great little clear case, a 4 gig SD Card (actually a mini with an adapter, which is great since the Netduino Plus has a mini SD slot), cables and power, but best of all, a breadboard, wires and a lovely little ribbon cable and "cobbler" that makes it super easy to keep things tidy while still messing with the Raspberry Pi's GPIO (General Purpose Input Output) connections.

Related posts you might like

LEGO Raspberry Pi CaseWhat's great about the Raspberry Pi and small devices like it isn't the price -although that's great - it's that the Raspberry Pi has a GPIO and HDMI. This means it's the easiest and cheapest little PC that can talk to the outside world's many hardware devices. Having the combination of  HDMI out (for your TV) and GPIO (for everything else) means it's extremely accessible to the beginner.

That GPIO port along with its ease of programming gives rise to such fun as as the RetroPie GPIO Adapter that let you hook up your old Super Nintendo (SNES) controllers to a Pi! You can order a RetroPie GPIO Adapter here. Here is Video of the RetroPie in action. I am not affiliated with this creative person at all, I just dig the idea.

So I've got four now. Some friends have tweeted me saying that they bought one Raspberry Pi and haven't gotten around to doing antyhing with it, usually because they aren't sure WHAT to use it for.

Here's what my Pi's are currently doing:

I'm sure there are more reasons to buy more Raspberry Pis. Here's a few.

Seventeen Awesome Raspberry Pi Projects

These are some exciting and fun projects for you to explore with Raspberry Pi that might make your Pi feel more useful and get you playing today!

Be sure to check out the Element 14 Community Site for Raspberry Pi. I also love AdaFruit and their Pi-related products like the Adafruit Pi Box (I have 2) or the Budget Pack (I have 1).

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

Reactive Extensions (Rx) is now Open Source

November 06, 2012 Comment on this post [10] Posted in LINQ | Open Source
Sponsored By

A few years back I did a podcast with Erik Meijer about Reactive Extensions for .NET (Rx). Since then thousands of people have enjoyed using Rx in the projects and a number of open source projects like ReactiveUI (also on the podcast) have popped up around it. Even GitHub for Windows uses Reactive Extensions. In fact, GitHub uses Rx a LOT in their Windows product. My friend Paul at GitHub says they liked the model so much they made a Mac version!

“GitHub for Windows uses the Reactive Extensions for almost everything it does, including network requests, UI events, managing child processes (git.exe). Using Rx and ReactiveUI, we've written a fast, nearly 100% asynchronous, responsive application, while still having 100% deterministic, reliable unit tests. The desktop developers at GitHub loved Rx so much, that the Mac team created their own version of Rx and ReactiveUI, called ReactiveCocoa, and are now using it on the Mac to obtain similar benefits.” – Paul Betts, GitHub

Today, Microsoft Open Technologies announced the open sourcing of Reactive Extensions! You can get the code with git up on Codeplex at https://rx.codeplex.com. You can’t stop the open source train! Congrats to the team!

There’s a LOT included, so be stoked. It’s not just Rx.NET, but also the C++ library as well as RxJS for JavaScript! Now everyone gets to play with IObservable<T> and IObserver<T>.

  • Reactive Extensions:
    • Rx.NET: The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators.
    • RxJS: The Reactive Extensions for JavaScript (RxJS) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in JavaScript which can target both the browser and Node.js.
    • Rx++: The Reactive Extensions for Native (RxC) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
  • Interactive Extensions
    • Ix: The Interactive Extensions (Ix) is a .NET library which extends LINQ to Objects to provide many of the operators available in Rx but targeted for IEnumerable<T>.
    • IxJS: An implementation of LINQ to Objects and the Interactive Extensions (Ix) in JavaScript.
    • Ix++: An implantation of LINQ for Native Developers in C++

A great way to learn about why Rx is useful is to check out the Rx Koan’s project or to read the IntroToRx online e-book.

Why do I think Rx matters? It’s a way to do asynchronous operations on event streams. Rather than hooking up click events and managing state with event handlers all over, you effectively “query” an infinite stream of events with LINQ. You can declaratively sequence events…no flags, no state machine.

For example, here’s a dragging event created (composed) via Mouse button and Mouse move events:

IObservable<Event<MouseEventArgs>> draggingEvent =
from mouseLeftDownEvent in control.GetMouseLeftDown()
from mouseMoveEvent in control.GetMouseMove().Until(control.GetMouseLeftUp())
select mouseMoveEvent;

Even better, Rx makes it easier (or possible!) to create event-based tests that are asynchronous, like this example from Jafar Husain:

Rating rating = new Rating();
IObservable<Unit> test = // Unit is an object that represents null.
ObservableExtensions
.DoAsync(() => TestPanel.Children.Add(rating))
.WaitFor(TestPanel.GetLayoutUpdated()) // Extension method GetLayoutUpdated converts the event to observable
.DoAsync(() => rating.Value = 1.0) // Calls the Ignite EnqueueCallback method
.WaitFor( // waits for an observable to raise before going on
// listen to all the actual value change events and filters them until ActualValue reaches Value
rating
.GetActualValueChanged() // extension method that converts ActualValueChanged event to IObservable
.SkipWhile(actualValueChangedEvent => actualValueChangedEvent.EventArgs.NewValue != rating.Value))
// check to make sure the actual value of the rating item is set appropriately now that the animation has completed
.Assert(() => rating.GetRatingItems().Last().ActualValue == 1.0) // crawls the expression tree and makes a call to the appropriate Assert method

Test.Subscribe(() => TestPanel.Children.Remove(rating)); //run the test and clean up at the end.

There’s amazing Time-related operators that let you simulate events over time. Note the Buffer and Subscribe calls.

var myInbox = EndlessBarrageOfEmail().ToObservable();

// Instead of making you wait 5 minutes, we will just check every three seconds instead. :)
var getMailEveryThreeSeconds = myInbox.Buffer(TimeSpan.FromSeconds(3)); // Was .BufferWithTime(...

getMailEveryThreeSeconds.Subscribe(emails =>
{
Console.WriteLine("You've got {0} new messages! Here they are!", emails.Count());
foreach (var email in emails)
{
Console.WriteLine("> {0}", email);
}
Console.WriteLine();
});

You can use await and async, like in this example returning the number 42 after 5 seconds:

static async void button_Click()
{
int x = await Observable.Return(42).Delay(TimeSpan.FromSeconds(5));
// x with value 42 is returned after 5 seconds
label.Text = x.ToString();
}
I’m just showing you the parts that tickle me, but one could easily teach a 10 week university course on Rx, and I’m still a beginner myself!

Here’s some more resources to check out about Rx. Congrats to the team for their contribution to Open Source!

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

Videos of talks from the 2012 BUILD Conference - Angle Brackets and Curly Braces

November 05, 2012 Comment on this post [14] Posted in ASP.NET | Azure | Speaking
Sponsored By

It was an insane week at BUILD. Much of my schedule was my own fault as I continue to treat Microsoft Outlook as if it were a game of Tetris, franticly packing appointments ten-deep.

The "Angle Brackets" team (ASP.NET, Azure, and Web Tools) had a good showing and lots of fun. We chose to create a little two day mini-conf by scheduling our talks on Thursday and Friday and I think it worked great. There was a Day 1 and Day 2 Keynote. I had a small 10 minute coding segment before ScottGu in the Day 2 Keynote. I kicked if off on Day 3 (Thursday) with an un-keynote at 8:30am called Angle Brackets, Curly Braces, One ASP.NET and the Cloud. Then the team had their talks on Thursday and Friday and finally Jon Galloway and I ended the show with the very LAST talk  on Friday afternoon called "Bleeding edge ASP.NET."

Here's video of my talks, as well as links to all the talks our team did! Remember that you can download these talks in various formats and watch them at your leisure!

Angle Brackets, Curly Braces, One ASP.NET and the Cloud

I'm very happy with how this talk turned out and I hope you enjoy it. If you do, let me know and share it with your friends.

Downloads:


Bleeding edge ASP.NET: See what is next for MVC, Web API, SignalR and more…

I played code monkey in this talk with Jon Galloway. We had great fun, showed lots of demos and generally picked on each other throughout.

Downloads


Talks from the Web Team

There were some amazing talks this year.

See how we're BUILDing stuff? Each of these talks is code-heavy and focused on getting you working and building great stuff and hopefully having fun while you do it.

Be sure to check out all the BUILD talks. They are up on http://channel9.msdn.com/Events/Build/2012 in their entirety, with both speaker cameras via Picture-in-Picture and high-def video. Hope you enjoy them!

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.