Skip to content

Instantly share code, notes, and snippets.

@igor-vovk
igor-vovk / ref.scala
Created September 24, 2023 12:52
Obtaining cats.effect.Ref that is always set to a let element of fs2.Stream
/**
* Returns a resource that contains a ref set to the last element of the stream.
*/
def streamRef[F[_] : Async, A](stream: Stream[F, A], default: A): Resource[F, RefSource[F, A]] = {
val ri = for
ref <- Ref.of(default)
interrupt <- SignallingRef.of(false)
_ <- Async[F].start {
stream
class KlinesRepositorySpec extends UnitSpec with TimescaleSuite(Some("/database.sql")) {
"KlinesRepository" should "return last klines" in {
withTimescale { timescale =>
val repository = new KlinesRepository(timescale.xa)
val date = LocalDate.of(2021, 1, 1)
.atStartOfDay()
.atOffset(ZoneOffset.UTC)
@igor-vovk
igor-vovk / example_di.scala
Created June 25, 2023 06:15
Dependency Injection with cats-effect Resource Monad
import cats.effect.*
import cats.effect.unsafe.IORuntime
import org.postgresql.core.ConnectionFactory
// repository, two services, and api:
class Repository(conn: ConnectionFactory) {}
class ServiceA(repo: Repository) {}
class ServiceB(repo: Repository) {}
directories:
domains
targets:
//domains/...
# //...:all
additional_languages:
# Uncomment any additional languages you want supported
# android
package com.x2sy.logserver
import java.io.File
import com.typesafe.config.Config
import com.typesafe.config.ConfigException.BadValue
import net.ceedubs.ficus.readers.ValueReader
trait FicusFileReader {
@igor-vovk
igor-vovk / docker-compose.yml
Created January 19, 2016 14:27
Docker Compose Consul cluster
consul:
image: progrium/consul:latest
# net: host
ports:
- "8400:8400"
- "8500:8500"
command: "-server -bootstrap -ui-dir /ui"
registrator:
command: -resync 30 -internal consul://consul:8500
image: gliderlabs/registrator:latest
@igor-vovk
igor-vovk / osx.sh
Created April 24, 2015 09:14
OSX settings
# Gratuitously stolen from @mathiasbynens
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Disable menu bar transparency
defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
# Expand print panel by default
@igor-vovk
igor-vovk / gist:5890608
Created June 29, 2013 10:03
Singleton to instantiate Neo4j
object Database extends Logging {
private var _instance: GraphDatabaseService = null
def instance: GraphDatabaseService = {
if (null == _instance) {
synchronized {
if (null == _instance) {
_instance = initDatabase()
}