Set your Azure VM to auto-shutdown and have it notify you on Slack

Virtual machines cost money when they’re powered on. Most servers obviously need to be on 24 hours a day. Others, like development machines, only have to be on when you’re using them. And if you forget to turn them off, they’ll empty out your Azure credits (or your credit card) before you know it.

Today, I’ll show you how to set an Auto-shutdown time to turn a VM off if you forget, as well as have Azure notify you on Slack 30 minutes ahead of time, so you have the option to postpone or cancel the shutdown.

Continue reading

Do something else, become better at what you love

Ok, time for a short “professional development” post to balance out all of the technical stuff.

For a couple of years, I worked as a spin instructor on the side. It was initially something I wanted to try for the challenge, it proved to have a lot of other benefits to my life besides the obvious health impact.

Performance tuning, IRL edition.

I picked up a huge amount of tricks and patterns along the way. Some of them may appear a little abstract, like working with diverse groups of people, dealing with motivations and meeting expectations, getting comfortable with public speaking and managing nervousness. Others are much more tangible, like microphone skills.

Then again, there are plenty of superpowers that will probably never be very relevant to my (current) line of work, like counting in a beat of a song.

But I digress: Having that extracurricular activity has an immense potential to improve your ability to do other things that you love or get paid for. You don’t have to go and apply to your local gym, and it doesn’t even have to be very expensive – just pick anything that challenges you.

You’ll find that even though the specific superpowers from your hobby may not apply at all to your work, there will be unexpected, derived skills and understandings, that will help you grow as a human and as a professional.

I’m sure there’s a management book on the topic, but this is my short version of it. Now, go and do awesome things!

Scan hundreds of SQL Saturday raffle tickets. Fast.

If you’re an organizer, sponsor and/or an exhibitor at a SQL Saturday event, you often collect raffle tickets from attendees. In exchange for giving you their contact information, they have the opportunity to win cool raffle prizes.

Here’s the thing, though. Raffle tickets can be a bit painful to scan on your mobile phone. You point the phone at the QR code, then click the URL that opens up the browser, after which the SQL Saturday web service takes another second or two (or three) to load. This is fine when you have just a few tickets, but it can be mindnumbing if you have hundreds.

What can I say, I’m lazy.

Continue reading

How to get an automated alert when your Azure cost takes off

I wrote this quick-and-dirty script to let me know if I happen to forget to turn off a P15 instance, or if I configure a service with a super-expensive performance tier without realizing. Maxing out your free Azure credits may be depressing enough, but emptying your credit card could really put you in the hurt locker.

So, here’s a Powershell script that warns me before any of this happens. It uses the Azure Consumption API to check how much money we’ve racked up on a subscription so far, and if any single instance exceeds, say, 50% of that total cost, it sends a notification to a Slack channel.

Continue reading

How to set up a beautiful Powershell Core terminal on Mac OS

I just recently had the opportunity to sit with Aaron Nelson and go through some really cool Powershell features, and I’m certainly going to spend time getting to know Powershell a lot better. If you didn’t know, Powershell isn’t exclusive to Windows anymore – you can actually run a basic set of Powershell features, called Powershell Core, on Mac OS and Linux as well.

But there’s a problem.

Continue reading

Conference hack: how to get great screenshots from demos

I take all my conference notes on my laptop, or occasionally on a tablet. Sometimes, I’ll want to take a screenshot of a powerpoint slide or a demo to add to my notes.

Here’s a trick to beautify those screenshots very easily:

The Microsoft Office Lens app (App store | Google Play) is an excellent document scanner, that you can also use to snap pictures of business cards, signs or basically anything rectangular with a little contrast around the edges – like a projector screen.

It’ll identify the framing and correct the image, so you can save it as a picture or a PDF, or beam it to another mobile device or computer.

Point it at the screen:

… and once you’ve taken the picture, it’ll beautify the image:

This is a killer app for conferences.

Make a Windows shortcut to compare files in Visual Studio

I like that there is a “Compare” function right out-of-the-box in Visual Studio, and even though many regular developers will choose to download a third-party application for the job, it’s perfectly fine for me.

Two problems: First off, I couldn’t find a straightforward way to open “compare” in the Visual Studio IDE without right-clicking an existing item in a source control repository. And second, wouldn’t it be cool if we could put a shortcut to it on the Windows “Send to” context menu?

Continue reading

Quick and dirty: How to right-align numeric columns in SSMS

Here are 50 random numbers:

--- 50 random numbers
WITH cte AS (
SELECT 0 AS i, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3) AS n
UNION ALL
SELECT i+1, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3)
FROM cte WHERE i<50)

SELECT *
FROM cte;

And in SSMS, with the variable-width default font, the output looks… slightly-less-than-readable in the grid view:

We could use STR() to format the output, but the indent looks a little off:

--- 50 random numbers
WITH cte AS (
SELECT 0 AS i, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3) AS n
UNION ALL
SELECT i+1, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3)
FROM cte WHERE i<50)

SELECT *, STR(n, 12, 2) AS with_str
FROM cte;

Here’s something I’ve found: the space character is roughly about half the width of a typical number character. So replace every leading space with two spaces, and it will look really neat in the grid:

--- 50 random numbers
WITH cte AS (
SELECT 0 AS i, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3) AS n
UNION ALL
SELECT i+1, 100000.*POWER(RAND(CHECKSUM(NEWID())), 3)
FROM cte WHERE i<50)

SELECT *, STR(n, 12, 2) AS with_str,
       REPLACE(STR(n, 12, 2), ' ', '  ') AS with_replace
FROM cte;

(and terrible everywhere else, obviously.)