I wanted to display my Gmail Inbox unread message count on my personal web page on Google Sites, so I made a tiny Google Apps Script widget to do this.
The code turned out very simple.
code.gs:
function doGet() { return HtmlService.createTemplateFromFile('page') .evaluate() .setSandboxMode(HtmlService.SandboxMode.NATIVE); }
function getInboxUnreadCount() { return GmailApp.getInboxUnreadCount(); }
The getInboxUnreadCount() function needed to be run from the script editor to grant the needed permissions to the script, after that it worked from my personal home page.
When I was traveling to a friend’s place to give her a Christmas not alone I got picked up by someone who suggested I learn jQuery… so I did, and in the process wrote a JavaScript Read Eval Print Loop that makes jQuery and JavaScript development as easy as interactive Python or BASH programming.
The result is a single file web application, JavaScript Read, Eval, Print, Loop. View the source to see what was needed to make it work.
loading...
started 0
started 1
finished 0: date = Sat Jan 04 2014 12:03:06 GMT-0400 (AST), last = -1
finished 1: date = Sat Jan 04 2014 12:03:06 GMT-0400 (AST), last = -1
started 2
started 3
finished 2: date = Sat Jan 04 2014 12:03:08 GMT-0400 (AST), last = -1
finished 3: date = Sat Jan 04 2014 12:03:08 GMT-0400 (AST), last = -1
Which leads me to the conclusion that the server is stateless, at least from the point of view of the scripts running on it.
I have a function that is not often used and has a long initialization step, when it is used it is used often, making it a very good candidate for lazy initialization. This function is in a Google Apps Script web application, so minimizing processing time is desirable.
Functions in JavaScript are assignable closures, so it is easy to write a lazy initializing function without any if statements.
var getImage = function(name) { var images = { };
var files = MESSAGES_FOLDER.getFiles(); while(files.hasNext()) { var file = files.next(); images[file.getName()] = file.getDownloadUrl(); }
After the initialization part of the function (making a map of file names to download urls) it is replaced by a new function that does not include the initialization, and that new function is called to get the result for the first use.
This is also an implementation of the State pattern.
Lazy method, it’s funny sounds. But about script, yes, its good. I was searched this information, thank you. Yesterday I found article about split method java https://explainjava.com/split-string-java/, pretty good describing this method. Im sure it will help you some day.