Skip to content

Instantly share code, notes, and snippets.

View davedavis's full-sized avatar
:octocat:

Dave Davis davedavis

:octocat:
View GitHub Profile
@davedavis
davedavis / gist:cbe4def011eaed3e78197b49c9343b8c
Created May 21, 2023 22:22
Copy large CSV into POSTGRES table
psql -d core -U dave -c "\copy saps from /home/dave/Desktop/SAPS/data.csv delimiter ',' csv header;"
@davedavis
davedavis / gist:6281ff60a76f72452f1fcba856d6d198
Created June 7, 2022 13:09
Add Paolo Alto Global Protect option to Ubuntu VPN settings
# Install the following packages from the command line and the option will appear.
sudo apt-get install network-manager-openconnect network-manager-openconnect-gnome
@davedavis
davedavis / gist:407abbd3800c6d31771b8ac93f9bc2fe
Created November 8, 2020 23:23
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)>
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 November 1, 2020 22:28
Allow remote access to MySQL 8 Database
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 October 13, 2020 20:57
Reduce the size of Ubuntu Docker images
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 September 28, 2020 09:54
Python - Check if current time is in a given range
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
@davedavis
davedavis / gist:cb1f75e09b81cc07f09e02c8167ac582
Created September 21, 2020 14:36
Server Side Deployment Commands
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 September 10, 2020 20:48
How to Sign Github Commits From PyCharm
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 July 29, 2020 12:44
Install Google Ads Editor 1.4+ on Ubuntu 20 - Focal Fossa
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 June 24, 2020 23:16
How to get Google Ads API ENUM Text Value From The The Returned Integer Index - Google Ads API ENUM Mapping
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.