Skip to content

Instantly share code, notes, and snippets.

View blast-hardcheese's full-sized avatar

Devon Stewart blast-hardcheese

View GitHub Profile
package models
import scala.util.matching.Regex
// Deps
object Types {
type Tag = String
}
import Types._
#!/bin/sh
DOWNLOAD_DIR="$HOME/Downloads/weather"
REGION=txgulf
die() {
ec=$1
shift
echo $@ >&2
exit $ec
// Given this definition,
def buildWrites[U, T <: DataTyped[U]](baseWrites: Writes[T])(implicit typeToJs: U => Json.JsValueWrapper): Writes[T]
// Works!
val someWrites: Writes[SomeDataTyped_v1] = DataTyped.buildWrites[FeedEntryTypes.Value, SomeDataTyped_v1](Json.writes[SomeDataTyped_v1])
// Fails.
val someWrites: Writes[SomeDataTyped_v1] = DataTyped.buildWrites(Json.writes[SomeDataTyped_v1])
[error] .../DataSpec.scala:65: type mismatch;
def countdown(a):
for i in a:
print a - i
if i == 3:
print "blast off!"
break
i+=1
countdown(3):
def split[A, B](f: A => A => C)(x: A): C = f(x)(x)
def swap[A, B, C](f: A => B => C): B => A => C = (b: B) => (a: A) => f(a)(b)
def filter[A](as: List[A])(f: A => Boolean): List[A] = foldRight2(as, List.empty[A])(uncurried[A, List[A], List[A]](split(f andThen (if(_) (Cons.apply[A] _).curried else swap(const[List[A], A] _))) _))
def filterAnnotated[A](as: List[A])(f: A => Boolean): List[A] = {
val prepend: A => List[A] => List[A] = (Cons.apply[A] _).curried
val ignore: A => List[A] => List[A] = swap(const[List[A], A] _)
val getApply: A => A => List[A] => List[A] = f andThen (if(_) prepend else ignore)
import shapeless._
sealed trait Animal
case class Point(x: Double, y: Double)
case class Color(r: Byte, g: Byte, b: Byte)
case class Turtle(position: Point, heading: Double, color: Color) extends Animal
case class Cat(position: Point, color: Color) extends Animal
implicit val turtlePosition = lens[Turtle].position
implicit val catPosition = lens[Cat].position
import shapeless._
import shapeless.labelled.KeyTag
import shapeless.record._
import shapeless.ops.hlist.ToList
import shapeless.ops.record.{ Keys, Values }
import shapeless.syntax.singleton._
import utils.ExtendedPostgresDriver.simple._
object slickless {
import shapeless._
case class Location(lat: Double, lon: Double)
case class User(id: Long, username: String, location: Location)
case class Car(id: Long, location: Location)
object ImplicitLenses extends App {
implicit val userLocationLens: Lens[User, Location] = {
val ret = lens[User].location
ret
...
type FirstName = (String @@ FirstName.Internal)
object FirstName { trait Internal; def apply(value: String): FirstName = value.asInstanceOf[FirstName] }
type LastName = (String @@ LastName.Internal)
object LastName { trait Internal; def apply(value: String): LastName = value.asInstanceOf[LastName] }
type Email = (String @@ Email.Internal)
object Email { trait Internal; def apply(value: String): Email = value.asInstanceOf[Email] }
...
scala> import shapeless.tag
import shapeless.tag
scala> trait FirstName
defined trait FirstName
scala> val FirstName = tag[FirstName]
FirstName: shapeless.tag.Tagger[FirstName] = shapeless.tag$Tagger@779a0926
scala> trait LastName