Quantcast
Channel: Scott Hanselman's Blog
Viewing all 1148 articles
Browse latest View live

Enabling Websockets for Socket.io Node apps on Microsoft Azure

$
0
0

Whoa my Blood Sugar is a CGM in the Cloud!NOTE: This is a technical post, I'll blog more about Nightscout later this week. Subscribe and watch for my take, or visit http://www.nightscout.info.

I'm running an application called Nightscout that is a node app with a MongoDB backend that presents a JSON endpoint for a diabetic's blood sugar data. I use my Dexcom G4 CGM (Continuous Glucose Meter) connected with a micro-USB OTG cable to an Android phone. An Android app bridges the device and POSTs up to the website.

Azure is well suited to run an app like this for a few reasons. Node works great on Azure, MongoLabs is setup in the Azure Store and has a free sandbox, Azure supports WebSockets, and *.azurewebsites.net has a wildcard SSL cert, so I could force SSL.

Enabling Websockets and Forcing SSL

So my goal here is to do two things, make sure Websockets/socket.io is enabled in my app because it's been using polling, and force my app to use SSL.

Setting up a node.js site on Azure is very easy. You can see a 3 minute video on how to do a Git Deploy of a node app here. Azure will see that there's a app.js or server.js and do the right thing.

However, because IIS and node are working together to host the site (IIS hands off to node using a thing called, wait for it, iisnode) you should be aware of the interactions.

There's a default web.config that will be created with any node app, but if you want to custom stuff like rewrites, or websockets, you should make a custom web.config. First, you'll need to start from the web.config that Azure creates.

Related Link:  Using a custom web.config for Node apps

Let's explore this web.config so we understand what's it's doing so we can enable Websockets in my app. Also, note that even though our project has this web.config in our source repository, the app still works on node locally or hosts like Heroku because it's ignored outside Azure/IIS.

  • Note that we say "webSocket enabled=false" in this web.config. This is confusing, but makes sense when you realize we're saying "disable Websockets in IIS and let node (or whomever) downstream handle it"
  • Note in the iisnode line you'll put path="server.js" or app.js or whatever. Server.js appears again under Dynamic Content to ensure node does the work.
  • I added NodeInspector so I can do live node.js debugging from Chrome to Azure.
  • Optionally (at the bottom) you can tell IIS/Azure to watch *.js files and restart the website if they change.
  • We also change the special handling of the bin folder. It's not special in the node world as it is in ASP.NET/IIS.
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:

https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>

<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>

<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>

<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />

<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled

See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>

Next, turn on Websockets support for your Azure Website from the configure tab within the Azure Portal:

Turn on Websockets in the Azure Portal

Now I need to make sure the node app that is using socket.io is actually asking for Websockets. I did this work on my fork of the app.

