Skip to content

Instantly share code, notes, and snippets.

View petruisfan's full-sized avatar

Petru Isfan petruisfan

View GitHub Profile
@loa
loa / semver.sh
Last active May 14, 2022 22:27
Bash Git SemVer Util
#!/bin/bash
# Author: Carl Loa Odin <carl.loa.odin@gmail.com>
# https://gist.github.com/loa/435da12af9494a112daf
test_res=0
function get_git_version() {
version=$(git describe)
if [ $? -eq 128 ]; then
# Return initial version incase no tags is found
@adrienjoly
adrienjoly / mostPostedTracks.js
Last active November 13, 2018 10:27
mongodb "group by" query using aggregation for counting documents per category, on a objectid-timestamp-based subset
db = db.getSiblingDB("whyd_music") // explicitely select collection
var jan2014 = ObjectId("52c35a800000000000000000"); // created using http://steveridout.github.io/mongo-object-time/
db.post.aggregate([
{"$sort": {"_id": -1}}, // order: antichronological
{"$match": {"_id": {"$gt": jan2014}}}, // only documents that were created after the 1syt january 2014
{"$group": {"_id": "$eId", // group by value of the eId attribute -> _id attribute in the resulting output collection
"name": {"$first": "$name"}, // -> include the name of each grouped category
"count": {"$sum": 1}}}, // -> count attribute will contain the number of documents for each value of _eid
{"$match": {"count": {"$gt": 50}}}, // limit output to results with count > 50
{"$sort": {"count": -1}} // output order: highest count first