Skip to content

Instantly share code, notes, and snippets.

View PureMath86's full-sized avatar

Bryan Arnold PureMath86

View GitHub Profile
@PureMath86
PureMath86 / pdf-report.py
Created November 13, 2018 23:20 — forked from chris1610/pdf-report.py
PDF Report Generation - pbpython.com
"""
Generate PDF reports from data included in several Pandas DataFrames
From pbpython.com
"""
from __future__ import print_function
import pandas as pd
import numpy as np
import argparse
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@PureMath86
PureMath86 / pdf2img.py
Created March 5, 2018 20:25
pdf2img.py
import sys
with open(sys.argv[1],"rb") as file:
file.seek(0)
pdf = file.read()
startmark = b"\xff\xd8"
startfix = 0
endmark = b"\xff\xd9"
endfix = 2
@PureMath86
PureMath86 / hough.py
Created March 5, 2018 20:25
hough.py
import cv2
import numpy as np
img = cv2.imread('path/to/img', 0) # 0 = grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(img,100,200)
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for rho, theta in lines[0]:
a = np.cos(theta)
@PureMath86
PureMath86 / ocr.py
Created March 5, 2018 20:23
ocr.py
# import the necessary packages
from PIL import Image # get image from disk in PIL format
import pytesseract # python "wrapper" of Google's Tesseract binaries
import argparse # build command-line interfaces
import cv2 # opencv-python
import os # operating system
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
@PureMath86
PureMath86 / rotate_img.py
Created March 5, 2018 20:22
rotate_img.py
# import packages
from PIL import Image
import os
import argparse # build command-line interfaces
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d",
"--directory",

API workthough

  1. Open a browser

    # start an instance of firefox with selenium-webdriver
    driver = Selenium::WebDriver.for :firefox
    # :chrome -> chrome
    # :ie     -> iexplore
    
  • Go to a specified URL
@PureMath86
PureMath86 / frame_clipboard.py
Created November 1, 2017 06:28
frame_clipboard
import pandas as pd
import pyperclip
import io
def frame_clipboard():
s = pyperclip.paste()
clip_df = pd.read_table(io.StringIO(s))
return clip_df
@PureMath86
PureMath86 / mouseXY.py
Created October 12, 2017 18:44
mouseXY
import pyautogui
def mouse_now():
print('Press Ctrl-C to quit.')
try:
while True:
# Get and print the mouse coordinates.
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)