How can I pull data out of an Option for independent use?

if let Some(origin) = resp.get(“origin”) { // use origin } If you can guarantee that it’s impossible for the value to be None, then you can use: let origin = resp.get(“origin”).unwrap(); Or: let origin = resp.get(“origin”).expect(“This shouldn’t be possible!”); And, since your function returns a Result: let origin = resp.get(“origin”).ok_or(“This shouldn’t be possible!”)?; Or with … Read more

Scala: short form of pattern matching that returns Boolean

This is exactly why I wrote these functions, which are apparently impressively obscure since nobody has mentioned them. scala> import PartialFunction._ import PartialFunction._ scala> cond(“abc”) { case “def” => true } res0: Boolean = false scala> condOpt(“abc”) { case x if x.length == 3 => x + x } res1: Option[java.lang.String] = Some(abcabc) scala> condOpt(“abc”) … Read more

How to use SIFT algorithm to compute how similar two images are?

First, aren’t you supposed to be using vl_sift instead of sift? Second, you can use SIFT feature matching to find correspondences in the two images. Here’s some sample code: I = imread(‘p1.jpg’); J = imread(‘p2.jpg’); I = single(rgb2gray(I)); % Conversion to single is recommended J = single(rgb2gray(J)); % in the documentation [F1 D1] = vl_sift(I); … Read more

Search for string allowing for one mismatch in any location of the string

Before you read on, have you looked at biopython? It appears that you want to find approximate matches with one substitution error, and zero insertion/deletion errors i.e. a Hamming distance of 1. If you have a Hamming distance match function (see e.g. the link provided by Ignacio), you could use it like this to do … Read more

Haskell GHC: what is the time complexity of a pattern match with N constructors?

A jump table is used, making the pattern-match a constant time operation. Unfortunately I’m unable to find an up-to-date citation for this, although this page mentions the implementation of Cmm-level switch statements as jump tables, and this old tagging design document uses a case on a Bool as an example, producing a jump table.

Case insensitive search in Mongo

You can Use $options => i for case insensitive search. Giving some possible examples required for string match. Exact case insensitive string db.collection.find({name:{‘$regex’ : ‘^string$’, ‘$options’ : ‘i’}}) Contains string db.collection.find({name:{‘$regex’ : ‘string’, ‘$options’ : ‘i’}}) Start with string db.collection.find({name:{‘$regex’ : ‘^string’, ‘$options’ : ‘i’}}) End with string db.collection.find({name:{‘$regex’ : ‘string$’, ‘$options’ : ‘i’}}) Doesn’t … Read more

Ant path style patterns

Ant-style path patterns matching in spring-framework: The mapping matches URLs using the following rules: ? matches one character * matches zero or more characters ** matches zero or more ‘directories’ in a path {spring:[a-z]+} matches the regexp [a-z]+ as a path variable named “spring” Some examples: com/t?st.jsp – matches com/test.jsp but also com/tast.jsp or com/txst.jsp … Read more