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 / Main.scala
Created September 29, 2021 10:00
Experimenting with Monoids and Validated
package com.pollpass.experimental
import cats.data.ValidatedNec
object Example1 {
def run(): Unit = {
type Checker = Char => Boolean
val isBraille: Checker = _ => false
@otobrglez
otobrglez / SimpleCache.scala
Created September 20, 2021 21:05
Playing around with caching with Cats Effect
final case class SimpleCache() {
private def tempDir(key: String): IO[Path] =
IO.fromTry(Try(System.getProperty("java.io.tmpdir")).map(s => Paths.get(s, key)))
private def serialize[V](path: Path)(v: V): Unit = {
val out = new ObjectOutputStream(new FileOutputStream(path.toString))
out.writeObject(v)
out.close()
}
@otobrglez
otobrglez / Server2.scala
Last active September 16, 2021 12:07
Booting Akka with Cats Effect
import akka.actor.ActorSystem
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.google.cloud.texttospeech.v1.TextToSpeechClient
import com.typesafe.scalalogging.LazyLogging
object Boot extends IOApp.Simple with LazyLogging {
@otobrglez
otobrglez / david-should-but-us-beer.js
Created September 1, 2021 13:01
Poking around with regex
const assert = require('assert');
describe('should-work', () => {
it('passes', () => {
const enhanceURL = (url) =>
url.replace(/https/g, 'http').replace(/^http:\/\/([a-zA-Z0-9]+)\./gm,
(m, p1) => m.replace(p1, 'admin--' + p1))
.replace(/\/(?=[^\/]*$)/, '/api/')
+ '?_content_format=json'
@otobrglez
otobrglez / HelloWorld.scala
Last active August 2, 2021 13:22
Exploring and visualising Scala 2.* compilation phases
object HelloWorld extends App {
val add2: Int => Int = _ + 2
println(s"Hello world! This is Scala. ${add2(40)}")
}
@otobrglez
otobrglez / 00-parser-HelloWorld2.scala
Created July 26, 2021 21:22
HelloWorld2 (jcdang example)
[[syntax trees at end of parser]] // HelloWorld2.scala
package <empty> {
object HelloWorld2 extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
def main(args: Array[String]): Unit = {
val add2: _root_.scala.Function1[Int, Int] = ((x$1) => x$1.$plus(2));
println(StringContext("Hello world! This is Scala. ", "").s(add2(40)))
@otobrglez
otobrglez / spawn_vim.scala
Last active May 28, 2021 21:30
Spawning VIM
import cats.effect._
import cats.implicits._
import java.io.PrintWriter
import java.nio.file.Path
object Editor {
type Editor = String
sealed trait EditorError
@otobrglez
otobrglez / Main.scala
Last active May 27, 2021 06:35
Exploring Cats Effect and sttp
// Oto Brglez - <otobrglez@gmail.com> - May 2021
package com.pinkstack.gen4
import cats.effect.implicits._
import cats.effect.{ExitCode, IO, IOApp}
import cats.implicits._
import com.pinkstack.gen1.CoinMarketCap.Implicits._
import com.pinkstack.gen1.CoinMarketCap._
import sttp.client3._
import sttp.client3.circe._
@otobrglez
otobrglez / Main.scala
Created May 20, 2021 23:00
Late Night Programming Session 001 - Markov Chains in Scala 🚀 🌕
// Author: Oto Brglez
// - https://www.twitch.tv/otobrglez
// - https://twitter.com/otobrglez
import org.apache.commons.math3.distribution.EnumeratedDistribution
import org.apache.commons.math3.util.Pair
import scala.jdk.CollectionConverters._
import scala.util.Random
object Generator {
@otobrglez
otobrglez / HttpClient.scala
Created April 29, 2021 08:18
HttpClient that uses Scala Cats, Circe and some caching for Akka and Akka Http.
/*
* HttpClient that uses Scala Cats, Circe and some caching for Akka and Akka Http.
* Author: Oto Brglez
*/
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.unmarshalling.Unmarshal
import better.files.Dsl._