« first day (3292 days earlier)      last day (1870 days later) » 

00:55
hey
Came across this in an Angular app..why is the setTimeout being called here before setting document event listeners? Is it to ensure document is rendered before adding these listeners?
setTimeout(() => {
        this.eventListeners = [
          this.renderer.listen('document', 'click', (event: Event) => this.onDocClick(event))
        ];
      });
Is there a better alternative than using setTimeout if that is the case?
01:08
There is anyone with knowledge in angular ?
To save me?
 
2 hours later…
02:52
@V.7 You need to ask server-side about the 405 error. A CORS restriction would be blocked by the browser, instead of 405. 405 is something that happens on the server.
Could anyone give me feedback on my smooth transitions? github.com/skylerspark/skylerspark.github.io/blob/master/…
I just want to know if this is an improvement of what I had before
the past one was colorless, kindof binding, and a little ugly
Frick its 11pm got school tommarrrrrrororororw
RIP me... goodnight
03:41
0
Q: Dockerfile - Unexpected token error in mocha

overexchangeBelow is the dockerfile which is stored as image tag somehub/someapp-specs: FROM ubuntu:trusty MAINTAINER Developer team <[email protected]> # Prevent dpkg source ENV TERM=xterm-256color # Set mirrors to ca RUN sed -i "s/http:\/\/archive./http:\/\/ca.archive./g" /etc/apt/sources.list # I...

 
2 hours later…
user11720628
05:29
@TaylorS The transitions are nice
@chuklore Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
user8732191
05:50
Hello, anyone there?
@NishantArora Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
user8732191
I have a doubt to ask regarding javascript
user11720628
What's up
user8732191
hey!! Can you please help me out solving a problem?
user11720628
I'll try
user8732191
05:53
ok, so there is a function with settimeout printing numbers from for loop.

function test() {
let ar = [];
for (let i = 1; i < 5; i++) {
setTimeout(function run() {
ar.push(i);
console.log(i);
}, Math.random() * 2000);
}
}

I want to alert after this function completed running only.
user8732191
like if it took 10ms to run for loop. I want alert after 10 ms only.
user8732191
please help me out.
user11720628
you could try using either a promise or async await
user8732191
I am not able to do with that so can you please give an example?
user8732191
so that it clarifies me where I am going wrong.
user8732191
06:00
you there?
user11720628
I'm trying out the code lemme see
user8732191
Ok sure, Thank you!!
user8732191
you there?
user11720628
Hey
user11720628
I've got something working
user11720628
06:14
try it out
user11720628
You there ...
user11720628
@NishantArora Hey......
user8732191
Yes I am here
user11720628
var testPrint = new Promise(
function test(resolve) {
let ar = [];
for (let i = 1; i < 5; i++) {
setTimeout(function run() {
ar.push(i);if(i === 4) resolve(ar);
console.log(i);
}, Math.random() * 2000);
}
}
);

// call our promise
var testtwo = function () {
testPrint
.then(function (fulfilled) {
// yay,
console.log('FINISHED');
})
.catch(function (error) {
// ops,
console.log(error.message);
});
}
testtwo();
user11720628
try that out
user8732191
06:15
Ok let me try, Thank you!!
user8732191
No, its giving but output like this:-
user8732191
1
4
FINISHED
3
5
user8732191
but i want it to be like:-
1
4
3
5
finished
user11720628
Darn it it actually because it's asynchronous let me think of something else
user8732191
Ok please
06:18
whispers recursion
user8732191
what's that?
iterating bkwards in the code
user8732191
Can you please give a example for that?
infitite loop version: function infinite() { infinite();}
Heyas. Anyone good with React and React-Navigation? I'm wondering if I can change the defaultNavigationOptions after the app has been rendered, to change the color of the header.
user8732191
06:24
@Gemtastic How can I merge my problem with this?
@NishantArora - you're resolving the promise before you do the console.log
Swap places of those two lines and you'll be fine
user8732191
@Amsvartner Sorry, I didn't got that
user8732191
Can you please show the code
Swap places of console.log and resolve
@NishantArora well why didn't you just say so?
06:32
console.log(i);
if (i === 4) resolve(ar);
yeah, you wouldn't use setTimeout for this
or at least not by itself
you gotta turn it into a promise, then perform an action only once all promises have resolved
the promise literally just starts a setTimeout and resolves only when the action occurs (your alert?)
user8732191
No, it wont work either because according to this if condition. It will console finished after 4.

