Skip to content

Instantly share code, notes, and snippets.

View agritheory's full-sized avatar

Tyler Matteson agritheory

View GitHub Profile
@agritheory
agritheory / graphql_ariadne.py
Last active November 25, 2019 21:52
Quart/ Ariadne example
"""
# graphql query to run in the playground
{
hello
}
"""
from ariadne import QueryType, graphql, make_executable_schema
from ariadne.constants import PLAYGROUND_HTML
from quart import Quart, request, jsonify
@agritheory
agritheory / gist:6c6117f9a7b9d3c15a99e4c0f22a8024
Created November 18, 2019 16:13
Patch a document method in Frappe
#this can be done in a either a document hook or
import types
import rounding_error_monkey_patch
doc = frappe.new_doc("Journal Entry")
# monkey patch validate_invoices method to bypass (incorrect) rounding error
doc.validate_invoices = types.MethodType(rounding_error_monkey_patch, doc)
return doc
@agritheory
agritheory / hooks.py
Created November 27, 2019 13:08
Basic document hook (snippets)
doc_events = {
"Sales Order": {
"on_submit": "my_custom_app.workflows.make_stock_entry_on_so_submit"
},
"on_cancel": "my_custom_app.workflows.cancel_stock_entry_on_so_cancel"
}
}
@agritheory
agritheory / README-Template.md
Created January 19, 2020 01:55 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@agritheory
agritheory / atom_extensions.md
Last active February 7, 2020 15:47
Atom Extensions
@agritheory
agritheory / Python Async Decorator.py
Created February 15, 2020 02:27 — forked from Integralist/Python Async Decorator.py
[Python Async Decorator] #python #asyncio #decorator
import asyncio
from functools import wraps
def dec(fn):
@wraps(fn)
async def wrapper(*args, **kwargs):
print(fn, args, kwargs) # <function foo at 0x10952d598> () {}
await asyncio.sleep(5)
@agritheory
agritheory / token_auth_example.py
Last active March 4, 2020 01:14
Frappe Token Authorization Example
from requests import request
from base64 import b64encode
api_secret = get_decrypted_password("User", "example_username", "api_secret") # this is an internal frappe method
token = frappe.get_value("User", "example_username", "api_key") # this is an internal frappe method
url = "https://" + subdomain + ".some_domain.com"
headers = {
"Content-Type": "application/json",
"Authorization": "Basic "
+ b64encode(bytes(token + ":" + api_secret, "ascii")).decode("ascii"),
@agritheory
agritheory / edgewise_create_data.py
Created April 1, 2020 17:28
Generate Company and User with Mimesis
import csv
import random
import typing
from pathlib import Path
import mimesis
def write_to_file(filename: str, data: list) -> typing.NoReturn:
raw_path = Path(__file__).parent / filename
@agritheory
agritheory / add_github_deploy.sh
Last active November 14, 2024 16:47
Add deploy key
# on local machine generate public and private keys
ssh-keygen -t ed25519
$ Generating public/private ed25519 key pair.
$ Enter file in which to save the key (/home/tyler/.ssh/id_ed25519): deploy_key
# add deploy_key.pub to github deploy keys via UI
# add both keys to server
# modify permissions
from frappe.modules.utils import export_customizations
def export_dimension_fields():
doctypes = [
"GL Entry",
"Sales Invoice",
"Purchase Invoice",
"Payment Entry",
"Expense Claim Detail",
"Expense Taxes and Charges",