This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT index-test | |
{ | |
"settings": { | |
"analysis": { | |
"normalizer": { | |
"my_normalizer": { | |
"type": "custom", | |
"char_filter": [], | |
"filter": ["lowercase", "asciifolding"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run `docker compose up` | |
# If in Windows while running WSL open the powershell and run `wsl -d docker-desktop` then `sysctl -w vm.max_map_count=262144` to increase memory limits | |
# Create an index: `curl -X PUT "https://localhost:9200/test00001?pretty"` | |
# Add test data to the previously created index: `curl -X POST "https://localhost:9200/test00001/_bulk?pretty&refresh" -H "Content-Type: application/x-ndjson" --data-binary @"test-data.json" -u "admin:admin" --insecure` | |
version: '3' | |
services: | |
opensearch-node1: | |
image: opensearchproject/opensearch:latest | |
container_name: opensearch-node1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO.Compression; | |
public static class Gzip | |
{ | |
private static async Task<byte[]> DecompressBytesAsync(byte[] bytes, CancellationToken cancel = default) | |
{ | |
using var inputStream = new MemoryStream(bytes); | |
using var outputStream = new MemoryStream(); | |
await using (var compressionStream = new GZipStream(inputStream, CompressionMode.Decompress)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Manhattan distance between two points is the sum of absolute difference of the coordinates. | |
static int Resolve(int M, int N, int X1, int Y1, int X2, int Y2) | |
{ | |
return Math.Abs(X2 - X1) + Math.Abs(Y2 - Y1); | |
} | |
public static void Main() | |
{ | |
// Define size of 2-D array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.Configure<ApiBehaviorOptions>(options => | |
{ | |
options.InvalidModelStateResponseFactory = actionContext => | |
{ | |
var problemDetails = new ValidationProblemDetails | |
{ | |
Detail = "For big problem!", | |
Title = "Get a big localized solution!", | |
}; | |
return new BadRequestObjectResult(problemDetails); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModelBindingFailureFilterSimple : IActionFilter | |
{ | |
private readonly ILogger _logger; | |
public ModelBindingFailureFilterSimple(ILogger logger) | |
{ | |
_logger = logger; | |
} | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModelBindingFailureFilter : IActionFilter | |
{ | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
if (!context.ModelState.IsValid) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringCalculator | |
{ | |
private const string DefaultDelimiters = ",\n"; | |
public int Add(string numbers) | |
{ | |
if (string.IsNullOrWhiteSpace(numbers)) | |
{ | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @valid BIT | |
DECLARE @geometryWKT NVARCHAR(MAX) | |
DECLARE @geometry GEOMETRY | |
SET @geometryWKT = 'LINESTRING(264424.9652 569222.1755, 264391.5552 569306.8028, 264347.5728 569370.1507, 264279.3844 569496.5162, 264151.5842 569779.2783, 264102.1571 569876.3473, 264064.9039 569909.1248, 264082.4099 569934.902, 264148.7657 569980.9312, 264197.7566 570045.2707, 264264.2537 570126.3715, 264351.5345 570242.1204, 264461.6298 570397.3514, 264508.7931 570471.0041, 264540.9409 570500.789, 264585.7437 570474.7547, 264663.5564 570446.4651, 264710.7298 570389.8719, 264861.704 570149.3973, 264802.3649 570104.5195, 264579.9936 570005.1748, 264774.1915 569593.5737, 264627.7661 569530.0202, 264604.2309 569589.8227, 264583.3815 569693.6588, 264564.4047 569744.5479, 264545.5456 569781.413, 264516.4291 569824.5021, 264497.7144 569849.1252, 264385.1763 569780.4476, 264471.0827 569602.4976, 264410.3238 569572.5101, 264548.9528 569291.7813, 264424.9652 569222.1755)'-- Test faulty value | |
SET @valid = 1 | |
BEGIN TRY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IValidatable | |
{ | |
(IEnumerable<string> results, bool valid) Validate(); | |
} |
NewerOlder