Scott Hanselman

How to map an Insert Key on your Surface Pro 3 Keyboard

January 13, '15 Comments [23] Posted in Tools
Sponsored By

I'm very happy with my Surface Pro 3 and continue to use it happily. However, the Type Keyboard on the Surface Pro 3 lacks an Insert Key.

Surface Pro 3 Type Cover

For some this may feel like a real problem, but remember your computer (and the internet itself) is not a black box. You can remap the keys if you like. The Windows, via the registry, supports keymapping at its core. SharpKeys is a free little utility that lets you easily create the registry entries you want to remap the keys the way you'd like them.

Here's a screenshot of my registry where I've remapped Right Alt to be Insert. But who wants to edit the registry manually, right?

The Registry is scary

Here's SharpKeys, where I mapped Right Alt to Insert on my Surface Pro 3 Keyboard. Then SharpKeys writes the Scancode Map key for me. Just log in and log out to see your changes in action.

Disclaimer: You can do dumb stuff and mess yourself up if you disable a key you REALLY need. That's why I changed just Right Alt, since I still have Left Alt. HOWEVER, some apps (VMWare, etc) you use may need specific keys, and you'll want to be smart about what you map to other keys.

You can click Type Key and map left to right, or pick from the list yourself as I've done here.

Mapping Right Alt to Insert in SharpKeys for my Surface Pro 3

It works great! Hope this helps you.


Sponsor: Welcome this week's feed sponsor, Stackify! - The only developer-friendly solution that fully integrates .NET error & log management with application monitoring. Easily isolate issues and focus your efforts – Support less, Code more. Free trial

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

NuGet Package of the Week: Polly wanna fluently express transient exception handling policies in .NET?

January 13, '15 Comments [12] Posted in NuGet | NuGetPOW
Sponsored By

LOL at my own post title. Pardon me.

Install-Package Polly

Michael Wolfenden has a very clever open source library called Polly. Polly is a .NET 3.5 / 4.0 / 4.5 / PCL library that allows developers to express transient exception handling policies such as Retry, Retry Forever, Wait and Retry or Circuit Breaker in a fluent manner.

Handling exceptions can be a hassle sometimes. Not just setting the try/catches up, but deciding on the policy for the catch can make the exception management code more complex than the method itself!

Polly has a fluent interface to make expressing rules like that much easier. For example:

// Single exception type
Policy
.Handle<DivideByZeroException>()

// Single exception type with condition
Policy
.Handle<SqlException>(ex => ex.Number == 1205)

// Multiple exception types
Policy
.Handle<DivideByZeroException>()
.Or<ArgumentException>()

// Multiple exception types with condition
Policy
.Handle<SqlException>(ex => ex.Number == 1205)
.Or<ArgumentException>(ex => x.ParamName == "example")

Then you can add Retry() logic, which is fantastic.

// Retry multiple times, calling an action on each retry 
// with the current exception and retry count
Policy
.Handle<DivideByZeroException>()
.Retry(3, (exception, retryCount) =>
{
// do something
});

Even do retries with multiplicative back off!

// Retry a specified number of times, using a function to 
// calculate the duration to wait between retries based on
// the current retry attempt, calling an action on each retry
// with the current exception, duration and context provided
// to Execute()
Policy
.Handle<DivideByZeroException>()
.WaitAndRetry(
5,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
(exception, timeSpan, context) => {
// do something
}
);

Once you have set up a policy, you execute on it.

Policy
.Handle<SqlException>(ex => ex.Number == 1205)
.Or<ArgumentException>(ex => ex.ParamName == "example")
.Retry()
.Execute(() => DoSomething());

Polly also supports the more sophisticated "Circuit Breaker" policy. For more information on the Circuit Breaker pattern see:

Circuit breaker tries and then "Trips the circuit breaker" so you'll get a BrokenCircuitException for some amount of time. This is a great way to give an external system to chill for a minute if it's down. It also externalizes the concept so that you could theoretically handle a down database the same as you handle a down external web API.

// Break the circuit after the specified number of exceptions
// and keep circuit broken for the specified duration
Policy
.Handle<DivideByZeroException>()
.CircuitBreaker(2, TimeSpan.FromMinutes(1))

