Skip to content

Instantly share code, notes, and snippets.


Dave Davis davedavis

View GitHub Profile
davedavis / gist:407abbd3800c6d31771b8ac93f9bc2fe
Created Nov 8, 2020
How to fix Python urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1124)>
View gist:407abbd3800c6d31771b8ac93f9bc2fe
OK, after a lot of heartache, I've solve this. As usual, the solution was painfully simple.
Certifi uses it's own bundled certificate bundle, so you can use the one from here:
Basically, download it (or use your own from the certifi dist directory)
Then, set the env variable (in /etc/envirnoment if you're on Ubuntu like me) for $SSL_CERT_FILE to the one you downloaded:
export SSL_CERT_FILE=/home/yourname/cacert.pem
Worked immediately from main system CLI. I had to uninstall PyCharm and reinstall it for it to pick up the env variable and start working in virtualenvs again.
davedavis / gist:3d49c0966a1314966b928427991122e4
Created Nov 1, 2020
Allow remote access to MySQL 8 Database
View gist:3d49c0966a1314966b928427991122e4
Comment out or set the IP of the bind address manually in /etc/mysql/my.cnf
Restart the service.
Create the user AGAIN (Because MySQL treats users on localhost and users on remote as different)
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
davedavis / gist:3d43e9746310706e170b039c6ce2f9c9
Created Oct 13, 2020
Reduce the size of Ubuntu Docker images
View gist:3d43e9746310706e170b039c6ce2f9c9
When you build from Ubuntu, apt-get update increases the size by about 600GB.
Instead, don't install the recommended updates, just what you need:
In your docker file:
RUN apt-get update && apt-get install --no-install-recommends --yes python3
davedavis / gist:e84c96e94ea01172b81df4d8425ca0a5
Created Sep 28, 2020
Python - Check if current time is in a given range
View gist:e84c96e94ea01172b81df4d8425ca0a5
from datetime import datetime, time
def is_time_between(begin_time, end_time):
# If check time is not given, default to current UTC time
check_time = datetime.utcnow().time()
if begin_time < end_time:
return begin_time <= check_time <= end_time
else: # crosses midnight
return check_time >= begin_time or check_time <= end_time
View gist:cb1f75e09b81cc07f09e02c8167ac582
source myprojectenv/bin/activate
git pull origin master
python makemigrations
python migrate
python collectstatic
sudo service gunicorn restart
sudo service nginx restart
davedavis / gist:0a8b62f6c15c8040faa6c833c82f4cee
Created Sep 10, 2020
How to Sign Github Commits From PyCharm
View gist:0a8b62f6c15c8040faa6c833c82f4cee
Set up your GPG key and add it to github by:
gpg --full-generate-key
gpg --default-new-key-algo rsa4096 --gen-key
Then, get your GPG ID:
gpg --list-secret-keys --keyid-format LONG
The ID is the bit after the "sec rsa4096/":
gpg --armor --export 3AA5C34371567BD2
davedavis / Install-Google-Ads-Editor-Ubuntu
Created Jul 29, 2020
Install Google Ads Editor 1.4+ on Ubuntu 20 - Focal Fossa
View Install-Google-Ads-Editor-Ubuntu
Download the Editor exe here:
Install Wine:
sudo dpkg --add-architecture i386
wget -O - | sudo apt-key add -
sudo add-apt-repository 'deb focal main'
sudo apt update; sudo apt install --install-recommends winehq-stable winetricks
Open Wineconfig and change the OS to Windows 10:
davedavis / gist:8a7933353a94d97f2929fab285845cbf
Created Jun 24, 2020
How to get Google Ads API ENUM Text Value From The The Returned Integer Index - Google Ads API ENUM Mapping
View gist:8a7933353a94d97f2929fab285845cbf
The Enum's come with some methods to translate between index and string
# client_service is the GoogleAdsClient object.
channel_types = client_service.get_type('AdvertisingChannelTypeEnum')
# => 2
# => 'SEARCH'
This was found by looking at docstrings, e.g.
davedavis / gist:9f7eafd1e215c0aee84d10d611e9f434
Created Jun 23, 2020
Fiscal Year and Quarter To Date in Python
View gist:9f7eafd1e215c0aee84d10d611e9f434
>> import fiscalyear
>> fiscalyear.setup_fiscal_calendar(start_month=4)
>> year = fiscalyear.FiscalYear(2021)
>> quarter = fiscalyear.FiscalQuarter.current()
>> print(year.start.year)
>> print(year.start.month)
>> print(
>> print(quarter)
>> print(type(quarter))
>> print(quarter.start)
davedavis / gist:44ef4a35cd190dc28dd03f034b8bc15a
Created Jun 23, 2020
Last 28 Days in Python - For Reporting
View gist:44ef4a35cd190dc28dd03f034b8bc15a
# Define the report date range: last 28 days including today"-", "") + timedelta(days= - 28)