Skip to content

Instantly share code, notes, and snippets.

View chipoglesby's full-sized avatar
🏠
Working from home

Chip Oglesby chipoglesby

🏠
Working from home
View GitHub Profile
@chipoglesby
chipoglesby / index.js
Last active October 23, 2023 01:23
Automatically move the sheets in a spreadsheet into alphabetical order.
function sortSheets(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetNameArray = [];
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
sheetNameArray.push(sheets[i].getName());
}
sheetNameArray.sort();
for( var j = 0; j < sheets.length; j++ ) {
ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j]));
@chipoglesby
chipoglesby / github.gs
Created October 2, 2016 22:29
A Google Apps Script that automatically opens a pull request on a Github Repo.
function github() {
username = "xxx"
repo = "xxx"
url = "https://api.github.com/repos/"+username+"/"+repo+"/issues"
payload = {
"title": "xxx",
"body": "xxx",
"assignee": "xxx"
}
sendToGithub(url, payload)
@chipoglesby
chipoglesby / google_sheets.txt
Last active September 13, 2022 07:25
Common Google Spreadsheet Formulas
1. Identifying Cells by Type in Google Spreadsheets
=if(index(split(D1, "::"),1) = "mobileapp", "Mobile", "Website")
-------
2. Get the root domain url of a cell in Google Spreadsheets
For sites with one TLD or one TLD and one subdomain: ie: xx.com or xx.xx.com
=iferror(join(".", index(split(A2, "."),2),index(left(split(A2, "."),3),3)), join(".", index(split(A2, "."),1),index(left(split(A2, "."),3),2)))
@chipoglesby
chipoglesby / conditional-formatting.js
Last active May 18, 2022 23:34
Conditional Formatting in Google App Script based on cell value
//If the current cell is more than the previous cell, set it as lime green
function onEdit(e) {
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var name = sheet.getName();
var range = sheet.getRange("A:J");
var values = range.getValues();
var cell = sheet.getActiveCell();
var value = cell.getValue();
@chipoglesby
chipoglesby / waiting.js
Last active June 3, 2021 22:02
Google App Script - Is range blank? If so, write predefined values
/***What should this script do?
1. Loop through all of the spreadsheets
2. If the row after the row that contains AssociatedCampaignName is blank, Write "Waiting For Spot" in the next row after the cell that contains AssociatedCampaignName, IE: A2
3. Write "#" in B2:H2
**/
function waiting(){
var ss = SpreadsheetApp.getActive();
for(var n in ss.getSheets()){// loop over all tabs in the spreadsheet
@chipoglesby
chipoglesby / costdata.gs
Last active November 29, 2020 19:27
Cost Data Upload via Google Analytic's Management API with Google Sheets
function uploadData() {
var accountId = "xxxxxxxx";
var webPropertyId = "UA-xxxxxxxx-x";
var customDataSourceId = "xxxxxxxx";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var maxRows = ss.getLastRow();
var maxColumns = ss.getLastColumn();
var data = [];
for (var i = 1; i <= maxRows;i++) {
data.push(ss.getRange([i], 1,1, maxColumns).getValues());
@chipoglesby
chipoglesby / getdistance.gs
Created August 4, 2015 19:15
Get Distance between two points in Google Sheets with the Maps API
function getDirection(city1, city2) {
var directions = Maps.newDirectionFinder()
.setOrigin(city1).setDestination(city2)
.setMode(Maps.DirectionFinder.Mode.DRIVING)
.getDirections();
var d = directions.routes[0].legs[0].distance.text;
return parseInt(d.split(" ")[0].replace(",", ""));;
@chipoglesby
chipoglesby / bigQueryMailChimp.gs
Last active November 18, 2019 12:38
This gist shows how to query the MailChimp API using Google Apps Script and pushes data to Google BigQuery
// This script is designed to run on a 1 hour trigger in Google Apps Script. It is also written to "WRITE_TRUNCATE" your table
// which means it deletes the table and updates it with the newest information. You can change the variables in campaignList
// if you want to adjust it for your needs.
function chimpyAPI30days() {
projectId = "xxx";
datasetId = "xxx";
tableId = 'xxx';
yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 29);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chipoglesby
chipoglesby / googleAnalyticsReporting.gs
Created June 2, 2016 15:40
Send your Google Analytics metrics and dimensions to Google Big Query using Google Apps Script.
//Replace xxx with your values as necessary.
function googleAnalyticsReporting() {
projectId = "xxx";
datasetId = "xxx";
tableId = 'xxx';
data = [];
yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = Utilities.formatDate(yesterday, 'UTC', "yyyy-MM-dd");