Skip to content

Instantly share code, notes, and snippets.

View justinhj's full-sized avatar

Justin Heyes-Jones justinhj

View GitHub Profile
@justinhj
justinhj / Scala3DefaultOptionMacro.scala
Created January 25, 2021 18:23
Macro that crashes the compiler
// Macro that crashes the compiler
import scala.quoted._
def takeOptionImpl[T](o: Expr[Option[T]], default: Expr[T])(using Quotes, Type[T]): Expr[T] = '{
$o match {
case Some(t1) => t1
case None: Option[T] => $default
}
}
@justinhj
justinhj / MultipleSameLayerZio1.scala
Created December 6, 2020 18:11
How to have multiple of the same ZLayer
object Temp {
final case class Person(name: String, age: Int)
case class Person2(p: Person)
val personLayer = ZLayer.succeed(Person("Nero", 4))
val ageLayer = personLayer.project(_.age)
val person2Layer = ZLayer.succeed(Person2(Person("Nero2", 8)))
val p = (for (
def play(gridStr: String): String = {
val grid = convertStringToGrid(gridStr)
val newG = grid.zipWithIndex.map {
case (row, x) =>
row.zipWithIndex.map {
case (col, y) => {
val count = countNeighbours(grid, x, y)
if(count == 2 || count == 3)
true
package org.example
import akka.stream.scaladsl.Source
import akka.NotUsed
import akka.stream.scaladsl.Sink
import akka.actor.ActorSystem
import akka.stream.Materializer
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
@justinhj
justinhj / fizzbuzzzio.scala
Created August 20, 2020 04:17
Fizz buzz using Zio
import zio._
import zio.console._
import zio.clock._
import zio.duration._
object ZioScheduleExample extends App {
val zLayers = Clock.live ++ Console.live
val everySecond = Schedule.spaced(1.second)
@justinhj
justinhj / cloudflowminikube.md
Last active August 17, 2020 16:18
How to run Cloudflow in minikube

After installing minikube via brew you can start it as follows. Assumes you have Mac for Desktop running but minikube supports other virtualization options. Make sure you give Docker a significant amount of drivespace (100Gb) and as much memory and cpus and as you provide to minikube.

Requirements: minikube, kubectl and helm should be installed

minikube start --cpus 4 --memory 16000 --kubernetes-version=1.15.6

Set up the local environment for kubectl commands.

eval $(minikube -p minikube docker-env)

package org.example
import zio.test._
import ZioExample._
import zio.test.environment.TestConsole
import zio.test.Assertion.{isEmpty,equalTo}
class ZioExampleSpec extends DefaultRunnableSpec {
def spec = suite("ZioExampleSpec")(
object callccInterpreter {
type Answer = Value;
/**
* A continuation monad.
*/
case class Cont[A](in: (A => Answer) => Answer) {
def bind[B](k: A => Cont[B]) = Cont[B](c => in (a => k(a) in c))
def map[B](f: A => B): Cont[B] = bind(x => unitM(f(x)))
@justinhj
justinhj / workdiary.org
Created June 9, 2020 19:09
Template for a work notes file

-*- mode: org; word-wrap: t; org-todo-keywords: ‘(TODO WIP QUESTION | DONE) -*-

Work diary/notes

Week beginning - 06/01/20

Fri

Thu

Wed

Tue

Mon

some random task

@justinhj
justinhj / stars.rb
Created May 4, 2020 17:20
Question a certain large company asked me to do in 15 minutes lol
require 'pry-byebug'
Star = Struct.new(:x, :y, :name, :constellation, :adjacents)
def calc_constellations(stars)
# Generate for each star, a list of adjacent stars
stars.each {|s|
s.adjacents = []
stars.each {|s2|
if s.x == s2.x && (s.y - s2.y).abs == 1 || s.y == s2.y && (s.x - s2.x).abs == 1