tanaike

The Thinker

Retirving All files in Folder with Spreadsheet

This sample retrieves all files in a folder with spreadsheet. When there are some folders in the folder with spreadsheet, this script can retrieve all files in all folders. This script has to be a container-bound script for spreadsheet. Script : function getFileList(){ var folderlist = (function(folder, folderSt, results){ var ar = []; var folders = folder.getFolders(); while(folders.hasNext()) ar.push(folders.next()); folderSt += folder.getId() + "#_aabbccddee_#"; var array_folderSt = folderSt.

Embedding a Map to a Cell using Custom Function on Spreadsheet

This sample script embeds a map to a cell using custom function on Spreadsheet. I think that this method is one of various ideas. Problem When the map is embeded to a cell on spreadsheet as an image, the function =IMAGE() is suitable for this situation. However, setFormula() for importing =IMAGE() and DriveApp.createFile() for creating images from maps also cannot be used for custom functions. Solution In order to avoid these limitations, I used Web Apps.

Changing from 'float64' to 'int' for Values did Unmarshal using 'map[string]interface{}'

This sample is for changing from “float64” to “int” for values did unmarshal using map[string]interface{}. When it did unmarshal using map[string]interface{}, a number with “int” was changed to “float64”. And it shows an error as follows. Error : panic: interface conversion: interface {} is float64, not int Sample Script : It solves using following script. package main import ( "encoding/json" "fmt" "reflect" ) func main() { data := `{"key": 10}` var i map[string]interface{} json.

Replacing JSON Key by Golang

This sample is for replacing JSON key by golang. package main import ( "encoding/json" "fmt" ) func main() { json1 := `{"key1": "value1"}` obj := map[string]interface{}{} json.Unmarshal([]byte(json1), &obj) fmt.Println(obj) // <-- map[key1:value1] obj["key2"] = obj["key1"] delete(obj, "key1") fmt.Println(obj) // <-- map[key2:value1] }

Benchmark: Splitting Command-Line Arguments by Golang

This sample script is for splitting command-line arguments by golang. There are 2 types. One is the regular expression is used. Another is that Split() and TrimSpace() are used. Here, each process speed was compared. Script : package main import ( "regexp" "strings" "testing" ) func BenchmarkB1(b *testing.B) { str := "test1.txt, test2.txt" b.ResetTimer() for i := 0; i < b.N; i++ { ar := regexp.MustCompile(`\s*,\s*`).Split(str, -1) var result []string for _, x := range ar { result = append(result, x) // --> 'test.