Skip to content

Instantly share code, notes, and snippets.

View hiranya911's full-sized avatar

Hiranya Jayathilaka hiranya911

View GitHub Profile
(async () => {
admin.initializeApp();
const message = {
data: {
time: '1:15 PM',
symbol: 'GOOG',
value: '1184.46'
},
tokens: [token1, token2, /* up to 100 tokens... */],
const admin = require('firebase-admin');
(async () => {
admin.initializeApp();
const message = {
data: {
time: '1:15 PM',
symbol: 'GOOG',
value: '1184.46'
func ScoreReview(ctx context.Context, e FirestoreEvent) error {
review := e.Value.Fields
reviweScore := score(review.Text.Value)
ref := client.NewRef("scores").Child(review.Author.Value)
updateTxn := func(node db.TransactionNode) (interface{}, error) {
var currentScore int
if err := node.Unmarshal(&currentScore); err != nil {
return nil, err
}
package scorer
import (
"context"
"log"
"time"
firebase "firebase.google.com/go"
"firebase.google.com/go/db"
)
import (
"context"
"cloud.google.com/go/firestore"
firebase "firebase.google.com/go"
)
// FirebaseClient is a helper for interacting with Firebase services.
type FirebaseClient struct {
db *firestore.Client
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
const firestore = admin.firestore();
export const sendCryptoAlerts = functions.firestore.document('prices/{currency}')
.onUpdate(async (change, context) => {
const currencyId: string = context.params.currency;
const data = change.after.data();
cron:
- description: "cryptocurrency price updater"
url: /fetch
schedule: every 30 minutes
// Prices is a map of crypto currency prices.
type Prices map[string]float64
// SavePrices saves the given crypto currency prices to the database.
func (client *FirebaseClient) SavePrices(ctx context.Context, prices Prices) error {
collection := client.db.Collection("prices")
batch := client.db.Batch()
for curr, price := range prices {
batch.Set(collection.Doc(curr), map[string]interface{}{"value": price}, firestore.MergeAll)
}
import com.google.android.gms.tasks.Task
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
suspend fun <T> Task<T>.await() =
suspendCancellableCoroutine<T> {
this.addOnSuccessListener(it::resume)
this.addOnFailureListener(it::resumeWithException)
this.addOnCanceledListener { it.cancel() }
}
class CryptoAlertMessagingService: FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage?) {
message?.notification?.let {
Log.d(TAG, "Message Notification Body: ${it.body}")
val mainHandler = Handler(mainLooper)
mainHandler.post {
Toast.makeText(applicationContext, "${it.body}", Toast.LENGTH_SHORT).show()
}
}