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 / Article.rb
Created July 12, 2011 20:51
Finding related articles using Jaccard index and tags
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t
@otobrglez
otobrglez / jaccard_recommendation.rb
Last active April 30, 2026 00:10
Simple recommendation system written in Ruby based on Jaccard index.
# Simple Recommendation Engine in Ruby
# Visit: http://otobrglez.opalab.com
# Author: Oto Brglez <otobrglez@gmail.com>
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@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 - <otobrglez@gmail.com> - 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]
id: 001-all-question-types
title: All question types
optionSets:
gender:
- { value: "female", label: "Female" }
- { value: "male", label: "Male" }
- { value: "other", label: "Other" }
- { value: "prefer_not", label: "Prefer not to say" }
id: 002-micro
title: Simple example
optionSets:
shirtSizes:
- { value: "S", label: "Small" }
- { value: "M", label: "Medium" }
- { value: "L", label: "Large" }
- { value: "XL", label: "Extra Large" }
@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 / 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