Skip to content

Instantly share code, notes, and snippets.

Avatar
🌐
Philadelphia, PA

Michael Lynn mrlynn

🌐
Philadelphia, PA
View GitHub Profile
@mrlynn
mrlynn / fetchData.js
Created Apr 5, 2020
Query MongoDB Stitch API for Data from A Google Apps Script - maintaining timeout to avoid overloading API
View fetchData.js
/**
|* Insert this code into your Google Sheets Script Editor
|* From there, you can insert into a cell in the sheet =fetchCode("somevalue")
|* This will return the value fetched from the database and set a last date fetched.
|* Next time you want to fetch - it will compare the last date fetched. If it's more than a day
|* It will fetch again - otherwise, not.
**/
function fetchCode(code) {
if (!code || code == "") {
@mrlynn
mrlynn / lookupTwilio.js
Last active Apr 20, 2019
MongoDB Stitch Function to Lookup a number using Twilio's lookup API
View lookupTwilio.js
exports = function(phoneNumber){
const host = "lookups.twilio.com";
const path = `/v1/PhoneNumbers/${phoneNumber}`;
const lookupUrl = `https://lookups.twilio.com/v1/PhoneNumbers/${phoneNumber}`;
const http = context.services.get("http");
const { SID, Secret } = context.values.get("twilioCredentials");
return http.get({
"scheme": "https",
host,
path,
@mrlynn
mrlynn / OnOpen.js
Created Mar 3, 2019
Google Sheet Script to Create a Menu Item OnOpen - part of Stitching Sheets blog article
View OnOpen.js
/****
* This function runs automatically and adds a menu item to Google Sheets
****/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheetByName("Events"));
var entries = [{
name : "Export Events to MongoDB",
functionName : "exportEventsToMongoDB"
},{
@mrlynn
mrlynn / StitchingSheets.js
Last active Oct 30, 2020
Google Sheets Script - Complete Script for Article Stitching Sheets
View StitchingSheets.js
/****
* Michael Lynn - http://blog.mlynn.org
* Stitching Sheets - Integrating Google Sheets with MongoDB Using MongoDB Stitch
****/
// Create an object which contains keys for each column in the spreadsheet
var columns = { // 0 indexed
type: 2,
date_start: 3,
date_end: 4,
@mrlynn
mrlynn / removeEventFromMongoDB.js
Created Mar 3, 2019
Google Sheets Script to Remove Events from a MongoDB Database
View removeEventFromMongoDB.js
/****
* Delete the events from the Calendar and remover the eventID Reference from the sheet - wipeout.
****/
function removeEventsFromMongoDB() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Events");
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var numRows = range.getNumRows();
var data = range.getValues();
@mrlynn
mrlynn / importGoogleSheetsEvent.js
Created Mar 3, 2019
Receive POST from Google Sheets and Insert into MongoDB Database
View importGoogleSheetsEvent.js
exports = async function(payload) {
const mongodb = context.services.get("mongodb-atlas");
const eventsdb = mongodb.db("events");
const eventscoll = eventsdb.collection("events");
const result= await eventscoll.insertOne(payload.query);
var id = result.insertedId.toString();
if(result) {
return JSON.stringify(id,false,false);
}
return { text: `Error saving` };
@mrlynn
mrlynn / exportEventsToMongoDB.js
Last active Oct 14, 2020
Google Sheets Script to Export Data to MongoDB Stitch API Service
View exportEventsToMongoDB.js
/****
* Export the events from the sheet to a MongoDB Database via Stitch
****/
function exportEventsToMongoDB() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Events");
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange(); // determine the range of populated data
var numRows = range.getNumRows(); // get the number of rows in the range
var data = range.getValues(); // get the actual data in an array data[row][column]
@mrlynn
mrlynn / removeEvent.js
Created Mar 3, 2019
MongoDB Stitch Delete Events Example
View removeEvent.js
exports = async function(payload) {
const mongodb = context.services.get("mongodb-atlas");
const eventsdb = mongodb.db("events");
const eventscoll = eventsdb.collection("events");
const delresult = await eventscoll.deleteOne({name:payload.query.name, location: payload.query.location});
return { text: `Deleted ${delresult.deletedCount} items` };
};
View Bubble Sort Example
var countOuter = 0;
var countInner = 0;
var countSwap = 0;
array = [3,9,4,5,1,200,2,88]
dump(array);
var swapped;
do {
countOuter++;
View urlstash-stitch-app
exports = async function (payload) {
const mongodb = context.services.get("mongodb-atlas");
const exampledb = mongodb.db("exampledb");
const examplecoll = exampledb.collection("examplecoll");
const args = payload.query.text.split(" ");
switch (args[0]) {
case "stash":
const result = await examplecoll.insertOne({
user_id: payload.query.user_id,
when: Date.now(),
You can’t perform that action at this time.