Winrm is missing after installing ChefDK

When you install the new version of ChefDK you may get the following error message when you try to run Test Kitchen
!!!!!! The `winrm` gem is missing and must be installed or cannot be properly activated. Run `gem install winrm --version '["~> 1.6"]'` or add the following to your Gemfile if you are using Bundler: `gem 'winrm ', '["~> 1.6"]'`.

To install Winrm for the correct Ruby version execute
gem install winrm
gem install winrm-fs

Berkshelf is missing after installing ChefDK

When you install a new version of ChefDK and try to run Test Kitchen the following error message may appear
!!!!!! The `berkshelf' gem is missing and must be installed or cannot be properly activated. Run `gem install berkshelf` or add the following to your Gemfile if you are using Bundler: `gem 'berkshelf'`.

To reinstall Brekshelf in the correct version of Ruby execute
gem install berkshelf

EC2 driver is missing after installing ChefDK

After installing a new version of ChefDK you may get the following error message when you try to run Test Kitchen:

Message: Could not load the 'ec2' driver from the load path. Please ensure that your driver is installed as a gem or included in your Gemfile if using Bundler.

To install the EC2 driver in the correct Ruby version execute

gem install kitchen-ec2

Error in Test Kitchen after installing ChefDK

You may get the following error when you try to run Test Kitchen after installing the latest version of ChefDK:

$ kitchen
C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- dl/import (LoadError)
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:1:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:5:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent.rb:22:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/key_manager.rb:4:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:4:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh.rb:11:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen/ssh.rb:20:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen.rb:46:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/lib/kitchen/cli.rb:21:in `<top (required)>'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/test-kitchen-1.7.3/bin/kitchen:10:in `<top (required)>'
from C:/Ruby22/bin/kitchen:23:in `load'
from C:/Ruby22/bin/kitchen:23:in `<main>'

To make Test Kitchen work again execute the following:

gem install net-ssh -v 2.9.3.beta1

Extract data from JSON with Ruby

Chef uses Ruby as the scripting language. If you need to extract data out from a JSON string you can use the following script


# Save the JSON values
instance_data_drive_config = '{"size":"500","type":"io1","iops":"15000"}'

# Parse the JSON to a hash
data = JSON.parse(instance_data_drive_config)

# Declare the variables
size = ''
type = ''
iops = ''

# Iterate through the hash
data.each do |child|
case child[0]
when 'size'
size = child[1]
when 'type'
type = child[1]
when 'iops'
iops = child[1]
end
end

# Display the result
puts "size=#{size}"
puts "type=#{type}"
puts "iops=#{iops}"

The output is
size=500
type=io1
iops=15000

DJI Phantom 4 firmware update stops at 92%

When I update the DJI Phantom 4 firmware with DJI Assistant 2 most of the times the update stops at 92%.

If I turn off the DJI Phantom 4 and turn it on again the rear lights blink fast yellow (or fast white), and the DJI Assistant 2 application cannot recognize the DJI Phantom 4 anymore through the USB cable.

I have not found a graceful way to finish the update, but the following steps make the Phantom work again.

  • Turn off the Phantom 4 with the power switch on the battery.
  • Connect a mobile device to the DJI Phantom 4 remote controller with a USB cable.
  • Turn on the Phantom 4 remote controller.
  • Start the DJI Go app on the mobile device connected to the DJI Phantom 4 remote controller.
  • Turn on the DJI Phantom 4 with the power switch on the battery.
  • Tap the Camera link in the DJI Go app to connect to the DJI Phantom 4 aircraft.
  • The DJI Go app should display the message that the Overall Status is “Normal, (Latest Firmware)”.
    If the status page does not open automatically to display the status page, tap the upper part of the DJI Go app right of the DJI logo where the GPS status message is displayed.
  • After the firmware update Multiple Flight Modes is usually turned off. To turn on Multiple Flight Modes
    • On the top of the DJI GO app tap the drone symbol next to the flight mode name (OPTI).
    • Slide the switch to the right in the Multiple Flight Modes section.

Git configuration

