Skip to content

Instantly share code, notes, and snippets.

View codeas's full-sized avatar

Ivan Kutil codeas

View GitHub Profile
@codeas
codeas / gas_gemini.gs
Created June 23, 2025 20:10
Calling Gemini API from Google Appps Script
function gemini_(model, payload) {
const apiKey = PropertiesService.getScriptProperties().getProperty('GEMINI_API_KEY');
const api = 'generateContent';
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:${api}?key=${apiKey}`;
const options = {
method: 'POST',
contentType: 'application/json',
muteHttpExceptions: true,
function start() {
const REGION = "us-central1";
const GCP_PROJECT_ID = "gcp-kutil";
const task = `
- Create a new label 'DEMO' in Gmail
- create only if it did not exist.
- Load last 10 emails with subject 'Security alert'.
- SET this new label 'DEMO' to found emails
function Agent() {
const ticks = "```";
this.person = `
Person
- You are Google Apps Script expert developer, who is able to generate valid code for V8 runtime
- Your goal is to create code for defined task
- Return only code in markdown between ${ticks}javascript and ${ticks}
- Return all code in one big function named main().
{
"timeZone": "Europe/Prague",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/script.external_request",
"https://mail.google.com/",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/spreadsheets",
@codeas
codeas / get-filtered-rows-from-sheet.js
Last active February 25, 2022 16:51
#GoogleSheet #GoogleSheetAPI
/*
Get filtered rows from Google Sheets
@author Ivan Kutil
Preparation: add Advanced service "Sheets" into Google Apps Script project
*/
function getFilteredRows() {
console.time("filtered-rows")
let spreadsheetId = SpreadsheetApp.getActive().getId();
let sheetName = "MySheetName"
/*
Apps Script code snippet based on GCPping.com
@author Ivan Kutil
*/
var URLS = {
"asia-east1": "http://104.155.201.52/ping",
"asia-east2": "http://35.220.162.209/ping",
"asia-northeast1": "http://104.198.86.148/ping",
"asia-south1": "http://35.200.186.152/ping",
"asia-southeast1": "http://35.185.179.198/ping",
@codeas
codeas / code.gs
Created January 22, 2019 17:12
Native Android application with Apps Script
function doGet(e) {
return HtmlService.createTemplateFromFile("view").evaluate();
}
var SPREADSHEET_ID = "xxxxx"; // <-- Google Spreadsheet ID
var settings = {
nomadland : "xxxxxx" // <--- subtitles fileId
}
function RUN() {
var movie = "nomadland"
var fileId = settings[movie];
var output = subitlesParser(fileId);
@codeas
codeas / gas-google-nlp.js
Created March 6, 2018 21:51
GAS Google NLP
/*
* Get sentiment from Google Cloud Natural Language API
*/
var getSentiment = function(text) {
var apiKey = PropertiesService.getScriptProperties().getProperty("apiKey")
var url = "https://language.googleapis.com/v1/documents:analyzeSentiment?key=%KEY".replace("%KEY", apiKey)
var data = {
document: {
language: "en-us",
@codeas
codeas / subtitlesParser.js
Last active April 26, 2021 06:54
OSCAR and Google NLP
var subitlesParser = function(fileId) {
var agregated = false;
var CHARS = "-->";
var BATCH_SIZE = 2; // time-window (e.g. 2minutes)
var epoch = 0;
var text = [];
var output = [];
var content = DriveApp.getFileById(fileId).getBlob().getDataAsString();
var rows = content.split("\n");