Skip to content

Instantly share code, notes, and snippets.

View JasonCrowe's full-sized avatar

Jason Crowe JasonCrowe

  • North Missouri
View GitHub Profile
@JasonCrowe
JasonCrowe / config_import
Created April 29, 2015 18:45
Import config file
"""import configuration settings"""
import os
if os.path.isfile('app.cfg'):
execfile('app.cfg')
@JasonCrowe
JasonCrowe / print_from_python.py
Created September 29, 2017 13:44
Printing from python
import tempfile
import win32api
import win32print
filename = tempfile.mktemp (".txt")
open (filename, "w").write (str(df))
win32api.ShellExecute (
0,
"print",
@JasonCrowe
JasonCrowe / compare_text.py
Last active April 17, 2019 19:25
Machine learning to see the cosine_simularity of two text variables.
import nltk, string
from sklearn.feature_extraction.text import TfidfVectorizer
nltk.download('punkt') # if necessary...
stemmer = nltk.stem.porter.PorterStemmer()
remove_punctuation_map = dict((ord(char), None) for char in string.punctuation)
def stem_tokens(tokens):
@JasonCrowe
JasonCrowe / airtable_item_vw.sql
Last active October 6, 2017 14:51
Gist for product transfer from sql to airtable
SELECT item.item,
qty AS inventory_level,
description,
product_code,
family_code,
plan_code,
unit_weight,
weight_units,
charfld1 AS upc,
stat,
@JasonCrowe
JasonCrowe / pandas_fwf.py
Created October 10, 2017 19:22
Pandas fixed-width data source
import pandas as pd
df = pd.read_csv('file.tab', sep='\t', lineterminator='\r')
import pandas as pd
fwidths = [34, 4, 4, 34, 11, 1, 1, 1, 1, 1, 8, 8, 2, 11, 1, 40, 1, 40, 1, 7, 7, 1, 1, 1, 4, 40, 40, 40, 40, 40, 2, 12, 1, 8, 40, 1, 11, 11, 11, 11, 1 ]
df = pd.read_fwf('file.tab', widths = fwidths, names = ['ACCOUNT', 'YEAR', 'JURISDICTION', 'TAX-UNIT-ACCT', 'LEVY', 'HOMESTEAD', 'OVER65', 'VETERAN', 'DISABLED', 'AG', 'DATE-PAID', 'DUE-DATE', 'OMIT-FLAG', 'LEVY-BALANCE', 'SUIT', 'CAUSENO', 'BANKCODE', 'BANKRUPTNO', 'ATTORNEY', 'COURT-COST', 'ABSTRACT-FEE', 'DEFERRAL', 'BILLSUPP', 'SPLIT-PMTFLAG', 'CATEGORY-CODE', 'OWNER', 'ADDRESS2', 'ADDRESS3', 'ADDRESS4', 'CITY', 'STATE', 'ZIP', 'ROLL-CODE', 'PARCEL NO.', 'PARCEL NAME', 'PAYMENT AGREEMENT', 'TOT_AMT_DUE', 'TOT_AMT_DUE-30', 'TOT_AMT_DUE-60', 'TOT_AMT_DUE-90', 'AMOUNT INDICATOR'])
df[:10]
@JasonCrowe
JasonCrowe / random_user_agent.py
Created October 19, 2017 13:15
Pick a random user agent to be used by requests
user_agent_list = [
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3",
"Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
]
num = random.randint(0, (len(user_agent_list) - 1))
def get_page_object(url):
response = requests.get(
@JasonCrowe
JasonCrowe / read_write_json.py
Created January 16, 2018 15:49
Read/Write data to/from json files
import json
from glob import glob
def save_data(data):
try:
asin = data['asin']
file_loc = 'data/{}.json'.format(asin)
file = open(file_loc, 'w+')
json.dump(data, file)
except KeyError:
@JasonCrowe
JasonCrowe / dict_2_excel.py
Created August 12, 2018 14:20
Save varied dicts to excel
from xlsxwriter import Workbook
players = [
{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player1', 'bank': 0.06},
{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player2', 'bank': 4.0, 'level': 'Gold'},
{'dailyWinners': 1, 'dailyFree': 2, 'user': 'Player3', 'bank': 3.1},
{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player4', 'bank': 0.32, 'time': 'AM'}
]
def write_excel(dict_objects, filename, sheetname=None):
ordered_list = []
@JasonCrowe
JasonCrowe / img_2_thumbnail.py
Created August 17, 2018 02:25
make image into thumbnail
import os, sys
import Image
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
@JasonCrowe
JasonCrowe / balancing_coins.py
Created October 16, 2018 12:58
Balance bitcoins by selling the higher to the lower
coins = [
{'name': 'ETH', 'qty': 0.81945672, 'price': 215.15},
{'name': 'USDT', 'qty': 125.99, 'price': .99},
{'name': 'BTC', 'qty': 0.02497291, 'price': 6895.15},
{'name': 'BNB', 'qty': 20.91476451, 'price': 10.25},
]
def generate_balance(coins, prec=8):
min = 999*999
max = 0