Javascript fuzzy search that makes sense

I tried using existing fuzzy libraries like fuse.js and also found them to be terrible, so I wrote one which behaves basically like sublime’s search. https://github.com/farzher/fuzzysort The only typo it allows is a transpose. It’s pretty solid (1k stars, 0 issues), very fast, and handles your case easily: fuzzysort.go(‘int’, [‘international’, ‘splint’, ‘tinder’]) // [{highlighted: ‘*int*ernational’, … Read more

How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?

Approach #1 This approach derives from a solution to Implement Matlab’s im2col ‘sliding’ in python that was designed to rearrange sliding blocks from a 2D array into columns. Thus, to solve our case here, those sliding blocks from field_array could be stacked as columns and compared against column vector version of match_array. Here’s a formal … Read more

Find common prefix of strings

string[] xs = new[] { “h:/a/b/c”, “h:/a/b/d”, “h:/a/b/e”, “h:/a/c” }; string x = string.Join(“https://stackoverflow.com/”, xs.Select(s => s.Split(“https://stackoverflow.com/”).AsEnumerable()) .Transpose() .TakeWhile(s => s.All(d => d == s.First())) .Select(s => s.First())); with public static IEnumerable<IEnumerable<T>> Transpose<T>( this IEnumerable<IEnumerable<T>> source) { var enumerators = source.Select(e => e.GetEnumerator()).ToArray(); try { while (enumerators.All(e => e.MoveNext())) { yield return enumerators.Select(e => e.Current).ToArray(); … Read more

POSIX character class does not work in base R regex

Although stringr ICU regex engines supports bare POSIX character classes in the pattern, in base R regex flavors (both PCRE (perl=TRUE) and TRE), POSIX character classes must be inside bracket expressions. [:alnum:] -> [[:alnum:]]. x <- c(“AZaz09 y AZaz09”, “ĄŻaz09 y AZŁł09”, “26 de Marzo y Pareyra de la Luz”) grepl(“[[:alnum:][:blank:]]+[[:blank:]][yY][[:blank:]][[:alnum:][:blank:]]+”, x) ## => [1] … Read more

Escape function for regular expression or LIKE patterns

To address the question at the top: Assuming standard_conforming_strings = on, like it’s default since Postgres 9.1. Regular expression escape function Let’s start with a complete list of characters with special meaning in regular expression patterns: !$()*+.:<=>?[\]^{|}- Wrapped in a bracket expression most of them lose their special meaning – with a few exceptions: – … Read more