io.configure(function () {
- io.set('transports', ['xhr-polling']);
+ io.set('transports', ['websocket','xhr-polling']);

It turns out the original author only put in one option for socket.io to try. I personally prefer to give it the whole list for maximum compatibility, but in this case, we clearly need Websockets first. When will Websockets fall back if it's unavailable? What Azure website pricing plans support WebSockets?

  • Free Azure Websites plans support just 5 concurrent websockets connections. They're free. The 6th connection will get a 503 and subsequent connections will fallback to long polling. If you're doing anything serious, do it in Shared or above, it's not expensive.
  • Shared Plans support 35 concurrent websockets connections, Basic is 350, and Standard is unlimited.

You'll usually want to use SSL when using Websockets if you can, especially if you are behind a proxy as some aggressive proxies will strip out headers they don't know, like the Upgrade header as you switch from HTTP to Websockets.

However, even free Azure websites support SSL under the *.azurewebsites.net domain, so doing development or running a small site like this one gets free SSL.

I can force it by adding this rule to my web.config, under <system.webServer>/<rewrite>/<rules/>:

<rule name="Force redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern=".+\.azurewebsites\.net$" />
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>

Note the pattern in this case is specific to azurewebsites.net, and will take any Azure website on the default domain and force SSL. You can change this for your domain if you ike, of course, assuming you have an SSL cert. It's a nice feature though, and a helpful improvement for our diabetes app.

I can confirm using F12 tools that we switched to WebSockets and SSL nicely.

image

The whole operation took about 15 minutes and was a nice compatible change. I hope this helps you out if you're putting node.js apps on Azure like I am!


Sponsor: Big thanks to Aspose for sponsoring the feed this week! Working with Files? Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and many other formats in your applications. Start a free trial today.



© 2014 Scott Hanselman. All rights reserved.
     

NuGet Package of the Week - Courtesy Flush to flush buffers earlier and optimize time to first byte

$
0
0

Yes, really. It's got to be the best name for an open source library out there. It's a great double entendre and a great name for this useful little library. Perhaps English isn't your first language, so I'll just say that a courtesy flush gives the next person a fresh bowl. ;)

However, in the computer world "flushing a buffer" means forcing a buffer to be moved along, usually to a file or the network. Rather than holding data, you flush it, and move it along.

Nik from Glimpse has a small NuGet package called Courtesy Flush. He's got a good write-up on his blog.

image

It's a library to enable easier flushing of your buffer in ASP.NET MVC. From their site:

Why Flush Early?

Flushing early can provide performance improvements in web applications and has been a recomended best practice in the web performance community since 2007.

To find out more, check out Nik's blog where he covered the benefits of flushing early in two posts:

It builds on top of ASP.NET ActionFilters, which you can apply as attributes to your methods, or call within controllers.

Let's say that you have some server-side work that's very slow. That slow operation could hold up the rendering of your page until it completes. With a pre-flush like this you can get bytes onto the network and into the user's browser faster.

Here we render some information and get it out fast before we do something that's unavoidably slow.

public ActionResult About()
{
ViewBag.Title = DateTime.Now.Second;
this.FlushHead();

Thread.Sleep(2000);
ViewBag.Message = "Your application description page.";

return View();
}

Let's think about really specifically. It's important to know WHY you would want to do this and what exactly happens in the browser.

If you have a long running, but important process (we are pretending that Thread.Sleep(2000) is important) that takes 2 seconds, no HTML is sent to the browser. It's just waiting. The timeline looks like this:

Here we didn't flush

See that blue line? We waited almost 5 seconds for the /about page, and while we were waiting, no Javascript and no CSS were being loaded. Why not? How could the browser know if it isn't seen the <head> of your HTML?

For an optimization, we could FLUSH the buffers that we have up to this point, putting the HTML that we have so far onto the network.

The Layout.cshtml we have a call to @Html.FlushHead() to get the the _Head.cshtml out and into the hands of the browser. It might look like this:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@if (ViewBag.Description != null)
{
<meta name="description" content="@ViewBag.Description">
}
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>

Here's what the SAME page looks like with the <head> flushed out first.

Here we flushed

Look closely at the timeline. Here, I'll do it for you...below shows when we flushed early versus just waiting.

See how when we flushed the head it gave the browser enough information to stat loading some css and javascript we had in the <head?> The whole page took 5 seconds, but when we flush at least we get things going early, while when we don't flush we can't do a thing until the long running task finishes.

See the difference?

See the difference? Now, to be clear, don't blindly go and add optimizations without reading the code and understanding what's going on, but this is a nice tool for our ASP.NET toolbox.

We may see a similar but even more powerful technique in ASP.NET vNext that includes async flushes at multiple points, while updating the model as data is available.


Sponsor: Big thanks to Aspose for sponsoring the feed this week! Working with Files? Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and many other formats in your applications. Start a free trial today.


© 2014 Scott Hanselman. All rights reserved.
     

Announcing .NET 2015 - .NET as Open Source, .NET on Mac and Linux, and Visual Studio Community

$
0
0

It's happening. It's the reason that a lot of us came to work for Microsoft, and I think it's both the end of an era but also the beginning of amazing things to come.

The .NET 2015 wave of releases is upon us. Here's what's happening and we announced it today in New York. There's a lot here, so drink it all in slowly.

Be sure to check out all the blog posts I'm linking to at the end, but here's my personal rollup and take on the situation.

  • We are serious about open source and cross platform.
    • .NET Core 5 is the modern, componentized framework that ships via NuGet. That means you can ship a private version of the .NET Core Framework with your app. Other apps' versions can't change your app's behavior.
    • We are building a .NET Core CLR for Windows, Mac and Linux and it will be both open source and it will be supported by Microsoft. It'll all happen at https://github.com/dotnet.
    • We are open sourcing the RyuJit and the .NET GC and making them both cross-platform.
  • ASP.NET 5 will work everywhere.
    • ASP.NET 5 will be available for Windows, Mac, and Linux. Mac and Linux support will come soon and it's all going to happen in the open on GitHub at https://github.com/aspnet.
    • ASP.NET 5 will include a web server for Mac and Linux called kestrel built on libuv. It's similar to the one that comes with node, and you could front it with Nginx for production, for example.
  • Developers should have a great experience.
    • There is a new FREE SKU for Visual Studio for open source developers and students called Visual Studio Community. It supports extensions and lots more all in one download. This is not Express. This is basically Pro.
    • Visual Studio 2015 and ASP.NET 5 will support gulp, grunt, bower and npm for front end developers.
    • A community team (including myself and Sayed from the ASP.NET and web tools team have created the OmniSharp organization along with the Kulture build system as a way to bring real Intellisense to Sublime, Atom, Brackets, Vim, and Emacs on Windows, Linux, and Mac. Check out http://www.omnisharp.net as well as blog posts by team members Jonathan Channon
  • Even more open source.
    • Much of the .NET Core Framework 4.6 and its Reference Source source is going on GitHub. It's being relicensed under the MIT license, so Mono (and you!) can use that source code in their .NET implementations.
    • There's a new hub for Microsoft open source that is hosted GitHub at http://microsoft.github.io.

Open sourcing .NET makes good sense. It makes good business sense, good community sense, and today everyone at Microsoft see this like we do.

The .NET 2015 Wave

Related Links



© 2014 Scott Hanselman. All rights reserved.
     

ASP.NET 5 (vNext) Work in Progress - Exploring TagHelpers

$
0
0

TagHelpers are a new feature of ASP.NET 5 (formerly and colloquially ASP.NET vNext) but it's taken me (and others) some time to fully digest them and what they mean.

Note that this, and all of ASP.NET 5 is a work in progress. TagHelpers can and will change. There is NO tooling support in Visual Studio for them, as they are changing day to day, so just be aware. That's why this post (and series is called Work in Progress.)

Historically we've used HtmlHelpers within a Razor View, so when you wanted a Label or a TextBox you'd do this. This is from the ASP.NET 5 Starter Web example.

<li>@Html.ActionLink("Home", "Index", "Home")</li>

There you have some HTML, then we start some C# with @ and then switch out. It's inline C#, calling a function that will return HTML.

Here's the same thing, using a TagHelper.

<li><a controller="Home" action="Index">Home</a></li>

The source for TagHelpers is (as with all ASP.NET source) up on GitHub, here. This is an anchor, A, so it'll be in AnchorTagHelper. The code is very simple, in fact, gets a collection of attributes and decides which to act upon.

In this case, "controller" and "action" are not HTML5 attributes, but rather ones that ASP.NET is looking for.

Question for You - Would you rather have these attributes and ones like them (including your own) be prefixed? Perhaps asp:controller or asp-controller? That's an open issue you can comment on! You could do [HtmlAttributeName("asp:whatever")] on a property or [TagName("foo")] for a tag if you liked.

How do these attributes get mapped to a TagHelper? Well, an attribute name is mapped directly to a C# property and automatically injected. See how AnchorTagHelper has public properties Action and Controller?

It's important to note that this isn't the second coming of WebForms controls, while the possible asp:foo syntax may look familiar (even though a prefix is optional.) This is more

Personally, I'd love to see them look different in the editor. For example, rather than

Tag Helpers

I'd like to see italics, or maybe a desaturation to show what's server-side and what's not, which will be super important if I'm NOT using a prefix to distinguish my attributes.

Tag Helpers, desaturated

The code below in this Before and After results in the same HTML and the same behavior. A nice aspect of TagHelpers it that you avoid the context switch from markup to C#.

Here is another example, a login partial form, before...

@using System.Security.Principal

@if (User.Identity.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}

and after...with the Microsoft.AspNet.Mvc.TagHelpers package added in project.json and then @addtaghelper "MyAssemblyName" in either your ViewStart.cshtml to get this in all views, or separately within a single view page.

@using System.Security.Principal

@if (User.Identity.IsAuthenticated)
{
<form method="post" controller="Account" action="LogOff" id="logoutForm" class="navbar-right">
<ul class="nav navbar-nav navbar-right">
<li>
<a controller="Account" action="Manage" title="Manage">Hello @User.Identity.GetUserName()!</a>
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
</form>
}
else
{
<ul class="nav navbar-nav navbar-right">
<li><a id="registerLink" controller="Account" action="Register">Register</a></li>
<li><a id="loginLink" controller="Account" action="Login">Log in</a></li>
</ul>
}

This makes for much cleaner markup-focused Views. Note that this Sample is a spike that Damian Edwards has on his GitHub, but you have TagHelpers in the Beta 1 build included with Visual Studio 2015 preview or OmniSharp. Get involved!

Remember also to check out http://www.asp.net/vnext and subscribe to my YouTube Channel and this playlist of the ASP.NET Weekly Community Standup. In this episode we talked about TagHelpers in depth!

Related Posts



© 2014 Scott Hanselman. All rights reserved.
     

OmniSharp - Making cross-platform .NET a reality, and a pleasure

$
0
0

In case you missed it, make sure to read Announcing .NET 2015 - .NET as Open Source, .NET on Mac and Linux, and Visual Studio Community because there's been some big stuff going on.

Here's the summary of the .NET 2015 Wave of awesomeness.

The other thing I wanted to talk about is a newly organized group of technologies called OmniSharp. Just to be sure there's no confusion, OmniSharp isn't a Microsoft project. While there are two Microsoft folks on the team of 8 or so, we are working on it as community members, not in an official capacity.

I "launched" this project in my talk at the Connect() mini-conference in New York a few weeks back. You can watch that video here on Channel 9 now if you like. However, the technologies around and under OmniSharp have been around for years...like over a decade!

As a team and a community we pulled together a bunch of projects and plugins, got organized, and created https://github.com/omnisharp and http://www.omnisharp.net. Jonathan Channon has a great overview blog post you should check out that talks about how Jason Imison created OmniSharpServer which is an...

HTTP wrapper around NRefactory allowing C# editor plugins to be written in any language. NRefactory is the C# analysis library used in the SharpDevelop and MonoDevelop IDEs. It allows applications to easily analyze both syntax and semantics of C# programs. It is quite similar to Microsoft's Roslyn project; except that it is not a full compiler – NRefactory only analyzes C# code, it does not generate IL code.

OmniSharp runs as its own process and runs a local Nancy-based web api that your editor of choice talks to. If you have an editor that you like to use, why not get involved and make a plugin? Perhaps for Eclipse?

We now have plugins for these editors:

  • Sublime
  • Brackets from Adobe
  • Atom from GitHub
  • Emacs
  • Vim

And these work on (so far) all platforms! It's about choice. We wanted to bring more than autocomplete (which is basically "I think you typed that before") to your editor, instead we want actual type-smart intellisense, as well as more sophisticated features like refactoring, format document, and lots of other stuff you'd expect only to see in Visual Studio.

We also brought in the Sublime Kulture package which gives Sublime users support for ASP.NET 5 (formerly ASP.NET vNext), so they can launch Kestrel (our libuv based local webserver), run Entity Framework migrations, and other arbitrary commands from within Sublime.

.NET in Sublime, in Vim, in Brackets, in Atom, and everywhere else, cross-platform

Here's OmniSharp running in emacs on my Windows machine. The emacs setup (here is an example) is a little more complex than the others, but it also gives emacs folks an extreme level of control. Note that I had to launch the OmniSharp server manually for emacs, while it launches automatically for the other editors.

image

Here is an ASP.NET MVC app running in Sublime. The Sublime OmniSharp package output can be seen in the debug console there (Ctrl+~ to see it).

image

OmniSharp is in very active development. We are looking at bringing in Roslyn, using the new ASP.NET Design Time Host, and improving robustness. It's not perfect, but it's pretty darn cool. There's lots of details in Jonathan's writeup with great animated gifs showing features. Also note that we have a Yeoman generator for ASP.NET that can get you started when creating ASP.NET 5 apps on Mac or Linux. The yeoman generator can create Console apps, MVC apps, and NancyFx apps.

You can get started at http://omnisharp.net.  See you there!



© 2014 Scott Hanselman. All rights reserved.
     

Getting ready for the future with the Microsoft .NET Portability Analyzer

$
0
0

.NET has been getting more and more portable. Not only is .NET Open Source going forward (read Announcing .NET 2015 - .NET as Open Source, .NET on Mac and Linux, and Visual Studio Community) but you of course know about Xamarin tools, as well as, I hope, the .NET Microframework, and much more.

You can run your .NET code all over, and there's a tool to make this even easier. While you'll rarely get 100% portable code with any platform, you can get into the magic 90-95% with smart refactoring, then keep the platform-specific shims pluggable.

The .NET Portability Analyzer is a free Visual Studio Add-in (or console app) that will give you a detailed report on how portable your code is. Then you can get a real sense of how far you can take your code, as well as how prepared you'll be for the Core CLR and alternate platforms.

.NET Portability

Take a look at this report on AutoFac, for example. You can see that the main assembly is in fantastic shape across most platforms. Understandably the more platform-specific Configuration assembly fares worse, but still there's a complete list of what methods are available on what platforms, and a clear way forward.

.NET Portability Report

You'll get suggestions with a direction to head when you bump up against a missing or not-recommended API.

img2

You can analyze specific assemblies, or an entire project. Once installed, you'll find the commands under the Analyze menu, and you can change options in the .NET Portability Analyzer options in the Tools | Options menu.

Even better, you can use this with the FREE Visual Studio Community that you can download at http://www.visualstudio.com/free.

Related Links



© 2014 Scott Hanselman. All rights reserved.
     

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

$
0
0

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.



© 2014 Scott Hanselman. All rights reserved.
     

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

$
0
0

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?



© 2014 Scott Hanselman. All rights reserved.
     

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

$
0
0

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



© 2014 Scott Hanselman. All rights reserved.
     

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

$
0
0

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



© 2014 Scott Hanselman. All rights reserved.
     

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

$
0
0

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


© 2014 Scott Hanselman. All rights reserved.
     

Reality TV for Developers - Where is Twitch.tv for Programmers?

$
0
0

Twitch.tv is basically YouTube where you can watch other folks play video games. It initially sounds ridiculous but it's actually surprisingly compelling. You can see how other people solve problems LIVE. Interestingly "watching interesting people solve interesting problems" is a good description for many of my favorite movies and TV shows.

Where is Twitch.tv for programmers? I'd like to watch a reality TV show where a competent and interesting programmer creates something interesting. There is CodersTV but somehow it isn't quite there. Minecraft's famous creator "Notch" has used Twitch to stream some of his crash coding sessions for gaming events like Ludum Dare. There is a small "Game Development" category on Twitch but it's not exactly Must-See-TV.

While I haven't seen any videos from Microsoft of developers live coding, maybe there should be. Certainly there's been a lot more transparency around design meetings lately. There was a great tweet recently that pointed out an unusual video on Channel 9, Microsoft's "inside the cockpit" website. The video is a nearly 2 hour API Review for the .NET Core Libraries.

Drink that in for a second. A compliment on a video of a two hour meeting? And the video has over 15,000 views...folks like to be a fly on a wall in meetings like this!

The ASP.NET Team has been hosting weekly Community Standup meetings using Google Hangouts. You can watch the archives here, or join us every Tuesday (unless someone is travelling, then we'll move things a bit).

Do you like this kind of video? Would you like to watch some real coding with or without running commentary? Do you enjoy seeing design meetings and real decisions being made...complete transparency?


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



© 2014 Scott Hanselman. All rights reserved.
     

Quake Mode Console for Visual Studio - Open a Command Prompt with a hotkey

$
0
0

Back in March of 2013 when Phil Haack was deep into GitHub for Windows development we were going back and forth in email about how to quickly get into a shell from a specific project. I hate always having to paste in a "CD somedirectory" so I usually use some kind of "Command Prompt Here" right click menu.

TIP: A lot of people don't realize that you can Shift-Right-Click on a folder in Windows Explorer and you'll automatically get a "Command Prompt Here" menu item!

Anyway, Phil and I were emailing and he said (remember that GitHub for Windows (GHfW) was in development)...and I've always loved how the Quake console pops up when you press ~ in Quake.

I feel ashamed I didn't know this, but I just discovered that CTRL+ALT+D brings up the shell when in GHfW. We are considering ways to make our keyboard shortcuts more discoverable. Kind of like the `?` support we have on GitHub.com. We should totally make that a ~ shouldn't we? Like in Quake, Doom, etc.

And they did. When you're in GitHub for Windows just press ~ and you'll automatically get a new command prompt (or Bash Shell or PowerShell) and be dropped in to the current folder's directory. It's my most favorite feature about GitHub for Windows.

I mentioned this to Mads Kristensen yesterday and said we should build this feature into Visual Studio. Rather than waiting, he just created a little single purpose extension called Open Command Line. It works in Visual Studio 2012, 2013, and 2015.

Open Command Line

But it's the hotkeys that make it awesome. Now I'm not sure how I lived without it. Alt-Space and it opens up a prompt right where I need it. Go download the Open Command Line free Visual Studio extension now, and remember, it works in Visual Studio Community which is also free! You can set it to open CMD, PowerShell, or a custom prompt.

Oh, by the way, the overlay there that shows what hotkey I'm using, that's Carnac.

Related Links


Sponsor: Big thanks to the folks at Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid - Download for free now!



© 2014 Scott Hanselman. All rights reserved.
     

Rollup: Microsoft HoloLens, Surface Hub, Windows 10, Xbox One game streaming and more.

$
0
0

Disclaimer: I currently work for Microsoft, but this blog, and the words within are all my opinion. Mistakes and dumb ideas are mine. My impartiality or lack thereof stands on its own.

I just got done watching the Windows 10: The Next Chapter live video stream. There's the Windows 10 news, updated interface, and more. As I get new Windows 10 builds I will go over them on my YouTube Channel. Please do subscribe. But let's talk about the truly magical stuff first.

"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke.

Microsoft HoloLens

Wow, an augmented virtual reality headset from Microsoft? Is this Oculus? Or Google Glass? It's something else. It's clear so you see the projected images as if they are in front of you. It's not a tiny screen like Glass or a screen that blinds/immerses you like Oculus (I have an Oculus).

This reveal totally puts the Microsoft purchase of Minecraft in context. We'll surely see Minecraft for Windows 10 and HoloLens in the future.

My first impression was, oh, Glass? Then, oh, Oculus. But this is more like immersive augmented reality. The real question is going to be, how smooth can they get the interactions? Will it be like Kinect or LeapMotion? Truly amazing. This could be the future of Windows itself.

Holy Crap It's VR Minecraft

This is clearly not something for wearing as you walk down the street (yet). Amazing.

The first step is allowing one person to see a hologram. The challenge is then letting everyone in the room seem them. I'm looking at you, Tony Stark.

Virtual stuff floating in front of a HoloLens

Microsoft Surface Hub

It looks like the Microsoft acquisition of Perceptive Pixel has culminated in a new brand for Surface - The Microsoft Surface Hub. It's a 80" 4K 100 touch points touchscreen display that runs Windows 10, a special OneNote, and includes cameras, microphones and Skype for Business (Lync/UC), and Office. Will it be priced within a small office's budget, or are we talking Tesla money here?

Two people working on a Microsoft Surface Hub

I gotta say, I'm surprised and impressed. Satya's vision is definitely clear.

Windows 10

We also learned a lot about Windows 10, including this slide that I didn't feel really HIT hard enough. I read this to say that you can upgrade from Windows 7 to Windows 10...basically everyone gets to go to Windows 10 for free and keep it. You own the license.

It says "Free upgrade for the first year" which I think is confusing because it is implying some kind of subscription or at least yearly license.

But if you read the details here it seems like you have a year to upgrade and if you/we do (from 7/8/8.1) then we get Windows 10 free and it's supported for the lifetime of the device. We all get free upgrades and they will be supported, is how I read it. But we have a year to get the free upgrade, and after that it costs.

Windows 10 upgrade will be free

We saw lots of Windows 10 features and things including:

  • Windows 10 is for PC, Xbox, Phone and Tablets
  • All new Web Browser codenamed "Spartan."'
  • Office Universal apps - Phone, Tablet, or PC, Office runs on every platform.
  • You can stream/play Xbox One games from your Xbox One to your PC.
    • "Players will also be able to play games on their PC, streamed directly from their Xbox One consoles to their Windows 10 tablets or PCs, within their home"
  • Surface and "2in1" devices will switch between desktop mode and tablet mode depending on the presence of a keyboard.
  • The Cortana personal assistant comes to Windows. This includes dictation as well!

So all these devices will run Windows 10.

Windows 10 runs everywhere

The Satya quotes that stuck out to me where very declarative and aspirational.

"We want to move from people needing Windows, to choosing Windows and loving Windows. That is our bold goal with Windows." - Satya Nadella

Now it's time to watch it all happen. 2015 could be a big year for Microsoft.


Sponsor: Big thanks to the folks at Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid - Download for free now!



© 2014 Scott Hanselman. All rights reserved.
     

VIDEO: Do you really know how to use Microsoft Word? The Power of Tabs and Indents

$
0
0

I spent part of my lunch hour today remoted into a friend's computer who was having a lot of trouble with Microsoft Word. Like most of you she's an "experience Word user" and would happily put "Proficient in Microsoft Word" on her resume. However, it was pretty clear that there's some powerful aspect to Word that folks aren't exploiting. These kinds of features will save you HOURS reformatting documents later, especially when those docs get long like books and long reports or essays.

I figured I'd do a quick YouTube video and see if there's an interested in a series of these. I like not to waste time OR keystrokes so this was the most efficient way to get the information out there. Within an hour this video already got these nice compliments:

  • Absolutely fantastic. This totally blew my mind. I'm not too proud to say that I didn't know any of this.
  • Thanks so much. You just saved me a ton of time editing lab documents.
  • Time to update my resume and this time the indents will be perfect.
  • This video is magic.

So that's telling me that there IS value in videos like this. Check it out and let me know! More importantly, share it with your family and friends and SUBSCRIBE to my YouTube channel.

TIP: If you're using Windows 8 and are confused, I have a whole SERIES of videos at http://hanselman.com/windows8. Please spread the word and share!

Here's my Word video. Hope this helps.

Microsoft Word: The Power of Tabs and Indents

What Office related topics would you be interested in seeing, done in this style?


Sponsor: Big thanks to the folks at Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid - Download for free now!



© 2014 Scott Hanselman. All rights reserved.
     

The Basics of 3D Printing in 2015 - from someone with 16 WHOLE HOURS' experience

$
0
0

Printrbot Simple MetalI bought a 3D printer on Friday, specifically a Printrbot Simple Metal from Amazon for US$599. I did a few days of research, looking at all the consumer models under $1000. Some were enclosed, others not. Some made of wood, some of plastic.

I selected the Printrbot Simple Metal because the reviews consistently said it was physically well made, rock solid, didn't require me to buy filament from the printer manufacturer, and Printrbot offers a number of updates like a heated bed and other attachments. I have the sense that this printer is basic, but flexible and expandable.

I've been using this printer now for basically 16 total hours over a few days, so we'll call it two days. I went through a number of emotions over this last two days an learned a TON, some about the Printrbot Simple Metal specifically, but also about 3D Printing in general.

Here's my 16 hours laid out for you, Dear Reader, so that you might save this time that was stolen from me. ;)

Disclaimer: I know jack squat about 3D Printing. If you're reading this, it's more likely than not that you know little as well. Any mistakes here are my own, but I hope my learning process helps you in your 3D printing journey.

Each hours includes an emotion and a lesson.

Hour 1 - Anticipation

Lesson 1: 3D Printers do not just work out of the box.

It's a hobby, not an appliance. Yet. There's a LOT of art to it, in addition to all this science. There's a million acronyms to remember. Here's the ones I've found useful.

  • PLA Filament - "Polylactic acid (PLA) is a bio-degradable polymer that can be produced from lactic acid, which can be fermented from crops such as maize." It's the basic starter plastic you'll use. It's harder than ABS and melts above 180C.
  • ABS - "Acrylonitrile Butadiene Styrene (ABS) is a commonly used thermoplastic as it is lightweight and can both be injection molded and extruded." It melts over 200C and should be used in a ventilated area.
  • JsCad and OpenJSCAD - It's JavaScript for CAD! Lets you design stuff procedurally like a programmer.
  • STL - STereoLithography or Standard Tessellation Language. It's the most common format you'll find as you look around for models of things to print.
  • G-Code - RS-274, a numerical control (NC) programming language. It's the "Assembly Code" for your printer. It is ASCII and uses control codes to tell your printer what to do. You'll take STL which is generic 3D and combine it with your specific settings and preferences to create G-Code that is the instructions that will be sent to your 3D printer.

3D Printers are like those cake decorator pipings. The 3D Printer pushes hot, molten plastic through a tiny tube in layers to make a real object just like a cake decorator pushes hot sugar through a piping tube to write Happy Birthday.

3D Printing is like Cake PipingCake Piping is like 3D Printing

Hour 2 - Annoyance

Lesson 2: 3D Printers really need to be calibrated.

The most important thing I've found is the "Z-Stop." Basically, you need to make sure that when your Printer's Head is at X0 Y0 Z0 that you can just barely fit a piece of paper between your extruder nozzle and bed.

The most important part of any print is the first few layers. If you build a good solid base for your 3D print then it will at least have a chance. If something goes wrong in the first few minutes it's not going to get better. Cancel the print before you waste more time.

I also found this list of tips useful: 10 Rules for top notch prints with your Printrbot Simple.

3D Printing Animated Gif

Hour 3 - Frustration

Lesson 3: 3D Printers are persnickety.

They are easily affected by the environment/temperature/your mood/Mercury in Retrograde. Cold garages aren't a great place for 3D printing as cold plastic is hard plastic and that breaks easily.

Temperature control : each filament has an optimum temperature for its extrusion. If you do not know, a value between 190 and 210° Celsius (374°-410° Fahrenheit). Start at 190° C and adjust the temperature according to the behavior of the filament: Shiny, too hot, Dull, not hot enough. Find balance.

Early on, expect only 1 in 4 or 1 in 5 prints to be useful. Fail fast, fail often. When you do have a failed 3D Print, write down your settings and compare it to previous prints.

Have a clear, solid table, find your place to print, and get organized.

Where I 3D print.

Hour 4 - Resentment

Lesson 4: This freaking piece of crap is incapable of producing anything other than a molten pile of crap.

Learn about how there's different kinds of support mechanisms to sit under and support your model. There's Rafts, Skirts, and Brims and they all have different uses.

3D Printing often requires a base

When in doubt, check your 3D Printer's Skirt.

Hour 5 - Disgruntlement

Lesson 5: Documentation for 3D printers is spotty because the tech changes every few months.

Collect links and compare notes. Start small. Don't print something massive (as I tried to, which made me more angry), print something tiny. 10 minutes max, then try again, change a setting. See what happens. There's a "calibration cube" file you can use.

The docs for your printer are useful, but you'll find even better information on Reddit but most of all on YouTube. There's a million great videos showing different techniques. Start by subscribing to Tom's YouTube Channel and go from there.

Hour 6 - Unfulfillment

Lesson 6: The first half-dozen things you print will be parts and improvements to the printer.

You'll wonder why it didn't come with all these things. There's no filament spool, no feet for the printer, no where to mount extra stuff. Fortunately for every problem I've had, there's someone on the Thingiverse 3D website that has had the SAME problem AND designed a part for me to print out.

My first "fix" was to print this small filament guide. A tiny victory, but still unfulfilling.

image

Hour 7 - Vexed

Lesson 7: Getting the filament to stick to the base will be your primary challenge without a heated bed. Ideas 'solutions' abound.

Whenever you have a problem with your 3D printer you will go and Google with Bing and find others with your problem. The 3D Printing community (in my 16 whole hours in it) is super nice. Everyone wants to help and share.

ASIDE: I LOVE ThingiVerse, it's like Wikipedia for stuff, and it's all Creative Commons. Share and Share Alike. I'm here.

However, when you search for your problem there are one of two things that will happen.

  • You find someone just like you with the same software and same printer and they SOLVED IT AND THEY HAVE THE SOLUTION THERE FOR YOU TO USE.

or

  • You find someone just like you with the same software and same printer and they NEVER FOUND THE ANSWER AND THIS QUESTON WAS ASKED IN 2009AND YOU WILL ALWAYS BE ALONE.

So. Ya. Be ready.

Hour 8 - Chagrin

Lesson 8: 3D Printing can take HOURS. Like, hours. Many hours. And then halfway through you'll bump it and start over.

But, while you're waiting for things to print, there are some amazing websites to explore, like OpenJSCAD.org. You can write JavaScript (you know JavaScript!) to describe the things you want to build.

Here's a cool example. Sometimes you'll find JsCad files and you'll want to turn them into STL files, then eventually GCode files to be sent to your printer.

function main() {

return union(
difference(
cube({size: 3, center: true}),
sphere({r:2, center: true})
),
intersection(
sphere({r: 1.3, center: true}),
cube({size: 2.1, center: true})
)
).translate([0,0,1.5]).scale(10);
}

Go and explore the relationship between STL and G-Code. Get the basics of G-Code in your brain. Remember typing "ATA" to answer your modem manually? No? Well, you had to do this back in the day, young lady, and it was magic. G-Code is just like typing ATA or ATDT to your modem, except it's instructions for your 3D Printer.

For example, my Printrbot was locking up at the same place during a print. I had no idea why. Rather than accepting the system is a "load a file, print, and pray," I looked at the G-Code and saw it was turning on a Heated Bed. I don't have a Heated Bed. I commented that part out and my print finished. Stuff like that will save you hours.

Hour 9 - Triumph

Lesson 9: Think about your printing area. Consider how your filament will feed into your printer and make a filament holder.

The Printrbot SImple Metal doesn't come with any formal way to feed the filament spool into the printer. I ended up having to move it every few minutes. After a while I used a broomstick and put the spool on it horizontally. Then I got sick of it and printed a Filament Spooler from Thingiverse to put on top of the printer. This was EPIC. This was my "I can do it" moment.

It was rough, and it broke off with just a few layers left, but it WORKED. It fixed a problem I had. Boom. I think this is going to be OK.

IMG_1095

Hour 10 - Bitterness

Lesson 10: I didn't notice that all the printing and shaking was literally causing the printer to shake slowly off the desk.

In my last print the piece shook itself off the print bed. 4 hours almost wasted. I was able to use some sandpaper and fix it, but for a few minutes there I was pretty upset. Watch for things like shaking and look for solutions. I printed a set of feet and put rubber bases on them.

Hour 11 - Rage

Lesson 11: Remember what I said about heated beds and stuff sticking to the base?

It hurts even worse when it breaks off and is thrown across the room and you're left with a pile of hot plastic spaghetti. I've decided I want to upgrade to a Heated Bed at this point. This $99 attachment will keep the bottom of the model warmish and pliable so it doesn't warp as it cools. It also helps keep it stuck to the base.

Before this Heated Bed shows up, here's some things you can try to help prevent peeling of your 3D print:

  • Glue Sticks - Get the Purples ones that dry clear. 99 cents.
  • Blue Painters Tape - Required. Don't print directly on the bed. I put my tape lengthwise and I'm sure NOT to over lay them. Make it FLAT.
  • Nail Polish Remover - Smear this over the tape with a cloth. I dunno if it works, and it stinks, but folks swear by it. I'm still testing it myself. Seems to do SOMETHING.

Also consider how thin/thick you're printing. I found that 0.2mm was my default, but for my current setup was hard to keep flat on the non-heated bed. I am having more success with 0.4mm, although the quality is less. There IS a setting that will work for your setup.

Avoid being near a vent or the AC. Cool air being blown inconsistently in a room can affect a print. I like to keep it toasty. Gotta get that Heated Bed soon. Damn these expensive hobbies that make you buy stuff after you just bought stuff.

Hour 12 - Heartened

Lesson 12: Use OctoPrint. It's amazing, it's brilliant, it's everything.

I started using the Repetier software that Printrbot recommends to load up STL files. These 3D models are then "sliced" with your choice of slicer software. The slicer is the thing that takes the 3D concept and makes it a series of G-Code instructions that will be fed to your printer. However my Printrbot would freeze up and I'd have to manually press OK in the Repetier software. I found lots of people with this problem, some fixed it with new USB cables, some never did. For me it came down to deciding NOT to use my Laptop as a print serve for 3 hour prints. If my 3D printer isn't wireless, well, darnit, I'm gonna make it wireless. So...

Hour 13 - Satisfaction

Lesson 13: Hook up a camera to OctoPrint so you can safely leave a print going while you go about your business.

As I read and absorbed, I found lots of references to OctoPrint as something I should explore. However, my Printrbot recommended software called Repetier and I didn't feel like setting up more software to get this thing to print, so I wasted a few hours NOT installing OctoPrint. This was foolish of me. Let me save you some time now. If you're not using OctoPrint you're in for a treat. Take the time.

Turns out since I had a Raspberry Pi and a spare Webcam lying around, this setup only took me 30 minutes. The basic idea is that rather than using your computer as a Print Server, you use a small embedded system. This can make your 3D Printer wireless!

What you do is this:

  • Get a Raspberry Pi B+ or newer and a fast Class 10 SD Card.
  • Optional: A cheap wireless USB dongle. I got this Edimax and it works great. Got two actually just in case.
  • A 1A or greater micro USB power supply. I used a Samsung phone power supply.
  • A USB keyboard (not wireless) temporarily.
  • A Logitech or Microsoft USB Camera.
  • Use Win32DiskImager and install OctoPi to the SD Card. Boot off the Pi, expand the partition to fill, optionally setup the WiFi on the PI, and you're set.

This little Raspberry Pi is now running my 3D Printer. Watch this wonderful YouTube by Tom who explains setting up OctoPrint on a Raspberry Pi better than I.

image

I hit http://octoprint.local and BEHOLD. I've got a nice bootstrapped website where I can see and control all aspects of my 3D Printer AND see the print via either my USB Webcam or a Raspberry Pi Camera.

OctoPrint is glorious

Now I can use my iPhone or Tablet to watch my print and shut it down if something goes around. No more babysitting!

Even better, you can setup OctoPrint to create cool Time-lapse videos of your 3D prints.

Hour 14 - Reassurance

Lesson 14: Maybe it will be OK. Why was I so angry early on?

I need to chill and 3D print some stuff. After a while things are starting to make sense. I'm still an unranked amateur but I'm one who can write this giant blog post, so I musta learned something.

I also learned that Ii t turns out that Windows 8.1 has support for 3D Printers built in. I didn't have to install any drivers, one was already on my machine. There's also a 3D Builder app in the Windows Store.

Here's the apps I've been trying and using:

  • 3D Builder - Can model, slice, and print.
  • Autodesk 123D Design - Free and for Windows, Mac, and iPad. Stores your designs in their cloud.
  • Repetier - Loads STL files and can launch a Slicer to make G-Code, then send the instructions to your printer.
  • Cura - A very well-thought-of slicer. You should explorer different slicers as you gain experience. These slicers have different algorithms, and some are smarter with different kinds of shapes. Some are focused on reducing "travel" (how far the print head moves) or minimizing your use of filament. Others are great at setting up "supports" for when you have a piece floating in mid-air, as I do in the pic below. That side bit will need a small temporary support to hold it up. I'll remove it later.
  • OctoPrint - YES. DO IT. It's the best app to manage your G-Code and your printer. Model with whatever you want, but print with OctoPrint.
  • Tinkercad - Do your 3D modeling all in the browser. Great for kids.

Also check out Jon Gallant's blog as he's on a quest for the perfect 3D Model Software. Here's his list so far:

Here I'm working on a holster for my Dyson Handheld Vacuum. I have a DC56 though, and this is a DC34. It's close...but, not quite.

3D Builder

Hour 15 - Encouragement

Lesson 15: In which I take a JsCad into a STL then into G-Code and successfully 3D print.

I made a Dyson Holster. I AM POWER.I want a holster for my Dyson Vacuum so I found this DC34 Wall Charger holster/holder. In this comments of this other model on Thingiverse, I saw someone modify the JsCad for the design to add a little room for the DC56 over the DC34. However, it was in this JsCad format.

  1. It took me a second but I realized I just needed to take the original JsCad file (remember this is JavaScript that expresses a 3D design), open it in Notepad, and change the parameters with the new measurements.
  2. Then I ran my new file through the OpenJsCad parser online.
  3. I took the resulting STL file and loaded it into Repetier and sliced it with Cura. This made a G-Code file that's MY custom instructions with my preferences.
  4. I then loaded the G-Code into OctoPrint and printed.
  5. PROFIT. Well, no, but FEEL ACCOMPLISHMENT.

Here it is. Now I'll mount it to the wall and check that off my Bucket List. What should I print next?

Hour 16 - Power

Lesson 16: You can do this. I can do this.

It will take days, perhaps weeks, but you'll have a satisfying new hobby that will make you more powerful than before.

OK, so I can't just print all the free LEGO I want whenever I want. (I would never do that, I respect the LEGO Group too much.) I mean, I can't just make stuff on-demand. Yet. But I can solve some small problems and I am learning. I'm getting better. Each print teaches me something. I'm MAKING physical stuff with Software. This must be what Woodworkers and proper Handypeople feel like.

Conclusion

  • Is 3D Printing ready like Inkjet and Laser Printers are ready? Nope.
  • Is 3D Printing ready like Microwaves are ready? Nope.
  • Is this Plug and Print? You'll need a few hours, days, weeks. Hopefully I've saved you some time or at least helped you decide if you want in.

But I bet in 3 to 5 years I'll be able to buy a solid enclosed reliable prosumer 3D printer for $599 from Office Depot, bring it home and have it just work. I'm stoked and I am happy with my Printrbot Simple Metal even if I don't get any further than I have after these last 16 hours.

What do YOU think?

* These are Amazon referral links. I use the few bucks I get if you buy stuff from Amazon to buy 3D Printer Filament! ;) Click click!


Sponsor: Big thanks to Amyuni for sponsoring the feed this week! Amyuni PDF Converter and Creator for .NET enables you to integrate powerful PDF functionality with just a few lines of code. Generate and process optimized PDFs with industry proven technology. Switch Now!



© 2014 Scott Hanselman. All rights reserved.
     

Changing perspectives on your job - Will you renew your boss for another season?

$
0
0
LEGO Stormtroopers on a Wire

Within a single week two different friends of mine called me to talk about their job satisfaction. One didn't like the project they were working on and felt that when they were pitched the job they were sold one job but ended up doing another. The other friend felt like review time each year was a Musical Chairs-type parade of employees and they were left wondering "Will I be picked again this year? Will I still have a job next year?"

This is such a challenge to talk about as some of you may be out of a job and looking right now, but some of you may be in a job and thinking some of the same things as my two friends.

I'm pretty happy with my job. I like my boss and my team. Remote work is a challenge sometimes, but we are doing some great work. However, I never assume my job is granted. I never assume "Hey, I'm Scott Hanselman, I refer to myself in the third person and have Google Juice, I can't be replace or canned."

At the same time, however, I DO feel good about my work and I think I DO provide value to my company. Therefore, I've changed my attitude about Annual Reviews. This isn't just the company's chance to review me, it's also my chance to review them.

Do I still want to work there?

My wife and I have been married 15 years. The joke is "She's decided to renew me for another season," just like TV ratings. Well, the Annual Review is my time to decide if *I* want to renew *my Employer* for another season. This is a small brain trick, or trivial change in thinking, but changes in thinking are the first step in changing your world view.

It also reinforces the impermanence of employment (and tech, and life, etc.) and makes it OK to broach the question. Do I still want to work here? And if you DO decide to "renew your boss for another season," remember you don't have to stay there forever.  One season at a time, while it feeds your spirit. When it stops, you should stop too.

This helped my two friends, and I wonder if it helps you, too.

* LEGO Stormtroopers on a Wire by Pedro Vezini, used under Creative Commons.


Sponsor: Big thanks to Amyuni for sponsoring the feed this week! Amyuni PDF Converter and Creator for .NET enables you to integrate powerful PDF functionality with just a few lines of code. Generate and process optimized PDFs with industry proven technology. Switch Now!



© 2014 Scott Hanselman. All rights reserved.
     

Creating exact 3D Models for 3D Printing with JavaScript and OpenJSCAD

$
0
0

I have this 3D Printed Spool Holder on the top of my Printrbot Simple Metal 3D Printerl that looks like this:

Printrbot Simple Metal

It works great and fits my RioRand generic PLA Filament spool exactly. However, I went down to Fry's Electronics to get some filament today and all they had was small Makerbot spools. They were cheap, so I got two. When I got home I noticed that the hole in the spool is HUGE. It totally won't fit my spool holder.

This brings us to..

The Three Rules of 3D Printing

  1. All problems in 3D Printing can be solved by 3D Printing something
  2. The only things that 3D Printing people print is stuff to make their 3D printers work better.
  3. See rules 1 and 2.

So, I needed an adapter for my 3D Printer (which I have nearly a week of experience with, so fear me) and opened up Tinkercad.com to create it. Someone recommended Tinkercad as a great HTML5 website for doing quick designs.

image

I got lost in this app. I couldn't find a way to make two cylinders and simply center them within each other. You can nudge them around but can't center them against their own centers. I actually found forum posts going back to 2012 with members of the team saying "yes, we need that feature" but couldn't figure it out. It's a lovely app and my kids enjoy it but I feel like if you want absolute precision this may not be the place. Then I realized that perhaps this 3D Model was more of a math problem than a modeling problem.

Now I realize I'm biased, and I am a programmer, but with a small set of digital calipers and the excellent OpenJSCAD documentation I was able to create my adapter in just 10 minutes of hacking and just 7 to 12 lines of JavaScript (depending on how you count).

function main() {

return union(
difference(
cylinder({h: 40, r:26, center:true}),
cylinder({h: 40, r:15.5, center:true})
),
difference(
cylinder({start: [0,0,0], end: [0,0,24], r1: 52.5, r2: 26, fn: 50}).translate([0,0,-44]),
cylinder({start: [0,0,0], end: [0,0,24], r1: 32.5, r2: 15.5, fn: 50}).translate([0,0,-44])
)
).translate([0,0,45]);
}

From here I downloaded my STL (the 3D description of the object)...

OpenJSCAD

I then ran it through the Microsoft 3D Model Repair Service (a good idea to make sure all your designs are manifold and watertight).

Repetier

Then into Repetier and sliced into G-Code (instructions to the printer on how to move) and printed it with OctoPrint on my OctoPi.

image

I'm clearly not a 3D designer or modeler and I apparently don't have the patience for CAD tools that won't let me type in a direct number. I KNOW this should be 31mm in diameter, don't force me to use a mouse to "eyeball it." I was thoroughly impressed with the concept and execution of OpenJSCAD. Of course, OpenJSCAD is a JavaScript implementation of OpenSCAD, the "Programmers Solid 3D CAD Modeler" so I'll be exploring their software and amazing gallery as well! If you're creating anything with regularity that's more mechanical and less organic, OpenJSCAD or OpenSCAD is the way to go, clearly.


Sponsor: Big thanks to Amyuni for sponsoring the feed this week! Amyuni PDF Converter and Creator for .NET enables you to integrate powerful PDF functionality with just a few lines of code. Generate and process optimized PDFs with industry proven technology. Switch Now!



© 2014 Scott Hanselman. All rights reserved.
     

The new Raspberry Pi 2 will run Windows 10 and run Universal Apps

$
0
0

I'm a huge Raspberry Pi fan. I've got three around the house, I use one for a Media Center, one for 3D Printing, and one for messing about. Now I'm gonna get a BUNCH more as the Raspberry Pi 2 has been announced and for a $35 computer that fits in your pocket this new version has some amazing things going for it.

  • Still tiny! Same size as a Raspberry Pi B+. My cases will still work. ;)
  • HDMI full sized! Ethernet! Camera port!
  • Still uses Micro USB for power!
  • BUT now it has...
    • A 900 MHz quad-core ARM Broadcom Cortex A7 with a BCM2836 system on a chip adds up to 3x to 6x the performance. Woof.
    • 1 GIG of RAM (shared with GPU)

Raspberry Pi 2I love using my Raspberry Pi as a "Dedicated Device." While it's clearly a general purpose computer, it's so cheap and powerful I'll use it for one thing and have it do that one thing well. Watch for water in my basement and text me if a sensor gets wet. A tiny Minecraft machine for my kids. A 3D Printing Print Server. A small games emulator. An open source media player.

And now it seems I'll be able to hack on a Raspberry Pi 2 running Windows 10 while I deploy a Universal Windows App!

Windows 10 is coming to the Raspberry Pi 2

Not only did the Raspberry Pi Foundation announce the Raspberry Pi 2, but it seems that Windows 10 will support Raspberry Pi 2 and we can get it free for the Maker community through the Windows Developer Program for IoT coming later this year. Last year Microsoft announced the Windows Developer Program for IoT and put Windows on the Intel Galileo board. Today Windows gets even better for IoT and Maker scenarios by supporting makers on RPi2.

This means you could theoretically have a Surface Pro 3 running a Universal App. Then a Windows Phone also running that same Universal App. And finally a Raspberry Pi 2 (note there's no shell) also running a Universal App. I could make my little Raspberry Pi 2 a dedicated device that runs Windows 10 plus my App. I can write code for it using the same languages, tools and techniques that I already know.

It's pretty clear that the way to go with Windows 10 from a developer's perspective is Universal Apps. You get a great development experience, good API coverage, tooling that makes cross-compilation easy, and now you can go from Raspberry Pi 2, to Phones, Tablets, Xboxen, the cloud and beyond. I'm pretty geeked.


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!



© 2014 Scott Hanselman. All rights reserved.
     

The .NET CoreCLR is now open source, so I ran the GitHub repo through Microsoft Power BI

$
0
0

The hits keep on coming, Dear Reader. Just as we announced a few months back, .NET Core is open source. We said it would run on Windows, Mac, and Linux, but then the work of doing it has to actually happen. ;)

Go check out the .NET Framework Blog. Today the .NET team put the Core CLR up on GitHub. It's open source and it's under the MIT License. This includes the Core CLR source, the new RyuJIT, the .NET GC, native interop and everything you need to fork, clone, and build your own personal copy of the .NET Core CLR. What a cool day, and what an immense amount of work (both technical and legal) to make it happen. Years in the making, but still lots of work to do.

The GitHub repo has 2.6ish MILLION lines of code. They say when it's all said and done.NET Core will be about 5 MILLION lines of open source code.

The .NET Blog did a nice pie chart, but honestly, I found it to be not enough. It basically was a big grey circle that said "other 2.2M." ;)

