Skip to content

Instantly share code, notes, and snippets.

View gstraymond's full-sized avatar

Guillaume Saint-Raymond gstraymond

View GitHub Profile
@gstraymond
gstraymond / ZioMongoSupport.scala
Last active February 16, 2023 16:55
Converts a MongoDB observable to a ZIO stream
import org.mongodb.scala.{Observable, Observer}
import zio.stream._
import zio.{IO, ZIO}
object ZioMongoSupport {
implicit class ObsConverter[T](observable: Observable[T]) {
def toStream: Stream[Throwable, T] = toStream(identity)
@gstraymond
gstraymond / LongExtensions.scala
Created July 5, 2018 09:48
BytesLengthConverter
import java.lang.Math._
object LongExtensions {
implicit class BytesLengthConverter(val bytes: Long) extends AnyVal {
def humanReadableByteCount(si: Boolean = false): String = {
val unit = if (si) 1000 else 1024
if (bytes < unit) bytes + "B"
else {
val exp = (log(bytes) / log(unit)).toInt
@gstraymond
gstraymond / Trie.scala
Last active February 15, 2018 20:15
Scala Trie
case class Trie(char: Char,
children: Seq[Trie] = Nil,
indices: Seq[Int] = Nil) {
def add(word: String,
index: Int): Trie = {
val updatedChildren = word.toSeq match {
case Seq(head) =>
update(head) {
Trie(head, indices = Seq(index))
@gstraymond
gstraymond / Trie.kt
Created February 14, 2018 18:23
Kotlin Trie
package fr.gstraymond.search
data class Trie(private val char: Char,
private val indices: MutableList<Int> = mutableListOf(),
private val children: MutableList<Trie> = mutableListOf()) {
fun add(word: String,
index: Int) {
val first = word.first()
val trie = findOrCreate(first)
@gstraymond
gstraymond / HomeController.scala
Last active January 5, 2017 09:59
play mongo bson - HomeController.scala
import ai.snips.bsonmacros.DatabaseContext
import models.{SampleData, SampleDataDAO}
import org.mongodb.scala.bson.BsonObjectId
import play.api.Logger
import play.api.mvc._
import scala.concurrent.ExecutionContext
class HomeController @Inject()(sampleDataDAO: SampleDataDAO,
dbContext: DatabaseContext)
@gstraymond
gstraymond / SampleDataDAO.scala
Last active January 5, 2017 09:45
play mongo bson - SampleDataDAO.scala
import javax.inject.{Inject, Singleton}
import ai.snips.bsonmacros.{BaseDAO, CodecGen, DatabaseContext}
import scala.concurrent.ExecutionContext
@Singleton
class SampleDataDAO @Inject()(val dbContext: DatabaseContext)
(implicit ec: ExecutionContext) extends BaseDAO[SampleData] {
// generating once a codec for you case class and putting in the registry
CodecGen[SampleData](dbContext.codecRegistry)
@gstraymond
gstraymond / SampleData.scala
Created January 4, 2017 16:48
play mongo bson - SampleData.scala
import org.mongodb.scala.bson.BsonObjectId
case class SampleData(_id: BsonObjectId,
string: String,
boolean: Boolean,
int: Int)
@gstraymond
gstraymond / build.sbt
Last active January 5, 2017 09:46
play mongo bson - build.sbt
resolvers ++= Seq(
 …
 "Sonatype OSS" at "https://oss.sonatype.org/content/groups/public"
)
libraryDependencies ++= Seq(
 …
 "ai.snips" %% "play-mongo-bson" % "0.2",
 "org.mongodb.scala" %% "mongo-scala-driver" % "1.1.1"
)
// ==UserScript==
// @name Jenkins
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://jenkins2.snips.ai/view/Monitor/
// @grant none
// ==/UserScript==
i#!/usr/bin/env zsh
# in fino veritas
# Borrowing shamelessly from these oh-my-zsh themes:
# fino-time
# pure
# https://gist.github.com/smileart/3750104
# Set required options