Skip to content

Instantly share code, notes, and snippets.

View justinhj's full-sized avatar

Justin Heyes-Jones justinhj

View GitHub Profile
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
@justinhj
justinhj / traverseFilter.scala
Last active April 6, 2020 18:15
It's always Traverse!
import cats._
import cats.implicits._
import cats.data.Const
// List version
Traverse[List].traverse(List(1,2,3,4,5,6))(a => if(a%2==0) Const.of[Any](List(a)) else Const.of[Any](List.empty[Int])
).getConst
res7: List[Int] = List(2, 4, 6)
@justinhj
justinhj / purefp1.scala
Created March 12, 2020 18:29
A pure function
def functionExample(a: A): B = {
// ... do something with A
// .. return a value of type B
}
@justinhj
justinhj / MyThrowable.scala
Last active February 25, 2020 02:36
I called this Throwable but it's actually just an implementation of Try (and Functor/Monad instance of it)
object MyThrowable {
// This is just here to keep Wartremover happy
@SuppressWarnings(Array("org.wartremover.warts.Equals"))
implicit final class AnyOps[A](self: A) {
def ===(other: A): Boolean = self == other
}
// Define Try and make it a monad/functor
sealed trait Try[+T]