Skip to content

Instantly share code, notes, and snippets.

@takvol
takvol / gist:0a0dd9b089314bc5463eaf6af83fa060
Last active January 18, 2023 16:31 — forked from siygle/gist:9678772
Parse Gmail Inbox to sheet
function extractData(data, startStr, endStr) {
// This function extracts text between two strings
// i.e. extractData("Good_news,_everyone!", "Good_", ",_Everyone!") will return "News"
var startIndex, endIndex, text = 'N/A';
startIndex = data.indexOf(startStr);
if(startIndex != -1) {
startIndex += startStr.length;
text = data.substring(startIndex);
@takvol
takvol / Code.gs
Last active February 20, 2023 15:50
Find distance and driving time between locations stored in google spreadsheet by using Distance Matrix API
function onOpen() {//adds new menu item to active spreadsheet
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [
{name : "Calculate distance", functionName : "findDistance"},
{name : "Clear distance", functionName : "clearIDs"}];
sheet.addMenu("Distance measure", entries);
}
function clearIDs() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
@takvol
takvol / Code.gs
Created June 29, 2016 19:54
Create directories in google drive from folder structure saved in spreadsheet
//Script limit is 6 min = 360 sec and folder creation operation lasts for half of a second.
//So max folders created in one run is around 360sec * 2 = 720
//To prevent time limit error was used workaround from https://ctrlq.org/code/20016-maximum-execution-time-limit
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Create folders')
.addItem('Create in current folder', 'createFolders')
.addItem('Create in current folder, starting from row', 'createAtRow')
.addItem('Create in root', 'createAtRoot')
@takvol
takvol / Copy.gs
Last active April 12, 2024 06:50
Copy google spreadsheet with all protected ranges permissions
function Main() {
var template = DriveApp.getFileById('YOUR_SPREADSHEET_ID'); //template spreadsheet
var destination = DriveApp.getFolderById('COPY_DESTINATION_FOLDER_ID'); //the directory to copy the file into
var curDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy-MM-dd");
var copyName = template.getName() + ' copy ' + curDate; //the filename that should be applied to the new copy (e.g. "My spreadsheet copy 2019-08-24")
copyTemplate(template, copyName, destination);
}
/**
@takvol
takvol / eBayItemCategory.gs
Created August 8, 2016 14:44
Custom function in GAS that takes eBay item URL and returns item category
function getCategory(itemUrl) {
var itemID = itemUrl.slice(itemUrl.lastIndexOf('/') + 1);
Logger.log(itemID);
var parameters =
"?callname=GetSingleItem" +
"&responseencoding=JSON" +
"&appid=" + "YourAppIDHere" +
"&siteid=0" +
"&version=963" +
@takvol
takvol / getCargoStatus.gs
Last active September 20, 2016 12:59
Google Sheets custom function that returns status of the shipment serviced by "Nova Poshta" express delivery.
//Keep in mind that Nova Poshta may change tracking API method to require phone number
/**
* Returns current status of cargo.
*
* @param {number} invoice Invoice number.
* @return {string} cargo status information.
* @customfunction
*/
function getCargoStatus(invoice) {
@takvol
takvol / MailOpenBeacon.gs
Last active September 4, 2016 15:01
Google script that checks that a user has accessed the content of email.
//USAGE
//sendMail("test@example.com", "test", "test", "test", "<body>test</body>");
//Or embed <img src=https://script.google.com/macros/s/macro_id_here/exec?id=someId style = "height: 1px; width: 1px; display: none !important;">
//in email html body
var SCRIPT_LINK = "https://script.google.com/macros/s/macro_id_here/exec";//macro url
var SHEET_ID = "spreadsheet_id_here";//logger spreadsheet id
function sendMail(email, subject, plainText, id, html) {
var html = html + '<img src=' + SCRIPT_LINK + '?id=' + id +
@takvol
takvol / readme.md
Created September 28, 2019 19:01
Leaflet polygon with area tooltip