This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Smarter way to access the data | |
function noob_smart_way(){ | |
var cars=get_data_set("basic"); | |
var format_string = "%s %s %s %s %s"; | |
for (var i in cars){ | |
Logger.log(format_string, cars[i]["model"] || "",cars[i]["trim"] || "",cars[i]["year"] || "", | |
cars[i]["wheel"] && cars[i]["wheel"]["wheel_size"] || "", | |
cars[i]["wheel"] && cars[i]["wheel"]["wheel_metal"] || "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_or(){ | |
var cars=[ | |
{make: "Jeep",model: "Cherokee",trim:"Sport 4dr Front-wheel Drive",year:"2016", | |
wheel:{wheel_size:"17 x 7.5",wheel_metal:"Aluminum"}}, | |
{make: "Jeep",model: "Wrangler",trim:"Sahara 2dr 4x4",year: "2015"} | |
] | |
for (var i in basic){ | |
Logger.log(cars[i]["wheel"] || "") // Logger.log() is Google App Script's console.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_and(){ | |
var cars=[ | |
{make: "Jeep",model: "Cherokee",trim:"Sport 4dr Front-wheel Drive",year:"2016",wheel:{wheel_size:"17 x 7.5",wheel_metal:"Aluminum"}}, | |
{make: "Jeep",model: "Wrangler",trim:"Sahara 2dr 4x4",year: "2015"} | |
] | |
for (var i in cars){ | |
if (cars[i]["wheel"] && cars[i]["wheel"]["wheel_size"]){ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_data_set(which){ | |
var all_data_set={ | |
basic:[ | |
{make: "Jeep",model: "Cherokee",trim:"Sport 4dr Front-wheel Drive",year:"2016",wheel:{wheel_size:"17 x 7.5", | |
wheel_metal:"Aluminum"}}, | |
{make: "Jeep",model: "Compass",trim:"Latitude 4dr Front-wheel Drive",year:"2014", | |
wheel:{wheel_metal:"Steel"}}, | |
{make: "Jeep",model: "Patriot",trim:"Sport 4dr 4x4"}, | |
{make: "Jeep",model: "Wrangler",trim:"Sahara 2dr 4x4",year: "2015"} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
app.get('/', function (req, res) { | |
res.send("<h1>hello world</h1>"); | |
}); | |
app.listen(8080, function () { | |
console.log('Example app listening on port 8080!'); | |
//call this app from https://<workspace name>-<user name>.c9users.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
var server = http.createServer(function(request, response) { | |
response.writeHead(200, {"Content-Type": "text/html"}); | |
response.write("<h1>Hello World</h1>"); | |
response.end(); | |
}); | |
server.listen(8080); | |
console.log("Server is listening"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Standard set up for the express code to work with your code | |
var express = require('express'); | |
var app = express(); | |
/* | |
Routes a get request, and in this simple case - to the server's root. It sends a | |
call back to handle the request. Not much will happen here, the call back is hardcoded | |
to send a hello world string. But in theory you can do something with the req variable | |
in the "/" directory, create a dynamic html and send that back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zd_get (cmd) { | |
var url = ZD_BASE+cmd; | |
var results =[]; | |
var service = getService(); | |
if (service.hasAccess()) { | |
do { | |
try { | |
var response = UrlFetchApp.fetch(url, {headers: {'Authorization': 'Bearer ' + service.getAccessToken(),}}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var all_results ={}; | |
var response = UrlFetchApp.fetch("https://www.googleapis.com/drive/v3/files?q="+mime_type,params); | |
var result=JSON.parse(response.getContentText()) ; | |
for (var i in result['files']) { | |
all_results[result['files'][i]['id']] = result['files'][i]['name']; | |
} | |
while (result['nextPageToken']) { | |
var pageToken = encodeURIComponent(result['nextPageToken']); |