Skip to content

Instantly share code, notes, and snippets.

View lsloan's full-sized avatar

Mr. Lance E Sloan «UMich» lsloan

  • Teaching and Learning (@tl-its-umich-edu) at University of Michigan: Information and Technology Services
  • Ann Arbor, Michigan, USA
  • 17:02 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / timedelta_iso.py
Created December 21, 2022 19:01 — forked from benkehoe/timedelta_iso.py
IS8601 functions for datetime.timedelta
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
@lsloan
lsloan / Slack thread print.md
Created October 31, 2022 19:17
Printing Slack Threads

Printing Slack Threads

Slack doesn't provide a way to export or even print important threads that one may want to keep. Here's what I do save threads to PDF.

TL;DR

Open the thread in a web browser and print to PDF.

Step by step

@lsloan
lsloan / yamlpath-example.py
Last active September 2, 2022 12:43
YAML Path (`yamlpath` on PyPI) examples
# Expanding on YAML Path basic Python library example from
# https://github.com/wwkimball/yamlpath/blob/master/README.md#searching-for-yaml-nodes
from types import SimpleNamespace
from yamlpath import Processor
from yamlpath import YAMLPath
from yamlpath.common import Parsers
from yamlpath.exceptions import YAMLPathException
from yamlpath.wrappers import ConsolePrinter
@lsloan
lsloan / process.py
Last active August 26, 2022 18:56
convert vulnerability YAML data (Grafeas format) to TSV
import csv
import sys
from operator import itemgetter
from types import SimpleNamespace
from yamlpath import Processor
from yamlpath import YAMLPath
from yamlpath.common import Parsers
from yamlpath.exceptions import YAMLPathException
from yamlpath.wrappers import ConsolePrinter
@lsloan
lsloan / jq-insert-var.sh
Last active August 24, 2022 17:37 — forked from joar/jq-insert-var.sh
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
@lsloan
lsloan / cisco-anyconnect-auto-login.md
Created May 13, 2022 15:35 — forked from zenglian/cisco-anyconnect-auto-login.md
auto login with cisco anyconnect (password saved, silent mode)

Cisco AnyConnect: auto login in silent mode

This gist is for Linux. For windows is the same thing.

Connect

create a file .login_info as below:

connect your.server.url    
usernanme 
@lsloan
lsloan / ! Python QTI.md
Last active April 10, 2023 21:11 — forked from IanHopkinson/lxml_examples.py
QTI data processing in Python; examples using pyslet, beautifulsoup4, and lxml.

Examples of processing QTI data with Python.

I attempted to use pyslet, which was designed for this purpose, but I found it awkward to use and its documentation unclear. Instead, I tried to use beautifulsoup4, but I learned that library doesn't support XPath to query for specific elements of the data. I turned to using the simple XML processing library lxml. It has similarities to other XML parsing libraries I've used before, but it has many unique features of its own.

Note that of the examples below, each does something a little differently. They don't all have the same output.
That's because they were mostly tests to see whether we preferred working with one library over another. Some

@lsloan
lsloan / pyslet-traverse.py
Created October 26, 2021 18:08
pyslet QTI example: traversing a parsed tree
from typing import Optional, Any, Sequence
import pyslet.qtiv2.xml as qti
from pyslet.xml.namespace import NSElement
from pyslet.xml.structures import Document, Element
def getChildElements(node: NSElement) -> Sequence[NSElement]:
# skips strings not enclosed within elements (e.g., linebreaks in XML file)
return [child for child in node.get_children() if
@lsloan
lsloan / Dockerfile-jupyterlab-telemetry
Last active May 24, 2021 20:02
Start JupyterLab in Docker after installing telemetry extension
ARG BASE_CONTAINER=jupyter/minimal-notebook
FROM $BASE_CONTAINER
# Is this a good place for this? This directory was available and
# seemed like a good location for this.
WORKDIR /home/jovyan/work
ENV JUPYTER_ENABLE_LAB='yes'
RUN git clone https://github.com/educational-technology-collective/hwf-jupyterlab-telemetry && \
version: '3'
services:
jupyter:
container_name: my_jupyter
#image: jupyter/datascience-notebook
image: jupyter/minimal-notebook
ports:
- '127.0.0.1:8888:8888'
environment: