Scott Hanselman

Using the Blockly visual programming editor to call a .NET Core WebAPI

June 23, '20 Comments [7] Posted in ASP.NET | ASP.NET Web API | Open Source
Sponsored By

I like to showcase interesting and cool open source projects that need more attention! Go give our friend a star on GitHub! NetCoreBlockly on GitHub is clever and fun!

Blockly is a JavaScript library for building visual programming editors. If you've used languages like Scratch you've seen block-style programming environments. The picture below shows you a demo of calling a .NET Core WebAPI using Blockly code!

Remember that once you have a WebAPI you can make it available in a number of ways. The "projection" of the methods that the WebAPI makes available can be presented visually, as Swagger/OData/GraphQL, however you like. Another project is WebAPI2CLI that lets you call WebAPI endpoints easily from a CLI (Command Line Interface) that is more high fidelity than curl or wget.

.NET Core as a Blockly Editor

What .NET Core Blockly is doing is looking at the projection/interface of your WebAPI and generating Blockly blocks! That means that anyone (business users, student, tester, whatever) could try out your WebAPI with a simple drag and drop interface in their browser!

You can pull in Swagger, OData, or GraphQL interfaces.

I love seeing fun projects like this that make the web (and .NET code) easier to use! Go give them some stars and get involved!


Sponsor: Upgrade from file systems and SQLite to Actian Zen Edge Data Management. Higher Performance, Scalable, Secure, Embeddable in most any programming language, OS, on 64-bit ARM/Intel Platform.

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 SherWeb

The Importance of Nesting when Remote Working and Quarantine Working

June 11, '20 Comments [9] Posted in Musings
Sponsored By

"08.30.10" by colemama is licensed under CC BY-NC-SA 2.0.We've all learned the hard way that Quarantine work is not Remote work. It doesn't feel the same because it's not the same. It's a hard time right now and tension is high.

"People are overwhelmed, afraid, and stressed. There's a background pressure - a psychic weight or stress - that is different in these times. This isn't a problem you can fix with a new webcam or a podcasting mic."

I really believe that self-care is important and one should be as deliberate as one can in how they live.

One day we were working in the office and the next day we were home indefinitely. Some in spare bedrooms, most in our kitchens, laundry rooms, garages and front porches.

What does "nesting" mean?

Nesting is not just what a bird does to prepare their space for the coming family, it's also what we can do as humans to make a space for ourselves to be successful. It's the deliberate practice of setting up your work area so that you can be successful and fulfilled.

Your space doesn't need to be fancy. Nesting isn't blinging your space or making it look expensive - nesting is making it YOURS.

  • Can you sit and work comfortably? Is your space ergonomic as it can be?
    • Is your monitor or laptop angled in a way that doesn't cause eyestrain or neck strain?
  • Do the things around you feed your spirit? Toys? Gadgets? Family pics? Post-It Notes?
    • Be intentional. Don't just let your space happen. What is calming for you? What's productive? Do you like a nice whiteboard?
    • Perhaps a fresh notebook can de-stress you? Your office can be a Zen garden. Does clutter calm? Fill it with fun. Do you like open space? Clear your desk.
  • What's your lighting situation?
    • Do you have natural light or a window nearby? Maybe you should.

Stop for a second. Perhaps while reading this blog post. Look around and ask yourself - why is this space like this? How did it get this way and do I feel good here. What can you do? Maybe it's just straightening up. Perhaps literally just turning another direction to adjust light.

This is the start of a process to make your space you own. You can't control your quarantine situation but you can be intentional about your nest.

What have YOU done to make your space your own? How are you nesting?


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

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 SherWeb

Easily rename your Git default branch from master to main

June 8, '20 Comments [38] Posted in Open Source
Sponsored By

