Skip to content

Instantly share code, notes, and snippets.

🌐
GopherCon

Michael Lynn mrlynn

🌐
GopherCon
Block or report user

Report or block mrlynn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 Jun 12, 2019
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 Jul 17, 2019
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(),
@mrlynn
mrlynn / index.html
Created Oct 30, 2018
MongoDB Stitch - Getting Started
View index.html
<!-- Base Stitch Browser SDK -->
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.14/stitch.js"></script>
<div class="results-bar">
<p>Count of Results:</p>
<span id="num-results" class="results-bar__count"></span>
</div>
<table class="table table-striped">
<thead class="thead">
<tr>
You can’t perform that action at this time.