Suppose if the loop is from 1 to 100 then in that case it will console finished after 4 only let it be in middle or at first positio but I want finished to be console at only last position.
user8732191
Hope I got my point cleared?
user8732191
is anyone there?
@NishantArora I understand the problem
You need to turn your asynchronous setTimeout into a "synchronous" function
in that the actions of the timeouts happen prior to the function ending
you can do that with Promise, I promise :)
06:47
When should we expect .any on promises? :D
@Raimonds when you don't care about the other promises after the first has been resolved
I needed that functionality days ago
Then I found out it is not supported yet
say, you're pinging servers to see which mirror server is faster before starting a download
once you know the fastest ping, you don't really need to wait on the others to resolve
Usually closest one is fastest
"usually"
I had a case where I was trying to download same file multiple times using promises, i managed to create multiple arrays with promises that target same file. At that point I just needed to cancel all of them after 1 resolved :(
user8732191
06:52
Yeah, I tried everything stated but none of the way is working
I ended up not even firing new requests my script file already exists, which I did my
document.createElement(script) and add src so it downloads sync
user8732191
everytime I am getting done console first only because of settimeout
Isn't it possible to call resolve on promise inside another promise and so forth
until you resolve them in order you want
I gave you a link with a number of solutions, the question has already been asked on StackOverflow and has excellent replies
user8732191
Ok, I'll try with those
07:16
@Raimonds yeah, not said that fastest ping is fastest for download
could be a momentary bandwidth problem that slows down ping for otherwise servers which would return a quick ping
you could just retry and take the average, but it's usually a little overkill to do so
@NishantArora for await of is the way to go
but check the browser compatibility. If you don't use bundlers, best to look out for alternatives
Promise.all would be sufficient as well
I don't think he wants to wait a random amount of time and afterwards start the next task
wouldn't await turn it synchronous?
each loop cycle is done sync yes
hmm maybe i need to re-read
I think he wants to launch all 5 and then print a message only when all 5 have finished
which is to say, launch asynchronously, but wait until they're done before doing something else
I'm just asking mainly because maybe I misunderstood what await does :P
it just wait when the promise is finished.
(if the method call is non-promisy, then it just proceeds)
07:22
our authorization system is dumb
we have a windows user and password, and then like an online login which uses the same user code, but that password you can set it to whatever you like
since every week the system resets, the password is never the same as my windows user, so I'll have to unblock it
Get this.. to unblock it, I have to enter my windows user and password.. so I ask you.. why wouldn't it just use this in the first place?
user8732191
@Neil Yes you are absolutely correct.I want to launch all 5 and then print a message only when all 5 have finished
I think promises would be your best bet then
user8732191
Can you please write the code for me then because I am not getting any solution for this.
user8732191
let ar = [];
for (let i = 1; i < 5; i++) {
    setTimeout(function run() {
        ar.push(i);
        console.log(i);
    }, Math.random() * 2000);
}
user8732191
This is the code by which I am pushing into array
user8732191
07:31
@Neil you there?
this is an example of what I mean
doAction calls setTimeout and it also returns a promise
You collect all your promises and call Promise.all on them
Only when they're all finished does the second part get executed
if you need an example with parameters or output, let me know
this is possible as well
user8732191
Yes, this worked like a charm. Thank you so much. I have applied with the parameters. Thank you so much bro
:)
user8732191
@Neil Hi, you still there?
YUP
user8732191
07:41
Can you please explain me the code as well?
user8732191
Actually I am new in this field so getting kind of difficulty.
ok, well the Promise object is a way to have a link to an asynchronous task before it's done
think of it like a balloon string. The balloon is launched into the air, and without that string, you can't obtain the results or know when it's done
the two things performed inside the setTimeout are important
the first one calls func(), so it calls the function you pass to it
it actually does the work
The second, resolve(), is a function passed by contract of how Promises work
if you wanted to send results back, you could do resolve('some value after task is done');
once you have a promise, you can chain them one after another using .then()
In your case, using Promise.all, which means given an array of promises, don't run the then part until all promises have called their respective "resolve()" function
Hi guys, I'm doing an SVG Indoor Mapping system.
which is what you wanted ultimately. Run this only once all async tasks are done
So far, I can draw sections of the building using JS Objects to represent each section
I'm having trouble with figuring out how to find path between two sections
Any ideas?
07:48
@HassanAlthaf is there a particular reason why you're drawing it dynamically?
@Neil: Great reply :)
yes, there is a reason.
our company is developing a software where you could design your indoor building
well then I'd say you're justified :P
on the administration's application
and the user is able to see the building indoors and route themselves.
yup haha.
what do you mean by finding paths between two sections?
the js object can hold whatever information you require to find one or the other in the svg, right?
07:52
Let me put this file up really quick, so I can explain better
So the brown is the workplace
Lets assume on the right of the workplace, there's another section lets say discussion room.
The gray boxes denote areas where you can walk. All these are basically Rect objects.
So, how would I iterate through the areas you can walk and find the shortest path?
use a coordinate system
I'll have to add elevators/staircases later on too (3-4 sets of elevators at different location).
turn it into a graph
then find shortest path
07:55
use the model to develop your svg, not the other way around
I would highly appreciate if you could provide me a resource
yup
the model should represent all the information you require
let me show you my JS code
give a room another coordinate, the one that indicates a door
07:55
trying to find the shortest path from some arbitrary svg would be hella difficult
even if you know the structure
@KarelG I was planning to add an invisible Rect
So, what I do is, basically, have coordinates of the doors
Get the coordinates of the current building
i mean the room
Draw a graph of all the coordinates?
if you have a point in front of every door to a room, and a point at every intersection in the hallway
Let me also show you how I insert data into the drawing tool
knowing how they connect, you can calculate and draw a path from any place to any other place, provided of course that they are connected
the trick I suppose would be knowing what points to add to your graph when a room is added
The biggest challenge I'm facing right now is
Sorry I had to use the captcha for that script. Its visible now.
This is how I use the above library I wrote.

« first day (3292 days earlier)      last day (1870 days later) »