JavaScript Functions Not Synchronized [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have created a JavaScript program that is intended to run on multiple computers at once.
I need to know how to run a function on all of the computers at the same time.
I have tried making a function that uses setTimeout to basically wait until a certain time. I have done multiple checks on both computers and it seems to think that it is making up for setTimeout's delay, but it is still off by around 0.4 seconds.

You can synchronize your applications either using a central server with Websockets, for example. Or, if you want to use something really fancy, you can use WebRTC signalling. It is a bit harder to get into, but it works brilliantly.
Update: I just read that you want to use it for a Rubik's cube competition? With WebRTC, you can even integrate a live video connection between both players so that they can see their opponents cube. Sounds fun!

There is no way to 100% guarantee that the function will run at the same time on both the computers. Even with Websockets there will be a network delay to reach each computer and you cannot guarantee network message will reach to all computers at the same time.

Related

High-Speed Website Screenshots with Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to take screenshots of a website continuously and pipe these data into a python array as fast as possible. Desirable would be at least 30 fps. It would be nice to have one screenshot/frame per function call, because I have to inject some JavaScript to the website after each frame.
The website is running a webgl canvas and is expecting keyboard input.
I already tried to make it with selenium and headless Firefox, but this is way too slow. What do you think is the best way to go to get close to my requirements?
Thanks in advance.
I would recommend to use Python MSS. This library is intended exactly to take screenshots really fast. It is currently maintainable and cross-platform, and has good documentation.

prevent bots / scrapers executing javascript to get output [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I see allot about Cpatcha's and Submission forms / methods to block bots and content scrapers / leechers but nothing about blocking those who take the entire JavaScript contents and execute it to obtain and view what it is outputting.
Is it possible to prevent bots executing JavaScript to obtain the output.
I have looked at if statements within JavaScipt checking screen resolutions, keyboards, mouse, touch screens basic human required functions etc but it is a hard area to find information on.
if (bot){ //don't execute Javascript don't let the bot get the real output.
return;
}
The only known mechanism is to use minification and obfuscation of your javacsript functions. Change them on every deploy or every day through a script process. Another thing is not to have window methods on the global space.
You may want to look at Web Assembly, but not all browsers have currently adopted it.
There is no straight forward way to achieve this perfectly. If people put enough time they can crack it out.

Make CSS animations fluid while JavaScript runs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working on an Ember app and it shows a lot of real time data, it makes the JS thread really busy.
I'd like to add some nice fluid animation with CSS3 but having JS which works under the hood makes the entire app laggy.
Is there a way to give priority to the CSS animations to make them fluid?
After all I don't care if for half second my data is not updated.
I mostly target Chrome and Firefox
You might want to look into webworkers.
If you let all your ajax and dataprocessing be done by the webworker thread, and the displaying only by the DOM thread you can save a lot of overhead/delays caused by computations.
One word of advice. Don't do worker.postMessage(arg,arg) but do worker.postMessage(arg) with a single argument.
The object itself will be posted then instead of it being converted to json and converted back in the other thread. Saves a lot of cpu time.
Keep in mind that the thread that posted the object will have "lost" the object(to prevent concurrency problems)
Also DOM elements cannot be posted to a webworker, so make sure your data is "clean" if you post to the worker.
Maybe trying to get the CSS animations to be rendered by the GPU would be an possibility.
CPU and GPU would run seperate, You should give it a try and see if it gives you an improvement!

AJAX Microgames [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
If you're not familiar with the concept of a Microgame, check out this video of WarioWare Twisted.
I'm interested in setting up a site where users can play series of browser-based Microgames which are delivered to them by a server. Ideally this would allow me to crowdsource the games and have an open submission system. What sort of scheme could I use to make this work?
I'm thinking that one way to do it would be to have each game consist of:
A javascript file that defines a MicroGame object that controls a rectangular portion of the screen, gets input and timing information from the main page, then calls back to the main page with a "Success" or "Failure" message.
A folder of assets that must be downloaded before the game executes.
Is this possible to do, client-side within a browser? Where would be a good place to start figuring this out?
There are a lot of open issues here. The biggest problem is what language do they submit games in which you can execute safely on the players machines? That said, there are tools like this out there. You could look at the excellent Play My Code for inspiration.

How to Detect, Measures & Debug Javascript strain on CPU? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
This question is pretty simple:
How does one go about detecting and debugging javascript stress on the CPU and/or optimize the code?
As you start building more and more code you reach points where things slow down. How do you figure out if you have unnecessary js running, maybe redundant code, OR if it's getting too much for a computer? My computer is pretty powerful but I can't assume everyone has a monster computer.
Is there a function, program or some tools that can help with this task?
This question seems general but I really don't know how to simplify it otherwise.
Any help or pointing in the right direction is much apprecitated :) Thank you.
Try this app called Spy-JS.
It is a tool which allows you to trace your code, and figure out which executions are taking the longest, allowing you to figure out where you need to optimize.
The tool you are searching for is called a "profiler".
The Firebug extension for Firefox comes with such a profiler and allows you to measure which parts of your Javascript code take how much time to execute.
Keep in mind that it only measures the execution speed in Firefox. Other browsers might implement certain javascript features more or less efficient, which means that the performance bottlenecks could be in other places when your application is executed in another browser. But more often than not your own code is at fault when a program runs slower than it should.

Categories