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
#!/bin/sh
awk 'function wl() {
rate=64000;
return (rate/160)*(0.87055^(int(rand()*10)))};
BEGIN {
srand();
wla=wl();
while(1) {
wlb=wla;
wla=wl();
@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.
@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'
@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.
@sloanlance
sloanlance / three_reasons.bas
Last active December 10, 2018 14:30
"Three Reasons To Own a Computer" for Commodore 64, from Compute!'s Gazette (via https://www.lemon64.com/forum/viewtopic.php?p=429351&sid=a78679bc4b8671443f9300905275b9e5#429351)
0 REM "THREE REASONS TO OWN A COMPUTER" FOR COMMODORE 64
1 REM FROM COMPUTE!'S GAZETTE
10 FORL=54272 TO 54295:POKEL,0:NEXT:POKE54296,15
20 POKE54277,8:POKE54278,255:POKE54276,23
30 F2=4
40 FORZ=1TO3:POKE54287,F2
50 FORF1=1TO200
60 POKE54273,F1:F2=F2+.01:NEXTF1:NEXTZ:POKE54278,15
@sloanlance
sloanlance / accessEncapsulation.py
Created July 19, 2018 17:33
Python: Class member access enforcement (not encapsulation)
# From Stack Overflow question:
# https://stackoverflow.com/questions/26216563/how-to-do-encapsulation-in-python
#
# Python has simple encapsulation, but it doesn't strictly enforce access to
# protected or private class members. This is one person's attempt to
# address that in a (misleadingly named) class.
#
# Could this be done with introspection rather than using on `self.privates` and
# `self.protected`? Follow the common Python style of naming variables `__a` and `_b`.
# Then the methods would check whether the names begin with `__` or `_` to allow or
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sloanlance
sloanlance / Jekyll & Liquid Cheatsheet
Last active September 17, 2022 11:33 — forked from magicznyleszek/jekyll-and-liquid.md
Jekyll & Liquid Cheatsheet (A fork of the gist by "magicznyleszek", FKA "smutnyleszek")
See: `Jekyll & Liquid Cheatsheet.md`
@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 / jq_jsonl_conversion.md
Last active March 22, 2024 18:05
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