Posts

Ignore errors returned from API calls nodeJS Ignore errors returned from API calls nodeJS

I have a NodeJS script which is making thousands of REST API GET calls to SharePoint to retrieve all folders and files recursively. A problem I have encountered is once in a while I am receiving ECONNRESET errors and 404 Not Found for some folders with unsupported characters. This causes my code to stop and I lose my progress in retrieving all the files and folders. Is there something I can do to prevent these errors from stopping my code and just have it ignore the error and continue onto the next folder? I thought catching the error and console logging it would suffice but this still ends the execution of the code. Thanks //Imports and Declarations const prompt = require("prompt-sync")({ sigint: true }); const { getCreds, pullFromSharePoint } = require('./helper'); const sprequest = require('sp-request'); var path = require('path'); let creds = getCreds(); let spr = sprequest.create(creds) let SPUrl = 'url to sharepoint site'; let files = [...

JS Upload file to HTML File Element preserving the effects of a regular click JS Upload file to HTML File Element preserving the effects of a regular click

How can I use javascript to upload an image to a specific HTML file element (for example, the dropzone on images.google.com)? I have tried doing fileElement.files = [myFile]; But that just uploads my file to the specific HTML file element, without triggering the normal effect of uploading to that file element (for example, triggering the actual google search of the image) from Stackoverflow

Is it possible to implement a two-way weak map in JavaScript? Is it possible to implement a two-way weak map in JavaScript?

Is it possible to make something like a WeakMap that is two way (get a value by its key, or get a key by its value)? The usage would look like this (in TypeScript syntax to better illustrate): class TwoWayWeakMap { // What goes here? } class SomeClass {} const map = new TwoWayWeakMap<SomeClass, number>() const o = new SomeClass map.set(o, 42) console.log(map.get(o)) // logs "42" console.log(map.keyFrom(42)) // logs "SomeClass {}" (the `o` object) At any point later, if o is no longer referenced except inside the TwoWayWeakMap , then the SomeClass object that o was pointing to could be collected. from Stackoverflow

Why changing variable equal to a HTML collection changes the original values of the collection? Why changing variable equal to a HTML collection changes the original values of the collection?

There's a different behaviour that I see that I can't really understand exactly why this happens. Originally, after making a variable equal to another, it will only copy the value of one variable to another, but if I change the value of a variable after that, the other variable won't be affected, right? As in: let a = 3 let b = 5 b = a //here the variable b, that was 5 will become the same as the variable a, becoming 3. a = 10 //now, if I change the value in a to 10, b will still have the value of 3. That's pretty basic JavaScript, I know. But knowing that, I can't understand why it's different when it comes to HTMLcollection. Here is the situation: const allLi = document.getElementsByTagName('li'); for (let xis of allLi) { xis.classList.toggle('highlight'); } Here I got a HTMLcollection and assigned it to the variable allLi, and then I used a for of loop to modify it, thus changing the original values in the HTMLcollection, that reefe...

Matrix array algorithm logic in javascript Matrix array algorithm logic in javascript

Need some help in solving this algorithm in javascript. How to write solution considering time complexity. Considering the maximum key value is 3. input1 = [{0: "small"},{0: "large"}] output1 = [ 'small.', 'large.'] ----------------------------------------- input2 = [ {0: "small"},{0: "large"}, {1: "red"} ] output2 = ['small.red', 'large.red'] ----------------------------------------- input3 = [{0: "small"},{0: "large"}, {1: "red"}, {2:"cake"} ] output3 = ['small.red.cake', 'large.red.cake'} ----------------------------------------- input4 = [{0: "small"},{0: "large"}, {1: "red"}, {1: "orange"}, {2: "cake"} ] output4 = ['small.red.cake', 'large.red.cake', 'small.orange.cake', 'large.orange.cake'} ------------------------------------------ input5 = [ {0: "small...

How to find what period of given timespans is currently How to find what period of given timespans is currently

I've been given 6 hour-and-minute timestamps which define a period of time, lets call them 1 trough 6. (example: 03:13, 05:22, 12:54, 16:55, 20:23, 22:14) For example: 1st period starts at 03:13 and lasts until 05:22 -1 minute, and so on Naturally, at the end, periods must cover all 24 hours in a day so the sixth period (which starts at 22:14) will last until 03:13 What is the best/most optimal way to write a function that can tell what period of time we are currently in? Here is my try (which doesn't work and is suboptimal): function currentPeriod(hrs, mins, now) { // hrs is an array of integers and they define only hours (3, 5, 12,...) // mins is an array of integers and they define minutes (13, 22, 54,...) // now is a JavaScript Date if(now.getHours() > 0 && now.getHours() < hrs[0]) { return 6; } else if(now.getHours() == hrs[0] && now.getMinutes() < mins[0]) { return 6; } else if(now.getHours() == ...

map values in an array to values in another array in Javascript map values in an array to values in another array in Javascript

please I have 2 arrays in the following format const images = ["image1", "image2", "image3", "image4"] const items = [{quantity: 1}, {quantity: 2}, {quantity: 4}, {quantity: 1}] I need the final output to be like below const newArray = [ { image: "image1", quantity: 1 }, { image: "image2", quantity: 2 }, { image: "image3", quantity: 4 }, { image: "image4", quantity: 1 }, ] from Stackoverflow

I am having trouble with this ajax timer it is not doing what I expect and does not execute I am having trouble with this ajax timer it is not doing what I expect and does not execute

Ok i am back to this not executing I have in php head the following https://deniserose.000webhostapp.com/fetch_sql.php <head> <title>Audio Stream</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> I have in java script which i am loading at end of the php file <script src = 'js/fetch_updater.js'></script> now this never seems to get run // Start Clock refresh // uses new new Ajax.PeriodicalUpdater( // in main fetch file to trigger the auto update of the page. // Written by Denise Rose var gUpdateDiv="...

Photoshop, script to find a layer that contains a word in its layer's name Photoshop, script to find a layer that contains a word in its layer's name

hope you guys can help me. I need a script that can find a layers name, for example if i have this layers: Wood 123 Canvas Wood 456 Specular Wood 789 Lights And i would like to find the layer that contains Canvas. And maybe, if its possible, change the layer's name color to green. I found also this code i tried: try { (ref1 = new ActionReference()).putName(stringIDToTypeID('layer'),"Canvas"); // replace Canvas with your layer name (desc1 = new ActionDescriptor()).putReference(stringIDToTypeID('null'), ref1) executeAction(stringIDToTypeID('select'), desc1, DialogModes.NO); } catch (e) { alert("Sorry, this layername does not exists"); } This works great but only if the layer's name is exactly "Canvas".. and that's the problem from Stackoverflow

How do I format ReactJs date picker to look normal? How do I format ReactJs date picker to look normal?

import React, { useState } from "react"; import DatePicker from "react-datepicker"; function GenericCalendarRange() { const [startDate, setStartDate] = useState(null); const [endDate, setEndDate] = useState(null); return ( <> <h4 className="datepicker__title"> From </h4> <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} selectsStart startDate={startDate} endDate={endDate} /> <h4 className="datepicker__title"> To </h4> <DatePicker selected={endDate} onChange={(date) => setEndDate(date)} selectsEnd startDate={startDate} endDate={endDate} minDate={startDate} /> </> ); } export default GenericCalen...