Search This Blog

Saturday, 5 November 2022

Elasticsearch Reindex / migration

ElasticSearch: Zero downtime reindexing
ElasticSearch has a solution to the problem, index aliases. The alias is like a symbolic link which can point to one or more indices. It gives us the flexibility to create a new index in the background and making the changes in a way that is almost unnoticeable to the application.

Friday, 4 November 2022

Elasticsearch

Elasticsearch is the distributed search and analytics engine at the heart of the Elastic Stack.

Reference

Thursday, 3 November 2022

AWS OpenSearch Deployment Best Practices

  • 3 Dedicated Master Nodes
  • Offload cluster managment task like health checks and maintain routing and cluster state.

  • Data Nodes deployed in multiples of 3
  • Store the data in shards and perform searches, query request, and CRUD operations.

  • Deploy across 3AZs
  • Destribute the data nodes equally across 3 AZs for the hightest availability.

Saturday, 22 October 2022

Validate Subsequence

List array = new List() { 5, 1, 22, 25, 6, -1, 8, 10 };
List sequence = new List { 1, 6, -1, 10 };
bool isValid = IsValidSubsequence(array, sequence);
Console.WriteLine(isValid);
//Expected Output: true
      

Solution 1.
public static bool IsValidSubsequence0(List array, List sequence)
{
    int seqIdx = 0;
    for (int arrIdx = 0; arrIdx < array.Count && seqIdx < sequence.Count; arrIdx++)
    {
        if (array[arrIdx] == sequence[seqIdx])
        {
            seqIdx++;
        }
    }
    return seqIdx == sequence.Count;
}
      

Test case

Test Case 1
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 10]
}
Test Case 2
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10]
}
Test Case 3
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 6, -1, 8, 10]
}
Test Case 4
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [22, 25, 6]
}
Test Case 5
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, 10]
}
Test Case 6
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 10]
}
Test Case 7
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, -1, 8, 10]
}
Test Case 8
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [25]
}
Test Case 9
{
  "array": [1, 1, 1, 1, 1],
  "sequence": [1, 1, 1]
}
Test Case 10
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10, 12]
}
Test Case 11
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [4, 5, 1, 22, 25, 6, -1, 8, 10]
}
Test Case 12
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 23, 6, -1, 8, 10]
}
Test Case 13
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 22, 25, 6, -1, 8, 10]
}
Test Case 14
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 22, 6, -1, 8, 10]
}
Test Case 15
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -1]
}
Test Case 16
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -1, 10]
}
Test Case 17
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, -2]
}
Test Case 18
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [26]
}
Test Case 19
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 25, 22, 6, -1, 8, 10]
}
Test Case 20
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 26, 22, 8]
}
Test Case 21
{
  "array": [1, 1, 6, 1],
  "sequence": [1, 1, 1, 6]
}
Test Case 22
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 10, 11, 11, 11, 11]
}
Test Case 23
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [5, 1, 22, 25, 6, -1, 8, 10, 10]
}
Test Case 24
{
  "array": [5, 1, 22, 25, 6, -1, 8, 10],
  "sequence": [1, 6, -1, 5]
}

Multi String Search

string bigstring = "this is a big string";
string[] smallstrings = { "this", "yo", "is", "a", "bigger", "string", "kappa" };

List result = MultistringSearch(bigstring, smallstrings);
foreach (bool b in result)
{
    Console.WriteLine(b);
}

//Expected output: [true, false, true, true, false, true, false]
      

Solution 1.
public static List MultistringSearch(string bigstring, string[] smallstrings)
{
    List result = new List();
    foreach (string smalString in smallstrings)
    {
        result.Add(isContain(smalString, bigstring));
    }
    return result;
}


public static bool isContain(string smallString, string bigString)
{
    for (int i = 0; i <= bigString.Length - smallString.Length; i++)
    {
        int j;
        for (j = 0; j < smallString.Length; j++)
        {
            if (bigString[i + j] != smallString[j])
            {
                break;
            }
        }
        if (j == smallString.Length)
        {
            return true;
        }
    }
    return false;
}
      

Solution 2:
public static bool IsContain(string smallString, string bigString)
{
    for (int i = 0; i < bigString.Length; i++)
    {
        if (i + smallString.Length > bigString.Length)
        {
            break;
        }

        if(IsContain(smallString, bigString, i))
        {
            return true;
        }
    }
    return false;
}

private static bool IsContain(string smallString, string bigString, int startIdx)
{
    int leftBigidx = startIdx;
    int rightBigIdx = startIdx + smallString.Length - 1;
    int leftSmallIdx = 0;
    int rightSmallIdx = smallString.Length - 1;
    while (leftBigidx <= rightBigIdx)
    {
        if (bigString[leftBigidx] != smallString[leftSmallIdx] ||
                bigString[rightBigIdx] != smallString[rightSmallIdx])
        {
            return false;
        }
        leftBigidx++;
        rightBigIdx--;
        leftSmallIdx++;
        rightSmallIdx--;
    }
    return true;
}

Test case

Test Case 1
{
  "bigString": "this is a big string",
  "smallStrings": ["this", "yo", "is", "a", "bigger", "string", "kappa"]
}

Test Case 2
{
  "bigString": "abcdefghijklmnopqrstuvwxyz",
  "smallStrings": ["abc", "mnopqr", "wyz", "no", "e", "tuuv"]
}

Test Case 3
{
  "bigString": "abcdefghijklmnopqrstuvwxyz",
  "smallStrings": ["abcdefghijklmnopqrstuvwxyz", "abc", "j", "mnopqr", "pqrstuvwxyz", "xyzz", "defh"]
}

