DEV Community

manuel
manuel

Posted on • Originally published at defer.cc on

1 1

Shamazing

Find the longest string or integer in a SHA1 Hash (or whatever). It’s just sha-mazing and without any sense :)

package shamazing
import (
   "regexp"
   "strconv"
)

// FindLongestString will retrieve a string like a SHA1, MD5 or whatever
// and return the longest string (first one)
func FindLongestString(str string) string {
   var re = regexp.MustCompile("[a-zA-Z]+")
   var values = re.FindAll([]byte(str), -1)
   return string(findLongest(values))
}
// FindLongestInteger will retrieve a string like a SHA1, MD5 or whatever
// and return longest integer (first one)
func FindLongestInteger(str string) (int64, error) {
   var re = regexp.MustCompile("[0-9]+")
   var values = re.FindAll([]byte(str), -1)
   var max = findLongest(values)
   var a, err = strconv.Atoi(string(max))
   if err != nil {
      return 0, err
   }
   return int64(a), nil
}
func findLongest(values [][]byte) []byte {
   var max []byte
   for _, value := range values {
      if len(value) > len(max) {
         max = value
      }
   }
   return max
}

Enter fullscreen mode Exit fullscreen mode

shamazing on GitHub

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more