Skip to content

Instantly share code, notes, and snippets.

View sengstacken's full-sized avatar

Aaron Sengstacken sengstacken

View GitHub Profile
@sengstacken
sengstacken / python_shiz.md
Last active February 5, 2019 23:15
Python Snips

Python Tips

File I/O!

f = open('workfile.b','r')
a = f.read() # or .readlines()
f.close()

f = open('workfile.b','w')
# import numpy and set the printed precision to something humans can read
import numpy as np
np.set_printoptions(precision=2, suppress=True)
# set some prefs for matplotlib
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams.update({'text.usetex': True})
fig_width_pt = 700.  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inches
1. Log into AWS
2. Select N. California as location
3. Select AMI - cs224d_tensorflow - ami-16327176
4.
OR go to EC2 > Instances > Start
ssh into machine
ssh -i cs224d_AWS.pem ubuntu@IP
@sengstacken
sengstacken / Git Cheat Sheat
Created February 9, 2017 15:33
Git for dummies
# create new repository (repo
git init
# check status of files
git status
# add file
git add <filename>
# commit files
Start the saved VM
Open Docker Quickstart - docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow
or docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow bash
or docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:0.12.1 bash
maybe install modules
@sengstacken
sengstacken / s3read.py
Created March 17, 2020 18:55
Read S3 File Into Python
import boto3
import json
bucket = 'blah'
f = 'fileblah'
# get file from s3, read it, convert to json
s3 = boto3.resource('s3')
content_object = s3.Object(bucket, f)
file_content = content_object.get()['Body'].read().decode('utf-8')
@sengstacken
sengstacken / train_test_val_split_seq.py
Last active September 23, 2021 19:27
code to perform the train test validation split on a pandas dataframe for a time sequence
trainpct = 0.7
trainidx = int(np.round(len(df)*trainpct))
train_df = df.iloc[0:trainidx,:]
valpct = 0.2
validx = int(np.round(len(df)*(trainpct+valpct)))
val_df = df.iloc[trainidx:validx,:]
test_df = df.iloc[validx::,:]
@sengstacken
sengstacken / scale_normalize.py
Created March 24, 2020 14:19
scale dataframes after train test split
# scale data between 0 and 1
scaler = MinMaxScaler(feature_range=(0, 1))
scaler.fit(train_df.values)
train_scaled = scaler.transform(train_df.values)
val_scaled = scaler.transform(val_df.values)
test_scaled = scaler.transform(test_df.values)
import json
with open('./data/generated/1127_22.json') as f:
data = json.load(f)
@sengstacken
sengstacken / video2frames.py
Created June 3, 2020 13:23
python code to save video frames to images
import cv2
fname = 'eye_detection.avi'
vidcap = cv2.VideoCapture(fname)
success,image = vidcap.read()
count = 0
while success:
cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file
success,image = vidcap.read()
print('Read a new frame: ', success)
count += 1