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
#!/usr/bin/env ruby | |
if ARGV.size < 2 | |
$stderr.puts 'usage: monitor <path> <command> [arg1 arg2 ...]' | |
exit 100 | |
end | |
PATH = ARGV[0] | |
COMMAND = ARGV[1] | |
ARGS = ARGV[2..-1] |
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
/* I'm trying to refactor $and and $or (which are essentially the same code returning a different outer query). | |
The problem is that currently only "String, Any" pairs work, and I need to be able to combine both those *AND* "Query Expression Objects". | |
Here's the $or spec right now | |
*/ | |
"Casbah's DSL $or Operator" should { | |
"Accept multiple values" in { | |
val or = $or("foo" -> "bar", "x" -> "y") |
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 Data.List | |
import Data.Maybe | |
import Control.Monad | |
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
base = length alphabet | |
encode :: Int -> String | |
encode 0 = "a" | |
encode id = map $ ((!!) alphabet) (reverse . tail) (map snd options) |
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
trait StorageCompopnent { | |
def storeUser(user: User) | |
def retrieveUser(id: Int): Option[User] | |
} | |
trait MySQLStorageComponent extends StorageComponent { | |
override def storeUser(user: User) { ... } | |
override def retrieveUser(id: Int): Option[User] = ... | |
} |
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
trait StorageCompopnent { | |
def storeUser(user: User) | |
def retrieveUser(id: Int): Option[User] | |
} | |
trait MySQLStorageComponent extends StorageComponent { | |
override def storeUser(user: User) { ... } | |
override def retrieveUser(id: Int): Option[User] = ... | |
} |
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
trait AuthComponent extends StorageComponent { | |
def authenticate(id: Int, hash: Vector[Byte]): Boolean = | |
retrieveUser(id) map { _.hash == hash } getOrElse false | |
} |
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
trait StorageComponent { | |
type User <: UserLike | |
def storeUser(user: User) | |
def retrieveUser(id: Int): Option[User] | |
trait UserLike { | |
def id: Int | |
def hash: Vector[Byte] | |
} |
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
trait ConfigComponent { | |
type Config | |
def config: Config | |
} | |
trait MySQLStorageComponent extends StorageComponent with ConfigComponent { | |
type Config <: MySQLConfig | |
override def storeUser(user: User) { ... } | |
override def retrieveUser(id: Int): Option[User] = ... |
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
trait Unifiable[A] { | |
??? | |
} | |
def symbol[A: Unifiable]: Symbol[A] = ??? | |
def pred[A: Unifiable](a: Symbol[A])(f: => Set[Fact]): Predicate1[A] = ??? | |
def pred[A: Unifiable, B: Unifiable](a: Symbol[A], b: Symbol[B])(f: => Set[Fact]): Predicate2[A, B] = ??? | |
lazy val factorial: Predicate2[Int, 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
def ???: Nothing = sys.error("TODO") |
OlderNewer