Skip to content

Instantly share code, notes, and snippets.

@y2k2mt
y2k2mt / minhash.cr
Created June 30, 2021 13:05
Minwise hashing scheme implementation in crystal
module Minhash
def random_vector
r = Random.new
(1..26).map do |_|
r.next_int
end
end
def generate_hash
rand = random_vector()
@y2k2mt
y2k2mt / keybase.md
Last active September 13, 2019 10:55
keybase.md

Keybase proof

I hereby claim:

  • I am y2k2mt on github.
  • I am y2k2mt (https://keybase.io/y2k2mt) on keybase.
  • I have a public key ASC1jiu_OOdswXEAe3RKmAN0uqmFMUZmY4-4MwjoS07QZgo

To claim this, I am signing this object:

require "try"
module Try(T)
def self.sequence(&f : -> Array(Try(T))) : Try(Array(T))
Success(Array(T)).new(yield.reduce([] of T) { |acc, t|
acc << t.get
})
rescue e
Failure(Array(T)).new e
end
@y2k2mt
y2k2mt / FlowOpsForComprehension.scala
Last active February 19, 2017 15:11
Flow and Source for for-comprehension
import akka.stream.{Graph,SourceShape}
import akka.stream.scaladsl.{Flow, Source,FlowOps}
object FlowOpsConcatForComprehension {
implicit class FlowFlatMapConcat[I,O,N,V](private val flow:Flow[I,O,V]) extends AnyVal {
def flatMap(f: O => Graph[SourceShape[N],V]) : Flow[I,N,V] = flow.flatMapConcat(f)
}
implicit class SourceFlatMapConcat[O,N,V](private val source:Source[O,N]) extends AnyVal {
def flatMap[T](f: O => Graph[SourceShape[T],V]) : Source[T,N] = source.flatMapConcat(f)
}