Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Developing & Launching

Michael Kimpton sketchthat

🚀
Developing & Launching
View GitHub Profile
View recursiveCloudFunction.ts
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) => {
View cloudFunction.ts
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;
View recursiveUpdate.ts
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;
View singleUpdate.ts
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,
});
View batchUpdate.ts
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;
@sketchthat
sketchthat / genesis_public_key
Last active Feb 21, 2018
genesis_public_key
View genesis_public_key
04817dcdc7a28e74131fbb54763415308c369e3d62d3e68149aea747cbdb2bcb755f17144c51060ed0f6445849fed2546fc770dad200c79471498fff45124a13c7
@sketchthat
sketchthat / shortenUrl (jQuery)
Last active Nov 28, 2017
Use bitly to generate a short URL with jQuery.
View shortenUrl (jQuery)
// 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);
View storage-example.js
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];
@sketchthat
sketchthat / gist:4ca9ca9986c9fd78c0185f54e5942c76
Created Jan 10, 2017
Remove Apple Configs from Unix Virtual Server
View gist:4ca9ca9986c9fd78c0185f54e5942c76
find . -name ".DS_Store" -depth -exec rm {} \;
find . -name ".AppleDouble" -depth -exec rm -Rf {} \;
You can’t perform that action at this time.