Skip to content

Instantly share code, notes, and snippets.

View sloanlance's full-sized avatar
Certified GitHub Pro

Mr. Lance E Sloan sloanlance

Certified GitHub Pro
View GitHub Profile
@sloanlance
sloanlance / clone-private-github-repo-in-google-colab.ipynb
Last active May 10, 2024 11:45
clone-private-github-repo-in-google-colab.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sloanlance
sloanlance / BASH: ISO 8601 Timestamp with Milliseconds
Last active May 6, 2024 14:40
How to get an ISO 8601 timestamp with milliseconds in BASH
Gist title: "BASH: ISO 8601 Timestamp with Milliseconds"
Summary: How to get an ISO 8601 timestamp with milliseconds in BASH
@sloanlance
sloanlance / jq_jsonl_conversion.md
Last active May 3, 2024 10:26
jq: JSONL ↔︎ JSON conversion

jq: JSONL ↔︎ JSON conversion

Prerequisites

  • jqhttps://jqlang.github.io/jq/ — "like sed for JSON data"

    There are several options available for installing jq. I prefer to use Homebrew: brew install jq

  1. JSONL → JSON

@sloanlance
sloanlance / jq_tsv_conversion.md
Last active April 12, 2024 04:33
jq: JSONL → TSV conversion

jq: JSONL → TSV conversion

What is TSV?

TSV means "tab-separated values". I prefer this format over CSV ("comma-separated values") because it doesn't require as much quoting. Many programs that can use CSV formatted data can also use TSV, although they may need to be explicitly told of the different format if it's not detected automatically.

However, in any of the jq scripts below, "@tsv" can usually be replaced with "@csv" to get CSV output instead.

@sloanlance
sloanlance / Editing remote files in Vim with SSH.md
Created July 13, 2017 16:11
Editing remote files in Vim with SSH

Editing remote files in Vim with SSH

  1. Configure SSH

    In ~/.ssh/config, include the lines:

    Host *
    ControlPath ~/.ssh/sockets/%r@%h-%p
    
@sloanlance
sloanlance / bgsounds.sh
Last active March 5, 2024 20:06
bgsounds.sh: Toggle macOS Background Sounds on or off.
#!/bin/sh --
# Toggle macOS Background Sounds on or off.
#
# See the System Settings panel for Accessibility > Audio to change settings
# like the sound played, volume level, and automatic stop.
# `read` returns an integer, but…
if [ $(defaults read com.apple.ComfortSounds 'comfortSoundsEnabled') = 0 ]
then
@sloanlance
sloanlance / git-temporary-ignore.md
Last active March 2, 2024 01:32
git: A couple ways to temporarily ignore changed or new files without altering .gitignore.

There are times notifications aren't wanted about either a changed repo file or a new file that needs to be added to the repo. However, adding the name of the file to .gitignore might not be a good option, either. For example, locally-generated files that other users aren't likely to generate (e.g., files created by an editor) or files of experimental test code might not be appropriate to appear in a .gitignore file.

In those cases, use one of these solutions:

  1. If the file is a changed repo file

    Use the command:

    git update-index --assume-unchanged "$FILE"

@sloanlance
sloanlance / Python utilities.md
Created June 28, 2017 15:30
Python: A document of ready to use utilities included in Python's standard modules

Python's Built-in Utilities

List of command line accessible tools built into the Python standard library.

Encoding and decoding

Base64 en/decoding:

python -m base64 -d [file]

python -m base64 -e [file]

@sloanlance
sloanlance / unicode-variables.py
Last active December 20, 2023 02:29
Python's handling of Unicode-character variables is surprising!
𝐀 = {'😀': 5}
for ℹ︎ in range(20):
# print(i, ℹ︎, i == ℹ︎) # NameError: name 'i' is not defined.
for _,__ in 𝐀.items():
if __ == ℹ︎:
print(_, ℹ︎)
print(𝐀) # Prints dictionary in 𝐀
print(A) # Also prints dictionary in 𝐀!
print(𝐀 is A) # True
@sloanlance
sloanlance / indexformatter1.py
Last active November 1, 2023 18:45
A Python class before and after optimization, as inspired by GitHub Copilot.
class IndexFormatter:
def __init__(self, volumeId: int):
self.itemPages = (
ItemPage.objects.filter(volume__id=volumeId)
.order_by('item__topic__name', F('page') * 1, 'item__name'))
def format(self) -> str:
"""
Format the index for printing.
"""