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
  • 00:08 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / copy-of-pandas-101-data-cleaning-in-pandas.ipynb
Last active July 18, 2023 02:42
Copy of Pandas 101 - Data Cleaning in Pandas.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lsloan
lsloan / phpunit_fluent_mock.php
Last active July 12, 2023 17:09
Mocking a Fluent Interface with PHPUnit
/*
* With PHPUnit one can easily mock a class that implements a fluent interface.
*
* This will make any method call to your mock object return a reference to itself.
*/
$mock = $this->getMock('MyClass');
$mock->expects($this->any())
->method(new PHPUnit_Framework_Constraint_IsAnything())
->will($this->returnSelf());
@lsloan
lsloan / GFM-sandbox.md
Created December 4, 2017 23:59
A place to test GFM

Test GitHub-Flavored Markdown in the comments below.

@lsloan
lsloan / ChatGPT.py
Last active May 17, 2023 20:23
ChatGPT experiment in Python
import json
import os
import openai
class ChatApp:
def __init__(self, model='gpt-3.5-turbo', load_file=''):
# Setting the API key to use the OpenAI API
# openai.api_key = os.getenv('OPENAI_API_KEY')
@lsloan
lsloan / canvas_API_query.js
Created April 12, 2023 18:08
Run a Canvas API query from the browser using CSRF token set by the site.
var csrfToken = getCsrfToken();
console.log('crsfToken', csrfToken);
fetch('/api/v1/conversations/unread_count', {
method: 'GET',
credentials: 'include',
headers: {
"Accept": "application/json",
"X-CSRF-Token": csrfToken
}
@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 / 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 / iso8601TimestampWithMilliseconds.php
Last active January 17, 2023 07:40
Get PHP DateTime objects with fractional seconds and format them according to ISO 8601.
/*
* The `DateTime` constructor doesn't create objects with fractional seconds.
* However, the static method `DateTime::createFromFormat()` does include the
* fractional seconds in the object. Finally, since ISO 8601 specifies only
* millisecond precision, remove the last three decimal places from the timestamp.
*/
// DateTime object with microseconds
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
@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