Code
Name:
File Type:


Django_ManageCommands.py
Last Update: Jan. 27, 2021, 5:17 a.m.
Description: Various commands associated with Django manage.py
File Type: application/x-python

# 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
Django_VirutalEnvironment.txt
Last Update: Jan. 27, 2021, 5:17 a.m.
Description:
File Type: text/plain

# Make virtual environment called env
python3 -m venv env

# Activate virtual environment called env
source env/bin/activate

# Deactivate virtual environment
deactivate
EnvironmentVariables.txt
Last Update: Oct. 23, 2022, 7:43 p.m.
Description:
File Type: text/plain

# 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]
Git_CommonCommands.txt
Last Update: June 17, 2022, 4:35 a.m.
Description: Common commands that can be used for git versioning and source control.
File Type: text/plain

# 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

Gunicorn_CommonCommands.txt
Last Update: Jan. 30, 2021, 8:57 p.m.
Description: Common commands that are used with Gunicorn Python WSGI HTTP Server
File Type: text/plain

# 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
LinuxCommandLine.txt
Last Update: June 17, 2022, 4:24 a.m.
Description: Linux Command Line
File Type: text/plain

// Copy
cp originalfile.txt destination
Options:
-r - recursive through all folders
- ../ - relative parent path
- /* all files types in a folder
Linux_SecureCopy.txt
Last Update: Jan. 27, 2021, 5:17 a.m.
Description: Use Secure Copy (SCP) to copy files with SSH security. The -r argument is to copy recursively.
File Type: text/plain

scp -r ~/directorypath/ username@host:/remotedirectorypath/
Nginx_CommonCommands.txt
Last Update: Jan. 28, 2021, 3:33 a.m.
Description: Linux commands to be used with Nginx web server.
File Type: text/plain

# Restart Nginx
sudo systemctl restart nginx
Python_Multithread.py
Last Update: Jan. 25, 2021, 2:42 a.m.
Description: This code allows for multi-threading of a user-defined 'custom_function' where data is returned from the custom function.
File Type: application/x-python

"""
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))
SQLite_BasicCommands.sqlite
Last Update: Jan. 27, 2021, 5:17 a.m.
Description: Contains common commands to run against a SQLite3 database
File Type: text/plain

# 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
VIM_CommonCommands.vim
Last Update: Jan. 25, 2021, 4:13 a.m.
Description: Shortcut commands that are used for VIM.
File Type: text/plain

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

All code listed on this page is hosted on GitHub currenlty licensed under GNU General Public License V3.0.