Skip to content

Instantly share code, notes, and snippets.

View blast-hardcheese's full-sized avatar

Devon Stewart blast-hardcheese

View GitHub Profile
scala> implicit class IInt(val value: Int)
defined class IInt
scala> def something(implicit int: IInt) = s"Deep down, got ${int.value}"
something: (implicit int: IInt)String
scala> def somethingElse(implicit int: IInt) = something
somethingElse: (implicit int: IInt)String
scala> somethingElse(5)
{% from 'java/map.jinja' import java with context %}
{% import_yaml 'gocd/defaults.yaml' as default_settings %}
{% set java_env = salt['pillar.get']('java:env', default='jre7') %}
{% do gocd.update({
'server': (gocd.get('server')|default({})).update({
'JAVA_HOME': java[java_env].home
}),
'agent': (gocd.get('agent')|default({})).update({
'JAVA_HOME': java[java_env].home
class Hey @Inject() (val app: Application) {
app.configuration // Guaranteed to work, since we can never get here unless we have enough contructor parameters
}
package se.hardchee.Pickr
import scala.language.higherKinds
import scala.language.implicitConversions
import scalaz.{ Coproduct, Free, Inject, ~>, \/-, -\/ }
package object algebras {
implicit def liftFCInj[A, P[_], F[_]](x: P[A])(implicit I: Inject[P, F]): Free.FreeC[F, A] = {
Free.liftFC(I.inj(x))
@blast-hardcheese
blast-hardcheese / Algebras.scala
Last active July 4, 2016 05:29
Type inference question in Cats
sealed trait ControlPanel[T]
case object ButtonPressed extends ControlPanel[Button]
case object StopEnabled extends ControlPanel[Unit]
case object StopDisabled extends ControlPanel[Unit]
case object CurrentFloor extends ControlPanel[Int]
sealed trait ElevatorControl[T]
case object GetFloor extends ElevatorControl[Int]
case class QueueFloor(x: Int) extends ElevatorControl[Unit]
@blast-hardcheese
blast-hardcheese / App.scala
Created October 24, 2016 04:16
Flexible genericism
import scala.concurrent.Future
object App extends App {
val play = new RouteService[PlaySpec] {
def handle(req: PlayRequest) = Future.successful(new PlayResponse)
def addCookie(request: PlayRequest, cookie: PlayCookieAtom): PlayRequest = request.copy(cookie :: request.cookies)
}
val akka = new RouteService[AkkaSpec] {
def handle(req: AkkaRequest) = Future.successful(new AkkaResponse)
[error] .../App2.scala:9: type mismatch;
[error] found : input.type (with underlying type H#Input)
[error] required: RouteService.this.Holder.Input
[error] def extractFoo(input: H#Input): Foo = Holder.input2Foo(input)
[error] ^
[error] one error found
[error] (core/compile:compileIncremental) Compilation failed
[error] Total time: 0 s, completed Oct 23, 2016 11:15:51 PM
publish:
./scripts/publish-to-gollum --prepare-docs-target --overwrite
sbt -no-colors tut
./scripts/publish-to-gollum --publish-docs --overwrite
scala> Foo.buildBar.baz(_, _)
res0: (Int, Int) => Int = <function2>
scala> res0(1,2)
Hello!
res1: Int = 3
scala> res0(1,2)
Hello!
res2: Int = 3
@blast-hardcheese
blast-hardcheese / error.txt
Created November 6, 2018 06:54
Pathed types
> compile
[info] Compiling 1 Scala source to /Users/dstewart/Projects/guardrail/modules/codegen/target/scala-2.12/classes...
[error] /Users/dstewart/Projects/guardrail/modules/codegen/src/main/scala/com/twilio/guardrail/CLI.scala:17: type mismatch;
[error] found : CLICommon.algebra.CoreTerms
[error] required: CLICommon.common.A.CoreTerms
[error] common.runM(algebra.coreTerm)
[error] ^
[error] one error found
[error] (codegen/compile:compileIncremental) Compilation failed
[error] Total time: 0 s, completed Nov 5, 2018 10:53:10 PM