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
export const covid19UserResponse = functions.https.onCall(async (data, context) => { | |
try { | |
// https://docs.google.com/spreadsheets/d/13x-6koKiqRnIK6_trJX-abLJyi65OzqV621u9iwM1qw/edit#gid=2008915096 | |
await admin.firestore().collection('corona-user-responses').add(data); | |
// tslint:disable-next-line:radix | |
let is_elder = parseInt(data['age']['answer']) > 60 ? '1' : '0'; | |
let has_diseases_history = data['high_risk']['answer'] === 'true' ? '1' : '0'; |
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
// Include Nodejs' net module. | |
const Net = require('net'); | |
// The port on which the server is listening. | |
const port = 8080; | |
// Use net.createServer() in your code. This is just for illustration purpose. | |
// Create a new TCP server. | |
const server = new Net.Server(); | |
// The server listens to a socket for a client to make a connection request. | |
// Think of a socket as an end point. |
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
resetScore(): Promise<void> { | |
return this.usersCollectionRef.ref.get().then(resp => { | |
console.log(resp.docs) | |
let batch = this.afs.firestore.batch(); | |
resp.docs.forEach(userDocRef => { | |
batch.update(userDocRef.ref, {'score': 0, 'leadsWithSalesWin': 0, 'leadsReported': 0}); | |
}) | |
batch.commit().catch(err => console.error(err)); | |
}).catch(error => console.error(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
db.usersProject.aggregate([ | |
{ | |
"$group": { | |
_id: {projectId: "$projectId"}, | |
dups: { $addToSet: "$_id" } , | |
count: { $sum : 1 } | |
} | |
}, | |
{ | |
"$match": { |
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
db.person.find().snapshot().forEach( | |
function (elem) { | |
db.person.update( | |
{ | |
_id: elem._id | |
}, | |
{ | |
$set: { | |
name: elem.firstname + ' ' + elem.lastname | |
} |
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 start = moment(); | |
var end = moment().add(1, 'months');; | |
end.from(start); // "in 5 days" | |
end.from(start, true); | |
console.log(end.from(start, true)) |
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 scores = [4, 13, 2, 66, 12, 5]; | |
var result = scores.reduce((total, score) => total + score) / scores.length; | |
console.log(result); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://code.jquery.com/jquery.min.js"></script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> |
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 Json2CSV(objArray) | |
{ | |
var | |
getKeys = function(obj){ | |
var keys = []; | |
for(var key in obj){ | |
keys.push(key); | |
} | |
return keys.join(); | |
}, array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray |
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
Student.findByIdAndUpdate( | |
req.body._id, { | |
$push: { | |
"comments": req.body.imagelink | |
} | |
}, | |
function (err, model) { | |
if (err) { | |
console.log(err); | |
res.send(err); |
NewerOlder