Skip to content

Instantly share code, notes, and snippets.

View eezis's full-sized avatar

Ernest Ezis eezis

  • Boulder, CO
View GitHub Profile
@eezis
eezis / Django EC2 Bad Request (400)
Last active June 28, 2023 16:23
Resolving Bad Request (400) when using Django on an EC2 instance DEBUG
This gist pertains to a Bad Request(400) error when trying to access an EC2 instance running django . . .
I set up an EC2 server, installed django, started runserver and tested. The result was
Bad Request (400)
When using Django 1.5 and higher, if you specify DEBUG=False in the settings.py file, you must also specify ALLOWED_HOSTS
or you will recieve a "Bad Request (400)" error message when attempting to retrieve a page.
On an Amazone EC2 instance, if you are ***testing*** with the public DNS, then you should include the public DNS as one of the allowed hosts.
@eezis
eezis / phemex_balance_ccxt.py
Last active November 13, 2022 04:21
Get your Phemex Positions and Balance using CCXT -- in jupyter notebook
# -*- coding: utf-8 -*-
import os
import sys
from pprint import pprint
import ccxt
import pandas as pd
PHEMEX_API_KEY = os.getenv('PHEMEX_API_KEY')
@eezis
eezis / elb-usptream-sent-more-data-than-specified.md
Created November 6, 2022 17:27
Django EC2 ELB Nginx PageSpeed upstream sent more data than specified in "Content-Length" header

While upgrading EC2 servers behind an AWS Elastic Load Balancer (ELB) I noticed that the nginx error log was reporting that my health-check was getting molested. Here is the simple curl test showing the 200 result. The error message, then the solution follow.

$ curl -I localhost/ELB-health-check

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 06 Nov 2022 16:59:46 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 105
@eezis
eezis / django-migrations-type-error-must-be-strings-not-bytes.md
Created October 6, 2022 19:56
Django Migrations TypeError: attribute name must be string, not 'bytes'

If you are updating and older Django project and getting an error in this form:

TypeError: attribute name must be string, not 'bytes'

It's likely that you have existing migrations in your code base that have legacy byte strings. I found them in two places. In the related_name as shown below

('article', models.ForeignKey(related_name=b'author', to='core.Article', on_delete=models.CASCADE, null=True)),
@eezis
eezis / crispy-forms-inlineradios.py
Created April 19, 2016 21:03
Horizontal Radio Buttons For Boolean Values Using Crispy Forms with Django
Quick guide to getting inlineradio buttons when using boolean values with Crispy Forms.
1. create chocies
BOOLEAN_YN = (
(True, u'Yes'),
(False, u'No'),
)
2. update model to point at the choices
@eezis
eezis / firebase.js
Created August 8, 2019 21:51
quasar firebase & vuefire boot file
import { firestorePlugin } from 'vuefire'
import { firebase } from '@firebase/app'
import 'firebase/firestore'
import 'firebase/auth'
import firebaseConfig from '../../firebaseConfig'
let firebaseApp = firebase.initializeApp(firebaseConfig)
let firebaseAuth = firebaseApp.auth()
const db = firebaseApp.firestore()
@eezis
eezis / gist:eddd935a942f24936dcf41edf780be9b
Created October 21, 2016 19:54
Spread locust.io across cores using the multiprocessing library
import sys
import subprocess
import multiprocessing
# use htop to see the utilization rates spread across cores
# use locust --help to see all the options
# the cmd launches 500 concurrent users on each core, hatch 5 per second, issue 10k requests then stops
# logs to results.txt, prints the summary in the terminal
@eezis
eezis / gist:1ae5050a524d7c14229db2658143ad4a
Last active January 5, 2021 13:23
Get Ethereum and ERC20 positions from an Ethereum address
"""
see my comment below the gist
"""
import re
import os
from requests_html import HTMLSession
BASE_ETHERSCAN_URL = "https://etherscan.io/address/"
@eezis
eezis / gist:3a198b9f65d1d3171c8cd20b30562d36
Created April 10, 2020 18:26
If you need to find the location of a poetry virtualenv for a project . . .
# inside an active poetry shell . . .
$ which python
/home/eezis/.cache/pypoetry/virtualenvs/airflow-_F6chCj4-py3.8/bin/python

Keybase proof

I hereby claim:

  • I am eezis on github.
  • I am ernestezis (https://keybase.io/ernestezis) on keybase.
  • I have a public key ASCKvfwAKTfOPX-0ro-E-kpjgG6zedSp2JUGk-4zSCRcuwo

To claim this, I am signing this object: