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
require 'formula' | |
class Phpunit < Formula | |
homepage 'http://www.phpunit.de/manual/current/en/index.html' | |
url 'https://phar.phpunit.de/phpunit.phar' | |
sha1 '4acc07c1730d85e2016a1ed613a1355a9d271636' | |
version 'HEAD' | |
def install | |
bin.install "phpunit.phar" => "phpunit" |
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
object x { | |
val mnem = Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ") | |
//> mnem : scala.collection.immutable.Map[Char,String] = Map(8 -> TUV, 4 -> GHI | |
//| , 9 -> WXYZ, 5 -> JKL, 6 -> MNO, 2 -> ABC, 7 -> PQRS, 3 -> DEF) | |
val charCode: Map[Char, Char] = | |
for ((digit, str) <- mnem; lrt <- str) yield lrt -> digit | |
//> charCode : Map[Char,Char] = Map(E -> 3, X -> 9, N -> 6, T -> 8, Y -> 9, J - |
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
var cursor = db.data.find({}).sort({State: 1, Temperature:-1}); | |
var state = ''; while (cursor.hasNext()) { var data = cursor.next(); if (state != data.State) { state = data.State; db.data.update(data, {$set: {"month_high": true}}); } } |
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
var cursor = db.students.aggregate([{$unwind: "$scores"}, {$match: {"scores.type": "homework"}}, {$sort: {"scores.score": 1}}]); | |
var ids = []; while (cursor.hasNext()) { var data = cursor.next(); if (ids.indexOf(data._id) === -1) { ids.push(data._id); db.students.update(data, {$pull: {"scores": data.scores}}); } } | |
// or | |
db.students.aggregate([{"$unwind":"$scores"}, {$match: {"scores.type": "homework"}}, {"$sort": {"scores.score": 1}}, {$group: {_id: "$_id", lowScore: {$first: "$scores.score"}, scores: {$push: "$scores"}}}]).forEach(function(myDoc){db.students.update({"_id": myDoc._id}, {$pull: {scores: {score: myDoc.lowScore}}})}); |
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
db.posts.aggregate([{$unwind:"$comments"}, {$group: {_id:"$comments.author", count: { $sum: 1 }}}, {"$sort": {"count": -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
db.grades.aggregate([{$group:{"_id": {state: "$state", city: "$city"}, pop: {"$sum": "$pop"}}}, {$match:{"pop":{"$gt":25000}, "_id.state": {"$in": ["CA", "NY"]}}}, {$group:{"_id":null,avg: {"$avg": "$pop"}}} ]) |
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
db.grades.aggregate([{$unwind:"$scores"}, {$match:{"scores.type":{$ne: "quiz"}}}, {$group:{"_id": {class_id: "$class_id", student_id: "$student_id"}, avg_per_student: {"$avg": "$scores.score"}}}, {$group:{"_id": "$_id.class_id",avg: {"$avg": "$avg_per_student"}}}, {$sort: {"avg": -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
db.zips.aggregate([ | |
{$project: {first_char: {$substr : ["$city",0,1]}, pop:1}}, | |
{$match:{"first_char":{"$regex": "[0-9]"}}}, | |
{$group:{"_id":null, sum: {"$sum": "$pop"}}} | |
]) |
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
db.messages.find({ | |
"headers.From": "[email protected]", "headers.To": "[email protected]" | |
}).count() |
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
db.messages.aggregate([ | |
{$project: {from:"$headers.From", to:"$headers.To"}}, | |
{$unwind:"$to"}, | |
{$group: { _id:{_id: "$_id", from: "$from"}, to: {$addToSet:"$to"} }}, | |
{$unwind:"$to"}, | |
{$group: { _id: {from:"$_id.from", to:"$to"}, count: {$sum:1}}}, | |
{$sort:{count:-1}} | |
]) |
OlderNewer