How to compare Go errors

Declaring an error, and comparing it with ‘==‘ (as in err == myPkg.ErrTokenExpired) is no longer the best practice with Go 1.13 (Q3 2019) The release notes mentions: Go 1.13 contains support for error wrapping, as first proposed in the Error Values proposal and discussed on the associated issue. An error e can wrap another … Read more

Extract the difference between two strings in Java

google-diff-match-patch The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text. Diff: Compare two blocks of plain text and efficiently return a list of differences. Match: Given a search string, find its best fuzzy match in a block of plain text. Weighted for both accuracy and location. … Read more

How to compare two dates along with time in java

Since Date implements Comparable<Date>, it is as easy as: date1.compareTo(date2); As the Comparable contract stipulates, it will return a negative integer/zero/positive integer if date1 is considered less than/the same as/greater than date2 respectively (ie, before/same/after in this case). Note that Date has also .after() and .before() methods which will return booleans instead.

Query comparing dates in SQL

Instead of ‘2013-04-12’ whose meaning depends on the local culture, use ‘20130412’ which is recognized as the culture invariant format. If you want to compare with December 4th, you should write ‘20131204’. If you want to compare with April 12th, you should write ‘20130412’. The article Write International Transact-SQL Statements from SQL Server’s documentation explains … Read more

How does one compare one image to another to see if they are similar by a certain percentage, on the iPhone?

As a quick, simple algorithm, I’d suggest iterating through about 1% of the pixels in each image and either comparing them directly against each other or keeping a running average and then comparing the two average color values at the end. You can look at this answer for an idea of how to determine the … Read more

Compare 2 JSON objects [duplicate]

Simply parsing the JSON and comparing the two objects is not enough because it wouldn’t be the exact same object references (but might be the same values). You need to do a deep equals. From http://threebit.net/mail-archive/rails-spinoffs/msg06156.html – which seems the use jQuery. Object.extend(Object, { deepEquals: function(o1, o2) { var k1 = Object.keys(o1).sort(); var k2 = … Read more

Compare version strings in groovy

This appears to work String mostRecentVersion(List versions) { def sorted = versions.sort(false) { a, b -> List verA = a.tokenize(‘.’) List verB = b.tokenize(‘.’) def commonIndices = Math.min(verA.size(), verB.size()) for (int i = 0; i < commonIndices; ++i) { def numA = verA[i].toInteger() def numB = verB[i].toInteger() if (numA != numB) { return numA <=> … Read more