This file contains hidden or 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 dequeue: MessageInvocation = withErrorHandling { | |
/** | |
* Retrieves first item in natural order (oldest first, assuming no modification/move) | |
* Waits 3 seconds for now for a message, else pops back out. | |
* TODO - How do we handle fetch, but sleep if nothing is in there cleanly? | |
* TODO - Should we have a specific query in place? Which way do we sort? | |
* TODO - Error handling version! | |
*/ | |
val msgInvocation = new DefaultPromise[MessageInvocation](3000) | |
db.findAndRemove(collName)(Document.empty) { msg: MongoDurableMessage => |
This file contains hidden or 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
/** | |
* Attempting to factor this method (Which used to take a hard argument for Qry of BSONDocument | |
* to use a type class, where the type class object SerializableBSONObject knows how to encode/decode the | |
* Document represented in Qry | |
* | |
* I was ***hoping*** That the Scala compiler would be smart enough to extract the type class type | |
* in the case of a Default Argument but it seems not. | |
* The compiletime error is: | |
* | |
* could not find implicit value for evidence parameter of type org.bson.SerializableBSONObject[Nothing] |
This file contains hidden or 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 com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.dynamic._ | |
val d = DynamicDBObject("_id" -> new ObjectId, "name" -> "Brendan McAdams", | |
"address" -> MongoDBObject("street" -> "134 5th Ave Fl 3", | |
"city" -> "New York", | |
"state" -> "NY", | |
"zip" -> 10011), | |
"email" -> "[email protected]") |
This file contains hidden or 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
scala> val x: PartialFunction[String, Unit] = { case "foo" => println("Foo") } | |
x: PartialFunction[String,Unit] = <function1> | |
scala> x("foo") | |
Foo | |
scala> x("bar") | |
scala.MatchError: bar | |
scala> val y: PartialFunction[String, Unit] = { case "bar" => println("Bar") } |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>org.mongodb.mongod</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/mongodb/bin/mongod</string> | |
<string>run</string> |
This file contains hidden or 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/python | |
# Connects to localhost, 27017 by default | |
import sys | |
import pymongo | |
import time | |
if len(sys.argv) < 2: | |
print >> sys.stderr, "Usage: ./tail_profile.py <dbName> [hostname] [port]" | |
sys.exit(-1) |
This file contains hidden or 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
#ruby | |
[1,2,3,4].select{ |x| x.even? } | |
#python | |
[x for x in [1,2,3,4] if not x%2] | |
#or, more norvingly | |
filter(lambda x: not x%2, [1,2,3,4]) | |
#clojure | |
(filter #(even? % ) [1 2 3 4]) |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>org.mongodb.mongod</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/mongodb/bin/mongod</string> | |
<string>run</string> |
This file contains hidden or 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
class CallableMap extends scala.collection.mutable.HashMap[String, Any] with Dynamic { | |
def invokeDynamic(name: String)(args: Any*) = { | |
println("Invoke Dynamic: (name = %s)(args: %s)".format(name, args)) | |
get(name) | |
} | |
def typed[T]: T = { | |
asInstanceOf[T] | |
} |
This file contains hidden or 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
implicit def pimpMyMap(underlying: Map[_,_]) = new { | |
/** Lazy utility method to allow typing without conflicting with Map's required get() method and causing ambiguity */ | |
def getAs[A <: Any : Manifest](key: Any): Option[A] = { | |
require(manifest[A] != manifest[scala.Nothing], | |
"Type inference failed; getAs[A]() requires an explicit type argument " + | |
"(e.g. mapObject.getAs[<ReturnType>](somegetAKey) ) to function correctly.") | |
underlying.get(key) match { | |
case null => None |