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 / 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 / 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 / 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 / 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._
# Oto Brglez - <otobrglez@gmail.com>
echo 'public class Main {public static void main(String[] args){ System.out.println(System.getProperty("java.home"));}}' > /tmp/Main.java && \
javac /tmp/Main.java && cd /tmp && java Main && rm Main.java && cd -
@otobrglez
otobrglez / my-project-dev.sh
Last active November 16, 2020 16:33
My "micro" wrapper for docker-compose
#!/usr/bin/env bash
set -e
# Author: Oto Brglez, <otobrglez@gmail.com>
# "MY_PROJECT_HOME" - is environment variable, usually set with
# something like direnv (via .env) or let to developer
if [[ -z "${MY_PROJECT_HOME}" ]]; then
echo "MY_PROJECT_HOME environment variable is not set!" && exit 255
fi
@otobrglez
otobrglez / post2pdf.sh
Last active November 13, 2020 21:53
Markdown notes to PDFs with Pandoc (post2pdf.sh)
#!/usr/bin/env bash
# Author: Oto Brglez
# Mail: otobrglez@gmail.com
# Version: 0.0.2
# LICENCE: MIT
# Install:
# - https://pandoc.org/
# - https://github.com/Wandmalfarbe/pandoc-latex-template
# - https://www.overleaf.com/learn/latex/XeLaTeX
# - https://github.com/be5invis/Iosevka