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:59 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@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 / 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 / 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 / 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 / set-dbeaver-timezone-to-UTC.txt
Created March 26, 2020 19:38 — forked from chetanppatil/set-dbeaver-timezone-to-UTC.md
Set dbeaver timezone to UTC (default timezone)
/* -------------- FOR LINUX USERS ---------------- */
1) Go to directory: "/usr/share/dbeaver"
2) Edit "dbeaver.ini" file
3) In that file add "-Duser.timezone=UTC" this line under "-vmargs" tag
4) Save it and restart dbeaver.
5) Enjoy with correct date without any date conversion.
Finally your dbeaver.ini file will look like this:
-startup
@lsloan
lsloan / gist:bad9f599695cc35d76402453624faa38
Created January 18, 2019 19:05 — forked from perusio/gist:1724301
Workaround in PHP cURL for the 100-continue expectation
<?php
// cURL obeys the RFCs as it should. Meaning that for a HTTP/1.1 backend if the POST size is above 1024 bytes
// cURL sends a 'Expect: 100-continue' header. The server acknowledges and sends back the '100' status code.
// cuRL then sends the request body. This is proper behaviour. Nginx supports this header.
// This allows to work around servers that do not support that header.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
// We're emptying the 'Expect' header, saying to the server: please accept the body right now.
// Read here: http://pilif.github.com/2007/02/the-return-of-except-100-continue/
def find(key, dictionary):
for k, v in dictionary.items():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
for d in v:
for result in find(key, d):
<?php
require_once 'CaliperTestCase.php';
use IMSGlobal\Caliper\actions\Action;
use IMSGlobal\Caliper\context\Context;
use IMSGlobal\Caliper\entities\agent\Organization;
use IMSGlobal\Caliper\entities\agent\Person;
use IMSGlobal\Caliper\entities\agent\SoftwareApplication;
use IMSGlobal\Caliper\entities\lis\CourseSection;
use IMSGlobal\Caliper\entities\lis\Membership;
{
"@context": ["https://some.domain.com/caliper/ctx/v1p1", "http://purl.imsglobal.org/ctx/caliper/v1p1"],
"id": "urn:uuid:956b4a02-8de0-4991-b8c5-b6eebb6b4cab",
"type": "MediaEvent",
"actor": {
"id": "https://example.edu/users/554433",
"type": "Person"
},
"action": "Paused",
"object": {
@lsloan
lsloan / bashdisplay.sh
Created November 1, 2018 18:31 — forked from scriptingosx/bashdisplay.sh
bash functions using osascript to use some user interaction on macOS
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
consoleUser() {
python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'
}
displaydialog() { # $1: message
message=${1:-"Message"}