Skip to content

Instantly share code, notes, and snippets.

View hiranya911's full-sized avatar

Hiranya Jayathilaka hiranya911

View GitHub Profile
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();
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
package scorer
import (
"context"
"log"
"time"
firebase "firebase.google.com/go"
"firebase.google.com/go/db"
)
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
}
const admin = require('firebase-admin');
(async () => {
admin.initializeApp();
const message = {
data: {
time: '1:15 PM',
symbol: 'GOOG',
value: '1184.46'
(async () => {
admin.initializeApp();
const message = {
data: {
time: '1:15 PM',
symbol: 'GOOG',
value: '1184.46'
},
tokens: [token1, token2, /* up to 100 tokens... */],
const messages = [];
messages.push({
notification: {
title: 'Good morning Alice',
body: 'The weather in your area is nice and sunny today.',
},
token: token1,
});
messages.push({
notification: {
function getMessages(count) {
const messages = [];
for (let i = 0; i < count; i++) {
messages.push({
topic: `test-topic-${i % 10}`,
});
}
return messages;
}
const user = firebase.auth().currentUser;
user.sendEmailVerification().then(function() {
displayHomePage();
}).catch(function(error) {
displayError(error);
});
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import * as sendgrid from '@sendgrid/mail';
admin.initializeApp();
export const sendEmailVerification = functions.auth.user().onCreate(
async (user: admin.auth.UserRecord, context: functions.EventContext) => {
const email = user.email;
const link = await admin.auth().generateEmailVerificationLink(email, {