Skip to content

Instantly share code, notes, and snippets.

View Max-Makhrov's full-sized avatar
🇺🇦

Max Makhrov Max-Makhrov

🇺🇦
View GitHub Profile
@tanaikech
tanaikech / submit.md
Last active May 3, 2024 08:08
Inserting Animated GIFs over Cells on Google Sheets using Google Apps Script

Inserting Animated GIFs over Cells on Google Sheets using Google Apps Script

Overview

This script demonstrates how to insert an animated GIF over cells in a Google Sheet using Google Apps Script.

Description

I recently received a request to create a Google Apps Script for inserting animated GIFs into cells on a Google Sheet. I previously published a sample script on my blog on June 6, 2017. Ref In that script, the animation GIF was inserted using a public link. This new script leverages data URLs, which simplifies the process for using GIFs stored in Google Drive. Since this approach might be helpful to others, I'm sharing it here.

// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@tanaikech
tanaikech / submit.md
Last active April 26, 2024 11:51
Allowing Access by IMPORTHTML, IMPORTDATA, IMPORTFEED, IMPORTXML, and IMPORTRANGE on Google Spreadsheet with Google Apps Script

Allowing Access by IMPORTHTML, IMPORTDATA, IMPORTFEED, IMPORTXML, and IMPORTRANGE on Google Spreadsheet with Google Apps Script

Updated on April 26

From this X and this blog, it seems that in the current stage, this situation can be resolved using Sheets API. The sample script of Google Apps Script is as follows. Before you test this, please enable Sheets API at Advanced Google services.

function myFunction() {
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@asabaylus
asabaylus / gist:3071099
Created July 8, 2012 14:12
Github Markdown Heading Anchors

Anchors in Markdown

To create an anchor to a heading in github flavored markdown. Add - characters between each word in the heading and wrap the value in parens (#some-markdown-heading) so your link should look like so:

[create an anchor](#anchors-in-markdown)

@mlconnor
mlconnor / country_date_formats.csv
Created February 22, 2012 20:49
Listing of countries with their preferred date formats, ISO3166 code, ISO629-2
ISO 3166 Country Code ISO639-2 Country Code Country ISO 3166 Country Code ISO639-2 Lang Language Date Format
ALB AL Albania sqi sq Albanian yyyy-MM-dd
ARE AE United Arab Emirates ara ar Arabic dd/MM/yyyy
ARG AR Argentina spa es Spanish dd/MM/yyyy
AUS AU Australia eng en English d/MM/yyyy
AUT AT Austria deu de German dd.MM.yyyy
BEL BE Belgium fra fr French d/MM/yyyy
BEL BE Belgium nld nl Dutch d/MM/yyyy
BGR BG Bulgaria bul bg Bulgarian yyyy-M-d
BHR BH Bahrain ara ar Arabic dd/MM/yyyy
@Max-Makhrov
Max-Makhrov / gist:5a36610a2dd1eaff3d3252d74e34d557
Last active April 23, 2024 22:02 — forked from peterherrmann/gist:2700284
GASRetry - Exponential backoff JavaScript implementation for Google Apps Script (Library project key: "MGJu3PS2ZYnANtJ9kyn2vnlLDhaBgl_dE")
/**
* Invokes a function, performing up to 5 retries with exponential backoff.
* Retries with delays of approximately 1, 2, 4, 8 then 16 seconds for a total of
* about 32 seconds before it gives up and rethrows the last error.
* See: https://developers.google.com/google-apps/documents-list/#implementing_exponential_backoff
* <br>Author: peter.herrmann@gmail.com (Peter Herrmann)
<h3>Examples:</h3>
<pre>//Calls an anonymous function that concatenates a greeting with the current Apps user's email
var example1 = GASRetry.call(function(){return "Hello, " + Session.getActiveUser().getEmail();});
</pre><pre>//Calls an existing function
@pallocchi
pallocchi / saveNewAttachmentsToDrive.js
Last active April 23, 2024 16:10
Automatically Save Email Attachments to Google Drive Using Google Apps Script
function saveNewAttachmentsToDrive() {
var folderId = "PUT_YOUR_FOLDER_ID_HERE"; // Replace with the ID of the destination folder in Google Drive
var searchQuery = "to:your-email@example.com has:attachment"; // Replace with the search query to find emails with attachments
var lastExecutionTime = getLastExecutionDate();
var threads = GmailApp.search(searchQuery + " after:" + lastExecutionTime);
var driveFolder = DriveApp.getFolderById(folderId);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
@tanaikech
tanaikech / submit.md
Last active April 17, 2024 14:33
Benchmark: fetchAll method in UrlFetch service for Google Apps Script

Benchmark: fetchAll method in UrlFetch service for Google Apps Script

By Google's update at January 19, 2018, fetchAll method was added to the UrlFetch service. When I saw the usage, I couldn't find the detail information about the actual running state. So I investigated about it.

As the result, it was found that the fetchAll method is worked by the asynchronous processing. The returned data is reordered by the order of requests. By this, it was also found that if you want to retrieve the data from the several URL, the process cost of UrlFetchApp.fetchAll() is much lower than that of UrlFetchApp.fetch() using for loop.

The sample scripts for server side and client side are as follows.

Sample script for server side

In this report, 5 Web Apps were used as the servers. At first, 5 standalone projects were created and the following server script was put to each project. Then, Web Apps was deployed for ea

@tanaikech
tanaikech / submit.md
Last active April 16, 2024 13:00
Consolidate Scattered A1Notations into Continuous Ranges on Google Spreadsheet using Google Apps Script

Consolidate Scattered A1Notations into Continuous Ranges on Google Spreadsheet using Google Apps Script

Abstract

Consolidate scattered cell references (A1Notation) in Google Sheets for efficiency. This script helps select cells by background color or update values/formats, overcoming limitations of large range lists.

Introduction