Monday 31 December 2018

Count files in a directory on a basic Linux system

find . -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo -e $(find {} | wc -l) {}' | sort -n

Thursday 27 December 2018

Using an Azure Function, Puppeteer and a headless Chrome to drive a Web site like Selenium

These are some notes to describe how you can use Azure Functions and a headless Chrome to parse a Web site similar to using Selenium. It allows you to periodically pull some data from a Website without needing a Virtual Machine or a Cloud Service.

Install nvm-windows

Install the correct version of node (at the time of writing 10.6.0 was compatible with Azure Functions).

nvm install 10.6.0
node use 10.6.0

There was a bug meaning that some packages were missing and the error message "npm-cli.js not found" was displayed when running npm. The solution was to uninstall and reinstall again.

nvm uninstall 10.6.0
nvm install 10.6.0

Install Visual Studio Code.

Install the Azure Functions extension for Visual Studio Code.

Create a folder for the Azure Function.

CD to the folder.
Initialise NPM, otherwise you will get this error.
npm init
npm i puppeteer

Using the Azure icon in Visual Studio Code, login to the Azure Subscription.

Create the function using the Azure Functions integration in Visual Studio Code.

Test the function.

Deploy the function.

Once the function has been deployed, open a Kudu console and navigate to the D:\home\site\wwwroot\[FunctionName].

install Puppeteer by typing 'npm i puppeteer'

However it doesn't work properly as Chromium won't launch because of Azure App Function limitations.

Another option is browserless.io, but this is a paid resource.

Addendum

This project uses an Azure Function to pull data from a website.

Sunday 11 November 2018

Opening an existing instance of Visual Studio Code


By default, VS Code will open a new Editor with the desired file. If you'd like to instead reveal the already open Editor, set workbench.editor.revealIfOpen to true in your User Settings.

To be concrete, that means adding the following line:
"workbench.editor.revealIfOpen": true,

https://stackoverflow.com/a/43135102/2970867

Friday 9 November 2018

Excel columns are truncated in confluence

To stop confluence truncating Excel columns:

Edit the spreadsheet in Excel
Page Layout > Width > Change from Automatic to 1 Page

https://confluence.atlassian.com/confkb/how-do-i-ensure-excel-file-with-wide-columns-does-not-get-truncated-in-confluence-file-previews-829068467.html

EE Voicemail commands

return #
Listen again 1
2 save for later
delete 3
receive a text of the caller's number 4
reply or forward 5
6 pause
7 rewind 10 secs
8 next
9 forward 10 secs

Sunday 30 September 2018

OSMC add-ons

To access the add-on menu:

System > Add-ons > Manage Dependencies > .. > Install from

Note it is important to select the '..'

To add Sources, Go To File Manager and Add the sources from there.

Thursday 19 July 2018

Multifactor authentication


chrome://flags/#tls13-variant

Tuesday 10 July 2018

Moving files in Sharepoint

To move files in Sharepoint, open Explorer and then type in the URL to the Sharepoint site.

Sunday 1 July 2018

Freenas: Mount NFS as an alternative to SMB

As Windows 10 no longer supports SMB v1 as used by FreeNAS 0.7.2, it was necessary to find an alternative.

NFS works in Windows 10. You can describe the NFS client as described here.

I found I needed the nolock option to be able to view files.

mount -o nolock -o anon \\<Server>\<mount> x:

e.g. mount -o nolock -o anon \\<Server>\mnt\Data x:

It was also necessary to set two registry keys on each client to set the user ID and Group ID. Restart the NFS client with nfsadmin client start | stop.

This article also describes how you can change the user ID so the share is mounted as a different user.

If you mount NFS shares from an elevated command prompt (Run as administrator), the mount will not show up in the explorer running with normal user privileges. The solution is to unmount the share and remount it, either from explorer or from an ordinary command prompt. Admin privileges are not required for NFS mounts.

To find a user's UID or GID in Unix, use the id command. To find a specific user's UID, at the Unix prompt, enter:
 id -u username
Replace username with the appropriate user's username. To find a user's GID, at the Unix prompt, enter:
 id -g username
