Skip to content

Instantly share code, notes, and snippets.

View kevinmeredith's full-sized avatar

Kevin Meredith kevinmeredith

  • https://twitter.com/Gentmen
View GitHub Profile
@kevinmeredith
kevinmeredith / jencode.md
Created July 11, 2017 16:02
What's going on here?
import argonaut._, Argonaut._
import scala.util.control.NoStackTrace

final case class UncaughtException(error: String) extends RuntimeException with NoStackTrace

implicit val UncaughtExceptionJsonEncoder: EncodeJson[UncaughtException] =
  jencode1L((e: UncaughtException) => e.getMessage)("error")

scala> UncaughtExceptionJsonEncoder.encode(UncaughtException("a"))
@kevinmeredith
kevinmeredith / A.md
Created June 16, 2017 21:00
Example from Stucchio's blog on scalaz-stream's `signal`
import scalaz._, Scalaz._, concurrent._, stream.Process, stream.async

val signal = async.signal[Boolean]
val signalChanges: Process[Task,Boolean] = signal.discrete

val updateSignal: Task[Unit] = Task.apply {
  signal.set(true).run // Time = 1
  Thread.sleep(2000)
 signal.set(true).run // Time = 2
@kevinmeredith
kevinmeredith / A.md
Created April 22, 2017 14:23
Trying to use SparkContext from `sbt console`
$mkdir spark_sandbox
$cd spark_sandbox
$cat build.sbt 
scalaVersion := "2.11.8"

libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.1.0"
$sbt console
scala> import org.apache.spark.SparkConf
scala> import org.apache.spark.SparkContext
@kevinmeredith
kevinmeredith / A.md
Last active April 3, 2017 19:14
Unexpected issue with `ko(String)` on "org.specs2" %% "specs2" % "2.4.17"

Using ko("some message") succeeds when it should not on "2.4.17"

$cat build.sbt
scalaVersion := "2.11.8"

libraryDependencies += "org.specs2" %% "specs2" % "2.4.17"

$cat src/test/scala/x/Test.scala 
package x
@kevinmeredith
kevinmeredith / Decoder.scala
Created April 2, 2017 16:32
Calling io.circe.Decoder#decodeList
import io.circe._
import io.circe.parser._
import io.circe.syntax._
scala> val ints = "[1,2,3]".asJson
ints: io.circe.Json = "[1,2,3]"
scala> Decoder.decodeList[Int].decodeJson(ints)
res1: io.circe.Decoder.Result[List[Int]] = Left(DecodingFailure([A]List[A], List()))
@kevinmeredith
kevinmeredith / failed.md
Created February 26, 2017 02:03
SO w/ shapeless on my puzzle exercise
scala> IsValidInductive[_3 :: _4 :: _5 :: _8 :: _8 :: _2 :: _8 :: _6 :: _5 :: HNil]
java.lang.StackOverflowError
	at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:110)
	at scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1058)
	at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:300)
	at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:298)
	at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:115)
	at scala.reflect.internal.tpe.TypeMaps$FilterTypeCollector.traverse(TypeMaps.scala:1058)
	at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:300)
@kevinmeredith
kevinmeredith / x.md
Created February 23, 2017 13:24
KataBankOCR #2 Attempt w/ Shapeless
@kevinmeredith
kevinmeredith / x.md
Last active February 21, 2017 14:27
Monad
Prelude> :i Monad
class Applicative m => Monad (m :: * -> *) where
  (>>=) :: m a -> (a -> m b) -> m b
  (>>) :: m a -> m b -> m b
  return :: a -> m a
  fail :: String -> m a
  {-# MINIMAL (>>=) #-}
  	-- Defined in ‘GHC.Base’
instance Monad (Either e) -- Defined in ‘Data.Either’
# project at https://github.com/kevinmeredith/KataBankOCR_shapeless
$pwd
/Users/kevinmeredith/Workspace/KataBankOCR_shapeless
$time ./runTest.sh
[info] Loading project definition from /Users/kevinmeredith/Workspace/KataBankOCR_shapeless/project
[info] Set current project to katabankocr_shapeless (in build file:/Users/kevinmeredith/Workspace/KataBankOCR_shapeless/)
[info] Compiling 5 Scala sources to /Users/kevinmeredith/Workspace/KataBankOCR_shapeless/target/scala-2.12/classes...
^C
real 774m29.336s
import org.joda.time._
import monix.execution._
import monix.execution.Scheduler.Implicits.global
import java.util.concurrent.TimeUnit
import scala.util.control.NonFatal
def scheduleOncePerDay(time: LocalTime, now: DateTime = DateTime.now())(cb: () => Unit)
(implicit s: Scheduler): Cancelable = {
val nextTick = {