Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@otobrglez
otobrglez / Hazelcast.scala
Created July 23, 2025 09:31
Hazelcast client wrapper for Scala with ZIO
import com.hazelcast.client.HazelcastClient
import com.hazelcast.client.config.ClientConfig
import com.hazelcast.core.HazelcastInstance
import com.hazelcast.map.IMap
import zio.*
import scala.reflect.ClassTag
final class Hazelcast private (private val client: HazelcastInstance):
def getMap[K: ClassTag, V: ClassTag](name: String): IMap[K, V] = client.getMap[K, V](name)
@otobrglez
otobrglez / Main.scala
Created July 22, 2025 12:21
Simple recommendation system with Scala
// Oto Brglez - July 2025
// Our entity
final case class Book(title: String)
// Sample data. Books. yey!
val books @ List(programmingInScala, jsGoodParts, _*) = List(
Book("Programming in Scala"),
Book("JavaScript: The Good Parts"),
Book("Designing Data-Intensive Applications"),
@otobrglez
otobrglez / Redis.scala
Created May 21, 2025 08:41
Tiny Redis (Jedis) client wrapper for ZIO with Scala 3.
// Tiny Redis (Jedis) client wrapper for ZIO with Scala 3.
// - Oto Brglez - <[email protected]> - May 2025
import redis.clients.jedis.*, redis.clients.jedis.params.*
import zio.*, zio.ZIO.*
import java.util.List as JavaList
import scala.concurrent.duration.*, scala.jdk.CollectionConverters.*
final case class Redis private (private val pool: JedisPool):
private type Binary = Array[Byte]
@otobrglez
otobrglez / GQL.scala
Created February 26, 2025 10:35
GraphQL in Scala 3
package si.ogrodje.flow.gql
import scala.annotation.targetName
object GQL:
private type Name = String
private type Arguments = Map[Name, Value]
private val emptyArguments: Arguments = Map.empty
private type Fields = List[Field]
private val emptyFields: Fields = List.empty
@otobrglez
otobrglez / EmailStream.scala
Last active November 11, 2024 09:08
A simple stream of emails from IMAP server.
import eu.timepit.refined.auto.autoUnwrap
import jakarta.mail.event.{MessageCountEvent, MessageCountListener}
import jakarta.mail.{Message, Session, Store}
import org.eclipse.angus.mail.imap.{IMAPFolder, SortTerm}
import zio.ZIO.{attempt, logInfo}
import zio.stream.{Stream, ZStream}
import zio.{Chunk, RIO, Scope, Task, ZIO}
import zio.durationInt
final case class MessageID(
@otobrglez
otobrglez / QScheduler.scala
Created July 11, 2024 14:36
Quartz Scheduler with Scala and Cats Effect / FS2
package si.ogrodje.oge.scheduler
import cats.effect.unsafe.implicits.global
import cats.effect.{IO, Resource}
import fs2.Stream
import fs2.concurrent.Topic
import org.quartz.*
import org.quartz.JobBuilder.*
import org.quartz.TriggerBuilder.*
import org.quartz.impl.StdSchedulerFactory
@otobrglez
otobrglez / shell.nix
Created October 4, 2023 21:16
Simple Ruby env
let
pkgs = import <nixpkgs> {};
rubyEnv = pkgs.ruby_3_2.withPackages(p: with p; [
pry
nokogiri
]);
in with pkgs;
mkShell {
@otobrglez
otobrglez / GameService.scala
Created August 24, 2023 11:03
GameService (WebSockets w/ Cats Effect, FS2 and http4s)
package com.pinkstack.tttx
package mk2.services
import mk2.services.Protocol.Connected
import cats.*
import cats.effect.*
import cats.effect.std.Queue
import cats.syntax.all.*
import fs2.Stream
@otobrglez
otobrglez / i-love-ps.ps1
Created April 14, 2023 09:44
Recursively renaming files with PowerShell
# Oto Brglez - <[email protected]>
$folderPath = "dodo-was-here" | Resolve-Path
Get-ChildItem -Path $folderPath -Recurse -File |
ForEach-Object {
$newName = Join-Path (Split-Path $_.FullName) `
-ChildPath ($_.FullName -replace $folderPath,'' -replace '/|\\','-' -replace '^(.)','')
Rename-Item -Path $_.FullName -NewName $newName -Force # -WhatIf
}
@otobrglez
otobrglez / DelayedTaskApp.scala
Created January 30, 2023 11:32
Delayed ZIO tasks with Jesque / Sidekiq and Redis
// Oto Brglez - <[email protected]>
import net.greghaines.jesque.client.{Client as JesqueClient, ClientImpl}
import net.greghaines.jesque.worker.{JobFactory, MapBasedJobFactory, WorkerImpl}
import net.greghaines.jesque.{Config as JesqueConfig, ConfigBuilder, Job as JesqueJob}
import zio.*
import zio.Clock.currentTime
import zio.Console.printLine
import zio.ZIO.{acquireRelease, attempt, blocking, fail, logDebug, logError, logInfo, service, succeed}
import zio.stream.ZStream.fromQueue