Skip to content

Instantly share code, notes, and snippets.

View tanyagupta's full-sized avatar

tanyagupta tanyagupta

  • Washington DC
View GitHub Profile
@tanyagupta
tanyagupta / hello_world_c9_express_with_comments.js
Last active April 1, 2022 16:00
Node.js web app using Express in Cloud9 - heavily commented
// 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
@tanyagupta
tanyagupta / project.js
Created December 5, 2015 19:40
MY FIRST ASYNC I/O! (Exercise 4 of 13)
var fs = require('fs');
var content = fs.readFile(process.argv[2],function(err,data){
if(err){
console.log('error');
}
var lines=data.toString().split('\n');
console.log(lines.length-1);
});
@tanyagupta
tanyagupta / Gruntfile.js
Last active May 26, 2018 18:14
Sample Gruntfile.js for GWG-MWS (Grow with Google Mobile Web Specialist)
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
responsive_images:{
myTask:{
options:{}, /* left blank to keep it simple */
files:[{
expand:true,
@tanyagupta
tanyagupta / extract_text_from_youtube.gs
Last active January 25, 2018 14:36
Use the YouTube ID of Udacity close captioned videos to extract the transcript
function doGet() { // this starts the Google Apps server
var template = HtmlService.createTemplateFromFile('extract_text_from_youtube');
var title_string='Get transcript from Udacity Video';
return template.evaluate()
.setTitle(title_string).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function getTranscript(id){
var resp = UrlFetchApp.fetch("http://video.google.com/timedtext?lang=en&v="+id) //UrlFetchapp to avoid ajax issues related to CORS
@tanyagupta
tanyagupta / duplicate-typing-knockout-js.markdown
Created December 6, 2017 00:32
Duplicate typing knockout js
@tanyagupta
tanyagupta / program.js
Created December 5, 2015 21:47
FILTERED LS (Exercise 5 of 13)
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)
})
})
@tanyagupta
tanyagupta / and_example_json_data.js
Last active October 28, 2017 11:23
Accessing heterogenous JSON data (using &&) - Part 4
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"]){
@tanyagupta
tanyagupta / UI.html
Created December 30, 2016 00:54
Using D3 in GAS
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
@tanyagupta
tanyagupta / find_item_in_array.js
Created January 8, 2017 20:02
How to find an item in an array
function item_in_array(){
var fruits = ["Bob", "Rob", "Amanda", "Cheryl","Susan"];
Logger.log(fruits.indexOf("Susan")) //returns 4 which is the index of Susan
Logger.log(fruits.indexOf("Frank")) //returns -1 since the item is not found
}
@tanyagupta
tanyagupta / fetch.js
Last active January 2, 2017 19:27
UrlFetchApp script with Zendesk (multiple pages)
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(),}});
}