Quick demo of Go’s context.WithTimeout

To better understand Go’s context withTimeout functionality (and as a reference for myself), I’ve created this small self-contained demo. I didn’t find the published documentation’s example to be clear enough. The interesting part, coming from other programming languages and platforms, was that the WithTimeout function only was a signal that something happened. It doesn’t do anything when there’s a time out (like abort a goroutine or anything dramatic like that).

The essential pieces:

  1. Call WithTimeout passing the Background() context and specify the timeout (I’ve specified  3.2 seconds)
  2. Be a good citizen and defer the cancellation (to be sure that it’s called) and defer close the channel
  3. Start the go routine which waits for the Done channel
  4. When the Done is signaled, display the current time in seconds and what caused the signal
  5. The main app is waiting for the goroutine to end, so signal that.
  6. In the main function, the code sleeps and wakes emitting some time stamps to the console
  7. Depending on whether cancel is called, the goroutine signal may be one of two things.
    1. If cancel is not called prior to the second sleep in the code, the ctx.Err() returns
      <-ctx.Done():  context deadline exceeded
    2. If cancel however is called, the ctx.Err() returns:
      <-ctx.Done():  context canceled
  8. Then, the goroutine uses the channel to signal completion (wait<-true).

You can experiment with this sample here.

With cancel called (the line cancel() not commented out):

first sleep completed,  02.00
Timeout: 02.00
in <-ctx.Done():  context canceled
after second sleep done,  04.00

And, with // cancel() commented out:

first sleep completed,  02.00
Timeout: 03.20
in <-ctx.Done():  context deadline exceeded
after second sleep done,  04.00

Hopefully this helps someone besides me.

Code-signing and self-signed certificates in Windows 10 with Powershell

I wanted to allow all signed Powershell scripts to run on a PC in our house on Windows 10. To do that, I needed a code-signing certificate.

Unfortunately, the days of easily obtaining a free code signing certificate seem to have ended. Have no fear! You can create a self-signed certificate if you don’t expect to use the certificate anywhere but on the PC where the certificate was created.

First, I enabled Powershell scripts to run. From an administrative Powershell command prompt:

> Set-ExecutionPolicy AllSigned

Acknowledge the warning and you’re ready to execute only signed scripts.

But, if you create your own script, you’ll need to sign it. To create the necessary code-signing certificate, you’ll again use Powershell. From an administrative Powershell command prompt:

PS C:\Dev>New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\ -Type CodeSigningCert -Subject "CN=PowershellScripts" -NotAfter (Get-Date).AddYears(10)

You can change the Common Name (CN) to anything you’d like, or adjust the expiration date (using -NotAfter). I’ve got the expiration as 10 years from today.

Once you’ve got the code signing certificate created as shown above, you’ll need to move the certificate to the Trusted Root Certification Authorities. If you don’t, when you sign the powershell script, it still won’t be allowed to run (and the act of signing will produce an UnknownError).

Start the certificate manager (press Windows key, type cert, and select “Manage computer certificates“, or hit Windows+R, then type: “certmgr.msc“).

Drag Certificate Into Trusted Root Certification Authorities

Expand Trusted Root Certification Authorities first, then expand Personal > Certificates and select the PowershellScripts Code Signing certificate and then drag it into the Trusted Certificates list as shown above (or you can right click, cut, and then paste it as well).

Now that you’ve got a trusted code signing cetificate, you can sign your Powershell scripts.

If you’ve only got one code signing certificate (which I presume you do otherwise you wouldn’t have needed a new one), from an administrative Powershell command prompt first switch directories to where the script you want to sign is located, then do these commands:

> $cert = (Get-ChildItem Cert:\LocalMachine\my -CodeSigningCert)[0]
> Set-AuthenticodeSignature .\reconnect-iscsi-targets.ps1 $cert

You should then see a table with the SignerCertificate, Status, and the Path. If everything went well, the Status should be Valid.

Here’s something interesting you can do with iSCSI targets and PowerShell using a signed PowerShell script.

 

 

Automatic Reconnection of iSCSI Targets in Windows 10 using PowerShell

