Monday, 28 June 2021

Django ReactJS: Pass array from JavaScript frontend to Django Python backend

I've made a website with Django and React JS. I'm trying to pass an array pict from my JavaScript frontend to Django, the Python backend.

let pict = [];

pictureEl.addEventListener(`click`, function () {
  console.log(`Take Pic`);
  pict += webcam.snap();
  console.log(pict);
});

pict is an array of images taken by the camera. How would I pass it to the backend?



from Django ReactJS: Pass array from JavaScript frontend to Django Python backend

Using ScrollReveal to animate in parts of SVG

I'm using the ScrollReveal library to animate in sections of my site.

I have a pretty complex vector which contains five groups. I'm trying to animate these five groups in separately using this library.

Here is my approach currently:

My SVG is a bit lengthy and Stack has a body count character limit, so I created a demo using JSFiddle here.

Each group has a class and as you can see from the demo, it initially loads, then disappears. None of the reveal effects are working? I have other divs with the same parameters which work, but it doesn't work with this SVG for some reason?

If we inspect the white space, I can see that the parts are not appearing because the opacity is 0. But, on scroll, this opacity isn't changing and I don't want to force opacity to 1 via CSS as this I want the part to fade in nicely, whereas setting it to 1 will just make it a static image.



from Using ScrollReveal to animate in parts of SVG

Redis Sentinel: How to refresh master client object when master changes on failover?

I have setup a Redis replica with one master and two slaves with Redis Sentinel monitoring each of the nodes. I'm using redis-py library to communicate with master and slaves. Here is the code that I use to connect with master and slaves:

from redis.sentinel import Sentinel

sentinel = Sentinel([("localhost", 5000)])  # connect to one of the sentinels
master = sentinel.master_for("mymaster")  # get master object
slave = sentinel.slave_for("mymaster")  # get slave object

Now, I would use master for write and slave for reads. But the problem is that when failover occurs, the master object needs to be refreshed in order to point to a new master. For that, as mentioned in this answer and the docs, I'm supposed to subscribe on +switch-master channel to receive the address of new master.

But the questions is that, using which object am I supposed to subscribe to that channel? I tried this using master object as following:

ps = master.pubsub()
ps.subscribe("+switch-master")

And when the master was down, I tried getting the message as following:

ps.get_message()

But this does not return the expected message because the master itself is down I think.

The sentinel object does not support the pubsub.

>>> sentinel.pubsub()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Sentinel' object has no attribute 'pubsub'

As an alternative, in the linked answer it's suggested to use client-reconfig-script. But how am I supposed to modify an object in my application using an external script?

What am I missing here? I am new to Redis, so any reference would be appreciated.



from Redis Sentinel: How to refresh master client object when master changes on failover?