Useful notes about using yq
- Display the path to each value in a YAML file
$ cat << EOF | yq e '.. | select(. == "*") | {(path | join(".")): .} ' - > a: > b: foo
> c: bar
# Note: Regex developed using regex101.com, which generated this code, then was edited further. | |
# See: https://regex101.com/r/Vj3CHI/5 | |
# The regex below is part of the solution for HackerRank challenge: | |
# https://www.hackerrank.com/challenges/validate-a-roman-number | |
# The regex is probably incomplete, but it's good enough to pass HackerRank tests. | |
import re | |
regex = r'^(M{,3}(?=([^M]))){,1}([C]{,1}M{,1}){,1}([C]{,1}D{,3}){,1}([X]{,1}C{,3}){,1}(X{,1}L{,1}){,1}(I{,1}X{,3}){,1}(I{1,3}[VX]{,1}|VI{,3}){,1}$' |
import urllib.request | |
import pymupdf # pip install PyMuPDF | |
url = ('https://pycon-assets.s3.amazonaws.com/2024/media/' | |
'documents/DLCC-Floorplan-Marked_up_PyCon_US_2024.pdf') | |
# url = 'file:DLCC-Floorplan-Marked_up_PyCon_US_2024.pdf' | |
with urllib.request.urlopen(url) as response: | |
pdfStream = response.read() |
𝐀 = {'😀': 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 |
#!/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 |
#!/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(); |
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. |
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. |
#!/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' |