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:55 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@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.
@sloanlance
sloanlance / recursiveFormat.py
Last active November 25, 2021 03:27
`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.
@zevisert
zevisert / pyproject.json
Created September 26, 2020 04:17
pyproject.toml json-schema including poetry definitions
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"poetry-authors": {
"type": "array",
"description": "List of authors that contributed to the package. This is typically the main maintainers, not the full list.",
"items": {
"type": "string",
"pattern": "^(?:\\S+?\\s)+?(?:<(?:[a-z\\d!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z\\d!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z\\d](?:[a-z\\d-]*[a-z\\d])?\\.)+[a-z\\d](?:[a-z\\d-]*[a-z\\d])?|\\[(?:(?:25[0-5]|2[0-4][\\d]|[01]?[\\d][\\d]?)\\.){3}(?:25[0-5]|2[0-4][\\d]|[01]?[\\d][\\d]?|[a-z\\d-]*[a-z\\d]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])>)?$"
}
@sloanlance
sloanlance / ngrok_public_url.sh
Last active August 25, 2020 18:00 — forked from lsloan/ngrok_public_url.sh
Get the local ngrok public URL, which includes the hostname, extracted using jq
#!/bin/sh --
# Get the local ngrok public URL, which includes the hostname, extracted using jq
# Inspiration: https://gist.github.com/rjz/af40158c529d7c407420fc0de490758b#gistcomment-2594627
curl --silent http://127.0.0.1:4040/api/tunnels | jq -r '.tunnels[0].public_url'
@lsloan
lsloan / ngrok_public_url.sh
Last active August 25, 2020 18:00
Get the local ngrok public URL, which includes the hostname, extracted using jq
#!/bin/sh --
# Get the local ngrok public URL, which includes the hostname, extracted using jq
# Inspiration: https://gist.github.com/rjz/af40158c529d7c407420fc0de490758b#gistcomment-2594627
curl --silent http://127.0.0.1:4040/api/tunnels | jq -r '.tunnels[0].public_url'
@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;";
@sloanlance
sloanlance / durationToSeconds.py
Last active November 25, 2021 03:27
Convert ISO 8601 durations to seconds.
import re
from functools import reduce
import string
def durationToSecondsRegex(duration: str) -> int:
"""
Parse duration string; return integer number of seconds.
For example, the duration string "1h2m3s" (1 hour, 2 minutes, 3 seconds)
would return 3723 seconds.
@stevecondylios
stevecondylios / resize-image-in-github-issue-github-flavored-markdown.md
Last active April 27, 2024 19:04
How to Resize an Image in a Github Issue (e.g. Github flavored Markdown)

How to Resize an Image in Github README.md (i.e. Github Flavored Markdown)

Percentage:

<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width=50% height=50%>

Pixels:

<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width="150" height="280">

@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
@gdcutting
gdcutting / google-bigquery-getting-started.ipynb
Last active June 17, 2022 00:32
Google BigQuery: Getting Started
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.