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 / 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",
@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 / 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 / async_server.py
Created May 1, 2020 15:29
Django Websocket Testing using pytest
"""
This will be in cookiecutter-django so it's easier to copy and understand.
To set up websockets, you should use: https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-extra-dependencies-2f6h
However, like in cookiecutter-django, you should put the websocket.py inside an app.
It's probably much better to use the stuff in cookiecutter-django (with use_async=y)
since I've already tested this functionality heavily, and those configurations are the best.
"""
import asyncio
import functools
@Andrew-Chen-Wang
Andrew-Chen-Wang / list_stripe.py
Last active July 12, 2020 04:23
Supported Stripe currencies list in Python (also available as Django choices list)
"""
List of the supported stripe currencies.
Also available as Django CHOICES list
if you'd like to store a product of whatever's
currency in integer form in the db.
"""
# https://stripe.com/docs/currencies
# http://jsfiddle.net/nick_craver/H6Mrt/
SUPPORTED_STRIPE_CURRENCIES = (
@Andrew-Chen-Wang
Andrew-Chen-Wang / .pre-commit-config.yaml
Created August 6, 2020 01:53
My pre-commit Python template
exclude: 'docs|node_modules|.git|.tox'
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
@Andrew-Chen-Wang
Andrew-Chen-Wang / snippet.html
Created August 15, 2020 03:50 — forked from japharr/snippet.html
Font Awesome Verified Icons
<!-- Verifed Icons -->
<span class="fa fa-stack fa-lg">
<i class="fa fa-certificate fa-stack-2x" style="color: green"></i>
<i class="fa fa-check fa-stack-1x fa-inverse"></i>
</span>
<span class="fa fa-stack fa-lg">
<i class="fa fa-certificate fa-stack-2x" style="color: red"></i>
<i class="fa fa-close fa-stack-1x fa-inverse"></i>
</span>
@Andrew-Chen-Wang
Andrew-Chen-Wang / README.md
Last active August 16, 2020 22:35
Initial Data for Donate Anything Items

There are some stupid things in there. I was getting pretty tired. For example, I put Barack Obama in there somewhere; not as some "objectifying someone" but more like I was thinking about JaidenAnimation's random pokemon video and I thought "what if a wild Barack Obama appeared" and started donating time :P

Other random stuff: some memey AP textbooks that I never read and some nice but non-sensical things in terms of materialism like love and time.

@Andrew-Chen-Wang
Andrew-Chen-Wang / migration.py
Created August 23, 2020 20:53
Cast Postgres Boolean type to Small int - demonstration for Django
# Generated by Django 3.1 on 2020-08-23 20:44
"""
The SQL statement provided will convert a boolean type in PostgreSQL
to numeric int and then change that to a smallint type. I'm not sure
why I couldn't use small int for blah::smallint::numeric(1,0)...
1 is True and 0 is False
"""
from django.db import migrations, models
@Andrew-Chen-Wang
Andrew-Chen-Wang / main.py
Last active November 13, 2020 00:24
Checks if a binary, square matrix is in partial order
# Henceforth arr
a = [
[1,1,1,1],
[1,1,1,1],
[1,1,1,1],
[1,1,1,1]
]
def find_ones(arr):
b = []