Skip to content

Instantly share code, notes, and snippets.

View danizen's full-sized avatar

Dan Davis danizen

View GitHub Profile
@danizen
danizen / multiauthenticator.py
Created March 15, 2018 23:06
MultiAuthenticator for jupyterhub
from urllib.parse import urlsplit
from tornado import gen
from tornado.escape import url_escape
from tornado.httputil import url_concat
from traitlets import (
Unicode, Integer, Dict, TraitError, List, Bool, Any,
Type, Set, Instance, Bytes, Float,
observe, default,
@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 / marcindex.py
Created July 5, 2022 21:40
Index a MARC file so you can read only the parts you need
import io
import logging
import os
import mmap
import time
from collections.abc import Sequence
from struct import pack, unpack
LOG = logging.getLogger(__name__)
@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 = [
@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/>
@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
import attr
@attr.s
class BibData:
mms_id = attr.ib()
title = attr.ib()
status = attr.ib()
mod_date = attr.ib()
@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'
(define (script_fu_batch_brushes inDir inLoadType)
(let*
(
(varLoadStr 0)
(varSaveStr 0)
(image 0)
(drawable 0)
(newfilename 0)
(filename 0)
(varFileList 0)
---
secret: "/dbsecrets/pgadmin@cfom_db_int"
database_name: cfom_db_int
search:
prefix: |
SELECT "physicians"."PHYSICIANID",
"physicians"."FIRSTNAME",
"physicians"."MIDDLENAME",
"physicians"."LASTNAME",
"physicians"."MAIDENNAME",