Skip to content

Instantly share code, notes, and snippets.

View index.js
// server
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
// client
var b = fetch('https://us-central1-{project}.cloudfunctions.net/{method}').then((response) => {
const a = response.json().then(c => {console.log(c)});
})
View index.js
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.helloWorld = (req, res) => {
let message = req.query.message || req.body.message || 'Hello World!';
res.status(200)
.set('Content-Type', 'text/html')
@grant
grant / listGmailLabels.js
Created Oct 30, 2018
Lists Gmail Labels in Apps Script
View listGmailLabels.js
function myFunction() {
var labels = GmailApp.getUserLabels();
labels[0].getName()
var sortedLabels = labels.sort(function (label1, label2) {
var a = label1.getName().toLowerCase();
var b = label2.getName().toLowerCase();
if(a < b) { return -1; }
if(a > b) { return 1; }
return 0;
})
@grant
grant / saxophone.js
Created Jul 24, 2018
Create a Saxophone tutorial presentation
View saxophone.js
var PRESENTATION_TITLE = 'Saxophone Tutorials';
var YOUTUBE_QUERY = 'saxophone tutorials';
/**
* Gets a list of YouTube videos.
* @param {String} query - The query term to search for.
* @ref https://developers.google.com/youtube/v3/docs/search/list
*/
function getYouTubeVideosJSON(query) {
var youTubeResults = YouTube.Search.list('id,snippet', {
View clasp.ts
var ts = require('typescript');
var t = ts.transpile(s, {
compilerOptions: {
strict: true,
lib: ["es2015"],
}
});
console.log(t);
View cal.js
var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var googleAuth = require('google-auth-library');
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/calendar-nodejs-quickstart.json
var SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'];
var TOKEN_PATH = 'creds.json';
@grant
grant / TestGoogleAPIs.go
Created Dec 21, 2017
Produces a list of Google APIs
View TestGoogleAPIs.go
package snippets
import (
"testing"
"github.com/stretchr/testify/assert"
"net/http"
"time"
"encoding/json"
"log"
"fmt"
@grant
grant / quickstart.go
Last active Dec 6, 2017
Sheets Quickstart – Go alternative (developers.google.com/sheets/api/quickstart/go)
View quickstart.go
package main
import (
"fmt"
"log"
)
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
var SpreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
@grant
grant / MusicXML.xml
Last active Mar 25, 2016
An example of MusicXML
View MusicXML.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise
PUBLIC '-//Recordare//DTD MusicXML 2.0 Partwise//EN'
'http://www.musicxml.org/dtds/partwise.dtd'>
<score-partwise>
<work>
<work-number>BWV 784</work-number>
<work-title>Invention 13</work-title>
</work>
<identification>
@grant
grant / algoDBSearch.js
Created Jan 1, 2016
Search ranking for AlgoDB
View algoDBSearch.js
/**
* Searches the elastic search db.
* @param {String} query The raw text query
* @param {Callback} cb The response callback
* @return {Object} hits The hits from elasticsearch
*/
var search = function(query, cb) {
var url = ELASTIC_SEARCH_URL + 'algorithm/_search';
var body = {
query: {
You can’t perform that action at this time.