I'd like a little more insight, but I don't know if I have the compute power, or the patience, frankly, to analyze this code repository. Or do I?

I decided to import the repository into Microsoft Power BI preview. Power BI (BI means "Business Intelligence") is an amazing service that you can use (usually for FREE, depending on your data source) to pull in huge amounts of data and ask questions of that data. Watch for a great video on this at http://friday.azure.com this week or next.

I logged into http://powerbi.com (It's US only for the preview, sorry) and clicked Get Data. I then selected GitHub as the source of my data and authorized Power BI to talk to GitHub on my behalf. Crazy, AMIRITE?

Screenshot (10)

After a few minutes of data chewing, I'm officially adding "BI and Big Data Analyst" to my resume and you can't stop me. ;)

What does Power BI tell me about the .NET Team's "CoreCLR" GitHub repository?

Here's what Power BI told me.

image

Let's dig in. Looks like Stephen Toub has worked on a LOT of this code. He's super brilliant and very nice, BTW.

image

Editing the query and looking at Dates and Times, it seems the .NET Team commits code at ALL hours. They are really feeling "committable" around 3 to 4 pm, but they'll even put code in at 4 in the morning!

image

Here's a more intense way to look at it.

image

One of the insanely cool things about Power BI is the ability to ask your data questions in plain English. Given that my SQL abilities have atrophied to "Select * from LittleBobbyTables" this is particularly useful to me.

I asked it "issues that are open sorted by date" and you'll notice that not only did it work, but it showed me what I meant underneath my query.

image

What about issues closed by a certain person?

image

I'm running around in this tool just building charts and asking questions of the repo. It's all in HTML5 but it's just like Excel. It's amazing.

image

Open issues from last year?

image

Average time to close an issue in hours?

image

It's amazing to be running queries like this on something as significant as the now open-sourced .NET Core CLR. I didn't need to be an employee to do it. I didn't need special access, I just did it. I'm enjoying this new Microsoft, and very much digging Power BI. Next I'm going to put my Blood Sugar and Diabetes Data in Power PI and encourage others to do the same.

P.S. Check out the code for the Core CLR Hello World app. When was the last time you saw an ASCII Art Linux Penguin in Microsoft Source code? ;)


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!


© 2014 Scott Hanselman. All rights reserved.
     
Viewing all 1148 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>