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
scalaVersion := "2.11.2" | |
val scalazVersion = "7.1.0" | |
libraryDependencies ++= Seq( | |
"org.scalaz" %% "scalaz-core" % scalazVersion, | |
"org.scalaz" %% "scalaz-effect" % scalazVersion, | |
"org.scalaz" %% "scalaz-typelevel" % scalazVersion, | |
"org.scalaz" %% "scalaz-scalacheck-binding" % scalazVersion % "test" | |
) | |
scalacOptions += "-feature" | |
initialCommands in console := "import scalaz._, Scalaz._" |
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
public class Quadratic { | |
public static double root1(double a, double b, double c) { | |
double determinant = determinant(a, b, c); | |
return (-b + Math.sqrt(determinant)) / (2*a); | |
} | |
public static double root2(int a, int b, int c) { | |
double determinant = determinant(a, b, c); | |
return (-b - Math.sqrt(determinant)) / (2*a); | |
} | |
private static double determinant(double a, double b, double c) { |
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
repositories { | |
mavenRepo urls: 'http://scala-tools.org/repo-releases' | |
mavenCentral() | |
} | |
dependencies { | |
// Libraries needed to run the scala tools | |
scalaTools 'org.scala-lang:scala-compiler:2.7.7' | |
scalaTools 'org.scala-lang:scala-library:2.7.7' |
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
use test; | |
var img_albums = []; | |
var imgs = []; | |
var img_in_albums = db.albums.aggregate({$unwind: "$images"}, {$group: {_id: {images: "$images"}}}); | |
img_in_albums.forEach( | |
function(img_alb) { |
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
use test; | |
db.images.find({tags: {$in: ["sunrises"]}}).count(); | |
var images = db.images.find({},{_id: 1}).toArray(); | |
var orphans = db.albums.find({"images": {$in: [2433]}}); | |
orphans.count(); | |
//while (images.hasNext()) { |
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
db.images.find({tags: {$in: ["sunrises"]}}).count() |
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
use test; | |
db.images.find({tags: {$in: ["sunrises"]}}).count(); | |
var images = db.images.find({},{_id: 1}); | |
//var orphans = db.albums.find({"images": {$in: [2433]}}); | |
//orphans.count(); |
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
public class TestLike { | |
public static void main(String[] args) throws UnknownHostException { | |
MongoClient mongoclient = new MongoClient(); | |
DB db = mongoclient.getDB("blog"); | |
DBCollection coll = db.getCollection("posts"); | |
DBObject comments = new BasicDBObject("permalink", "csukcsijclxkgvzoojde"); | |
String comment = "comments." + 2 + ".num_likes"; |
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
db.zips.aggregate([ | |
{$project: | |
{first_char: {$substr: ["$city",0,1]}, | |
pop: 1 | |
} | |
}, | |
{$match: {'first_char': {$in: ['0','1','2','3','4','5','6','7','8','9']}}}, | |
{$group: | |
{_id: {'firstchar': "$first_char"}, |
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
db.grades.aggregate([ | |
{$unwind: "$scores"}, | |
{$match: | |
{'scores.type': "homework"}}, | |
{$group: | |
{_id: {student_id: "$student_id", | |
class_id: "$class_id", | |
scorestype: "$scores.type", | |
}, | |
avg_scores: {$avg:"$scores.score"} |