Skip to content

Instantly share code, notes, and snippets.

View danizen's full-sized avatar

Dan Davis danizen

View GitHub Profile
@danizen
danizen / middleware.py
Last active December 11, 2023 07:59
Django middleware to collect slow queries using force_debug_cursor
import logging
import time
from django.conf import settings
from django.db import connection
THRESHOLD = getattr(settings, 'SLOW_REQUEST_THRESHOLD', 1.0)
LOG_SQL = getattr(settings, 'SLOW_REQUEST_LOG_SQL', False)
LOG = logging.getLogger(__name__)
@danizen
danizen / backends.py
Last active August 3, 2020 17:58
Excerpt of logout flow
class LogoutMixin:
def logout_params(self, next_page):
# Backend should provide this
return {
'logout_uri': next_page
}
def logout_baseurl(self):
# Backend should provide this
return '/logout'
import json
import sys
from argparse import ArgumentParser, ArgumentTypeError
from copy import deepcopy
from datetime import datetime, timedelta
import attr
import requests
from dateutil import parser as date_parser
---
secret: "/dbsecrets/pgadmin@cfom_db_int"
database_name: cfom_db_int
search:
prefix: |
SELECT "physicians"."PHYSICIANID",
"physicians"."FIRSTNAME",
"physicians"."MIDDLENAME",
"physicians"."LASTNAME",
"physicians"."MAIDENNAME",
(define (script_fu_batch_brushes inDir inLoadType)
(let*
(
(varLoadStr 0)
(varSaveStr 0)
(image 0)
(drawable 0)
(newfilename 0)
(filename 0)
(varFileList 0)
@danizen
danizen / getbibs.py
Created November 18, 2020 20:42
Python3 script to access Alma APIs
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from io import BytesIO
import requests
from lxml import etree
DFLT_ENDPOINT = 'https://api-na.hosted.exlibrisgroup.com'
@danizen
danizen / queries.yaml
Created December 29, 2020 20:00
Non-authorized mechanism to export/convert MeSH RDF to SKOs
prefixes: |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX meshsv: <http://id.nlm.nih.gov/mesh/skos/>
import attr
@attr.s
class BibData:
mms_id = attr.ib()
title = attr.ib()
status = attr.ib()
mod_date = attr.ib()
@danizen
danizen / sqlproc.py
Last active October 22, 2021 23:25
SQL processing management command
import os
from django.core.management.base import BaseCommand
from django.core.management import call_command
class Command(BaseCommand):
def handle(self, *args, **options):
# create a pipe and turn the output file descriptor into a Python IO object
@danizen
danizen / areport.py
Created July 5, 2022 16:02
base management command to run a PL/SQL report
from . import BaseReportCommand
class Command(BaseReportCommand):
help = 'Report on records with both .....'
LOGFILE = 'report_output.log'
TEMPLATE = 'report_template.sql'
SUBJECT = 'Record has ERMS data and FER flag'
RECIPIENTS = [