Skip to content

Instantly share code, notes, and snippets.

Avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
View out.txt
~/Projects/compression-puzzle   feature/red-language ●  nix-env -iA nixpkgs.red
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.
$ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1
b) For `nixos-rebuild` you can set
@otobrglez
otobrglez / puzzle.js
Created Jan 28, 2022
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)
.join('')
assert.equal(sequence("AAABBAAC"),"3A2B2A1C")
@otobrglez
otobrglez / changeswithkey.scala
Created Nov 12, 2021
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
otobrglez / Main.scala
Created Sep 29, 2021
Experimenting with Monoids and Validated
View Main.scala
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 Sep 20, 2021
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("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 Sep 16, 2021
Booting Akka with Cats Effect
View Server2.scala
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 {
View david-should-but-us-beer.js
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 / 00-parser-HelloWorld2.scala
Created Jul 26, 2021
HelloWorld2 (jcdang example)
View 00-parser-HelloWorld2.scala
[[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 / HelloWorld.scala
Last active Aug 2, 2021
Exploring and visualising Scala 2.* compilation phases
View HelloWorld.scala
object HelloWorld extends App {
val add2: Int => Int = _ + 2
println(s"Hello world! This is Scala. ${add2(40)}")
}
View spawn_vim.scala
import cats.effect._
import cats.implicits._
import java.io.PrintWriter
import java.nio.file.Path
object Editor {
type Editor = String
sealed trait EditorError