This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
//Note that this is an INEFFICIENT way to solve the problem | |
function noob_way() { | |
// get test data from a test data utility | |
var cars=get_data_set("basic"); | |
for (var i in cars){ | |
if(cars[i]["model"]!==undefined) { | |
Logger.log(cars[i]["model"]); // Logger.log() is Google App Script's console.log |
This file contains hidden or 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
/* | |
The most common way to track users in Google Analytics is by using cookies. But sometimes | |
there are platform and security limitations that will not allow cookies to be set or | |
stored for multiple sessions. The following code uses the localStorage property (available | |
now in most browsers) to provide an alternate way to the cookie-based solution. The code | |
is heavily commented to help even the most casual users understand the overall workings | |
of the code. Feel free to ignore this part if you know what you are doing. | |
This work is based on a Google example: | |
https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id |
This file contains hidden or 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 bl = require('bl'); | |
var http = require('http'); | |
var url = process.argv[2]; | |
http.get(url, function(res) | |
{ | |
res.setEncoding("utf8"); | |
res.pipe(bl(function (err,data) | |
{ | |
if(err) |
This file contains hidden or 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') | |
http.get(process.argv[2], function (response) { | |
response.setEncoding('utf8') | |
response.on('data', console.log) | |
response.on('error', console.error) | |
}) |
This file contains hidden or 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 mod = require('./module1'); | |
mod(process.argv[2], process.argv[3], function (err, listf) { | |
if (err) { | |
console.log('Error!') | |
} else { | |
for (var i = 0; i < listf.length; i++) { | |
console.log(listf[i]); | |
} | |
} |
This file contains hidden or 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 fs = require('fs') | |
var path = require('path') | |
fs.readdir(process.argv[2], function (err, list) { | |
list.forEach(function (file) { | |
if (path.extname(file) === '.' + process.argv[3]) | |
console.log(file) | |
}) | |
}) |