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
@pvoznenko
pvoznenko / upgrade.md
Created May 30, 2019 09:13 — forked from zulhfreelancer/upgrade.md
How to upgrade Heroku Postgres database plan?
  1. Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin      git@bitbucket.org:xxx/xxx.git  (fetch)
origin      git@bitbucket.org:xxx/xxx.git  (push)
production  https://git.heroku.com/xxx.git (fetch)
production  https://git.heroku.com/xxx.git (push)
staging https://git.heroku.com/xxx.git (fetch)
@pvoznenko
pvoznenko / circe-loop-json-object-example.md
Last active May 11, 2018 19:25
How to loop through json object and change values with circe, scala

How to go through json object and change values with Circe in Scala

Small gist with some demo trait that shows an example on how to loop through json object and change values with circe in Scala.

Code example you can find below at circe-loop-json-object-example.scala.

The input JSON for test is kinda in in DynamoDB dump format:

@pvoznenko
pvoznenko / ad-hoc-polymorphism-in-scala-with-type-classes.md
Last active March 11, 2016 20:33
Example of ad-hoc polymorphism in scala with type classes

Ad hoc polymorphism in Scala with Type Classes

Below you can find example of the ad hoc polymorohism in Scala.

@pvoznenko
pvoznenko / f7.js
Created September 25, 2014 06:30
f7
db.albums.ensureIndex( {"images" : 1} );
db.albums.aggregate(
{ $unwind : "$images" },
{$group: { _id:null, images: {$addToSet:"$images"}}}
).forEach(function(doc){
db.images.remove({_id: {$nin: doc.images}});
// var kittens = db.images.find({tags: "kittens", _id: {$in: doc.images}});
// print(kittens.count());
});
@pvoznenko
pvoznenko / f3.js
Created September 25, 2014 06:29
f3
db.messages.find({
"headers.Message-ID": "<8147308.1075851042335.JavaMail.evans@thyme>"
});
db.messages.update({
"headers.Message-ID": "<8147308.1075851042335.JavaMail.evans@thyme>"
}, { $push: { "headers.To": "mrpotatohead@mongodb.com" } });
@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}}
])
@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 / 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 / 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.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"}}} ])