Skip to content

Instantly share code, notes, and snippets.

View sketchthat's full-sized avatar
🚀
Developing & Launching

Michael Kimpton sketchthat

🚀
Developing & Launching
View GitHub Profile
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) => {
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;
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;
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,
});
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 February 21, 2018 00:56
genesis_public_key
04817dcdc7a28e74131fbb54763415308c369e3d62d3e68149aea747cbdb2bcb755f17144c51060ed0f6445849fed2546fc770dad200c79471498fff45124a13c7
@sketchthat
sketchthat / shortenUrl (jQuery)
Last active November 28, 2017 19:24
Use bitly to generate a short URL with 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);
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 January 10, 2017 22:02
Remove Apple Configs from Unix Virtual Server
find . -name ".DS_Store" -depth -exec rm {} \;
find . -name ".AppleDouble" -depth -exec rm -Rf {} \;