Skip to content

Instantly share code, notes, and snippets.

@tcely
tcely / newtons_sqrt.py
Last active May 3, 2025 04:24
Python square root functions
def newtons_sqrt(i, /, *, precision=1e-10):
loops = 0
x = (1+i) // 2
d = i
n_x = 0
print(f'{precision=}', flush=True)
while loops < x and abs(d) > precision:
loops += 1
print(f'{loops=} abs(d) = {abs(d)}: {d=}', flush=True)
n_x = x - (x*x - i)/(2*x)
@tcely
tcely / last_boot.py
Last active April 19, 2025 02:10
Getting Windows Last Boot Time in Python
#!/usr/bin/env python3
import datetime
import os
# import wmi
# https://github.com/tjguk/wmi
# https://github.com/tcely/wmi
class LastBoot:
@tcely
tcely / links.md
Last active April 4, 2025 13:46
Various links
@tcely
tcely / sum_files.py
Created April 2, 2025 09:50
Creating a sums file from the GitHub workflow
#!/usr/bin/env python3
import hashlib
import io
import os
import pathlib
import sys
def sum_file(hasher, file_path):
@tcely
tcely / README.md
Last active February 14, 2025 09:12
Useful GPG commands for GitHub

Using GitHub & GPG together

Fetching GPG keys

Any GitHub user account can contain GPG keys used for signed commits. To verify these signatures, your local gpg.program needs the public key.

To fetch them, just use a URL such as this: https://github.com/<ACCOUNT>.gpg

@tcely
tcely / url_decode.inc.sh
Last active December 17, 2024 01:48
sh url_decode
url_decode() {
local arg ;
if [ $# -gt 0 ]; then
for arg; do
printf -- '%s\n' "${arg}" ;
done | url_decode ;
else
check_printf ;
printf -- '%b\n' "$(sed -E -e 's/\+/ /g' -e 's/%([0-9a-fA-F]{2})/\\x\1/g')" ;
fi ;
@tcely
tcely / config
Created September 8, 2023 14:28
Turn on ssh-rsa for only the hosts that require that option
# Add this to the ~/.ssh/config file
#
Match Exec "ssh-rsa-needed.sh '%n' '%C' '%l' '%h' '%p' '%r'"
PubkeyAcceptedKeyTypes +ssh-rsa
@tcely
tcely / history.inc.sh
Last active August 24, 2023 20:33
Bash History Configuration
if [ "${BASH_VERSION-}" ]; then
# Local variables the functions depend upon
_bash_history_prefix=~/.local/history/bash
# {{{ Begining of the temporary functions block
_bash_history_get_today() {
date '+%Y/0%m/%d'
}
@tcely
tcely / Social_Media.md
Created December 18, 2022 23:04
Social Media Information
@tcely
tcely / simple-echo.function.sh
Created September 22, 2020 00:04
A simple echo using the shell printf for consistent behavior
#!/usr/bin/env sh
secho() {
_arg="${1}";
_fmt='%s';
_sentinel='--';
case "${_arg}" in
(-e|-en|-ne) _fmt='%b'; shift ;;
(-n|-En|-nE) shift ;;