If you wish to find out all the groups a user belongs to, instead enter:
 id -G username
If you wish to see the UID and all groups associated with a user, enter id without any options, as follows:
 id username

Setting up on a machine for the first time
It is important to set the underlying Unix account that will be used by the anonymous account and nfs.

Without registry settings:

Test1: Folder created by FreeNas (root):  root/wheel - inaccessible by explorer
Test2: Folder created by SSH (root): root/wheel   - inaccessible by explorer
Test3: Folder created by X: drive before resgistry settings applied:  4294967294/wheel - accessible by explorer

By setting the registry settings:
AnonymousUid (DWORD32) : 1001 (decimal) - For <username>
AnonymousGid (DWORD32) : 0 (decimal)

and restarting nfsadmin client stop / start 
then:

Test4: Folder created by X: drive:  <username>/wheel - accessible by explorer


SSH to FreenNAS
ssh -oHostKeyAlgorithms=+ssh-dss <username>@freenas

Saturday 23 June 2018

Galaxy Tab S tablet volume goes up and down: Farming Simulator 18

I was listening to BBC iPlayer (in Chrome) on my son's Galaxy Tab S and I noticed that the volume kept going up and down. All rather annoying. My other son's Tab S was doing the same. Other people have complained about this too.

So I did some debugging.

I put the Tab into developer mode, connected the USB and ran adb logcat > c:\temp\debug.txt from a command prompt.

Whenever the volume dropped I looked for patterns. I started to notice
requestAudioFocus() from android.media.AudioManager$8d530e6org.chromium.content.browser.AudioFocusDelegate$f901627 req=3flags=0x0

AudioManager dispatching onAudioFocusChange(-3)

and
AudioFocus  abandonAudioFocus() from android.media.AudioManager$8d530e6org.chromium.content.browser.AudioFocusDelegate$f901627

AudioManager dispatching onAudioFocusChange(1)

So I ran baretail with the syntax highlighting turned on and it confirmed the pattern was happening whenever the volume dropped.

Looking at the documentation it indicated that the audio was requesting to be reduced (and then subsequently returned to normal).

I ran adb shell ps > c:\temp\process to determine the process names that correlated to the PIDs in the log output.

Looking further in the logs I could see entries like

com.giantssoftware.fs18.google  14229 W AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 48000 Hz, output 44100 Hz

/system/bin/mediaserver  9422 W AudioPolicyIntefaceImpl: Skipped to add effects on session 332


Farming Simulator 18? What is this doing? It is installed, but not running in the foreground. It kept trying to do something with the audio.

It also kept trying to download some Javascript.
com.giantssoftware.fs18.google  com.giantssoftware.fs18.google  I chromium: [INFO:CONSOLE(1)] "05bd228f", source: https://vpaid.springserve.com/production/vpaid_a1597ab3.js (1)

So I uninstalled it. And the audio is back to normal!

The problem is known as "ducking". This article provides greater background.

It seems like Farming Simulator 18 was causing the problem. It was also installed on my other son's tablet.


Friday 22 June 2018

Group Policy

Group Policy settings are stored at: C:\WINDOWS\system32\grouppolicy
Registry: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies

Let's Encrypt provides free certificates


https://letsencrypt.org/about/

Monday 18 June 2018

Testing sql for concurrency bugs

There is a method for checking SQL or Stored Procedures against concurrency bugs. Using the SQL Server scheduler you can run two queries in parallel.

To do this:
Open two SQL Server query windows and then split them vertically.
Then in each window, run:

waitfor time '13:16:20.00'
exec uspMyStoredProcedure

You might need to run it several times as the scheduler is not accurate to microseconds, but if you have a long-running query it should show the bug relatively quickly.

Saturday 16 June 2018

Pairing a Dualshock 4 (DS4) with the Playstation 3 (PS3)

Click on Accessory settings
Manage Bluetooth devices
Register a device

Note you must hold down the Share + PS3 button on the DS4 for about 3 seconds until the front display flashes rapidly.

Also note that the PS button and the rumble will not work.

