Skip to content

Instantly share code, notes, and snippets.

@feloy
feloy / devfile.yaml
Created November 17, 2021 14:28
devfile with inner and outer loop
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: /project
id: install
- exec:
#!/bin/bash
while : ; do
go run main.go &
fswatch -xrn1 -m inotify_monitor --event Created --event Removed --event Updated --event Renamed .
killall main
done
// Package p contains a Firestore Cloud Function.
package p
import (
"context"
"errors"
"fmt"
"log"
"os"
"strings"
package p
// Score represents the Score collection in Firestore
type Score struct {
Uid string
Name string
Points int
Details string
Country string
}
package p
import (
"errors"
"fmt"
"strconv"
)
// FirestoreValue holds Firestore fields.
type FirestoreValue struct {
// Package p contains a Firestore Cloud Function.
package p
import (
"context"
"fmt"
"log"
"cloud.google.com/go/functions/metadata"
)
module cloudfunction
require cloud.google.com/go v0.34.0
#!/bin/bash
gcloud beta functions deploy newScore \
--entry-point OnNewScore \
--memory 256MB \
--region us-central1 \
--runtime go111 \
--trigger-event providers/cloud.firestore/eventTypes/document.create \
--trigger-resource "projects/<your-project-id>/databases/(default)/documents/Score/{id}"
// Package p contains a Firestore Cloud Function.
package p
import (
"context"
"fmt"
"log"
"cloud.google.com/go/functions/metadata"
)
@feloy
feloy / SendScore.java
Created January 19, 2019 09:53
Send a score from Android app
[...]
Map<String, Object> doc = new HashMap<>();
doc.put("uid", currentUser.getUid());
doc.put("name", name);
doc.put("points", score.getTotalScore());
doc.put("details", score.getDetailsToSave());
doc.put("country", countryCode);
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("Score")