This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start here: https://gist.github.com/wcarhart/48ce5d7e14a8172352db62af9705c183 | |
# Edit the default network adapter settings | |
cd /etc/sysconfig/network-scripts/ifcfg-eth0 | |
# IPADDR can be anything in our range | |
sed -i.bak -e 's/IPADDR = ".*"/IPADDR = "192.168.1.2"/' | |
# GATEWAY needs to match the gateway defined in Hyper-V | |
sed -i.bak -e 's/GATEWAY= ".*"/GATEWAY = "192.168.1.1"/' | |
# Configure DNS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list all VMSwitches | |
Get-VMSwitch | |
# for each VMSwitch, do the following: | |
Remove-VMSwitch <VM_SWITCH_NAME> | |
# list all NetNATs | |
Get-NetNAT | |
# for each NetNAT, do the following: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to deploy a Django application to Heroku with PostgreSQL | |
#========== Pre-requirements ==========# | |
### 1. make sure Heroku CLI is installed | |
### read more here: https://devcenter.heroku.com/articles/heroku-cli | |
### 2. use virtualenv to control python packages | |
### 3. replace 'projectname' with your project's name throughout this script | |
### 4. this script is for MacOS and Bash, but is very similar for Linux and other shells | |
#========== if you're lazy like me, make an alias ==========# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reset git repository (before commit) | |
git reset HEAD \* | |
git checkout -- . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize Git LFS and start tracking files with it | |
## Install Git LFS (MacOS) | |
brew install git-lfs | |
## Change to repository | |
cd $PROJECT_REPO | |
## If you've already added or committed the file(s) you'd like to track with LFS, | |
## you'll need to edit them out of the Git history. See: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import pickle | |
import base64 | |
from googleapiclient.discovery import build | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
from google.auth.transport.requests import Request | |
from email.mime.text import MIMEText | |
def get_gmail_api_instance(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List of Python tricks from Dan Bader's (realpython.com) newsletter | |
# ===================================== # | |
# How to merge two dictionaries (3.5+) | |
x = {'a': 1, 'b': 2} | |
y = {'b': 3, 'c': 4} | |
z = {**x, **y} | |
print(z) | |
# {'c': 4, 'a': 1, 'b': 3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, re | |
from bs4 import BeautifulSoup | |
def get_nyt_headlines(): | |
r = requests.get('https://www.nytimes.com/') | |
soup = BeautifulSoup(r.text, 'html.parser') | |
headers = soup.find_all('h2') | |
spans = [tag.find_all('span') for tag in headers] | |
headlines = [re.findall("<span>(.*?)</span>", str(span[0]))[0] for span in spans if not len(span) == 0] | |
for index, headline in enumerate(headlines): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove a commit from git history | |
## Detach from the remote | |
git remote rm origin | |
## Make necessary changes. If you want to keep a file locally but not remotely: | |
git rm --cached $FILE | |
echo $FILE >> .gitignore | |
git add .gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jsonize(self): | |
variables = [var for var in dir(self) if not var.startswith(('_', '__')) and not callable(getattr(self, var))] | |
return "{" + ",".join([f"\"{var}\": \"{getattr(self, var)}\"" for var in variables]) + "}" |