You can explore the code, of course, up on Github in the Polly repository. Go give the Polly project a star. They've recently added async support for .NET 4.5 as well!


Sponsor: Welcome this week's feed sponsor, Stackify! - The only developer-friendly solution that fully integrates .NET error & log management with application monitoring. Easily isolate issues and focus your efforts – Support less, Code more. Free trial

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Refresh Your PC in Windows, AppData, and my missing Minecraft worlds

January 8, '15 Comments [30] Posted in Win8
Sponsored By

I thought I lost everything today. Well, not really, I have a very regular Backup Strategy (stop reading this blog post NOW and back your stuff up!) so I could get stuff back if I really needed to.

But a laptop died today. It just wouldn't start up and I had to run "Refresh my PC," a very cool feature of Windows that basically mostly reinstalls Windows without reinstalling. It promises not to lose your files. And it's (99%) true, because when I got Windows back up later my Documents and Desktop were just as I left them, untouched by the this major operation.

Refresh your PC - Windows 8.1

Fortunately I used Boxstarter, Chocolately, and a list of the programs I have installed as a Gist and was able to get my Windows machine with all my desktop programs back up and running in a few hours. All my files were backed up to the cloud and every file was where I left it.

Except the most important ones. ;)

I launched Minecraft, and saw this. And almost died.

My minecraft worlds are missing!

Where's my Minecraft save games/worlds?

I thought Windows promised to not change my files!? Well, sadly Minecraft doesn't save worlds in "My Documents\Minecraft," where it should. It puts them instead in c:\Users\YOURNAME\AppData\Roaming\.minecraft\saves which is basically like a temp folder of sorts for config data.

Fortunately after my initial freak out, even these files aren't lost, they are in C:\Windows.old\users\YOURNAME\AppData\Roaming\.minecraft\saves along with all your other AppData stuff including the npm-cache, .emacs.d, and other config data you might want.

Move them back, and you're (I'm) all set!

To the (Minecraft) Cloud!

Whew.

Related Links

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Getting Started with Robots for kids and children in STEM this holiday season

December 26, '14 Comments [27] Posted in Parenting
Sponsored By

Now's the perfect time to buy your kids/nieces/cousins some robots. Robots are a great way to get children excited about computers. Robots get them stoked in a way that a simple Hello World console app just can't.

If you're not careful you can spent hundreds on robots. However, I'm notoriously frugal and I believe that you can build some amazing stuff with children with a reasonable budget.

Here's some of the robot and electronics kits I recommend and have built with my kids.

4M Tin Can Robot

This is just a teaser but it's less than a trip to the movies. This silly little kit takes 2 AAA batteries and will take an aluminum can and animate it. It gets kids thinking about using found objects in their robots, as opposed to them thinking custom equipment is always required.

tincan

Quadru-Bot 14-in-1 Solar Robot

One of the challenges is "what age should I start?" and "how complex of a robot can my __ year old handle?" Kits like this are nice because they are starting with batteries and gears and include two levels of building, basic and experienced. It's also a nice kit because it includes solar power as an option and also can work in water (the bath).

713-IOSBdAL._SL1500_

OWI Robotic Arm Edge

This isn't a kit but it's a reasonably priced robotic arm to get kids thinking in terms of command and control and multiple dimensions. OWI also has a cool 3in1 robot RC kit if you prefer driving robots around and more "rebuildability."

51LAkVypvAL

Mirobot

This Christmas my 7 year old and I built a Mirobot. You can get pre-soldered and solder-yourself kits. We got the main Mirobot Kit PLUS the Addons Kit which includes clever additional modules for Line Following, Sound, and Collision Detection.

The whole Mirobot execution is brilliant. The hardware and software are all open source, so if you want to acquire the parts and make it yourself you can. You can get kits in various levels of preassembly.

It's built on an Arduino but is preloaded with some very clever software that takes advantage of its onboard Wifi. You can program it in C with Arduino tools, of course, but for kids, they can use JavaScript and an in-browser editor, much like Logo. It will create its own ad-hoc wifi network by default, or you can join it to your home network.

image

The creator is also building an Apps Platform so you can control the Mirobot from other apps within your browser and websocket your way over to the robot.

It took us about a weekend to build and you can see in the pic below that my 7 year old was able to install a pen and get the bot to draw a stickman. He was THRILLED.

10838706_883990588298288_1242836197_n

Edison

This isn't the Intel Edison, although you can make some great robots with it as well. No, this is Edison, a little LEGO compatible robot from the makers of Microbric, a great robot platform from a few years ago. I actually made a Microbric robot in 2007 and blogged about it.

Edison is fantastic and just $50. If you're a teacher and can get a multiples pack, you can get them as cheap as $35 each. You program Edison with a clean drag and drop icon system then download the program to your robot with a cable from your computer's headphone jack.

Out of the box you can have it follow a flashlight/torch, follow lines on paper, fight each other in a sumo ring, avoid walls, and lots more. In this picture there's two Edison's stacked on each other. The top one has the wheels removed and replaced with Lego elements to make robot arms.

image

LEGO Mindstorms

OK, yes, LEGO Mindstorms are $350, so that's not exactly frugal. BUT, I've seen parents buy $500 iPads without a thought, why not consider a more tactile and engineering-focused gift for a girl or boy?

This is THE flagship. It's got Wifi, Bluetooth, color sensors, iPad apps, collision detection, motors galore and unlimited replayability. There's also a huge online community dedicated to taking Mindstorms to the next level. If you can swing it, it's worth the money and appropriate for anyone from 6 to 60.

81Hn0H3SyAL._SL1500_

Snap Circuits

I couldn't love Snap Circuits more. I started with the Jr. Snap Circuits and we eventually graduated to Snap Circuits Pro. They are my #1 go-to gift idea for kids of friends and relatives.

While this isn't a robotics kit, per se, it really builds the basic understanding of batteries, electronics, and motors that kids will need to move to the next level.

91lfaA93v0L._SL1500_

What robot kids do YOU recommend?

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

The real and complete story - Does Windows defragment your SSD?

December 3, '14 Comments [71] Posted in Win7 | Win8
Sponsored By

There has been a LOT of confusion around Windows, SSDs (hard drives), and whether or not they are getting automatically defragmented by automatic maintenance tasks in Windows.

There's a general rule of thumb or statement that "defragging an SSD is always a bad idea." I think we can agree we've all heard this before. We've all been told that SSDs don't last forever and when they die, they just poof and die. SSDs can only handle a finite number of writes before things start going bad. This is of course true of regular spinning rust hard drives, but the conventional wisdom around SSDs is to avoid writes that are perceived as unnecessary.

Does Windows really defrag your SSD?

I've seen statements around the web like this:

I just noticed that the defragsvc is hammering the internal disk on my machine.  To my understanding defrag provides no value add on an SSD and so is disabled by default when the installer determines the disk is SSD.  I was thinking it could be TRIM working, but I thought that was internal to the SSD and so the OS wouldn’t even see the IO.

One of the most popular blog posts on the topic of defrag and SSDs under Windows is by Vadim Sterkin. Vadim's analysis has a lot going on. He can see that defrag is doing something, but it's not clear why, how, or for how long. What's the real story? Something is clearly running, but what is it doing and why?

I made some inquiries internally, got what I thought was a definitive answer and waded in with a comment. However, my comment, while declarative, was wrong.

Windows doesn’t defrag SSDs. Full stop. If it reports as an SSD it doesn’t get defraged, no matter what. This is just a no-op message. There’s no bug here, sorry. - Me in the Past

I dug deeper and talked to developers on the Windows storage team and this post is written in conjunction with them to answer the question, once and for all

"What's the deal with SSDs, Windows and Defrag, and more importantly, is Windows doing the RIGHT THING?"

It turns out that the answer is more nuanced than just yes or no, as is common with technical questions.

The short answer is, yes, Windows does sometimes defragment SSDs, yes, it's important to intelligently and appropriately defrag SSDs, and yes, Windows is smart about how it treats your SSD.

The long answer is this.

