# Start debug server
python manage.py runserver
# Make migrations for an app called 'app'
python manage.py makemigrations app
# Migrate project
python manage.py migrate
# Check project
python manage.py check
# Collect static files for deployment to Production
python manage.py collectstatic
# Make virtual environment called env
python3 -m venv env
# Activate virtual environment called env
source env/bin/activate
# Deactivate virtual environment
deactivate
# List all environment variables
printenv
# Print specific environment variable
echo $[variable name]
# Set a temporary environment variable
export [name]=[value]
# Add permanent environment variable, navigate to path below and add new variable
~/.bash-profile
# Update with variables (or restart terminal)
source ~/.bash-profile
# Remove variable
unset [name]
# Start new repo
# First, Create a folder then run below in the folder
git init
# View logs
git log # View recent logs
git log --pretty=oneline # Display all comments on single lines
# Branches
git branch # View branches
git branch -r # View origin branches
git branch feature/Name # Create a new branch named feature/Name
git checkout feature/Name # Checkout branch
git checkout - # Quickly switch between last checked out branch
git branch -d feature/Name # Remove unused branches
git push origin feature/Name # Push feature branch into remote repo
git push origin --delete feature/Name # Delete remote branch on repo
# Stage all changes
git add .
# Commit with comments
git commit -m "Comment"
# Merge
git checkout master # Changes will go away because master working directory is show (no changes yet)
git merge feature/Name # Merge feature branch
# Status of local vs origin master
git status
# Push
git push # Push local master changes to remote server
# Versions
git show HEAD~4:src/main.c # Example to show 4 versions ago
# Global configuration
git config --global user.name "NAME"
git config --global user.email "email@example.com"
# Create a file with credentials - IMPORTANT: THIS STORES CREDENTIALS IN PLAIN TEXT
git config --global credential.helper 'store --file ~/.my-credentials'
# On the next git pull/push, enter credentials and they get automatically stored in the file and retrieved in the future.
# Close without SSL verification or Update Certs
git -c http.sslVerify=false clone <repository>
git config --system http.sslCAPath /cacerts/path
# Below are Unix commands
# Check Gunicorn status
sudo systemctl status gunicorn
# Restart Gunicorn
sudo systemctl restart gunicorn
# Reread service definition
sudo systemctl daemon-reload
# Check Gunicorn process log
sudo journalctl -u gunicorn
// Copy
cp originalfile.txt destination
Options:
-r - recursive through all folders
- ../ - relative parent path
- /* all files types in a folder
scp -r ~/directorypath/ username@host:/remotedirectorypath/
# Restart Nginx
sudo systemctl restart nginx
"""
Python_Multithread
This code allows for multi-threading of a user-defined 'custom_function' where data is returned from the custom function.
"""
import numpy as np
import pandas as pd
from threading import Thread
import time
def custom_function(var1, var2):
# Input function that needs to run multi-threaded here
pass
return df # Returned to the thread as res
def wrapper(func, args, res):
res.append(func(*args))
threads = []
starttimer = time.time()
res = []
for index,row in df_inputs.iterrows():
# Multi thread the custom_function
t = Thread(
target=wrapper, args=(custom_function, (var1, var2), res))
t.start()
threads.append(t)
for thread in threads:
thread.join()
# Combine into one final DataFrame
df_output = pd.DataFrame(res)
print('Time to complete: ' + str(time.time() - starttimer))
# Access SQLite database named "database"
sqlite database
# See tables
.tables
# See schema for table 'cars'
.schema cars
# Select all data for table 'cars'
select * from cars;
# Help to see all commands
.help
# Quit
.quit
Save & Quit:
:w - save
:q - quit
ZZ - save & quit
! - force (can be combined with :q! or :w!)
Cursor Movement
h - move cursor to the left one character
l - move cursor to the right one character
k - move cursor up one line
j - move cursor down one line
0 - move cursor to beginning of line
$ - move cursor to end of line
w - move cursor one word forward
b - move cursor one work backward
G - move cursor to end of file
gg - move cursor to beginning of file
Deletion
dw - delete word
d0 - delete to beginning of line
d$ - delete to end of line
dgg - delete to beginning of file
dG - delete to end of file
Undo / Redo
u - undo last change
Ctrl-r - redo last change
Search
/text - search for 'text' keyward
n / N - move to the next or previous instance
:%s/text/replacement text/g - find 'text' and replace with 'replacement text'
:%s/text/replacement text/gc - find 'text' and replace with 'replacement text' with confirmation first
Copy & Paste
v - highlight one word
V - highlight one line
y - copy
p - paste after current line
P - paste on current line