Skip to content

Instantly share code, notes, and snippets.

View grant's full-sized avatar

Grant Timmerman grant

View GitHub Profile
@grant
grant / clasp.ts
Last active March 24, 2018 07:38
var ts = require('typescript');
var t = ts.transpile(s, {
compilerOptions: {
strict: true,
lib: ["es2015"],
}
});
console.log(t);
@grant
grant / saxophone.js
Created July 24, 2018 16:21
Create a Saxophone tutorial presentation
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', {
@grant
grant / listGmailLabels.js
Created October 30, 2018 01:05
Lists Gmail Labels in Apps Script
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 / index.js
Created February 19, 2019 18:50
GCF + HTML
/**
* 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 / index.js
Created March 5, 2019 18:01
CORS + GCF
// 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)});
})
@grant
grant / btc.js
Created April 12, 2019 17:45
BTC API – GCF
const rp = require('request-promise');
const DEFAULT_DATE = '2019-04-10';
exports.btc = async (req, res) => {
const date = req.query.date || DEFAULT_DATE;
async function getBTC(date) {
const res = await rp(`https://api.coinbase.com/v2/prices/BTC-USD/spot?date=${date}`, {
headers: {
'CB-VERSION': '2016-10-10',
Authorization: `Bearer ${process.env.COINBASE_TOKEN}`
@grant
grant / btc_sheets.js
Last active April 12, 2019 18:21
BTC API – GCF + Apps Script
/**
* Get's the bitcoin price at a date.
*
* @param {string} date The date in yyyy-MM-dd format. Defaults to today.
* @return The value of BTC in USD at the date. From Coinbase's API
* @customfunction
*/
function BTC_CF(date) {
var dateString = Utilities.formatDate(new Date(date), "GMT", "yyyy-MM-dd");
var res = UrlFetchApp.fetch("https://us-central1-new-project-as-test.cloudfunctions.net/btc?date=" + dateString);
@grant
grant / launch.json
Created July 20, 2019 00:32
GCF Debugging VSC launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]
@grant
grant / settings.json
Created July 20, 2019 00:33
GCF Debugging VSC settings.json
{
"debug.node.autoAttach": "on"
}
@grant
grant / index.js
Last active July 20, 2019 01:45
GCF Debugging VSC List Google APIs
const {google} = require('googleapis');
/**
* Returns a list of Google APIs and their descriptions.
* @param {Express.Request} req The API request.
* @param {Express.Response} res The API response.
*/
exports.listGoogleAPIs = async (req, res) => {
// Call the API
const apis = await google.discovery('v1').apis.list();
// Build the response