This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ChangeDataSnapshot = functions.Change<DataSnapshot>; | |
type DataSnapshot = admin.database.DataSnapshot; | |
interface RecursiveData { | |
lastKey: string; | |
iteration: number; | |
records: number; | |
} | |
export const batchUpdateUser = functions.database.ref('/triggerUsers').onWrite(async (change: ChangeDataSnapshot) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const batchUpdateUser = functions.database.ref('/triggerUsers').onWrite(async (_change) => { | |
const updateUsers = async (lastKey: string = '', iteration: number = 0, records: number = 0) => { | |
const snapshots: DataSnapshot = await admin.database().ref('/users') | |
.orderByKey() | |
.startAt(lastKey) | |
.limitToFirst(10) | |
.once('value'); | |
const batchUpdate = {}; | |
let nextKey = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function updateUsers(lastKey: string = '', iteration: number = 0, records: number = 0) { | |
const snapshots: DataSnapshot = await admin.database().ref('/users') | |
.orderByKey() | |
.startAt(lastKey) | |
.limitToFirst(10) | |
.once('value'); | |
const batchUpdate = {}; | |
let nextKey = null; | |
let counter = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const snapshots: DataSnapshot = await firebase.database().ref('/users') | |
.once('value'); | |
snapshots.forEach(async snapshot => { | |
const userId = snapshot.key; | |
await firebase.database().ref(`/users/${userId}`).update({ | |
lastProcessed: firebase.database.ServerValue.TIMESTAMP, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const snapshots: DataSnapshot = await firebase.database().ref('/users') | |
.once('value'); | |
const batchUpdate = {}; | |
snapshots.forEach(snapshot => { | |
const userId = snapshot.key; | |
batchUpdate[`/users/${userId}/lastProcessed`] = firebase.database.ServerValue.TIMESTAMP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04817dcdc7a28e74131fbb54763415308c369e3d62d3e68149aea747cbdb2bcb755f17144c51060ed0f6445849fed2546fc770dad200c79471498fff45124a13c7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate Access Token | |
// https://bitly.com/a/oauth_apps | |
var shortenUrl = function(accessToken, longUrl) { | |
$.getJSON('https://api-ssl.bitly.com/v3/shorten', { | |
access_token: accessToken, | |
longUrl: longUrl | |
}) | |
.success(function(resp) { | |
console.log('URL: ', resp.data.url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const gcs = require('@google-cloud/storage')(); | |
exports.listener = functions.database.ref('/test/storage').onWrite(() => { | |
const bucket = gcs.bucket(functions.config().firebase.storageBucket); | |
const filePath = __dirname + '/image.png'; | |
return bucket.upload(filePath, { destination: 'storage-folder/sample/test-image.png' }) | |
.then(files => { | |
const file = files[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -name ".DS_Store" -depth -exec rm {} \; | |
find . -name ".AppleDouble" -depth -exec rm -Rf {} \; |