When my highly recommended Synology Disk Station reboots for a required update (I’ve got it set to automatically reboot), a shared Windows 10 PC in our house cannot always successfully reconnect to the iSCSI targets without manual intervention. Unfortunately, I haven’t always noticed which has led to several features of Windows not functioning the way I want (I have mapped the iSCSI drives/disks via Windows and made them into network shares for the other PCs/laptops in our house — this way I can use Windows bitlocker encryption on the iSCSI drive contents).

To make the connection more automatic, I created a simple one line PowerShell script that periodically attempts to connect to any disconnected iSCSI targets using the Windows Task Scheduler.

I saved this into a script file called reconnect-iscsi-targets.ps1:

Get-IscsiTarget | where ($_.isConnected -eq $false) | Connect-IscsiTarget

Then, in the Task Scheduler, I created a new task set to run every 10 minutes daily. The script just gets all iSCSI targets, filters only those that aren’t connected, and then passes the results to the connection cmdlet.

For the action, I selected “Start a program” for program/script, I entered: “powershell.exe”, and then added the arguments “-File” and the full path to the file name, like:

-File c:\Users\aaron\Documents\reconnect-iscsi-targets.ps1

If there are spaces in the path to the PowerShell file, be sure to add quotes around the full path and file name.

You shouldn’t need the start in option set (leave it empty if you’d like).

On the General tab of the task, make sure you’ve set the “Run whether user is logged on or not” option and “Run with highest privileges.”

Next up — how to quickly create a Self-Signed Code-Signing certificate. And, how to actually allow scripts to run!

Frustrated by the DocumentDB Emulator

I was very excited about the announcement of a DocumentDB emulator!

I could finally explore the magic of this new document-based database (I can’t say “NoSQL” as it supports a SQL dialect) without spending money just to explore the database (it was a “pay to play”).

However, it’s not to be for me:

  1. Worst: It supports requests from LOCALHOST only. Its ports are bound to 127.0.0.1 rather than 0.0.0.0, thus preventing it from being usable from other machines. I wanted to install this on an always-on PC in our house rather than install it on my home workstation. I can sort of see why they want to limit it, but come-on, this is for development purposes. It’s not set up for availability, performance, etc. One simple right click of the app-tray icon resets and clears all the data. There are a number of effective ways for making it developer only — and I wouldn’t have picked this one.
  2. It has constantly used CPU, even when it’s not being used. On my laptop for example, it was hovering around 10-15% CPU, even when there were zero active connections. This problem isn’t consistent as I installed it on a secondary workstation and it’s using a lot of RAM (nearly 400MB), but only 1% CPU.
  3. It’s Windows only. This is actually a minor point if you’re using Windows, but if you want to use a Mac and do development, even with a VM hosted emulator, you won’t be able to.

So, for the best experience with DocumentDB, you’ll likely need to stick with the pay-to-play option of hosting it in Azure. I’m disappointed. I’ll look for a different database … something that doesn’t have this limitation.

Bummer.

Alternatives to Monopoly: Some table-top board games you should try

In the USA, there are some traditional board games that are commonly found in the closets of many households. The staple board games if you will.

Monopoly comes to mind for example. If you did a survey of 100 adults in the USA to name a board-game, I’d bet Monopoly would be number 1 on the list. Even McDonald’s for years has run various gaming promotions that involved the Monopoly brand. It’s ingrained in the culture. Let’s face it though: Monopoly isn’t for everyone. I think I enjoyed a game one time. But, I’m not sure we actually ever finished the game. Maybe that’s why I enjoyed it.

There may be a few games of Monopoly still underway since 1935 when it was released.

Once you get beyond Monopoly, there’s the Scrabbles, Clue, BattleshipRisk, and many more. We had many of those games in our home’s closet until recently. We looked at the stack of games, talked briefly, and donated them all to a local charity. They just don’t hold our interest anymore compared to the modern board game.

As a child I was playing Risk with a cousin …, he got so unhappy with his bad-luck and my good-luck that he threw his dice at me as hard as he could. I hadn’t know I’d be at Risk (!!! 🙂 ) for playing that. There are better games than Risk as far as I’m concerned.

I played Axis and Allies (I think it was that edition) some in college and never got into it. My group of friends played it occasionally for a year or two; I played it very casually. I played more “speed Axis and Allies” and friends played, “give me 20-30 minutes to consider my actions as the WORLD IS AT STAKE HERE.”  That experience turned me off to board games for the most part for a long time.

