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
  • 23:54 (UTC -05:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / generateAlter.sql
Created July 27, 2020 15:29 — forked from jonespm/generateAlter.sql
Convert database to utf8mb4 as admin
-- Fill in the name of your DB in @dbname then run the following as the admin user, should be all updated to utf8mb4!
-- mysql --silent < generateAlter.sql > alterTables.sql
-- mysql < alterTables.sql
SET @dbname = "myla_dev";
use information_schema;
-- Update DB to utf8mb4
SELECT "SET FOREIGN_KEY_CHECKS=0;";
@lsloan
lsloan / replace_pandas.py
Created August 13, 2020 19:49 — forked from okdolly-001/replace_pandas.py
Replace values in dataframe from another dataframe ? #pandas
1. Substitute the NaN's in a dataframe with values from another dataframe
If you have two DataFrames of the same shape, then:
df[df.isnull()] = d2
2.Replace values in a dataframe with values from another dataframe by conditions
@lsloan
lsloan / recursiveFormat.py
Last active October 16, 2020 18:08 — forked from sloanlance/recursiveFormat.py
`recursiveFormat()` – Recursively apply `string.format()` to all strings in a data structure.
def recursiveFormat(args, **kwargs):
"""
Recursively apply `string.format()` to all strings in a data structure.
This is intended to be used on a data structure that may contain
format strings just before it is passed to `json.dump()` or `dumps()`.
Ideally, I'd like to build this into a subclass of `json.JsonEncoder`,
but it's tricky to separate out string handling in that class. I'll
continue to think about it.
@lsloan
lsloan / reverseadmin.py
Last active October 21, 2020 20:09 — forked from wolever/reverseadmin.py
Forked from (https://gist.github.com/wolever/fdd36cbde02ca5cf085c), updated to work with Django 3.1
# -*- coding: utf-8 -*-
import functools
from django.contrib.admin import ModelAdmin
from django.contrib.admin.options import InlineModelAdmin
from django.contrib.admin.utils import flatten_fieldsets
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import OneToOneField, ForeignKey
from django.forms import ModelForm
from django.forms.models import BaseModelFormSet, modelformset_factory
@lsloan
lsloan / markdown-details-collapsible.md
Created November 6, 2020 15:35 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets
@lsloan
lsloan / docker-compose.yml
Created May 12, 2021 03:29 — forked from cboettig/docker-compose.yml
debugging NGINX configuration for Jupyter
jupyter:
image: jupyter/datascience-notebook
environment:
- PASSWORD=${PASSWORD}
nginx:
image: nginx
links:
- jupyter
## Initial setup you should only have to do this once
# Checkout docker stacks project
git clone https://github.com/jupyter/docker-stacks
cd docker-stacks/base-notebook
# Clone the telemetry in this directory, this is currently a private repo.
git clone https://github.com/educational-technology-collective/hwf-jupyterlab-telemetry
# git needs to be added to base image
@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 / 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 / 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}'
{