The Internet Engineering Task Force (IETF) points out that "Master-slave is an oppressive metaphor that will and should never become fully detached from history" as well as "In addition to being inappropriate and arcane, the master-slave metaphor is both technically and historically inaccurate." There's lots of more accurate options depending on context and it costs me nothing to change my vocabulary, especially if it is one less little speed bump to getting a new person excited about tech.

You might say, "I'm all for not using master in master-slave technical relationships, but this is clearly an instance of master-copy, not master-slave" but that may not be the case. Turns out the original usage of master in Git very likely came from another version control system (BitKeeper) that explicitly had a notion of slave branches.

Regardless, I've dozens of git repositories that have 'master' as the main branch. Changing that would be a hassle right?

image

Let's see. I'll just "git branch -m master main" and then push it back! Remember that -m is --move so your history isn't changed! Even better I can "git push -u origin main" to set the upstream at the same time.

D:\github\WindowsTerminalHere [master]
> git branch -m master main
D:\github\WindowsTerminalHere [main]
> git push -u origin main
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'main' on GitHub by visiting:
remote: https://github.com/shanselman/WindowsTerminalHere/pull/new/main
remote:
To https://github.com/shanselman/WindowsTerminalHere.git
* [new branch] HEAD -> main

That was easy.

NOTE: Changing the default branch to "main" also has the benefit of starting with "ma" so that autocomplete <TAB> muscle memory still works. Another great option for your main github branch is "latest." The goal is to just be unambiguous.

Now I just need to change my default branch in my GitHub settings for my repository.

image

I can also update the tracking branch manually as seen here, but if you use git push -u origin main it'll do both.

git branch -u origin/main main

The last thing to think about is if you have a CI/CD, GitHub Action, Azure DevOps pipeline or some other build system that pulls a specific branch. You'll just change that to main. However, usually unless your CI explicitly calls for a branch by name, changing master to main will "just work!"

NOTE: For more complex repos also check your protected branch rules.

image

This is because -m is --move and all your reflog is unchanged!

TL;DR in conclusion:

git branch -m master main
git push -u origin main

Updating local clones

If someone has a local clone, then can update their locals like this:

$ git checkout master
$ git branch -m master main
$ git fetch
$ git branch --unset-upstream
$ git branch -u origin/main
$ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

From the tweet above (Thanks Brad from XUnit.net!), these steps

  1. Go to the master branch
  2. Rename master to main locally
  3. Get the latest commits from the server
  4. Remove the link to origin/master
  5. Add a link to origin/main
  6. Update the default branch to be origin/main

You can add an alias "git new" that will default to whatever starting branch you like.

git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/main'

Hope this helps! Other good names are latest, trunk, and stable!


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

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 SherWeb

Mirroring your Presence Status from the Microsoft Graph in Teams to LIFX or Hue bias lighting

May 21, '20 Comments [4] Posted in Open Source | Win10
Sponsored By

During the Microsoft Build keynote last week - that you can watch free online here - we snuck in a LOT of detail and easter eggs. We planned the whole thing out like a live stage play (I have a background in theatre) and one of the things that mattered to me was lighting.

If you're going to watch something you for an extended time you'll need a little visual interest. Ya gotta mix it up! So I partnered with LIFX and Isaac Levin to accomplish two things:

  • Can we change room lighting to match Teams/Skype/Slack/Whatever presence status?
  • Can we change room lighting to match the Windows Theme/Background accent color?
    • If I'm not mirroring my pretense status, pull the accent color out and change the light.

Here's what it looked like in the keynote:

Purple light and Purple background
Green light and green background

The PresenceLight app is open source and up on Github by Isaac Levin and you can get it on the Windows Store free or in Chocolatey, WinGet, or download a nightly build.

So what's needed? We need an API to pull presence from and an API to push our chosen color to. So that's the Microsoft Graph that includes presence APIs. On the lighting side, using LIFX as an example, they have a great clean LIFX HTTP API.

RANDOM: If you're looking for my wallpapers from the BUILD keynote, I've put them up here.

