Best JavaScript code snippet using wpt
strava_helper.js
Source:strava_helper.js
1/**2 * Created by avi on 8/31/15.3 */4var strava = require('strava-v3');5/**6 * gets OAUTH code from Strava7 */8exports.authenticate = function () {9 var authURL = strava.oauth.getRequestAccessURL({scope: "write"});10 console.log(authURL);11 return authURL;12};13/**14 *15 * Log into strava with auth cookie and processes teh activity16 *17 * @param w_token18 * bearer token19 */20exports.processUser = function (w_token, onerror) {21 var yesterday = Date.now() / 1000 - 86400;22 var params = {'access_token':w_token, 'after': yesterday };23 strava.athlete.listActivities(params, function(err,payload) {24 if (err) {25 console.log(err);26 onerror(err);27 } else {28 for (var id in payload) {29 processActivity(payload[id], w_token);30 }31 }32 });33};34/**35 * Retrieves a bearer token with write scope, based on temp auth code36 *37 * @param code38 * OAUTH temp code39 *40 */41exports.getWriteToken = function(code, callback) {42 var response = null;43 strava.oauth.getToken(code,function(err,payload) {44 if (err) {45 console.log(err);46 callback(err, null);47 } else {48 callback(null,{49 'token': payload.access_token,50 'id': payload.athlete.id,51 'name': payload.athlete.email,52 'valid': true53 });54 }55 });56 return response;57};58/**59 *60 * Log into strava with auth cookie and list all activities for the athlete61 *62 * @param w_token63 * bearer token64 */65exports.getActivities = function (w_token, onsucces, onerror) {66 var params = {'access_token':w_token };67 strava.athlete.listActivities(params, function(err,payload) {68 if (err) {69 console.log(err);70 onerror(err);71 } else {72 onsucces(payload);73 }74 });75};76function isWorkout(activity) {77 return activity.type == 'Workout' && !activity.private;78}79function isInsignificant(activity) {80 return (activity.type == 'Run' && activity.distance <100.0) ||81 (activity.type == 'Ride' && activity.distance<100.0);82}83function processActivity(activity, w_token) {84 if (isWorkout(activity) || isInsignificant(activity)) {85 console.log('DEBUG: processing activity '+activity.name);86 var params = {87 'access_token': w_token,88 'id': activity.id89 ,'private': true,90 'name': '! ' + activity.name91 };92 strava.activities.delete(params, function (err, payload) {93 if (!err) {94 console.log(payload);95 console.log('INFO: processed activity: ' + activity.name + '\n');96 }97 else {98 console.log(err);99 }100 });101 }...
index.js
Source:index.js
1const path = require("path");2const config = {3 root: path.resolve(__dirname, '../../'),4 rootSrc: path.resolve(__dirname, '../../src'),5 maxAge: 1 * 24 * 60 * 60 * 1000,6 server: {7 domain: '0.0.0.0',8 port: 3003,9 image: ''10 },11 db: {12 domain: '127.0.0.1',13 port: '27017',14 username: '',15 password: '',16 dbName: 'test',17 table: {18 user: 'W_user',19 token: 'W_token',20 uid_id: 'W_uid_id',21 token: 'W_token',22 log: 'W_log',23 auth: 'W_auth',24 setting: 'W_setting',25 }26 },27 error: {28 400: `400 - 请æ±æ æï¼æªç»å½ææªææ. Client error`,29 401: `401 - æ°æ®æ误ï¼è¯·æ£æ¥è¯·æ±çæ°æ®æ¯å¦æ£ç¡®. Client error`,30 403: `403 - æ 访é®æéï¼è¯·è系管çåè·åç¸å
³æéåå¨å°è¯è®¿é®. Client error`,31 404: `404 - èµæºæªæ¾å°ï¼è¯·æ£æ¥ç½åè¾å
¥æ¯å¦æ£ç¡®. Client error`,32 500: `500 - æå¡å¨é误ï¼å¤çç¨åºæªå®ä¹. Server Error`,33 501: `501 - 请æ±é误ï¼Token éªè¯å¤±è´¥ï¼éæ³è¯·æ±. Server Error`,34 502: '502 - æå¡å¨é误ï¼æ¥å¿è®°å½åå
¥å¤±è´¥. Server Error',35 503: `503 - 请æ±é误ï¼æ²¡ææ¾å°å¯¹åºçå¤çç¨åº. Server Error`,36 505: `505 - æå¡å¨é误ï¼æ°æ®åºå¤çåºéï¼è¯·è系管çå. Server Error`,37 }38}...
cross-origin-isolated.window.js
Source:cross-origin-isolated.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=./resources/common.js5const http = get_host_info().HTTP_ORIGIN;6const https = get_host_info().HTTPS_ORIGIN;7let crossOriginIsolatedTest = (8 description,9 origin ,10 headers,11 expect_crossOriginIsolated) => {12 promise_test_parallel(async test => {13 const w_token = token();14 const w_url = origin + executor_path + headers + `&uuid=${w_token}`;15 const w = window.open(w_url)16 add_completion_callback(() => w.close());17 const this_token = token();18 send(w_token, `19 if (window.crossOriginIsolated)20 send("${this_token}", "crossOriginIsolated");21 else22 send("${this_token}", "not isolated")23 `);24 assert_equals(await receive(this_token), expect_crossOriginIsolated);25 }, description);26}27crossOriginIsolatedTest("Main crossOriginIsolated case:",28 https, coop_same_origin +29 coep_credentialless, "crossOriginIsolated");30crossOriginIsolatedTest("Missing HTTPS:",31 http, coop_same_origin +32 coep_credentialless, "not isolated");33crossOriginIsolatedTest("Missing COOP:same-origin:",34 https, coep_credentialless, "not isolated");35crossOriginIsolatedTest("Report-only:",36 https, coop_same_origin +37 coep_report_only_credentialless, "not isolated");38crossOriginIsolatedTest("Report-only + enforced:",39 https, coop_same_origin +40 coep_credentialless +...
Using AI Code Generation
1const wptools = require('wptools');2wptools.page('Albert Einstein').then(function(page) {3 return page.getWikiText();4}).then(function(wikitext) {5 console.log(wikitext);6});7const wptools = require('wptools');8wptools.page('Albert Einstein').then(function(page) {9 return page.getWikiText();10}).then(function(wikitext) {11 console.log(wikitext);12});13const wptools = require('wptools');14wptools.page('Albert Einstein').then(function(page) {15 return page.getWikiText();16}).then(function(wikitext) {17 console.log(wikitext);18});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('wpt_api_key');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var wptools = require('wptools');2var w_token = wptools.token;3var wpt = wptools.page('Albert Einstein');4wpt.get(function(err, resp, infobox) {5 console.log(infobox);6});7var wptools = require('wptools');8var wpt = wptools.page('Albert Einstein');9wpt.get(function(err, resp, infobox) {10 console.log(infobox);11});12var w_token = require('./w_token');13var w_token = require('./lib/w_token');
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.w_token(function(err, res){4 if(err){5 console.log('error: '+err);6 }else{7 console.log('token: '+res);8 }9});10var wpt = require('wpt');11var wpt = new wpt('API_KEY');12 if(err){13 console.log('error: '+err);14 }else{15 console.log('test: '+res);16 }17});18var wpt = require('wpt');19var wpt = new wpt('API_KEY');20 if(err){21 console.log('error: '+err);22 }else{23 console.log('test: '+res);24 }25});26var wpt = require('wpt');27var wpt = new wpt('API_KEY');28 if(err){29 console.log('error: '+err);30 }else{31 console.log('test: '+res);32 }33});34var wpt = require('wpt');35var wpt = new wpt('API_KEY');36 if(err){37 console.log('error: '+err);38 }else{39 console.log('test: '+res);40 }41});42var wpt = require('wpt');43var wpt = new wpt('API_KEY');44 if(err){45 console.log('error: '+err);46 }else{47 console.log('test: '+res);48 }49});50var wpt = require('wpt');51var wpt = new wpt('API_KEY');
Using AI Code Generation
1var wpt = require('./wpt.js');2var wpt = new wpt('API_KEY');3wpt.getLocations(function (err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10var request = require('request');11var WPT = function (api_key) {12 this.api_key = api_key;13};14WPT.prototype.getLocations = function (callback) {15 request({16 }, function (error, response, body) {17 if (error) {18 callback(error);19 } else {20 callback(null, body);21 }22 });23};24module.exports = WPT;25var wpt = require('./wpt.js');26var wpt = new wpt('API_KEY');27wpt.getLocations(function (err, data) {28 if (err) {29 console.log('Error: ' + err);30 } else {31 console.log(data);32 }33});34var request = require('request');35var WPT = function (api_key) {36 this.api_key = api_key;37};38WPT.prototype.getLocations = function (callback) {39 request({40 }, function (error, response, body) {41 if (error) {42 callback(error);43 } else {44 callback(null, body);45 }46 });47};48module.exports = WPT;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!