If you need to reset the DS4, you can use a paperclip to press the reset button on the back near the R2 trigger.

Assigning nominal codes in Kashflow

Run the Profit and Loss report
Click on the value of the Other colum.
Select the entries to be moved.
Select Re-assign selected transaction(s)

Sunday 27 May 2018

Outlook.live.com not previewing PDF files

I was unable to view PDF files in the outlook.live.com. In the end I found it was because my browser settings were set to download files. To fix:

In Chrome
Open chrome://settings. Click on the Advanced link at the bottom. Turn the "Ask where to save each file before downloading" to OFF.

In Firefox
Go to Options. Under applications, type in PDF. Set the action to "Preview in Firefox".

Saturday 3 March 2018

Minikube hello world example

https://medium.com/@claudiopro/getting-started-with-kubernetes-via-minikube-ada8c7a29620

Hyper-V networking

In Hyper-V I had a Virtual Network Switch, 'NAT', which I could not delete.
I found that this was associated with docker.

running docker network list indicated the network:

a1b23ca940cb        Default Switch                 ics                 local
dd38da06ad19        Minikube                       transparent         local
e1f9b2de34f2        Wired Hyper-V Virtual Switch   transparent         local
b927d4e2fab9        nat                            nat                 local
20a4b1e6aec4        none                           null                local

ics is Internet Connection Sharing.

the nat switch is created by Docker For Windows and is used for Windows containers.
Conversely, if you use Linux mode then Docker for Windows creates the DockerNAT switch.

If you create a Hyper-V external switch then a bridge is also required. It connects the
Wireless Network Connection adapter to the MAC Bridge Filter, the LLDP protocol driver and the Hyper-V Extensible Virtual Switch.

This article explains why:
https://blogs.msdn.microsoft.com/virtual_pc_guy/2015/02/02/hyper-v-and-wireless-networking/


This article explains a lot about the Windows networking

Moby Linux VMs use DockerNAT switch with Docker for Windows (a product of Docker CE) instead of HNS internal vSwitch
Docker for Windows (the Windows driver for the Docker CE engine) on Windows 10 will use an Internal vSwitch named 'DockerNAT' to connect Moby Linux VMs to the container host. Developers using Moby Linux VMs on Windows should be aware that their hosts are using the DockerNAT vSwitch rather than the vSwitch that is created by the HNS service (which is the default switch used for Windows containers).

To get the docker container to have access to the network (as if it were a peer to the host)

docker network ls

NETWORK ID          NAME                              DRIVER              SCOPE
acd360485ea3        Wired Hyper-V Virtual Switch      transparent         local
cf9c25350a73        Wireless Hyper-V Virtual Switch   transparent         local
bf621e7722a1        nat                               nat                 local
1655e1f6e86f        none                              null                local

then
docker run --network "Wired Hyper-V Virtual Switch" -ti microsoft/nanoserver ping 8.8.8.8


To set up a good development machine you would expect:

Wireless
Network Bridge - using the Wireless Network Connection adapter and connecting the Hyper-V Extensible Virtual Switch, Microsoft LLDP Protocol Driver and Microsoft MAC Bridge.

Wired


Do not configure the Local Area Network Connection for TCP/IP settings. This should be done at the Hyper-V virtual switch level.


Testing
Test your main wireless and wired host networking.
Test a normal Hyper-V VM's access to the internet, via wireless and wired independently.
Test a Docker containers access to the internet.
Test MiniKubes ability to start up and get an IP address.

Friday 2 March 2018

Minikube working with Docker for Windows on Windows 10 - avoid the network problems

Turn off IPV6 for the physical network connection (it is believed there is a race condition which if both IPv4 and V6 are on then V6 sometimes wins the race to DHCP. If your network doesn't support IPV6 then you don't get an IP address).


Add the Hyper-V virtual switch called Minikube. Make it an internal network.

Go to the physical network and allow it to be shared with the virtual network.

RegEx for beginning of line and end of line

Regex start of line
^
Regex end of line
(.)$

Thursday 1 March 2018

Git configuration

 git config credential.helper store
git config --global difftool.prompt false
git config --global diff.tool bc3

Tuesday 27 February 2018

Building dotnet core for Raspberry PI: NU1605: Detected package downgrade

You can build a dotnet core app on a 64-bit Linux machine for running on a 32-bit Raspberry PI.

My dockerfile ran the following command (note the -r parameter):
RUN dotnet publish -c Release -o out -r linux-arm

I did get one error when building it though:

C:\Source Code\GitHub\buyers-remorse-containers\src\BuyersRemorseService\BuyersRemorseService\BuyersRemorseService.csproj : error NU1605: Detected package downgrade: Microsoft.Win32.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. C:\Source Code\GitHub\buyers-remorse-containers\src\BuyersRemorseService\BuyersRemorseService\BuyersRemorseService.csproj : error NU1605: BuyersRemorseService -> Microsoft.Azure.ServiceBus 2.0.0 -> Microsoft.Azure.Amqp 2.1.2 -> System.Net.WebSockets.Client 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.unix.System.Net.Primitives 4.3.0 -> Microsoft.Win32.Primitives (>= 4.3.0) C:\Source Code\GitHub\buyers-remorse-containers\src\BuyersRemorseService\BuyersRemorseService\BuyersRemorseService.csproj : error NU1605: BuyersRemorseService -> Microsoft.Win32.Primitives (>= 4.0.1)

And the solution was to edit the .csproj and manually insert the following line:

<PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />

Monday 26 February 2018

Running MiniKube and Azure AKS together

I was running MiniKube locally on my dev machine but trying to use kubectl to connect to an Azure AKS cluster.
The "active" cluster that kubectl is trying to manage is set in .kube\config.
To switch from the local MiniKube to managing the AKS cluster I had to run the following PowerShell:

az login
az account set –-subscription "MySubscription"
az aks get-credentials --resource-group andy-test-aks --name andy-test-aks-cluster

Merged "andy-test-aks-cluster" as current context in C:\Users\AndrewPotts\.kube\config

kubectl cluster-info

Minikube on Windows

