Skip to content

Instantly share code, notes, and snippets.

Avatar

Drew Rothstein drewrothstein

View GitHub Profile
View index.js
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';
View automower_function.py
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():
View produce_google_action_data.py
#!/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 Jun 6, 2021
Automower Prometheus Exporter
View automower_prometheus.py
#!/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
View async_await_promises_ohmy.js
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 Jul 11, 2020
Example Firestore interaction w/JS
View firestore.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,
View resolving.js
Promise.all([
parseIncoming,
delegateReader,
writeDb,
writeSummary,
preCache,
])
.then((res) => {
// ...
});
@drewrothstein
drewrothstein / promises.js
Created Jul 11, 2020
.then() gets pretty old pretty fast
View promises.js
Promise.resolve(skipPosting)
.then((res) => {
if ( res === 'skipPosting' ) {
throw new Error('skipPosting');
}
})
.then(() => {
const fromTs = ...;
let countOfQuestions = ...;
queryQuestions.get().then((querySnapshot) => {
View oauth.js
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 Jan 21, 2019
Expo: Firebase Console `json`
View expo.json
{
"project_info": {
"project_number": "1234567890",
"firebase_url": "https://yourapp.firebaseio.com",
"project_id": "yourapp",
"storage_bucket": "yourapp.appspot.com"
},
"client": [
{
"client_info": {