Here's what the app looks like. You can auth against Phillips Hue, Yeelight or LIFX. The code for LIFX, as an example, is very clean.

PresenceLight

Check out Isaacs detailed blog post about PresenceLight with code samples and explanations! The LIFX folks also set up a 10% off coupon "BUILD" for use on their online store. I'm sure they'll sell out, but the LIFX Beam that I have is $99 refurbished.


Sponsor: This week's sponsor is...me! This blog and my podcast has been a labor of love for over 18 years. Your sponsorship pays my hosting bills for both AND allows me to buy gadgets to review AND the occasional taco. Join me!

About Scott

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

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Developing on Docker with the new and improved Visual Studio Container Tools (and WSL2)

May 19, '20 Comments [6] Posted in Docker | VS2019
Sponsored By

I've been spending a lot of time with Docker lately. Docker Desktop on Windows is great and getting better every day. Now that WSL2 (Windows Subsystem for Linux) is rolling out stable over the coming weeks and Docker Desktop supports WSL to host Linux containers directly, I'm finding myself using Visual Studio to develop my sites under Docker.

Visual Studio Container Tools are actively improving as well and the latest release is pretty sweet. You likely already HAVE this as the Containers tool window is now included in Visual Studio 2019 starting with version 16.4 Preview 2 and above!

NOTE: Be sure to check out the Visual Studio Code Docker Extension as well!

First thing that is impressive is that Visual Studio now tries to help you get to a successful place with helpful guidance, as sometimes set up can be daunting.

When you create or open a Docker-enabled project:

  • VS container tools help you install Docker Desktop
  • VS container tools make sure Docker Desktop is running

Start Docker Desktop?

You've got the Container Tools already if you've installed the Web or Azure Workload in Visual Studio 2019 and it is included in the free Visual Studio 2019 Community!

You can Docker-enable a project with a checkbox when you create it OR you can right click Add Docker Support after the fact.

Enable Docker Support

When working with .NET Core the Container Tools will make a great multi-stage Dockerfile that encapsulates best practices. It uses Docker layering to build within Docker using the .NET SDK but then publishing into a smaller runtime container for the smallest possible resulting image for maximum density.

Multistage Dockerfile

Multi-container Debugging

Debugging real systems with multiple containers has been a challenge in the past. VS2019 now has Container Orchestrator Support built-in. This screenshot shows Docker Compose appearing itself as a Debug Target within the standard VS2019 toolbar!

Docker Compose

Once you have a bunch of containers running, the Containers Tool finds a nice balance between showing you the text logs and getting out of your way but also giving you a GUI to start and stop and manage multiple running containers.

You can see below the images I have, the Solution Containers. I can even right click and Attach to Process within a running Linux container! Again, all using WSL2 and wicked fast.

Docker Container Tools

Coming soon to Visual Studio! Native WSL2 debugging

I like my containers BUT if you just want to dev on Linux directly (no containers) then this is one of the "coming soons" that you'll be the most excited about - WSL 2 Debugging! Coming soon to the Marketplace as a preview with a plan to ship in future Visual Studio tooling releases, you'll be able to just select WSL2 (Linux) as a compilation and debug target! That means dev/test/run native Linux on Windows right from VS.

Remember that WSL2 uses a real Linux kernel so there's no emulators here. The WSL2 Linux starts up in about a second and you'll be debugging FAST. WSL2 is rolling out now!

WSL2 in Visual Studio

That means breakpoints and full debugging on Linux from Visual Studio 2019 on Windows. Scott Hunter and I talked about this and showed a demo in our "Journey to One .NET" talk at BUILD this year that you can watch free here!

If you want all these nice Container Tools either install VS2019 or just run the Visual Studio Installer and UPDATE your existing installation.


Sponsor: This week's sponsor is...me! This blog and my podcast has been a labor of love for over 18 years. Your sponsorship pays my hosting bills for both AND allows me to buy gadgets to review AND the occasional taco. Join me!

About Scott

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

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

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