Skip to content

Instantly share code, notes, and snippets.

@pretorh
pretorh / Bash TAP producer.md
Last active January 1, 2023 08:06
Bash test helper to general TAP output

shell script that can be sourced to have produce TAP output for test files

setup

  • create tests/setup.sh
  • create test files, ex tests/example.test.sh
  • run tests, and on success call ok <test name> or fail <test name> (or skip <test-name>)

do need to ensure that none of the tests output TAP related output (ex redirecting stdout)

@pretorh
pretorh / stock.py
Created December 18, 2022 06:11
print stocks' last price in month as a csv string
"print stock prices as a csv string. see https://github.com/ranaroussi/yfinance for disclaimers"
import datetime
import sys
import yfinance as yf
def get_last_stock_price(stock, before):
"get the last price of the stock before the given date"
start = before - datetime.timedelta(days=7)
tick = yf.Ticker(stock)
@pretorh
pretorh / README.md
Last active September 7, 2022 08:17
List missing sequentially numbered files

for example for photos from a camera (IMG_xxxx.JPG): ./missing-files-in-sequence.sh '*IMG_' 3409 '.jpg'

@pretorh
pretorh / changelog.sh
Last active August 15, 2021 07:05
Read changelog items from Android xml resource file
#!/usr/bin/env sh
# skip first few lines in file (xml setup)
# replace explicit new lines in strings with nothing (all newlines are on own line)
# remove leading spaces
# read up to first blank line
tail -n +6 app/src/main/res/values/changelog.xml | \
sed s'|\\n||g' | \
sed s'|^\ *||' | \
sed -e '/^$/,$d'
@pretorh
pretorh / mergeLiveData.kt
Last active August 10, 2019 21:04
merge two live data sources into a single mediator live data, returning data when either of them changed (not chained)
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
fun <T1, T2> mergeLiveData(source1: LiveData<T1>, source2: LiveData<T2>): LiveData<Pair<T1, T2>> {
val result = MediatorLiveData<Pair<T1, T2>>()
var data1: T1? = null
var data2: T2? = null
fun postDataIfBothAvailable() {
@pretorh
pretorh / setup and use test gpg keys.md
Created September 30, 2018 08:31
GPG test environment

creating:

GNUPGHOME=${GNUPGHOME?'need path for new gnupg home dir'}
GPG_PASS_PHRASE=${GPG_PASS_PHRASE-passphrase}

# refuse to overwrite existing
if [ -e "$GNUPGHOME" ] ; then
    echo "$GNUPGHOME already exists!"
 exit 1

Keybase proof

I hereby claim:

  • I am pretorh on github.
  • I am pretorh (https://keybase.io/pretorh) on keybase.
  • I have a public key whose fingerprint is DA8A 02D8 D0B7 97EB 91DE 6C23 1CD8 941B F35B 7444

To claim this, I am signing this object:

openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
openssl req -new -key server.key -out server.csr -subj "/CN=localhost"
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
rm server.pass.key server.csr

(use "/C=/ST=/L=/O=IT/CN=localhost" with country code, state|province name, location name for more details in the cert)

echo LANG=en_US.UTF-8 >> /etc/environment
echo LC_ALL=en_US.UTF-8 >> /etc/environment
hostnamectl set-hostname --static example.com