Skip to content

Instantly share code, notes, and snippets.

@tomverran
tomverran / keybase.md
Created September 13, 2016 09:19
really

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 September 15, 2016 21:39
National rail FTP timetable downloader
import xml.etree.cElementTree as ET
from ftplib import FTP
import StringIO
import gzip
import time
import re
import json
import boto3
import tempfile
@tomverran
tomverran / shapeless.scala
Created December 10, 2016 15:02
shapeless-lenses
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)
@tomverran
tomverran / numbers.scala
Last active December 13, 2016 22:43
type level natural numbers + a fixed length list
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")
*/
@tomverran
tomverran / eithers.scala
Created December 16, 2016 09:40
Nested either value extraction
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 / converter.scala
Last active March 14, 2017 14:15
This hangs the Scala compiler (tried 2.11.8 and 2.12.1)
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 / DeepGeneric.scala
Last active March 15, 2017 22:53
A typeclass to recursively turn case classes into labelled nested HLists
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 / fs2.scala
Created March 16, 2018 23:22
Demonstrating an issue I'm having with IOs of None in FS2
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 / App.scala
Created December 19, 2018 15:13
ScalaJS demo
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 / TimeTravelTest.scala
Created August 13, 2021 15:33
TimeTravelTest
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 =>