Skip to content

Instantly share code, notes, and snippets.

View agritheory's full-sized avatar

Tyler Matteson agritheory

View GitHub Profile
@agritheory
agritheory / manch_vegas.py
Created April 27, 2018 11:31
Hypothesis Example from NH Python project night 4/26/18
import unittest
import datetime as dt
from hypothesis import assume, given, example
from hypothesis.strategies import text, integers, floats, dates, composite, shared
# also discuss: from_regex, random and shared strategies: http://hypothesis.readthedocs.io/en/latest/data.html
class TestTransaction(unittest.TestCase):
@composite
@agritheory
agritheory / bench_setup.sh
Last active May 21, 2018 17:51
Bench and setup commands to remember
# Manual Install:
git clone https://github.com/frappe/bench bench-repo
pip install --user -e bench-repo
#delete existing site databases if reinstalling:
sudo mysql -u root - p # then it expects root MySQL password
show databases;
drop database alskjdfhalsdfhasldfj;
# name the bench based on client or workflow desired eg "Evaqua" or frappe-bench-backup
@agritheory
agritheory / opening_invoice_creation_tool.py
Last active May 22, 2018 21:24
Open invoice tool edits - lines 176 - 181
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _, scrub
from frappe.utils import flt, nowdate
from frappe.model.document import Document
@agritheory
agritheory / datenight.py
Created July 26, 2018 19:41
NH python datetime code
# datetime
# dateutil
# parser is awesome: https://dateutil.readthedocs.io/en/stable/parser.html, built into pendulum and Maya
# datetime
# arrow vs pendulum: https://www.reddit.com/r/Python/comments/595tcd/please_stop_using_arrow_for_your_datetime/
# timestring -> similar to ctparse
@agritheory
agritheory / ocr.py
Last active September 27, 2018 01:16
Tesseract + Python Stub for Python project night
# install tesseract per instructions for your os
# ubuntu: sudo apt-get install tesseract-ocr
# sudo pip install pytesseract
# sudo pip install python-Levenshtein
# sudo pip install fuzzywuzzy
# load image(s) in working directory
import re
import pytesseract
import pillow
sudo apt-get install git
sudo apt-get install python-minimal
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.3/ubuntu xenial main'
sudo apt-get update
sudo apt-get install mariadb-server-10.3
sudo apt-get install libmysqlclient-dev
sudo apt install python-pip
# do not upgrade pip; breaks in pip bench install
@agritheory
agritheory / HID_scanner.js
Created December 13, 2018 12:06
HID_scanner.js
// USB Event Detection
const usbDetect = require('usb-detection');
// USB HID library used to interface with USB devices
const HID = require('node-hid');
class Scanner {
constructor(config, socket) {
this.socket = socket;
this.device = null;
@agritheory
agritheory / so_print.py
Created January 30, 2019 01:21
Sales Order Print Template
{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
{% if letter_head and not no_letterhead %}
<div class="letter-head">{{ letter_head }}</div>
{% endif %}
{%- if doc.meta.is_submittable and doc.docstatus==0-%}
<div class="alert alert-info text-center">
<h4 style="margin: 0px;">{{ _("DRAFT") }}</h4></div>
{%- endif -%}
{%- if doc.meta.is_submittable and doc.docstatus==2-%}
<div class="alert alert-danger text-center">
import requests
from base64 import b64encode
import json
def push_po(doc, method):
# additional business logic or other validations
# prune document fields and turn into json
payload = json.loads({"docfield": doc})
api_key, api_secret = frappe.get_value("User", frappe.session.user, ["api_key", "api_secret"])
@agritheory
agritheory / hook_workflow_action.py
Last active January 16, 2021 11:51
Hook onto the workflow action API
# Overriding Whitelisted Methods (in my_app/hooks.py)
# ------------------------------
override_whitelisted_methods = {
"frappe.model.workflow.apply_workflow": "my_app.workflows.apply_workflow"
}
# in my_app/workflows.py
import frappe
from frappe.model.workflow import apply_workflow as model_apply_workflow