Skip to content

Instantly share code, notes, and snippets.

View drewrothstein's full-sized avatar

Drew Rothstein drewrothstein

View GitHub Profile
@drewrothstein
drewrothstein / index.js
Created June 28, 2021 23:23
Function Webhook
const {
conversation,
} = require('@assistant/conversation');
const functions = require('firebase-functions');
const fetch = require('node-fetch');
const app = conversation({debug: true});
const URL = 'https://<YOUR FUNCTION URL>.cloudfunctions.net/automower';
@drewrothstein
drewrothstein / automower_function.py
Created June 28, 2021 23:15
Automower Cloud Function
import os
import sys
from flask import abort, escape
from google.cloud import firestore
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'sa_key.json'
def get_automower():
#!/usr/bin/python3
import datetime
import time
from shapely import geometry
import geopandas as gpd
import pandas as pd
import requests
import timeago
@drewrothstein
drewrothstein / automower_prometheus.py
Created June 6, 2021 20:32
Automower Prometheus Exporter
#!/usr/bin/python3
import requests
import time
from prometheus_client import Gauge, start_http_server
# Source: github.com/chrisz/pyhusmow
# ./husmow --login <> --password <> server
DATA_API = 'http://127.0.0.1:1234/status'
PORT_API = 8182
TIME_BETWEEN_CHECKS_SECONDS = 30
@drewrothstein
drewrothstein / async_await_promises_ohmy.js
Created July 11, 2020 05:34
Mixing Async/Await & Promises
var saveDoc = async function(data) {
const saveData = {
...data,
...{ savedTimestamp: admin.firestore.FieldValue.serverTimestamp() }
}
db.collection('Auth').doc(data.team_id).set(saveData).then(res => {
console.log('Auth data updated for:', data.team_id);
});
}
@drewrothstein
drewrothstein / firestore.js
Last active July 11, 2020 05:31
Example Firestore interaction w/JS
query.get()
.then((doc) => {
if (!doc.exists) {
console.log('Item: No such document for:', loggingEvent);
collection.add(item)
.then((documentReference) => {
console.log(`Added item with ref/id: ${documentReference.id}`);
track('Wrote Message to DB Completed', {
team: item.team,
channel: item.channel,
@drewrothstein
drewrothstein / resolving.js
Created July 11, 2020 05:29
Resolving Promises
Promise.all([
parseIncoming,
delegateReader,
writeDb,
writeSummary,
preCache,
])
.then((res) => {
// ...
});
@drewrothstein
drewrothstein / promises.js
Created July 11, 2020 05:27
.then() gets pretty old pretty fast
Promise.resolve(skipPosting)
.then((res) => {
if ( res === 'skipPosting' ) {
throw new Error('skipPosting');
}
})
.then(() => {
const fromTs = ...;
let countOfQuestions = ...;
queryQuestions.get().then((querySnapshot) => {
@drewrothstein
drewrothstein / oauth.js
Created May 11, 2020 02:00
Slack OAuth v2
const installUrl = `https://slack.com/oauth/v2/authorize?\
client_id=${process.env.SLACK_CLIENT_ID}&scope=${process.env.SLACK_SCOPES}`;
module.exports.save = async function (data) {
await saveDoc(data);
}
var saveDoc = async function(data) {
//
@drewrothstein
drewrothstein / expo.json
Created January 21, 2019 18:24
Expo: Firebase Console `json`
{
"project_info": {
"project_number": "1234567890",
"firebase_url": "https://yourapp.firebaseio.com",
"project_id": "yourapp",
"storage_bucket": "yourapp.appspot.com"
},
"client": [
{
"client_info": {