To run MiniKube on Windows you need to create a new Virtual Switch (let's call it "MiniKube Virtual Switch").

To start minikube with full debugging, run:
minikube start --vm-driver="hyperv" --hyperv-virtual-switch="Wired Hyper-V Virtual Switch" -v 999

Friday 9 February 2018

IIS Express displayed the error "Failed to register URL" "Access is denied"

Running a Website on IIS Express displayed the error "Failed to register URL" "Access is denied"

The solution is to close VS, delete the file below, and reopen.

<<path_to_solution_folder>>\.vs\config\applicationhost.config

Docker for Windows: re-exec error: exit status 1: output: archive/tar: invalid tar header

I was building a docker image with SQLExpress and some custom databases within.

There are some layer size limitations in Windows
If you get the message:
re-exec error: exit status 1: output: archive/tar: invalid tar header
then you may have exceeded the maximum allowable layer size
https://github.com/moby/moby/issues/33586



You can increase the storage options:


{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": true,
  "storage-opts": [
    "size=40G"
  ]
}


Friday 2 February 2018

Azure Service Bus - interoperable serialization

We had a problem where we were serializing a message to ASB but the Mulesoft client was failing to deserialize. It was performing a byte[] to string conversion.

The problem is that we are writing things like @ string 3http://schemas.microsoft.com/2003/10/Serialization/
on the wire, and the client’s Byte[] to string is serializing it back badly.

There are numerous discussions about interoperability.
There is a difference in behaviour between the ASB SDKs (nice!).
This article explains the solution if you want to write bytes directly to ASB.
Service Bus Explorer hides the problem. It doesn’t show the prefix bytes. If you read the binary bytes back they are there.
You can fix the problem by code in the subscriber , but this ignores the fact those bytes are still there. Subscriber fixes isn't very interoperable (after all does Java care about a
@ string 3http://schemas.microsoft.com/2003/10/Serialization/
?

Summary solution: you have to pass a stream for serialization. Anything else (string, byte array, object) and BrokeredMessage will apply a DataContractSerializer which will append the byte and schema declation beforehand.

This works:

var order = new SubmitOrder() { OrderRef = Guid.NewGuid().ToString() };
          
           var json = JsonConvert.SerializeObject(order);
           var data = Encoding.UTF8.GetBytes(json);
          
           using (var ms = new MemoryStream())
           {
                ms.Write(data, 0, data.Length);
               
                ms.Seek(0, SeekOrigin.Begin);
                BrokeredMessage msg = new BrokeredMessage(ms);
                msg.Label = order.OrderRef;
                sender.Send(msg);
           }

Converting to a string doesn’t work:
var order = new SubmitOrder() { OrderRef = Guid.NewGuid().ToString() };
          
           var json = JsonConvert.SerializeObject(order);
          
           BrokeredMessage msg = new BrokeredMessage(json);
           msg.Label = order.OrderRef;
           sender.Send(msg);

Nor does directly serializing the object:
var order = new SubmitOrder() { OrderRef = Guid.NewGuid().ToString() };
          
           BrokeredMessage msg = new BrokeredMessage(order);
           msg.Label = order.OrderRef;
           sender.Send(msg);



https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messages-payloads

The bad data looked like:
0x40 0x06 0x73 0x74 0x72 0x69 0x6e 0x67 0x08 0x33 0x68 0x74 0x74 0x70 0x3a 0x2f 0x2f 0x73 0x63 0x68 0x65 0x6d 0x61 0x73 0x2e 0x6d 0x69 0x63 0x72 0x6f 0x73 0x6f 0x66 0x74 0x2e 0x63 0x6f 0x6d 0x2f 0x32 0x30 0x30 0x33 0x2f 0x31 0x30 0x2f 0x53 0x65 0x72 0x69 0x61 0x6c 0x69 0x7a 0x61 0x74 0x69 0x6f 0x6e 0x2f 0x99 0x33 0x7b 0x22 0x4f 0x72 0x64 0x65 0x72 0x52 0x65 0x66 0x22 0x3a 0x22 0x39 0x33 0x38 0x61 0x65 0x32 0x32 0x62 0x2d 0x66 0x39 0x36 0x65 0x2d 0x34 0x37 0x65 0x32 0x2d 0x61 0x38 0x31 0x37 0x2d 0x31 0x64 0x31 0x30 0x63 0x31 0x62 0x61 0x35 0x61 0x61 0x35 0x22 0x7d

?@? ?s?t?r?i?n?g? ?3?h?t?t?p?:?/?/?s?c?h?e?m?a?s?.?m?i?c?r?o?s?o?f?t?.?c?o?m?/?2?0?0?3?/?1?0?/?S?e?r?i?a?l?i?z?a?t?i?o?n?/?™?3?{?"?O?r?d?e?r?R?e?f?"?:?"?9?3?8?a?e?2?2?b?-?f?9?6?e?-?4?7?e?2?-?a?8?1?7?-?1?d?1?0?c?1?b?a?5?a?a?5?"?}

The working data looked like:
0x7b 0x22 0x4f 0x72 0x64 0x65 0x72 0x52 0x65 0x66 0x22 0x3a 0x22 0x66 0x30 0x63 0x31 0x66 0x32 0x38 0x62 0x2d 0x63 0x35 0x33 0x64 0x2d 0x34 0x32 0x63 0x62 0x2d 0x39 0x65 0x31 0x37 0x2d 0x66 0x33 0x35 0x39 0x35 0x31 0x39 0x30 0x62 0x38 0x66 0x38 0x22 0x7d

?{?"?O?r?d?e?r?R?e?f?"?:?"?f?0?c?1?f?2?8?b?-?c?5?3?d?-?4?2?c?b?-?9?e?1?7?-?f?3?5?9?5?1?9?0?b?8?f?8?"?}

This link probably describes the problem the best and offers a solution.

Tuesday 2 January 2018

Laptop running slow - check power settings

I noticed my laptop was running very slow. Then one day in Task Manager I noticed under the Performance tab that the CPU was only running at 0.97 GHz. Why was this?

I discovered the power options were set to "Power Saver". On setting it to "Balanced", the CPU returned to it's true 2.8 GHz.