Skip to content

Instantly share code, notes, and snippets.

💭

Lance E Sloan «UMich» lsloan

💭
  • @tl-its-umich-edu - Teaching & Learning, ITS, Univ. of Michigan
  • Ann Arbor, Michigan, USA
Block or report user

Report or block lsloan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lsloan
lsloan / umich_mcomm_api_query.py
Created Jun 19, 2019
Example of using the Univ. of Michigan API Directory to query the MCommunity service for a person by their uniqname.
View umich_mcomm_api_query.py
import os
import sys
import http.client
from base64 import b64encode
import json
clientId = os.getenv('UMICH_API_DIR_CLIENT_ID')
clientSecret = os.getenv('UMICH_API_DIR_CLIENT_SECRET')
uniqname = sys.argv[1] if len(sys.argv) > 1 else os.getenv('USER')
View query_urllib2.py
#!/usr/bin/env python2 --
# A program I wrote for Univ. of Michigan sysadmins who are
# supporting a legacy system. They need to query various
# URLs, and get the response code and content in return.
# However, they only have an old version of curl available
# to them, one without the option to show content even when
# responses come back with an error-like HTTP status code.
# For example, a 500 code for server error may be returned
# along with content that explains the error. The old version
@lsloan
lsloan / v1p0p0.php
Created Apr 19, 2019
Parse hangouts.json from Google Takeout, via https://paste.jay2k1.com/view/5fcebdfe
View v1p0p0.php
<?php
/*
(in this version, I added support for more message types and offer both plaintext and HTML message format)
This is a function that transforms the JSON you get from Google Takeout when you export your Hangouts history
into a PHP array which can be used to further manipulate the data.
A use case is my hangouts parser at http://hangoutparser.jay2k1.com/ -- a description can be seen at
http://blog.jay2k1.com/2014/11/10/how-to-export-and-backup-your-google-hangouts-chat-history/
View JAPH.md

perl -e '$_ = "wftedskaebjgdpjgidbsmnjgc";tr/a-z/oh, turtleneck Phrase Jar!/; print;'

@lsloan
lsloan / gist:bad9f599695cc35d76402453624faa38
Created Jan 18, 2019 — forked from perusio/gist:1724301
Workaround in PHP cURL for the 100-continue expectation
View gist:bad9f599695cc35d76402453624faa38
<?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/
View dictionaryKeyFind.py
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):
View EventMediaPausedVideoMultiContextTest.php
<?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;
View caliperEventMediaPausedVideoMultiContext.json
{
"@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 Nov 1, 2018 — forked from scriptingosx/bashdisplay.sh
bash functions using osascript to use some user interaction on macOS
View bashdisplay.sh
#!/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"}
@lsloan
lsloan / mh2mbox.sh
Created Oct 5, 2018 — forked from ericlathrop/mh2mbox.sh
Convert MH mail folders to MBOX files, which are used by Mozilla Thunderbird.
View mh2mbox.sh
#!/bin/bash
#
# mh2mbox.sh
# By Eric Lathrop <eric@ericlathrop.com>
#
# Convert MH mail folders to MBOX files
# Useful for switching to Mozilla Thunderbird
#
# Copy this script to ~/Mail/ and execute.
#
You can’t perform that action at this time.