Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Dave Davis davedavis

:octocat:
View GitHub Profile
@davedavis
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: https://curl.haxx.se/ca/cacert.pem
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
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
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
Ref: https://ubuntu.com/blog/we-reduced-our-docker-images-by-60-with-no-install-recommends
@davedavis
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 manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
sudo service gunicorn restart
sudo service nginx restart
@davedavis
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
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: http://dl.google.com/adwords_editor/GoogleAdsEditorSetup.exe
Install Wine:
sudo dpkg --add-architecture i386
wget -O - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main'
sudo apt update; sudo apt install --install-recommends winehq-stable winetricks
Open Wineconfig and change the OS to Windows 10:
winecfg
@davedavis
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')
channel_types.AdvertisingChannelType.Value('SEARCH')
# => 2
channel_types.AdvertisingChannelType.Name(2)
# => 'SEARCH'
This was found by looking at docstrings, e.g.
@davedavis
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(year.start.day)
>> print(quarter)
>> print(type(quarter))
>> print(quarter.start)
@davedavis
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
start=datetime.today().date().isoformat().replace("-", "")
end=datetime.now() + timedelta(days= - 28)
end= end.date().isoformat().replace("-","")
You can’t perform that action at this time.