Test Case 4
{
  "bigString": "hj!)!%Hj1jh8f1985n!)51",
  "smallStrings": ["%Hj7", "8f198", "!)5", "!)!", "!!", "jh81", "j181hf"]
}

Test Case 5
{
  "bigString": "Mary goes to the shopping center every week.",
  "smallStrings": ["to", "Mary", "centers", "shop", "shopping", "string", "kappa"]
}

Test Case 6
{
  "bigString": "adcb akfkw afnmc fkadn vkaca jdaf dacb cdba cbda",
  "smallStrings": ["abcd", "acbd", "adbc", "dabc", "cbda", "cabd", "cdab"]
}

Test Case 7
{
  "bigString": "test testing testings tests testers test-takers",
  "smallStrings": ["tests", "testatk", "testiing", "trsatii", "test-taker", "test"]
}

Test Case 8
{
  "bigString": "ndbajwhfawkjljkfaopwdlaawjk dawkj awjkawkfjhkawk ahjwkjad jadfljawd",
  "smallStrings": ["abc", "akwbc", "awbc", "abafac", "ajjfbc", "abac", "jadfl"]
}

Test Case 9
{
  "bigString": "Is this particular test going to pass or is it going to fail? That is the question.",
  "smallStrings": ["that", "the", "questions", "goes", "mountain", "passes", "passed", "going", "is"]
}

Test Case 10
{
  "bigString": "Everything in this test should fail.",
  "smallStrings": ["everything", "inn", "that", "testers", "shall", "failure"]
}

Test Case 11
{
  "bigString": "this ain't a big string",
  "smallStrings": ["this", "is", "yo", "a", "bigger"]
}

Test Case 12
{
  "bigString": "bbbabb",
  "smallStrings": ["bbabb"]
}

Two Number Sum

int[] array = { 1, 2, 4, 5, 7, 8, 9, 6 };
int targetSum = 10;
int[] expectedResult = TwoNumberSum_Solution0(array, targetSum);

foreach (int item in expectedResult)
{
	Console.WriteLine(item);
}
      

Solution 1.
public static int[] TwoNumberSum_Solution0(int[] array, int targetSum)
{

    for (int i = 0; i < array.Length - 1; i++)
    {
        int firstNum = array[i];
        for (int j = i + 1; j < array.Length; j++)
        {
            int secondNum = array[j];
            if (firstNum + secondNum == targetSum)
            {
                return new int[] { array[i], array[j] };
            }
        }
    }
    return new int[0];
}
      

Solution 2
//using System.Collections.Generic;

public static int[] TwoNumberSum(int[] array, int targetSum)
{
    HashSet visited = new HashSet();

    foreach (int num in array)
    {
        int expectedResult = targetSum - num;

        if (visited.Contains(expectedResult))
        {
            return new int[] { expectedResult, num };
        }
        else
        {
            visited.Add(num);
        }
    }
    return new int[0];
}

Test case

{
  "array": [4, 5, -4, 8, 12, 1, -2, 6],
  "targetSum": 10
}

{
  "array": [4, 6],
  "targetSum": 10
}

{
  "array": [4, 6, 1],
  "targetSum": 5
}

{
  "array": [4, 6, 1, -3],
  "targetSum": 3
}

{
  "array": [1, 2, 3, 4, 5, 6, 7, 8, 9],
  "targetSum": 17
}

{
  "array": [1, 2, 3, 4, 5, 6, 7, 8, 9, 15],
  "targetSum": 18
}

{
  "array": [-7, -5, -3, -1, 0, 1, 3, 5, 7],
  "targetSum": -5
}

{
  "array": [-21, 301, 12, 4, 65, 56, 210, 356, 9, -47],
  "targetSum": 163
}

{
  "array": [-21, 301, 12, 4, 65, 56, 210, 356, 9, -47],
  "targetSum": 164
}

{
  "array": [3, 5, -4, 8, 11, 1, -1, 6],
  "targetSum": 15
}

{
  "array": [14],
  "targetSum": 15
}

{
  "array": [15],
  "targetSum": 15
}

Thursday, 20 October 2022

The Ultimate Live Testing Tool for .NET

ncrunch.net See real-time test results and metrics inline, as you code.

Reference

Single Entity API can perform Bulk operation using Postman

You can use data files to pass Postman sets of values to use in a collection run. By selecting a JSON or CSV data file in the Collection Runner, you can test your API requests with multiple values as part of a single run.

Friday, 7 October 2022

curl

command line tool and library for transferring data with URLs.

What's curl used for?

curl is used in command lines tool or scripts to transfer data.
URL based data transfer
Simple usage for all HTTP verbs
Used in applications that affect billions of users daily.

HTTP Methods With curl

Every HTTP request contains a method. The most commonly used methods are GET, POST, PUT and DELETE.

GET

curl -v https://www.w3schools.com/angular/customers.php

output
C:\curl\bin>curl -g https://www.w3schools.com/angular/customers.php
{
"records":[
{"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
{"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
{"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
{"Name":"Around the Horn","City":"London","Country":"UK"},
{"Name":"B's Beverages","City":"London","Country":"UK"},
{"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
{"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
{"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"},
{"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
{"Name":"Bon app'","City":"Marseille","Country":"France"},
{"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
{"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
{"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
{"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
{"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
]
}
C:\curl\bin>
        

Format JSON!

curl -g https://www.w3schools.com/angular/customers.php | json

  • Download and install NodeJS from its official homepage https://nodejs.org/en/.
  • cmd> npm install -g jsontool

Elasticsearch - Nodes, clusters, and shards

Elastic Stack Video - Load your gun in short time.   Beginner's Crash Course to Ela...

Recent Post