Skip to content

Instantly share code, notes, and snippets.

View pvoznenko's full-sized avatar
👟
offline is the new luxury

Pavlo Voznenko pvoznenko

👟
offline is the new luxury
View GitHub Profile
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"
@pvoznenko
pvoznenko / x.sc
Created June 9, 2014 16:34
scala mnemonic
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 -
@pvoznenko
pvoznenko / hw2.2.js
Last active August 29, 2015 14:05
hw2.2
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}}); } }
@pvoznenko
pvoznenko / hw3.1.js
Last active August 29, 2015 14:05
hw3.1
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}}})});
@pvoznenko
pvoznenko / hw5.1.js
Created September 11, 2014 05:37
hw5.1
db.posts.aggregate([{$unwind:"$comments"}, {$group: {_id:"$comments.author", count: { $sum: 1 }}}, {"$sort": {"count": -1}}]);
@pvoznenko
pvoznenko / hw5.2.js
Created September 11, 2014 06:02
hw5.2
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"}}} ])
@pvoznenko
pvoznenko / hw5.3.js
Created September 11, 2014 06:16
hw5.3
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}}]);
@pvoznenko
pvoznenko / hw5.4.js
Created September 11, 2014 06:24
hw5.4
db.zips.aggregate([
{$project: {first_char: {$substr : ["$city",0,1]}, pop:1}},
{$match:{"first_char":{"$regex": "[0-9]"}}},
{$group:{"_id":null, sum: {"$sum": "$pop"}}}
])
@pvoznenko
pvoznenko / f1.js
Created September 25, 2014 06:28
f1
db.messages.find({
"headers.From": "andrew.fastow@enron.com", "headers.To": "jeff.skilling@enron.com"
}).count()
@pvoznenko
pvoznenko / f2.js
Created September 25, 2014 06:29
f2
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}}
])