Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar

Oto Brglez otobrglez

View GitHub Profile
otobrglez / shell.nix
Created October 4, 2023 21:16
Simple Ruby env
View shell.nix
pkgs = import <nixpkgs> {};
rubyEnv = pkgs.ruby_3_2.withPackages(p: with p; [
in with pkgs;
mkShell {
otobrglez / GameService.scala
Created August 24, 2023 11:03
GameService (WebSockets w/ Cats Effect, FS2 and http4s)
View GameService.scala
package com.pinkstack.tttx
import cats.*
import cats.effect.*
import cats.effect.std.Queue
import cats.syntax.all.*
import fs2.Stream
otobrglez / i-love-ps.ps1
Created April 14, 2023 09:44
Recursively renaming files with PowerShell
View i-love-ps.ps1
# Oto Brglez - <>
$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 / DelayedTaskApp.scala
Created January 30, 2023 11:32
Delayed ZIO tasks with Jesque / Sidekiq and Redis
View DelayedTaskApp.scala
// Oto Brglez - <>
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}
View out.txt
~/Projects/compression-puzzle   feature/red-language ●  nix-env -iA
installing 'red-0.6.4'
error: Package ‘red-0.6.4’ in /nix/store/02jzg4iiafapgb2p77aspm6ama87qp5y-nixpkgs-22.05pre338661.3c52ea8c921/nixpkgs/pkgs/development/interpreters/red/default.nix:81 is not supported on ‘x86_64-darwin’, refusing to evaluate.
a) To temporarily allow packages that are unsupported for this system, you can use an environment variable
for a single invocation of the nix tools.
b) For `nixos-rebuild` you can set
otobrglez / puzzle.js
Created January 28, 2022 12:51
Word sequence puzzle
View puzzle.js
const assert = require('assert');
const sequence = (string) => string.split(/(?<=(.))(?!\1|$)/g)
.filter((_, i) => !(i % 2))
.map((c) => [c.length, c[0]])
.flatMap((c) => c)
otobrglez / changeswithkey.scala
Created November 12, 2021 20:36
Detecting "addition" or "change" within two lists.
View changeswithkey.scala
import java.util.UUID
sealed trait Change[V] extends Product { val value: V }
final case class Added[V](value: V) extends Change[V]
final case class Updated[V](value: V, prev: V) extends Change[V]
def changesWithKey[T, K](previous: Array[T], current: Array[T])
(implicit key: T => K): Array[Change[T]] = {
val updates: Array[Change[T]] = for {
p <- previous; c <- current
otobrglez / Main.scala
Created September 29, 2021 10:00
Experimenting with Monoids and Validated
View Main.scala
package com.pollpass.experimental
object Example1 {
def run(): Unit = {
type Checker = Char => Boolean
val isBraille: Checker = _ => false
otobrglez / SimpleCache.scala
Created September 20, 2021 21:05
Playing around with caching with Cats Effect
View SimpleCache.scala
final case class SimpleCache() {
private def tempDir(key: String): IO[Path] =
IO.fromTry(Try(System.getProperty("")).map(s => Paths.get(s, key)))
private def serialize[V](path: Path)(v: V): Unit = {
val out = new ObjectOutputStream(new FileOutputStream(path.toString))
otobrglez / Server2.scala
Last active September 16, 2021 12:07
Booting Akka with Cats Effect
View Server2.scala
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import cats.effect.{IO, IOApp, Resource}
import cats.syntax.all.catsSyntaxMonadErrorRethrow
import ch.megard.akka.http.cors.scaladsl.CorsDirectives.cors
import com.typesafe.scalalogging.LazyLogging
object Boot extends IOApp.Simple with LazyLogging {