It’s changed a lot in the last 10 years. There are thousands of great games in a wide variety of genre these days at all price points.

In this post, I’ve included a handful of games which my wife and I consider great transitional games for someone who has tried (and either liked or disliked) the old-traditional board games. I’ve seen some lists recently that contain a few games that I’d definitely not consider transitional or starter games, so I was motivated to build my own list.

Ticket to Ride, Europe

Ticket to Ride Europe, by Days of Wonder, with over 3 million copies sold, is for 2-5 players and works well with 2-4 (I’ve not tried with 5). Games usually take about one hour and a little longer if people are learning to play. It’s stand-alone and does not require a base set (be careful to note that some boxed Ticket to Ride games require a base set to play).

The essential part of the game is that you’re building a hand of cards that eventually can be converted into rail lines for points. Most points at the end wins. It’s learn-able in 5 minutes or so on average and usually takes players a few rounds of play before they’re comfortable with the rules in action.

For my USA based readers, you’ll see that there’s an edition of the United States and you might be inclined to buy that. Buy it if you’re playing with 4 people. But, if you’re playing with fewer people, I’d strongly suggest you try a smaller map, like Europe (as it’s stand-alone). You’ll find that it’s a more competitive game that way as you’ll be likely working to complete the same rail lines as the other players. Europe is great with 4 players.

There are many variations on Ticket to Ride that  you might want to try as well.

What’s great about it is that while you can see the progress of other players, and occasionally unknowingly hinder their progress, it’s not necessarily obvious who will win the game until the end. There’s a bit of mystery as there are special cards called Destination Tickets in this edition of the game that are kept secret until the end of the game and may dramatically affect the score of individual players.

Pandemic

pandemic

If you aren’t prepared for a game that takes a little longer to learn, Pandemic may not be a good transitional game. You should give this one a chance though.

Assuming you can get through the rules (which admittedly are more complex than those of Monopoly), you’ll enjoy this cooperative game with friends and family (ages 12+ probably is best). Nearly every game I’ve played has ended up as a close win or close loss. You often don’t know right until the end which leads to a lot of enthusiastic and sometimes overly dramatic play by the players (but that’s the fun!). As the pandemics spread across the map, it’s your job as a band of specialists to reduce the spread, find the cure, and possibly eradicate the diseases entirely. The reason that I suggest this game is that it’s a great cooperative game. Everyone MUST play together or YOU WILL LOSE. Most of the games I played as a child were “versus” or team games and so this game was an eye-opener for me. The game plays against us all?

You might choose to ignore the thousands of positive reviews and instead look at the 1-star reviews on Amazon. Don’t. I honestly believe the folks that gave up on the game simply did not give it a fair chance or wanted to not learn it. If after reading the instructions, it’s still not clear, find one of the hundreds of walk-through videos that exist online. Here’s one from the publisher. Here’s another from TableTop where they play through an episode.

Also, until you’re committed to this type of game, do not mistakenly buy Pandemic Legacy. Absolutely, it’s a FUN game; one that requires a commitment of at least 12 plays to finish the game. It’s best played by a group that is consistent from play to play (as it’s telling a story as it goes through so jumping in during the middle of the game won’t be as interesting or as engaging). I’ve only played through June so far, and having the back-story and experience of playing the early episodes is really what makes that game top notch.

Onami from Wyvern Gaming

onami

This is a great reasonably quick game (under 30 minutes). It’s really easy to learn and play. However, Strategy! As you take turns, you place numbered tiles on a grid. Each tile placed then may allow the player to mark one or more other tiles as their own. In the end, it’s the person with the most tiles that win. The challenge is that until the last turn is played, a tile may change owners many times. My wife and I were surprised by this board game that we picked up by chance at Gen Con 2016 in August. (Apparently, it had been a Kickstarter game).

But it direct from Wyvern here for $30.

Carcassonne

carcassonneI first played an Android tablet version of this game on a plane with a friend. I’d heard of the game but never played it (digitally or physically). While the rules at first were a bit strange, it only took a few rounds of play to understand the basics.

