tanaike

The Thinker

Transposing JSON Object using Google Apps Script

Gists This is a sample script for transposing JSON object using Google Apps Script. Input data : [ {"key1":"a1","key2":"a2","key3":"a3","key4":"a4","key5":"a5"}, {"key1":"b1","key2":"b2","key3":"b3","key4":"b4","key5":"b5"}, {"key1":"c1","key2":"c2","key3":"c3","key4":"c4","key5":"c5"}, {"key1":"d1","key2":"d2","key3":"d3","key4":"d4","key5":"d5"}, {"key1":"e1","key2":"e2","key3":"e3","key4":"e4","key5":"e5"} ] Output data : { "key1": ["a1", "b1", "c1", "d1", "e1"], "key2": ["a2", "b2", "c2", "d2", "e2"], "key3": ["a3", "b3", "c3", "d3", "e3"], "key4": ["a4", "b4", "c4", "d4", "e4"], "key5": ["a5", "b5", "c5", "d5", "e5"] } Script : At first, keys have to be defined by yourself, because the order of json is not decided.

Transposing Slice From (n x m) To (m x n) for golang

Gists This is a sample script for transposing slice from (n x m) to (m x n) for golang. Script : package main import "fmt" func transpose(slice [][]string) [][]string { xl := len(slice[0]) yl := len(slice) result := make([][]string, xl) for i := range result { result[i] = make([]string, yl) } for i := 0; i < xl; i++ { for j := 0; j < yl; j++ { result[i][j] = slice[j][i] } } return result } func main() { sample := [][]string{ []string{"a1", "a2", "a3", "a4", "a5"}, []string{"b1", "b2", "b3", "b4", "b5"}, []string{"c1", "c2", "c3", "c4", "c5"}, } ar := transpose(sample) fmt.

Open Site with New Window using Google Apps Script

Gists This is a sample script for opening a site with new window using Google Apps Script. It is possible to open the site inside the opened dialog box using iframe. But in my situation, I had to open the site as new window. So I created this. As a sample application, it can think of like this. When the special keyword was inputted, open sites and files in Google Drive as a help window.

Uploading Files From Local To Google Drive by Python without Quickstart

Gists This is a sample script for uploading files from local PC to Google Drive using Python. In this sample, Quickstart is not used. So when you use this script, please retrieve access token. Curl sample : curl -X POST \ -H "Authorization: Bearer ### access token ###" \ -F "metadata={name : 'sample.png', parents: ['### folder ID ###']};type=application/json;charset=UTF-8" \ -F "file=@sample.png;type=image/png" \ "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart" ] Python sample : When above curl sample is converted to Python, it becomes as follows.