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 / bot.js
Created October 14, 2021 21:04
Save Plate shouter for ICC Houses
let spreadsheet = "Today's Save Plates"
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function increment_char(c) {
return c !== 'Z' ? String.fromCharCode(c.charCodeAt(0) + 1) : 'A';
}
@Andrew-Chen-Wang
Andrew-Chen-Wang / Excel-karabiner.md
Last active August 22, 2024 00:56
Using Karabiner to let me press CMD+Return/Enter/Shift to edit cells in MacOS Excel 2016+

Shortcuts that I overrode for Excel:

  • Editing a cell is now CMD + Return/Enter/Shift (used to be Option + U or F2)

Setup:

  1. Install Karabiner-Elements
  2. Set everything up properly
  3. Go to your terminal and run cd ~/.config/karabiner/assets/complex_modifications && touch excel.json
  4. Copy and paste everything from the json content below into excel.json
  5. Go to Karabiner-Elements > Complex Modifications > Import Rule then enable the Excel rule thingy
@Andrew-Chen-Wang
Andrew-Chen-Wang / apps.py
Created November 24, 2020 07:39
Django-ratelimit behind a reverse proxy without changing ip key
"""
I've had to monkeypatch django-ratelimit due to slow development.
The patch is basically allowing Django Axes with Django ipware
to grab the IP address rather than taking the IP straight from
META attribute in the request object.
You can find an initial implementation here:
https://github.com/jsocol/django-ratelimit/pull/208
but the PR lead no where due to just not knowing how
@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 = []
@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 / 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 / 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 / .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 / 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 / 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