Skip to main content

Peter Marshall

Sunday Bike run bike

1 min read

 

 

 Cycle to wooton roundabout and back 

 

Route map for Martins To Roundabout by Peter Marshall on plotaroute.com

 

Route map for V Short Run by Peter Marshall on plotaroute.com

Down hill and back up

Route map for Martins Down Hill And Back by Peter Marshall on plotaroute.com

Peter Marshall

Peter Marshall

Call Service Fabric endpoint internally

1 min read

        private async Task CallServiceAsync()
        {
            string schedulerServiceName = "fabric:/DataServices/Scheduler";
            var resolver = ServicePartitionResolver.GetDefault();
            var partition = await resolver.ResolveAsync(new Uri(schedulerServiceName), ServicePartitionKey.Singleton, CancellationToken.None);
            var endpoints = JObject.Parse(partition.GetEndpoint().Address)["Endpoints"];
            var endpoint = endpoints[""].ToString().TrimEnd('/');
            string method = "/api/scheduler/classes/sync";
            var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var getTask = client.GetAsync(endpoint + method);
            var msg = await getTask;
        }

Peter Marshall

Call Service Fabric endpoint internally

1 min read

        private async Task CallServiceAsync()
        {
            string schedulerServiceName = "fabric:/DataServices/Scheduler";
            var resolver = ServicePartitionResolver.GetDefault();
            var partition = await resolver.ResolveAsync(new Uri(schedulerServiceName), ServicePartitionKey.Singleton, CancellationToken.None);
            var endpoints = JObject.Parse(partition.GetEndpoint().Address)["Endpoints"];
            var endpoint = endpoints[""].ToString().TrimEnd('/');
            string method = "/api/scheduler/classes/sync";
            var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var getTask = client.GetAsync(endpoint + method);
            var msg = await getTask;
        }

Peter Marshall

Debug Jest tests in Visual Studio Code

1 min read

    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    }

Peter Marshall

removing duplicates in sql server

1 min read

Find your duplicates

  SELECT    [col1], [col2], COUNT(*)
  FROM      [db].[mstar].[table1]
  GROUP BY  [col1], [col2]
  HAVING    COUNT(*) > 1
THEN
begin transaction
SET NOCOUNT ON
SET ROWCOUNT 1
while 1 = 1
 BEGIN
   DELETE  
   FROM [mstar].[InvalidFundShareClassAttribute]
   WHERE [FundShareClassId]+ [CustomState] IN
        (SELECT  [FundShareClassId]+ [CustomState]
         FROM    [mstar].[InvalidFundShareClassAttribute]
         GROUP BY [FundShareClassId]+ [CustomState]
         HAVING  COUNT(*) > 1)
      IF @@Rowcount = 0
      BREAK ;
end;
 SET ROWCOUNT 0
 rollback;
or commit;

 

There is another way

;WITH CTE AS 
(
    SELECT EmpName, ROW_NUMBER() OVER 
    (
        PARTITION BY EmpName ORDER BY EmpID
    ) RowNumber
    FROM  dbo.Employee
)
SELECT *FROM CTE WHERE RowNumber > 1
Then
;WITH CTE AS 
(
SELECT EmpName, ROW_NUMBER() OVER 
(
    PARTITION BY EmpName ORDER BY EmpID
) RowNumber
FROM  dbo.Employee
)
DELETE FROM CTE WHERE RowNumber > 1

Peter Marshall

remove duplicates in sql server

1 min read

Find your duplicates

  SELECT    [col1], [col2], COUNT(*)
  FROM      [db].[mstar].[table1]
  GROUP BY  [col1], [col2]
  HAVING    COUNT(*) > 1
THEN
begin transaction
SET NOCOUNT ON
SET ROWCOUNT 1
while 1 = 1
 BEGIN
   DELETE  
   FROM [mstar].[InvalidFundShareClassAttribute]
   WHERE [FundShareClassId]+ [CustomState] IN
        (SELECT  [FundShareClassId]+ [CustomState]
         FROM    [mstar].[InvalidFundShareClassAttribute]
         GROUP BY [FundShareClassId]+ [CustomState]
         HAVING  COUNT(*) > 1)
      IF @@Rowcount = 0
      BREAK ;
end;
 SET ROWCOUNT 0
 rollback;
or commit;

 

There is another way

;WITH CTE AS 
(
    SELECT EmpName, ROW_NUMBER() OVER 
    (
        PARTITION BY EmpName ORDER BY EmpID
    ) RowNumber
    FROM  dbo.Employee
)
SELECT *FROM CTE WHERE RowNumber > 1
Then
;WITH CTE AS 
(
SELECT EmpName, ROW_NUMBER() OVER 
(
    PARTITION BY EmpName ORDER BY EmpID
) RowNumber
FROM  dbo.Employee
)
DELETE FROM CTE WHERE RowNumber > 1

Peter Marshall

Discover endpoints in service fabric

1 min read

Discover endpoints in service fabric

private static void ListEndpoints()
{
    var resolver = ServicePartitionResolver.GetDefault();
    var fabricClient = new FabricClient();
    var apps = fabricClient.QueryManager.GetApplicationListAsync().Result;
    foreach (var app in apps)
    {
        Console.WriteLine($"Discovered application:'{app.ApplicationName}");

        var services = fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName).Result;
        foreach (var service in services)
        {
            Console.WriteLine($"Discovered Service:'{service.ServiceName}");

            var partitions = fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName).Result;
            foreach (var partition in partitions)
            {
                Console.WriteLine($"Discovered Service Partition:'{partition.PartitionInformation.Kind} {partition.PartitionInformation.Id}");


                ServicePartitionKey key;
                switch (partition.PartitionInformation.Kind)
                {
                    case ServicePartitionKind.Singleton:
                        key = ServicePartitionKey.Singleton;
                        break;
                    case ServicePartitionKind.Int64Range:
                        var longKey = (Int64RangePartitionInformation)partition.PartitionInformation;
                        key = new ServicePartitionKey(longKey.LowKey);
                        break;
                    case ServicePartitionKind.Named:
                        var namedKey = (NamedPartitionInformation)partition.PartitionInformation;
                        key = new ServicePartitionKey(namedKey.Name);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("partition.PartitionInformation.Kind");
                }
                var resolved = resolver.ResolveAsync(service.ServiceName, key, CancellationToken.None).Result;
                foreach (var endpoint in resolved.Endpoints)
                {
                    Console.WriteLine($"Discovered Service Endpoint:'{endpoint.Address}");
                }
            }
        }
    }
}

Peter Marshall

DOTNETCORE RUNTIME MISMATCH

1 min read

This issue is resolved here

here

 in the Package Manager Console get the version you need

Install-Package Microsoft.NETCore.App -Version 2.0.5

and do this

    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
in the .proj

Peter Marshall

DOTNET.Core.App blocked by project

1 min read

This issue is resolved here

here

 in the Package Manager Console get the version you need

Install-Package Microsoft.NETCore.App -Version 2.0.5

and do this

    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
in the .proj