Skip to content

Instantly share code, notes, and snippets.

View Andrew-Chen-Wang's full-sized avatar
🐢
herro

Andrew Chen Wang Andrew-Chen-Wang

🐢
herro
View GitHub Profile
@Andrew-Chen-Wang
Andrew-Chen-Wang / DjangoRedisPubSubSingleton.py
Created April 27, 2020 01:28
Redis Handling using three connections max for Django Websocket Applications using Pub/Sub
"""
Import RedisSingleton and create the object by doing:
redis_singleton = await RedisSingleton()
That way, you've not only created a new object in memory but also
executed the await in the magic method. This is helpful when you have
wayyy too many Django's and connections become overloaded.
There should now only be three connection for:
PUBSCRIBE x2 and PUBLISH
@Andrew-Chen-Wang
Andrew-Chen-Wang / multi-chat-native-django-3.0.md
Last active January 23, 2021 13:57
Instructions for Multi-Chat One Websocket connection native Django 3.0, no Django channels

That's right, one websocket connection per user because I'm cheap like that (and it's actually easier for mobile devs when it comes to needing info about several other things plus only handling ONE connection).

In wake of growing expectations, I've just created a Django 3.0 multi-chat option, as well, using just caching and the asgi.py. No Django channels. Anyways, I've implemented multi-chat using ONE WebSocket connection per user. Why? One main reason is that my iOS app's ContainerViewController which is like Android's ViewPager and Android's One-activity-multiple-fragment architecture makes using one web socket connection optimal. 1. I needed to communicate several other things between the server and the user by using custom headers and 2. AWS costs a lot of money, especially with API Gateway or simply using EC2 with data transferring On-Demand... The following assumes you've set up native Django 3.0 like so to work with websockets: https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-

@Andrew-Chen-Wang
Andrew-Chen-Wang / stripe-ip-addresses.py
Created February 2, 2020 15:00
Stripe API IP Addresses in Python for Webhooks
stripe_ip_addresses = [
"13.112.224.240",
"13.115.13.148",
"13.210.129.177",
"13.210.176.167",
"13.228.126.182",
"13.228.224.121",
"13.230.11.13",
"13.230.90.110",
"13.55.153.188",