Skip to content

Instantly share code, notes, and snippets.

View wcarhart's full-sized avatar
🦉
Hoot hoot

Will Carhart wcarhart

🦉
Hoot hoot
View GitHub Profile
@wcarhart
wcarhart / restart.sh
Created July 19, 2018 19:04
Restart Touch Bar on Macbook Pro
pkill "Touch Bar agent"
killall "ControlStrip"
@wcarhart
wcarhart / instructions.md
Last active August 31, 2018 05:51
Instructions for installing Sublime packages (ST3)

Installing Package Manager:

  1. Press Ctrl+` to open Sublime's command prompt.
  2. Paste in:
import urllib.request,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

If the above command fails, it's likely because it needs to be updated. Go here for the source of the above command.

  1. Restart Sublime.
@wcarhart
wcarhart / nyt.py
Created March 29, 2019 16:44
Get the NYT headlines for the day!
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):
@wcarhart
wcarhart / undo_git.sh
Last active August 1, 2019 21:54
Completely remove a file from git history
# 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
@wcarhart
wcarhart / reset_git.sh
Created August 5, 2019 16:44
Reset a git repository (before commit)
# Reset git repository (before commit)
git reset HEAD \*
git checkout -- .
@wcarhart
wcarhart / deploy_django_to_heroku.sh
Last active August 6, 2019 10:25
How to deploy a Django application to Heroku
# 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 ==========#
@wcarhart
wcarhart / new-net-nat.ps1
Created October 22, 2019 18:13
Add Network NAT for Hyper-V VM
# 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:
@wcarhart
wcarhart / setup_networking.sh
Last active October 22, 2019 18:36
Setup networking for a CentOS VM (on Hyper-V)
# 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
@wcarhart
wcarhart / setup_docker.sh
Created October 22, 2019 18:45
Setup Docker for a Centos VM (on Hyper-V)
# THIS IS FOR AN OLDER VERSION OF DOCKER
# if you're using a custom docker space on a mounted drive, ensure the drive mounted correctly
# determine where the mount is
df -h
# then, format the disk as necessary (may have to remove partition and remount)
fdisk /dev/sda # or /dev/sdb, etc.
p # print partitions
d # delete partition
@wcarhart
wcarhart / setup_python.sh
Last active October 22, 2019 19:51
Setup Python for a CentOS VM (on Hyper-V)
# you might need these, if they are not already installed:
yum install -y zlib
yum install -y zlib-devel
yum install -y opensll
yum install -y opensll-devel
# Install Python 3.6.8 (change version # as necessary)
cd /usr/src
yum install -y gcc
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz