Skip to content

Instantly share code, notes, and snippets.

@trennepohl
trennepohl / main.go
Created May 13, 2020 20:25
Mongodb pipeline example
package main
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"time"
[
{ "_id": 1, "cust_id": "abc1", "ord_date": "2012-11-02T17:04:11.102Z", "status": "A", "amount": 50 },
{ "_id": 2, "cust_id": "xyz1", "ord_date": "2013-10-01T17:04:11.102Z", "status": "A", "amount": 100 },
{ "_id": 3, "cust_id": "xyz1", "ord_date": "2013-10-12T17:04:11.102Z", "status": "D", "amount": 25 },
{ "_id": 4, "cust_id": "xyz1", "ord_date": "2013-10-11T17:04:11.102Z", "status": "D", "amount": 125 },
{ "_id": 5, "cust_id": "abc1", "ord_date": "2013-11-12T17:04:11.102Z", "status": "A", "amount": 25 }
]
@trennepohl
trennepohl / sub-all.go
Created September 22, 2019 09:28
Subscribe all messages
package main
import (
"fmt"
"time"
"github.com/nats-io/stan.go"
)
func main() {
@trennepohl
trennepohl / pub.go
Created September 22, 2019 09:27
Nats publish
package main
import (
"os"
"github.com/nats-io/stan.go"
)
func main() {
sc, err := stan.Connect("test-cluster", "client1", stan.NatsURL("localhost:4222"))
/*
* created by Rui Santos, https://randomnerdtutorials.com
*
* Complete Guide for Ultrasonic Sensor HC-SR04
*
Ultrasonic sensor Pins:
VCC: +5VDC
Trig : Trigger (INPUT) - Pin11
Echo: Echo (OUTPUT) - Pin 12
GND: GND
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
)
@trennepohl
trennepohl / gist:3e9f06b29113f303917678d506d63588
Created February 19, 2019 13:22
Add tags to volumes using aws cli
for i in $(aws ec2 describe-volumes | jq .Volumes[].Attachments[].VolumeId | tr -d "\"");do aws ec2 create-tags --resources $i --tags Key=,Value=; done
@trennepohl
trennepohl / main.go
Created June 5, 2018 23:07
Cifra de césar
package main
import (
"fmt"
"strings"
)
func main() {
var input string
fmt.Println("Insira o texto")
@trennepohl
trennepohl / mongodb-aggregation.txt
Last active February 15, 2018 16:16
MongoDB Aggregation command example
`db.myCollection.aggregate([ { $group : { _id: "$someField", count: {$sum:1} }}])`