If you use 2-factor authentication in GitHub,  generate a 40 character Personal Access Token that you can use as a password to access GitHub repositories.

Create a Personal Access Token to use it as password in the Git client

  1. Log into GitHub and in the pull down at the upper right select Settings,

  2. On the left select Developer Settings,
  3. On the left select Personal access tokens,
     
  4. Click the Generate new token button,
  5. Enter a description for your token (so you can keep track and revoke them individually later, should you have a security breach),
  6. Select the repo checkbox,
  7. Click the Generate token button,
  8. Copy the token (40 characters long) to the clipboard and use that as your password in the command line.
  9. If your organization use SSO (Single Sign On) click the Enable SSO button
  10. This will open your organization’s authentication pages to enable access for your token.

Store or update your username and password in the Git credential helper


In macOS and Linux

Set the credential helper to store your username and password

To store the Git credentials on your hard disk in unencrypted form, use the Git Credential Store

git config credential.helper store

When you have already stored your password in the credential helper of Git and switching to 2-factor authentication, or just want to update your GitHub username or password


In Windows

  • In the command line execute the following to instruct the Git client to use the Wincred Windows credential helper to store your username and password
    git config --global credential.helper wincred
  • The next time you will access the GitHub repository to fetch, clone or push changes the Git CLI will pup up a dialog box to ask your username and password.

To update an already stored username or password in the Windows Credential Manager

When you access GitHub from your Windows workstation, Windows stores your credentials in the Credential Manager. If you want to enter an updated password, enter your personal access token when you switch to 2-factor authentication or switch between GitHub accounts, delete the GitHub entry from the Credential Manager.

  1. Open the Windows Credential Manager
    1. Open a command window
    2. Execute
      control /name Microsoft.CredentialManager
  2. On the Windows Credentials tab click the down arrow next to github.com
  3. Click the Remove link
  4. Click Yes to delete the link.

Disable database triggers in Microsoft SQL databases

If you need to temporarily disable triggers in Microsoft SQL databases during database maintenance use the following script
--Disable triggers on all tables
DECLARE @enable BIT = 0;
DECLARE @trigger SYSNAME;
DECLARE @table SYSNAME;
DECLARE @cmd NVARCHAR(MAX);
DECLARE trigger_cursor CURSOR FOR SELECT trigger_object.name trigger_name,
table_object.name table_name
FROM sysobjects trigger_object
JOIN sysobjects table_object ON trigger_object.parent_obj = table_object.id
WHERE trigger_object.type = 'TR';
OPEN trigger_cursor;
FETCH NEXT FROM trigger_cursor INTO @trigger, @table;
WHILE @@FETCH_STATUS = 0 BEGIN
IF @enable = 1
SET @cmd = 'ENABLE ';
ELSE
SET @cmd = 'DISABLE ';
SET @cmd = @cmd + ' TRIGGER dbo.'+QUOTENAME(@trigger)+' ON dbo.'+QUOTENAME(@table)+' ';
EXEC (@cmd);
FETCH NEXT FROM trigger_cursor INTO @trigger, @table;
END
CLOSE trigger_cursor;
DEALLOCATE trigger_cursor;
GO

Disable foreign key constraints in Microsoft SQL databases

Databases do not allow the deletion of rows if those are referenced in other tables with the foreign key constraint. You can turn off the validation of foreign keys in Microsoft SQL databases for the duration of the maintenance with the following script.


--Disable foreign keys on all tables
DECLARE @table_name SYSNAME;
DECLARE @cmd NVARCHAR(MAX);
DECLARE table_cursor CURSOR FOR SELECT name FROM sys.tables;
OPEN table_cursor;
FETCH NEXT FROM table_cursor INTO @table_name;
WHILE @@FETCH_STATUS = 0 BEGIN
SELECT @cmd = 'ALTER TABLE '+QUOTENAME(@table_name)+' NOCHECK CONSTRAINT ALL';
EXEC (@cmd);
FETCH NEXT FROM table_cursor INTO @table_name;
END
CLOSE table_cursor;
DEALLOCATE table_cursor;
GO