Skip to content

Instantly share code, notes, and snippets.

View wbhinton's full-sized avatar

Weston Hinton wbhinton

View GitHub Profile
@wbhinton
wbhinton / contacts.json
Created April 7, 2021 15:40
contacts.json
[
{
"region": "Oklahoma",
"office":"",
"leasing":"Leasing: Michael Todd Taylor, 940-210-9638",
"parts": "Screens and Parts: Michael Todd Taylor, 940-210-9638",
"services":"Technical Serivces: Ryan Hendrickson, 936-264-6044; Luther Gressett, 936-446-8325"
},
@wbhinton
wbhinton / files2parent.py
Created April 1, 2020 17:20
Move all files from subfolders in a parent directory up to the parent directory. It essentially flattens a folder structure, dumping all files into the parent folder.
import os
import shutil
target = input("What is the starting directory?")
def files2parent(target):
for root, dirs, files in os.walk(target):
for file in files:
try:
path_file = os.path.join(root,file)
shutil.move(path_file,target)
@wbhinton
wbhinton / reorg-by-date.py
Created February 4, 2020 17:43
Reorganize files by creation date
#!/usr/bin/python3
import os, time, shutil, sys
dir = sys.argv[1]
os.chdir(dir)
for f in os.listdir('.'):
ftime = time.gmtime(os.path.getmtime(f))
ctime_dir = str(ftime.tm_year) '-' str(ftime.tm_mon) '-' str(ftime.tm_mday)
if not os.path.isdir(ctime_dir):
os.mkdir(ctime_dir)
@wbhinton
wbhinton / stabilize-ffmpeg.md
Last active March 16, 2023 14:02
Video Stabilization

Default

ffmpeg -i shaky-input.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:stepsize=6:mincontrast=0.3:show=2 -y dummy.mp4
ffmpeg -i shaky-input.mp4 -vf scale=trunc((iw*1.15)/2)*2:trunc(ow/a/2)*2 -y scaled.mp4
ffmpeg -i scaled.mp4 -vf vidstabtransform=smoothing=30:input="transforms.trf":interpol=linear:crop=black:zoom=-15:optzoom=0,unsharp=5:5:0.8:3:3:0.4 -y stabilized-output.mp4

Crop

ffmpeg -i shaky-input.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:stepsize=6:mincontrast=0.3:show=2 dummy_crop.mp4
ffmpeg -i shaky-input.mp4 -vf scale=trunc((iw*0.90)/2)*2:trunc(ow/a/2)*2 scaled_crop.mp4
@wbhinton
wbhinton / organize.py
Created January 20, 2020 16:55
File clean up
"""
-*- coding: utf-8 -*-
========================
Python Lazy Junk Files Organizer
========================
========================
"""
import os
from pathlib import Path
@wbhinton
wbhinton / excel-iferror.md
Created January 15, 2020 22:27
Apply IFERROR to all formulas within a selected range

Apply IFERROR to all formulas within a selected range

Create a macro with the following code.

Then select the range of formulas and run the code.

Sub InsertIFERROR()
    Dim R As Range
    For Each R In Selection.SpecialCells(xlCellTypeFormulas)
 R.Formula = "=IFERROR(" & Mid(R.Formula, 2) & ",""N/A"")"
@wbhinton
wbhinton / pd-regex-list.md
Last active January 13, 2020 18:25
Format a string for SQL IN statement from Pandas Dataframe Column

The following snippet generates a regex string that can be used to query DF's

r = "'("
for i in df['columnA']:
    r = r+str(i)+"|"
r = r[:-1]+")'"
@wbhinton
wbhinton / dockerfile
Last active December 18, 2019 05:45
Anaconda Docker Image
# We will use Ubuntu for our image
FROM ubuntu:latest
# Updating Ubuntu packages
RUN apt-get update && yes|apt-get upgrade
RUN apt-get install -y vim
# Adding wget and bzip2
RUN apt-get install -y wget bzip2
@wbhinton
wbhinton / pip.md
Created December 13, 2019 20:07
Install python packages behind a firewall

Install python packages behind a firewall

PIP

add filed named pip.ini in a folder in your home directory (~/pip/pip.ini) or name it pip.conf if .ini doesn't work Add the following lines to the file

[global]
trusted-host =  pypi.python.org
                files.pythonhosted.org
                pypi.org
@wbhinton
wbhinton / pct_chng_group.py
Last active December 12, 2019 17:50
Calculate the percent change of a value within a group
#This first method calculates the percent change from previous observation with in a group.
#An example: The change in a patient's lab value from obs to obs overtime
#The DF should have a field that you want to group, a time range, and value you want
# to perform the calculation on.
# first step is to order the DF by the Group, then by time
df = df.sort(['GroupID','time'])
# step two performs the calculation.
df['pct_chg']=df.groupby('GroupID)['Value'].pct_change()
# Method 2 % change from the inital to final observation