tanaike - Google Apps Script, Gemini API, and Developer Tips

The Thinker

Removes Duplicate JSON Elements for a Value of a Certain Key

This sample removes duplicate JSON elements for a value of a certain key. When the value of the certain key is removed, only a first duplicate element is left. Also I had wanted to be used for Google Apps Script. So it became like this. Script : function removeDup(arr, key){ var temp = []; var out = []; arr.forEach( function (e, i) { temp[i] = (temp.indexOf(e[key]) === -1) ? e[key] : false; if (temp[i]) out.

Flattening Nested Array using CoffeeScript

This sample flattens a nested array using CoffeeScript. flatten = (array) -> array.reduce(((x, y) -> if Array.isArray(y) then x.concat(flatten(y)) else x.concat(y)), []) console.log flatten [1, [2, 3, [4, 5]], 6, [7, [8, [9], 10] ,11 , 12], 13] >>> [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]

How to use "fields" of Drive APIs

There are a lot of APIs on Google. When we use Google Drive APIs, they usually have “fields” as a resource. The parameter “fields” gives various information which is selected to us. This is one of important parameters. And this can be used at Google Apps Script (GAS) although that version is v2. About how to use it, there are some documents. But it is difficult to find how to use it at GAS.

Retrieve old revision file from Google Drive

I introduce 2 kinds of methods. One is to use curl. Another is to use wget. At this time, I could know that wget can be also used as same as curl. In order to use this, at first, please retrieve your access token and enable Drive API. 1. File ID Retrieve file id from file name. curl -X GET -sSL \ -H 'Authorization: Bearer ### Access token ###' \ 'https://www.

Put a channel to a channel for golang

I have never heard this. I would like to use this from now. package main import "fmt" type st struct { data1 int data2 int } func main() { c1 := make(chan *st, 1) c2 := make(chan *st, 1) c1 <- &st{1, 2} c2 <- <-c1 close(c1) close(c2) res, _ := <-c2 fmt.Println(res.data2) } >>> 2