This is a tile laying game and ideally needs a large space in which to play as there’s not a traditional board like other games. Instead, you’re building the board as you play by laying tiles that represent various aspects of the French countryside. Games take between 30-45 minutes. It’s easy to learn for kids and adults. Make certain you’re not buying an expansion as there are a few.

It’s about $28 on Amazon.

Patchwork

patchwork

 

This is a two player game that takes about 20-30 minutes to play and maybe about 5 to learn. Essentially, you take turns choosing various pieces using your buttons (as money) to build the best high scoring quilt. It’s really easy to learn and play but is very strategic. In some ways, it’s like a dynamic Tetris as you try to fit pieces to your board, yet not everything will fit perfectly and in the end may cause you to lose the game! Some apparently have said it’s a puzzle game, but I don’t consider it puzzle-styled at all. It’s luck, strategy, and the skill of your opponent that determines whether you’ll win. (I dislike puzzle games and wouldn’t play it if it were puzzle-oriented).

It’s usually around $22 on Amazon.

Castle Panic

castlepanic

Castle Panic ($20), like Pandemic, is a co-operative game. Everyone wins or loses. The difference here is that there is a player that comes out ahead of the others by score (victory points are counted by how many monsters are slain). It’s considered a tower-defense game. That just means that the monsters are attacking the castle and that it’s your job as a player to defend the tower (castle). Each turn players try to eliminate or push back the various monsters that are making their way to the tower. This could definitely be played by younger kids if you don’t mind that they’re killing orcs and other monsters and that they can do a bit of strategy with their parents or family to think beyond just the current turn.

There are variations like Star Trek Panic ($32) that are also available (and slightly more expensive and have a few more rules that may be too challenging for younger kids).

One Hit Kill

onehitkill

Originally available via Kickstarter, One Hit Kill is easy to play and learn, and just as easy to lose.  We played this with some family earlier this year and they hated and loved it! There are a lot of ways to lose the game and only one way to win. Basically, you’re just trying to build a run of numerically sequenced cards (2,3,4,5 for example) in two different colors. The colors will need to match a special card. Once you’ve matched it, Win. The entire rules are explained on the page I linked above. It’s that easy.

It’s available direct via the publisher here.

10 Days in Africa

outofafrica

For two to four players, this quick game will challenge you to build a route between various countries in Africa. You’ll need to take a creative route that starts in one country and using land, water, and air travel plots a successful route to a final country. The rules and game play are simple. Plays in less than 30 minutes. My nine-year old nephew understood the game and the rules, but was stressed by the planning that was required (as he couldn’t see all of the options that might be available to him). So, consider it possibly better for slightly older children if they’re playing against older kids or adults.

Of course, there are other countries, like USA, Europe, Asia, and the Americas available. You may have to hunt around for a copy of any of them though which is disappointing.

And Many many more!

Don’t be afraid to look around. Amazon has literally tens of thousands of board game listings. Seriously.

Also, find your local board game store and stop by. HOWEVER, if you’ve never been to the board game store, make sure you call ahead or look at their website to confirm they have a variety of board game options. (Some cater to wargaming rather than board-gaming). My wife and I, when we visit a new city in the USA, always try to find a few local board game stores and stop in and buy a few small games to play on our vacation (and spread the board game love I guess a little). We’ve met some really interesting people doing that and gone to a few stores that were unique to say the least (one in particular where we developed a case of claustrophobia walking through the overly packed and stacked boxes and aisles. Two people couldn’t fit down an aisle and it felt like it was all going to tumble on our heads!).

You can also use the web site Board Game Geek.com, but for those new to board games, I’d suggest you stick to Amazon and your local stores. While it has a lot of great information, it’s often a bit intense for newcomers. 🙂

I had a few more games that I’d intended to add here, but now that I search for them on the Internet, I see that they’re no longer published and they’re all hard to obtain. While you might enjoy the challenge of spending hours tracking down a copy, I’d suggest you buy a different board game and play that instead. So, I’m not going to list them today.

Some of the best games tend to be available on Amazon and are well reviewed by hundreds and thousands of people.

(Next , I’ll create a post with some of the cooperative games that I’ve enjoyed playing with my wife and friends and family).

Comments and feedback welcome!