Skip to content

Instantly share code, notes, and snippets.

View oreillyross's full-sized avatar
🏠
Working from home

Faktor 10 oreillyross

🏠
Working from home
View GitHub Profile
@oreillyross
oreillyross / build.sbt
Created April 24, 2015 14:21
Here’s build.sbt to test Scalaz 7.1.0: All you have to do now is open the REPL using sbt 0.13.0: $ sbt console
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._"
@oreillyross
oreillyross / Quadratic.java
Created April 22, 2015 12:29
Page 86 of Clean code, use this in your problem for FRP course
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) {
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'
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) {
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()) {
db.images.find({tags: {$in: ["sunrises"]}}).count()
@oreillyross
oreillyross / Q7
Last active August 29, 2015 14:15
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();
@oreillyross
oreillyross / FinalQ4.java
Last active August 29, 2015 14:15
Mongo course - part solution
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";
@oreillyross
oreillyross / Check for Digits
Created February 8, 2015 14:09
MongoDB aggregate with a check for the first char being a digit, and summing the projection
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"},
@oreillyross
oreillyross / Aggregate
Created February 8, 2015 12:34
H5.3 Mongo course. Aggregate and group function
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"}