Skip to content

Instantly share code, notes, and snippets.

View kgriffs's full-sized avatar

Kurt Griffiths kgriffs

View GitHub Profile
@kgriffs
kgriffs / stream_httpx_response_falcon.py
Created August 23, 2021 15:14
Falcon - Stream httpx response example
# Courtesy of Vytautas Liuolia @vytas7
import falcon.asgi
import httpx
class Proxy(object):
UPSTREAM = 'https://falconframework.org'
def __init__(self):
@kgriffs
kgriffs / example_lowercase_env.sh
Created August 9, 2021 21:24
Bash - Lowercase an environment variable
echo $(tr '[:upper:]' '[:lower:]' <<<"$ENV")
@kgriffs
kgriffs / shell-prompt-example.sh
Created July 7, 2021 16:52
Bash and ZSH prompt example including password or secret prompting
# NOTE: For zsh use:
#
# read CONTINUE"?Deploy now? [y/N]: "
# read -s PWD"?Vault password: "
#
read -p "Deploy now? [y/N]: " CONTINUE
if [[ ! $CONTINUE =~ ^[Yy]$ ]]; then
exit
fi
@kgriffs
kgriffs / install.sh
Created June 8, 2021 15:29
pyenv install on macOS Big Sur with ssl workaround using brew
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.8.9 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
@kgriffs
kgriffs / results.py
Created May 21, 2021 23:05
Benchmarking Python JSON libs: std vs. orjson vs. simdjson - simple encode/decode tests
# ----------------------------------------------------------------------------
import json
import simdjson
import libpy_simdjson
decoder_std = json.JSONDecoder()
encoder_std = json.JSONEncoder(ensure_ascii=False)
p = simdjson.Parser()
p2 = libpy_simdjson.Parser()
@kgriffs
kgriffs / example.py
Created May 12, 2021 00:01
Python: Generate a random string of random length from a finite character set
def randstr(max_count=32, charset=(string.ascii_letters + '-')):
return ''.join(
random.choice(charset)
for _ in range(random.randint(1, max_count))
)
@kgriffs
kgriffs / example.ps
Last active July 7, 2021 16:13
Change user password on Windows from Powershell
# Credit: https://blog.netwrix.com/2018/10/16/how-to-create-change-and-test-passwords-using-powershell/
# RDP: 3389
$Password = (Read-Host -Prompt "New Password" -AsSecureString)
$User = (Read-Host -Prompt "Username")
$UserAccount = Get-LocalUser -Name $User
$UserAccount | Set-LocalUser -Password $Password
@kgriffs
kgriffs / background_queue_falcon.py
Created July 9, 2020 22:26
Pattern for saving / doing background work from a Falcon App using a queue from the standard Python Library
# Credit: @vytas7 (Vytautas Liuolia)
import queue
import signal
import threading
import time
import uuid
import falcon
@kgriffs
kgriffs / autologout.sh
Last active July 1, 2020 04:02
Automatically Log Out Bash Session (Also SSH) for All Users - Linux Server (Tested on Ubuntu 18.04)
# sudo vim /etc/profile.d/autologout.sh
TMOUT=900
readonly TMOUT
export TMOUT
@kgriffs
kgriffs / example.py
Created June 29, 2020 23:49
Get directory of containing module (Python)
import os
_MYDIR = os.path.abspath(os.path.dirname(__file__))
print(_MYDIR)