Actually Scott and Vadim are both wrong. Storage Optimizer will defrag an SSD once a month if volume snapshots are enabled. This is by design and necessary due to slow volsnap copy on write performance on fragmented SSD volumes. It’s also somewhat of a misconception that fragmentation is not a problem on SSDs. If an SSD gets too fragmented you can hit maximum file fragmentation (when the metadata can’t represent any more file fragments) which will result in errors when you try to write/extend a file. Furthermore, more file fragments means more metadata to process while reading/writing a file, which can lead to slower performance.

As far as Retrim is concerned, this command should run on the schedule specified in the dfrgui UI. Retrim is necessary because of the way TRIM is processed in the file systems. Due to the varying performance of hardware responding to TRIM, TRIM is processed asynchronously by the file system. When a file is deleted or space is otherwise freed, the file system queues the trim request to be processed. To limit the peek resource usage this queue may only grow to a maximum number of trim requests. If the queue is of max size, incoming TRIM requests may be dropped. This is okay because we will periodically come through and do a Retrim with Storage Optimizer. The Retrim is done at a granularity that should avoid hitting the maximum TRIM request queue size where TRIMs are dropped.

Wow, that's awesome and dense. Let's tease it apart a little.

When he says volume snapshots or "volsnap" he means the Volume Shadow Copy system in Windows. This is used and enabled by Windows System Restore when it takes a snapshot of your system and saves it so you can rollback to a previous system state. I used this just yesterday when I install a bad driver. A bit of advanced info here - Defrag will only run on your SSD if volsnap is turned on, and volsnap is turned on by System Restore as one needs the other. You could turn off System Restore if you want, but that turns off a pretty important safety net for Windows.

One developer added this comment, which I think is right on.

I think the major misconception is that most people have a very outdated model of disk\file layout, and how SSDs work.

First, yes, your SSD will get intelligently defragmented once a month. Fragmentation, while less of a performance problem on SSDs vs traditional hard drives is still a problem. SSDS *do* get fragmented.

It's also worth pointing out that what we (old-timers) think about as "defrag.exe" as a UI is really "optimize your storage" now. It was defrag in the past and now it's a larger disk health automated system.

Used under CC. Photo by Simon WüllhorstAdditionally, there is a maximum level of fragmentation that the file system can handle. Fragmentation has long been considered as primarily a performance issue with traditional hard drives. When a disk gets fragmented, a singular file can exist in pieces in different locations on a physical drive. That physical drive then needs to seek around collecting pieces of the file and that takes extra time.

This kind of fragmentation still happens on SSDs, even though their performance characteristics are very different. The file systems metadata keeps track of fragments and can only keep track of so many. Defragmentation in cases like this is not only useful, but absolutely needed.

SSDs also have the concept of TRIM. While TRIM (retrim) is a separate concept from fragmentation, it is still handled by the Windows Storage Optimizer subsystem and the schedule is managed by the same UI from the User's perspective. TRIM is a way for SSDs to mark data blocks as being not in use. Writing to empty blocks on an SSD is faster that writing to blocks in use as those need to be erased before writing to them again. SSDs internally work very differently from traditional hard drives and don't usually know what sectors are in use and what is free space. Deleting something means marking it as not in use. TRIM lets the operating system notify the SSD that a page is no longer in use and this hint gives the SSD more information which results in fewer writes, and theoretically longer operating life. 

In the old days, you would sometimes be told by power users to run this at the command line to see if TRIM was enabled for your SSD. A zero result indicates it is.

fsutil behavior query DisableDeleteNotify

However, this stuff is handled by Windows today in 2014, and you can trust that it's "doing the right thing." Windows 7, along with 8 and 8.1 come with appropriate and intelligent defaults and you don't need to change them for optimal disk performance. This is also true with Server SKUs like Windows Server 2008R2 and later.

Conclusion

No, Windows is not foolishly or blindly running a defrag on your SSD every night, and no, Windows defrag isn't shortening the life of your SSD unnecessarily. Modern SSDs don't work the same way that we are used to with traditional hard drives.

Yes, your SSD's file system sometimes needs a kind of defragmentation and that's handled by Windows, monthly by default, when appropriate. The intent is to maximize performance and a long life. If you disable defragmentation completely, you are taking a risk that your filesystem metadata could reach maximum fragmentation and get you potentially in trouble.

Related Links

* photo by Simon Wüllhorst, used under CC BY 2.0.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

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