Skip to content

Instantly share code, notes, and snippets.

View TimeTravelTest.scala
import cats.effect.IO
import cats.effect.unsafe.{IORuntime, IORuntimeConfig, Scheduler}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import java.time.Instant
import java.time.temporal.ChronoUnit.MILLIS
import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.duration.FiniteDuration
trait TimeTravelTest extends BeforeAndAfterAll with BeforeAndAfterEach { self: Suite =>
View App.scala
package com.ovoenergy.green.demo
import cats.effect.IO._
import cats.effect.{ConcurrentEffect, ExitCode, IO, IOApp}
import cats.implicits._
import fs2._
import fs2.concurrent.Queue
import org.scalajs.dom.document.body
import org.scalajs.dom.{Element, Event, Node}
import scalatags.JsDom.all._
@tomverran
tomverran / fs2.scala
Created Mar 16, 2018
Demonstrating an issue I'm having with IOs of None in FS2
View fs2.scala
import fs2._
import cats.effect.IO
import cats.instances.int._
val none = IO[Option[Int]](None)
Stream.eval(none).unNone.groupAdjacentBy(identity).compile.drain.unsafeRunSync
@tomverran
tomverran / DeepGeneric.scala
Last active Mar 15, 2017
A typeclass to recursively turn case classes into labelled nested HLists
View DeepGeneric.scala
import shapeless._
import shapeless.labelled._
trait DeepGeneric[T] {
type Repr <: HList
def to(t: T): Repr
}
trait LowPriority {
implicit def plainHconsDeepGeneric[H, T <: HList](
@tomverran
tomverran / converter.scala
Last active Mar 14, 2017
This hangs the Scala compiler (tried 2.11.8 and 2.12.1)
View converter.scala
import shapeless.{:+:, CNil, Coproduct, HList, LabelledGeneric}
import shapeless.ops.hlist.{Align, Intersection}
/**
* Allows you to convert between case classes which have compatible generic representations
* i.e. Foo(bar: String) is convertable to Baz(bar: String) due to the field names & types being the same
*/
trait Converter[A, B] {
def convert(a: A): B
}
@tomverran
tomverran / eithers.scala
Created Dec 16, 2016
Nested either value extraction
View eithers.scala
type NestedEither = Either[Either[String, Int], Double]
val foo: NestedEither = Left(Right(5))
sealed trait Extractor[H, N] {
def value(a: H): Option[N]
}
implicit def FoundExtractor[A] = new Extractor[A, A] {
def value(a: A) = Some(a)
}
@tomverran
tomverran / numbers.scala
Last active Dec 13, 2016
type level natural numbers + a fixed length list
View numbers.scala
import scala.language.higherKinds
// trying to understand why shapeless does things it does by reimplementing them
/*
* scalaVersion := "2.11.8"
* resolvers += Resolver.sonatypeRepo("releases")
* addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
*/
View shapeless.scala
import shapeless._
import shapeless.syntax.singleton._
import shapeless.labelled._
case class Foo(name: String)
val f = LabelledGeneric[Foo]
case class Lens[O, K, V](get: O => V)
View keybase.md

Keybase proof

I hereby claim:

  • I am tomverran on github.
  • I am tomverran (https://keybase.io/tomverran) on keybase.
  • I have a public key whose fingerprint is C8CF B320 8C28 B08D D171 A69A DA79 910D F5D8 49E2

To claim this, I am signing this object:

@tomverran
tomverran / ftp.py
Last active Sep 15, 2016
National rail FTP timetable downloader
View ftp.py
import xml.etree.cElementTree as ET
from ftplib import FTP
import StringIO
import gzip
import time
import re
import json
import boto3
import tempfile