This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.czarism.blog | |
import scalaz._ | |
import Scalaz._ | |
/** | |
* Created by tstevens on 7/18/14. | |
*/ | |
object FavorValidation { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import rapture.core._; import rapture.data._; import rapture.json._ | |
import rapture.core._ | |
import rapture.data._ | |
import rapture.json._ | |
scala> import jsonBackends.scalaJson._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Returns the smallest index, i, into sizes such that `vs(i) >= n`, | |
* assuming `vs` is sorted. If `n` exceeds the maximum value in `vs`, | |
* throws an exception. This takes time `O(lg i)`, so searches which | |
* succeed near the front of `vs` return more quickly. | |
*/ | |
def search(vs: Vector[Long], n: Long): Int = { | |
// progressively double index, starting from 0, until | |
// hitting an index whose value exceeds `n`, then use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used as a term `the[T]` yields the unique implicit value of type `T` in the current | |
// implicit scope, if any. It is a compile time error if there is no such value. Its | |
// primary advantage over `Predef.implicitly` is that it will preserve any refinement that | |
// the implicit definition has, resulting in more precisely typed, and hence often more | |
// useful, values, | |
scala> trait Foo { type T ; val t: T } | |
defined trait Foo | |
scala> implicit val intFoo: Foo { type T = Int } = new Foo { type T = Int ; val t = 23 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.atomic._ | |
import collection.mutable.ArrayBuffer | |
/** | |
* Buffer type with purely functional API, using mutable | |
* `ArrayBuffer` and cheap copy-on-write scheme. | |
* Idea described by Bryan O'Sullivan in http://www.serpentine.com/blog/2014/05/31/attoparsec/ | |
*/ | |
class Buffer[A](id: AtomicLong, stamp: Long, values: ArrayBuffer[A], size: Int) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import play.api.libs.ws.WS | |
import play.core.parsers._ | |
import scala.concurrent.Future | |
import play.api.libs.concurrent.Execution.Implicits._ | |
case class OAuth2Settings( | |
clientId: String, | |
clientSecret: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- !Ups | |
CREATE TABLE users( | |
email VARCHAR(255) NOT NULL PRIMARY KEY, | |
name VARCHAR(255) | |
); | |
CREATE TABLE subjects( | |
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
title LONGTEXT NOT NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pellucid.data.util | |
import java.util.concurrent.Executors | |
import java.util.concurrent.atomic.AtomicInteger | |
import org.joda.time.format.DateTimeFormat | |
import scala.util.Random | |
import scalaz.concurrent.Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use with Options: | |
var maybeTweak: Option[Tweak[TextView]] = Some(text("Hi")) | |
myTextView ~> maybeTweak // this will set the text | |
maybeTweak = None | |
myTextView ~> maybeTweak // this will be ignored | |
// use with Futures: | |
val showInASecond = future { | |
Thread.sleep(1000) | |
show |